@@ -316,89 +316,87 @@ describe('S3Adapter tests', () => {
316
316
} ) ;
317
317
318
318
describe ( 'getFileLocation' , ( ) => {
319
- [ 'http://example.com/files' , ( ) => 'http://example.com/files' ] . forEach ( ( baseUrl ) => {
320
- const testConfig = {
321
- mount : 'http://my.server.com/parse' ,
322
- applicationId : 'xxxx' ,
319
+ const testConfig = {
320
+ mount : 'http://my.server.com/parse' ,
321
+ applicationId : 'xxxx' ,
322
+ } ;
323
+ let options ;
324
+
325
+ beforeEach ( ( ) => {
326
+ options = {
327
+ presignedUrl : false ,
328
+ directAccess : true ,
329
+ bucketPrefix : 'foo/bar/' ,
330
+ baseUrl : 'http://example.com/files' ,
323
331
} ;
324
- let options ;
325
-
326
- beforeEach ( ( ) => {
327
- options = {
328
- presignedUrl : false ,
329
- directAccess : true ,
330
- bucketPrefix : 'foo/bar/' ,
331
- baseUrl,
332
- } ;
333
- } ) ;
332
+ } ) ;
334
333
335
- it ( 'should get using the baseUrl' , ( ) => {
336
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
337
- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
338
- } ) ;
334
+ it ( 'should get using the baseUrl' , ( ) => {
335
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
336
+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/foo/bar/test.png' ) ;
337
+ } ) ;
339
338
340
- it ( 'when use presigned URL should use S3 \'getObject\' operation' , ( ) => {
341
- options . presignedUrl = true ;
342
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
343
- const originalS3Client = s3 . _s3Client ;
344
- let getSignedUrlOperation = '' ;
345
- s3 . _s3Client = {
346
- getSignedUrl : ( operation , params , callback ) => {
347
- getSignedUrlOperation = operation ;
348
- return originalS3Client . getSignedUrl ( operation , params , callback ) ;
349
- } ,
350
- } ;
339
+ it ( 'when use presigned URL should use S3 \'getObject\' operation' , ( ) => {
340
+ options . presignedUrl = true ;
341
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
342
+ const originalS3Client = s3 . _s3Client ;
343
+ let getSignedUrlOperation = '' ;
344
+ s3 . _s3Client = {
345
+ getSignedUrl : ( operation , params , callback ) => {
346
+ getSignedUrlOperation = operation ;
347
+ return originalS3Client . getSignedUrl ( operation , params , callback ) ;
348
+ } ,
349
+ } ;
351
350
352
- s3 . getFileLocation ( testConfig , 'test.png' ) ;
353
- expect ( getSignedUrlOperation ) . toBe ( 'getObject' ) ;
354
- } ) ;
351
+ s3 . getFileLocation ( testConfig , 'test.png' ) ;
352
+ expect ( getSignedUrlOperation ) . toBe ( 'getObject' ) ;
353
+ } ) ;
355
354
356
- it ( 'should get using the baseUrl and amazon using presigned URL' , ( ) => {
357
- options . presignedUrl = true ;
358
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
359
-
360
- const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
361
- expect ( fileLocation ) . toMatch ( / ^ h t t p : \/ \/ e x a m p l e .c o m \/ f i l e s \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
362
- expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F \w { 2 } - \w { 1 , 9 } - \d % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
363
- expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
364
- expect ( fileLocation ) . toMatch ( / X - A m z - S i g n a t u r e = .{ 64 } / ) ;
365
- expect ( fileLocation ) . toMatch ( / X - A m z - E x p i r e s = \d { 1 , 6 } / ) ;
366
- expect ( fileLocation ) . toContain ( 'X-Amz-Algorithm=AWS4-HMAC-SHA256' ) ;
367
- expect ( fileLocation ) . toContain ( 'X-Amz-SignedHeaders=host' ) ;
368
- } ) ;
355
+ it ( 'should get using the baseUrl and amazon using presigned URL' , ( ) => {
356
+ options . presignedUrl = true ;
357
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
369
358
370
- it ( 'should get direct to baseUrl' , ( ) => {
371
- options . baseUrlDirect = true ;
372
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
373
- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example.com/files/test.png' ) ;
374
- } ) ;
359
+ const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
360
+ expect ( fileLocation ) . toMatch ( / ^ h t t p : \/ \/ e x a m p l e .c o m \/ f i l e s \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
361
+ expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F \w { 2 } - \w { 1 , 9 } - \d % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
362
+ expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
363
+ expect ( fileLocation ) . toMatch ( / X - A m z - S i g n a t u r e = .{ 64 } / ) ;
364
+ expect ( fileLocation ) . toMatch ( / X - A m z - E x p i r e s = \d { 1 , 6 } / ) ;
365
+ expect ( fileLocation ) . toContain ( 'X-Amz-Algorithm=AWS4-HMAC-SHA256' ) ;
366
+ expect ( fileLocation ) . toContain ( 'X-Amz-SignedHeaders=host' ) ;
367
+ } ) ;
375
368
376
- it ( 'should get without directAccess ' , ( ) => {
377
- options . directAccess = false ;
378
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
379
- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://my.server. com/parse/ files/xxxx /test.png' ) ;
380
- } ) ;
369
+ it ( 'should get direct to baseUrl ' , ( ) => {
370
+ options . baseUrlDirect = true ;
371
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
372
+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http://example. com/files/test.png' ) ;
373
+ } ) ;
381
374
382
- it ( 'should go directly to amazon ' , ( ) => {
383
- delete options . baseUrl ;
384
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
385
- expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https ://my-bucket.s3.amazonaws. com/foo/bar /test.png' ) ;
386
- } ) ;
375
+ it ( 'should get without directAccess ' , ( ) => {
376
+ options . directAccess = false ;
377
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
378
+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'http ://my.server. com/parse/files/xxxx /test.png' ) ;
379
+ } ) ;
387
380
388
- it ( 'should go directly to amazon using presigned URL' , ( ) => {
389
- delete options . baseUrl ;
390
- options . presignedUrl = true ;
391
- const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
392
-
393
- const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
394
- expect ( fileLocation ) . toMatch ( / ^ h t t p s : \/ \/ m y - b u c k e t .s 3 .a m a z o n a w s .c o m \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
395
- expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F u s - e a s t - 1 % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
396
- expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
397
- expect ( fileLocation ) . toMatch ( / X - A m z - S i g n a t u r e = .{ 64 } / ) ;
398
- expect ( fileLocation ) . toMatch ( / X - A m z - E x p i r e s = \d { 1 , 6 } / ) ;
399
- expect ( fileLocation ) . toContain ( 'X-Amz-Algorithm=AWS4-HMAC-SHA256' ) ;
400
- expect ( fileLocation ) . toContain ( 'X-Amz-SignedHeaders=host' ) ;
401
- } ) ;
381
+ it ( 'should go directly to amazon' , ( ) => {
382
+ delete options . baseUrl ;
383
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
384
+ expect ( s3 . getFileLocation ( testConfig , 'test.png' ) ) . toEqual ( 'https://my-bucket.s3.amazonaws.com/foo/bar/test.png' ) ;
385
+ } ) ;
386
+
387
+ it ( 'should go directly to amazon using presigned URL' , ( ) => {
388
+ delete options . baseUrl ;
389
+ options . presignedUrl = true ;
390
+ const s3 = new S3Adapter ( 'accessKey' , 'secretKey' , 'my-bucket' , options ) ;
391
+
392
+ const fileLocation = s3 . getFileLocation ( testConfig , 'test.png' ) ;
393
+ expect ( fileLocation ) . toMatch ( / ^ h t t p s : \/ \/ m y - b u c k e t .s 3 .a m a z o n a w s .c o m \/ f o o \/ b a r \/ t e s t .p n g \? / ) ;
394
+ expect ( fileLocation ) . toMatch ( / X - A m z - C r e d e n t i a l = a c c e s s K e y % 2 F \d { 8 } % 2 F u s - e a s t - 1 % 2 F s 3 % 2 F a w s 4 _ r e q u e s t / ) ;
395
+ expect ( fileLocation ) . toMatch ( / X - A m z - D a t e = \d { 8 } T \d { 6 } Z / ) ;
396
+ expect ( fileLocation ) . toMatch ( / X - A m z - S i g n a t u r e = .{ 64 } / ) ;
397
+ expect ( fileLocation ) . toMatch ( / X - A m z - E x p i r e s = \d { 1 , 6 } / ) ;
398
+ expect ( fileLocation ) . toContain ( 'X-Amz-Algorithm=AWS4-HMAC-SHA256' ) ;
399
+ expect ( fileLocation ) . toContain ( 'X-Amz-SignedHeaders=host' ) ;
402
400
} ) ;
403
401
} ) ;
404
402
0 commit comments