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