@@ -5,7 +5,7 @@ const it = require("mocha/lib/mocha.js").it;
5
5
const describe = require ( "mocha/lib/mocha.js" ) . describe ;
6
6
const beforeEach = require ( "mocha/lib/mocha.js" ) . beforeEach ;
7
7
const afterEach = require ( "mocha/lib/mocha.js" ) . afterEach ;
8
- const AWS = require ( 'aws-sdk' ) ;
8
+ const AWS = require ( 'aws-sdk-mock ' ) ;
9
9
const nock = require ( 'nock' ) ;
10
10
const CONFIG = require ( '../lib/config' ) . CONFIG ;
11
11
const sinon = require ( 'sinon' ) ;
@@ -19,13 +19,12 @@ describe('S3 handler tests', () => {
19
19
beforeEach ( ( ) => {
20
20
sandbox . spy ( scanii . ScaniiClient ) ;
21
21
22
- // wrapping some fakes around the AWS sdk:
23
- AWS . S3 . prototype . getSignedUrl = ( ) => 'https://example.com/1234?q=124' ;
24
22
CONFIG . CALLBACK_URL = "https://example.com/callback/" ;
25
23
CONFIG . KEY = "k" ;
26
24
CONFIG . SECRET = "s" ;
27
25
CONFIG . MAX_ATTEMPTS = 1 ;
28
26
CONFIG . MAX_ATTEMPT_DELAY_MSEC = 1_000 ;
27
+ CONFIG . SIGNED_URL_DURATION = 10 ;
29
28
} ) ;
30
29
31
30
afterEach ( ( ) => {
@@ -228,5 +227,60 @@ describe('S3 handler tests', () => {
228
227
assert ( result . body . includes ( "cannot process directory" ) ) ;
229
228
} ) ;
230
229
} ) ;
231
- } ) ;
230
+ it ( 'should honor configurable signed url timeout' , async ( ) => {
231
+
232
+ nock ( 'https://api-us1.scanii.com' )
233
+ . post ( '/v2.2/files/fetch' )
234
+ . reply ( 202 , Buffer . from ( "{\"id\":\"12356789\"}" ) , { "Location" : "https://api-us1.scanii.com/v2.2/files/1234" } ) ;
235
+
236
+ AWS . mock ( 'S3' , 'getSignedUrl' , ( operator , params ) => {
237
+ assert . ok ( params . Expires === CONFIG . SIGNED_URL_DURATION ) ;
238
+ return true ;
239
+ } )
240
+
241
+ return await handler ( {
242
+ "Records" : [
243
+ {
244
+ "eventVersion" : "2.0" ,
245
+ "eventSource" : "aws:s3" ,
246
+ "awsRegion" : "us-west-2" ,
247
+ "eventTime" : "2015-10-01T23:28:54.280Z" ,
248
+ "eventName" : "ObjectCreated:Put" ,
249
+ "userIdentity" : {
250
+ "principalId" : "AWS:principal"
251
+ } ,
252
+ "requestParameters" : {
253
+ "sourceIPAddress" : "98.167.155.191"
254
+ } ,
255
+ "responseElements" : {
256
+ "x-amz-request-id" : "EEC943B096DE3DF9" ,
257
+ "x-amz-id-2" : "W/myEjyXFBsOA6N0byxW0tOxMA4m1fmv9KAVcovvG0nD9W1s5aX5+Wx61tlCop8LbZAw1Nz0mnc="
258
+ } ,
259
+ "s3" : {
260
+ "s3SchemaVersion" : "1.0" ,
261
+ "configurationId" : "948c2c1a-a028-4564-93fc-76cea7622633" ,
262
+ "bucket" : {
263
+ "name" : "scanii-mu" ,
264
+ "ownerIdentity" : {
265
+ "principalId" : "principal"
266
+ } ,
267
+ "arn" : "arn:aws:s3:::scanii-mu"
268
+ } ,
269
+ "object" : {
270
+ "key" : "Screen+Shot+2016-01-19+at+7.24.37+PM.png" ,
271
+ "size" : 519 ,
272
+ "eTag" : "aa1e5c8a6a07217c25f55aa8e96ea37a" ,
273
+ "sequencer" : "00560DC1B62F962FCD"
274
+ }
275
+ }
276
+ }
277
+ ]
278
+
279
+ } , { } , ( error , result ) => {
280
+ assert . ok ( error === null , "there should be no errors" ) ;
281
+ assert . ok ( result . statusCode === 200 , "signed url timeout not configurable" ) ;
282
+
283
+ } ) ;
284
+ } ) ;
285
+ } )
232
286
0 commit comments