1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414import * as assert from 'assert' ;
15- import * as dateFormat from 'date-and-time' ;
1615import * as crypto from 'crypto' ;
1716import * as sinon from 'sinon' ;
1817import { describe , it , beforeEach , afterEach } from 'mocha' ;
@@ -29,7 +28,7 @@ import {
2928 Query ,
3029 SignerExceptionMessages ,
3130} from '../src/signer' ;
32- import { encodeURI , qsStringify } from '../src/util' ;
31+ import { encodeURI , formatAsUTCISO , qsStringify } from '../src/util' ;
3332import { ExceptionMessages } from '../src/storage' ;
3433
3534describe ( 'signer' , ( ) => {
@@ -187,11 +186,7 @@ describe('signer', () => {
187186 expires : expiresNumber ,
188187 } ) ;
189188 const blobToSign = authClientSign . getCall ( 0 ) . args [ 0 ] ;
190- assert (
191- blobToSign . includes (
192- dateFormat . format ( accessibleAt , 'YYYYMMDD[T]HHmmss[Z]' , true )
193- )
194- ) ;
189+ assert ( blobToSign . includes ( formatAsUTCISO ( accessibleAt , true ) ) ) ;
195190 } ) ;
196191
197192 it ( 'should throw if an expiration date from the before accessibleAt date is given' , ( ) => {
@@ -211,11 +206,7 @@ describe('signer', () => {
211206
212207 describe ( 'checkInputTypes' , ( ) => {
213208 const query = {
214- 'X-Goog-Date' : dateFormat . format (
215- new Date ( accessibleAtNumber ) ,
216- 'YYYYMMDD[T]HHmmss[Z]' ,
217- true
218- ) ,
209+ 'X-Goog-Date' : formatAsUTCISO ( new Date ( accessibleAtNumber ) , true ) ,
219210 } ;
220211
221212 it ( 'should accept Date objects' , async ( ) => {
@@ -688,7 +679,7 @@ describe('signer', () => {
688679 const query = ( await signer [ 'getSignedUrlV4' ] ( CONFIG ) ) as Query ;
689680 const arg = getCanonicalQueryParams . getCall ( 0 ) . args [ 0 ] ;
690681
691- const datestamp = dateFormat . format ( NOW , 'YYYYMMDD' , true ) ;
682+ const datestamp = formatAsUTCISO ( NOW ) ;
692683 const credentialScope = `${ datestamp } /auto/storage/goog4_request` ;
693684 const EXPECTED_CREDENTIAL = `${ CLIENT_EMAIL } /${ credentialScope } ` ;
694685
@@ -697,7 +688,7 @@ describe('signer', () => {
697688 } ) ;
698689
699690 it ( 'should populate X-Goog-Date' , async ( ) => {
700- const dateISO = dateFormat . format ( NOW , 'YYYYMMDD[T]HHmmss[Z]' , true ) ;
691+ const dateISO = formatAsUTCISO ( NOW , true ) ;
701692
702693 const query = ( await signer [ 'getSignedUrlV4' ] ( CONFIG ) ) as Query ;
703694 const arg = getCanonicalQueryParams . getCall ( 0 ) . args [ 0 ] ;
@@ -787,9 +778,9 @@ describe('signer', () => {
787778 } ) ;
788779
789780 it ( 'should compose blobToSign' , async ( ) => {
790- const datestamp = dateFormat . format ( NOW , 'YYYYMMDD' , true ) ;
781+ const datestamp = formatAsUTCISO ( NOW ) ;
791782 const credentialScope = `${ datestamp } /auto/storage/goog4_request` ;
792- const dateISO = dateFormat . format ( NOW , 'YYYYMMDD[T]HHmmss[Z]' , true ) ;
783+ const dateISO = formatAsUTCISO ( NOW , true ) ;
793784
794785 const authClientSign = sinon
795786 . stub ( authClient , 'sign' )
0 commit comments