@@ -54,6 +54,7 @@ import {
5454 AttachmentSizeLimitExceededError ,
5555 AttachmentTooLargeError ,
5656 DownloadCleanFileFailedError ,
57+ GuardDutyInvalidFileKeyError ,
5758 InvalidFieldIdError ,
5859 InvalidFileExtensionError ,
5960 InvalidFileKeyError ,
@@ -67,7 +68,7 @@ import {
6768 downloadCleanFile ,
6869 getQuarantinePresignedPostData ,
6970 transformAttachmentMetasToSignedUrls ,
70- triggerVirusScanning ,
71+ triggerGuardDutyScanning ,
7172} from '../submission.service'
7273import {
7374 buildMrfMetadata ,
@@ -2299,18 +2300,10 @@ describe('submission.service', () => {
22992300 // Arrange
23002301 const awsSpy = jest . spyOn ( aws . s3 , 'createPresignedPost' )
23012302 const expectedCalledWithSubset = {
2302- Bucket : aws . virusScannerQuarantineS3Bucket ,
2303+ Bucket : aws . guarddutyQuarantineS3Bucket ,
23032304 Fields : { key : expect . stringMatching ( REGEX_UUID ) } ,
23042305 Expires : 1 * 60 , // expires in 1 minutes
23052306 }
2306- const expectedPresignedPostData = expect . objectContaining ( {
2307- url : `${ aws . endPoint } /${ aws . virusScannerQuarantineS3Bucket } ` ,
2308- fields : expect . objectContaining ( {
2309- key : expect . stringMatching ( REGEX_UUID ) ,
2310- bucket : aws . virusScannerQuarantineS3Bucket ,
2311- 'X-Amz-Algorithm' : 'AWS4-HMAC-SHA256' ,
2312- } ) ,
2313- } )
23142307
23152308 const expectedPresignedPostDataGuardDuty = expect . objectContaining ( {
23162309 url : `${ aws . endPoint } /${ aws . guarddutyQuarantineS3Bucket } ` ,
@@ -2328,24 +2321,8 @@ describe('submission.service', () => {
23282321
23292322 // Assert
23302323 expect ( actualResult . isOk ( ) ) . toEqual ( true )
2331- expect ( awsSpy ) . toHaveBeenCalledTimes ( 4 )
2324+ expect ( awsSpy ) . toHaveBeenCalledTimes ( 2 )
23322325 expect ( awsSpy . mock . calls ) . toEqual ( [
2333- [
2334- {
2335- ...expectedCalledWithSubset ,
2336- Fields : { key : uuid1 } ,
2337- Conditions : [ [ 'content-length-range' , 0 , 1 ] ] ,
2338- } ,
2339- expect . any ( Function ) , // anonymous error handling function
2340- ] ,
2341- [
2342- {
2343- ...expectedCalledWithSubset ,
2344- Fields : { key : uuid2 } ,
2345- Conditions : [ [ 'content-length-range' , 0 , 2 ] ] ,
2346- } ,
2347- expect . any ( Function ) , // anonymous error handling function
2348- ] ,
23492326 [
23502327 {
23512328 ...expectedCalledWithSubset ,
@@ -2368,8 +2345,6 @@ describe('submission.service', () => {
23682345 const actualResultValue = actualResult . _unsafeUnwrap ( )
23692346 expect ( actualResultValue ) . toEqual (
23702347 expect . objectContaining ( [
2371- { id : fieldId1 , presignedPostData : expectedPresignedPostData } ,
2372- { id : fieldId2 , presignedPostData : expectedPresignedPostData } ,
23732348 {
23742349 id : fieldId1 ,
23752350 presignedPostData : expectedPresignedPostDataGuardDuty ,
@@ -2403,7 +2378,7 @@ describe('submission.service', () => {
24032378 )
24042379 expect ( awsSpy ) . toHaveBeenCalledWith (
24052380 {
2406- Bucket : aws . virusScannerQuarantineS3Bucket ,
2381+ Bucket : aws . guarddutyQuarantineS3Bucket ,
24072382 Fields : { key : expect . stringMatching ( REGEX_UUID ) } ,
24082383 Expires : 1 * 60 , // expires in 1 minutes
24092384 Conditions : [ [ 'content-length-range' , 0 , 1 ] ] ,
@@ -2442,7 +2417,7 @@ describe('submission.service', () => {
24422417 } )
24432418 } )
24442419
2445- describe ( 'triggerVirusScanning ' , ( ) => {
2420+ describe ( 'triggerGuarddutyScanning ' , ( ) => {
24462421 const MOCK_VALID_FILE_KEY = '1b90195b-ce8a-4590-810b-04ebaef8e4dd'
24472422 const MOCK_SUCCESS_BODY_PAYLOAD = {
24482423 cleanFileKey : 'cleanFileKey' ,
@@ -2451,31 +2426,35 @@ describe('submission.service', () => {
24512426 it ( 'should return errAsync when quarantine file key is not a valid uuid' , async ( ) => {
24522427 // Arrange
24532428 const awsSpy = jest
2454- . spyOn ( aws . virusScannerLambda , 'invoke' )
2429+ . spyOn ( aws . guarddutyLambda , 'invoke' )
24552430 . mockImplementationOnce ( ( ) => {
24562431 return Promise . reject ( )
24572432 } )
24582433 const mockQuarantineFileKey = 'not a uuid'
24592434
24602435 // Act
2461- const actualResult = await triggerVirusScanning ( mockQuarantineFileKey )
2436+ const actualResult = await triggerGuardDutyScanning ( mockQuarantineFileKey )
24622437
24632438 // Assert
24642439 expect ( awsSpy ) . not . toHaveBeenCalled ( )
24652440 expect ( actualResult . isErr ( ) ) . toEqual ( true )
2466- expect ( actualResult . _unsafeUnwrapErr ( ) ) . toEqual ( new InvalidFileKeyError ( ) )
2441+ expect ( actualResult . _unsafeUnwrapErr ( ) ) . toEqual (
2442+ new GuardDutyInvalidFileKeyError (
2443+ 'GUARDDUTY Invalid file key. File keys should be valid UUIDs.' ,
2444+ ) ,
2445+ )
24672446 } )
24682447
24692448 it ( 'should return errAsync when lambda invocation fails' , async ( ) => {
24702449 // Arrange
24712450 const awsSpy = jest
2472- . spyOn ( aws . virusScannerLambda , 'invoke' )
2451+ . spyOn ( aws . guarddutyLambda , 'invoke' )
24732452 . mockImplementationOnce ( ( ) => {
24742453 return Promise . reject ( )
24752454 } )
24762455
24772456 // Act
2478- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2457+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
24792458
24802459 // Assert
24812460 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2488,13 +2467,13 @@ describe('submission.service', () => {
24882467 it ( 'should return errAsync when data is undefined' , async ( ) => {
24892468 // Arrange
24902469 const awsSpy = jest
2491- . spyOn ( aws . virusScannerLambda , 'invoke' )
2470+ . spyOn ( aws . guarddutyLambda , 'invoke' )
24922471 . mockImplementationOnce ( ( ) => {
24932472 return Promise . resolve ( undefined )
24942473 } )
24952474
24962475 // Act
2497- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2476+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
24982477
24992478 // Assert
25002479 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2507,13 +2486,13 @@ describe('submission.service', () => {
25072486 it ( 'should return errAsync when data.Payload is undefined' , async ( ) => {
25082487 // Arrange
25092488 const awsSpy = jest
2510- . spyOn ( aws . virusScannerLambda , 'invoke' )
2489+ . spyOn ( aws . guarddutyLambda , 'invoke' )
25112490 . mockImplementationOnce ( ( ) => {
25122491 return Promise . resolve ( { Payload : undefined } )
25132492 } )
25142493
25152494 // Act
2516- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2495+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
25172496
25182497 // Assert
25192498 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2530,7 +2509,7 @@ describe('submission.service', () => {
25302509 body : JSON . stringify ( MOCK_SUCCESS_BODY_PAYLOAD ) ,
25312510 }
25322511 const awsSpy = jest
2533- . spyOn ( aws . virusScannerLambda , 'invoke' )
2512+ . spyOn ( aws . guarddutyLambda , 'invoke' )
25342513 . mockImplementationOnce ( ( ) => {
25352514 return Promise . resolve ( {
25362515 Payload : JSON . stringify ( successPayload ) ,
@@ -2542,7 +2521,7 @@ describe('submission.service', () => {
25422521 }
25432522
25442523 // Act
2545- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2524+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
25462525
25472526 // Assert
25482527 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2553,15 +2532,15 @@ describe('submission.service', () => {
25532532 it ( 'should return errAsync if payload cannot be parsed' , async ( ) => {
25542533 // Arrange
25552534 const awsSpy = jest
2556- . spyOn ( aws . virusScannerLambda , 'invoke' )
2535+ . spyOn ( aws . guarddutyLambda , 'invoke' )
25572536 . mockImplementationOnce ( ( ) => {
25582537 return Promise . resolve ( {
25592538 Payload : '{' ,
25602539 } )
25612540 } )
25622541
25632542 // Act
2564- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2543+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
25652544
25662545 // Assert
25672546 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2578,15 +2557,15 @@ describe('submission.service', () => {
25782557 body : JSON . stringify ( MOCK_SUCCESS_BODY_PAYLOAD ) ,
25792558 }
25802559 const awsSpy = jest
2581- . spyOn ( aws . virusScannerLambda , 'invoke' )
2560+ . spyOn ( aws . guarddutyLambda , 'invoke' )
25822561 . mockImplementationOnce ( ( ) => {
25832562 return Promise . resolve ( {
25842563 Payload : JSON . stringify ( successPayload ) ,
25852564 } )
25862565 } )
25872566
25882567 // Act
2589- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2568+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
25902569
25912570 // Assert
25922571 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2603,15 +2582,15 @@ describe('submission.service', () => {
26032582 body : 2023 , // not a string
26042583 }
26052584 const awsSpy = jest
2606- . spyOn ( aws . virusScannerLambda , 'invoke' )
2585+ . spyOn ( aws . guarddutyLambda , 'invoke' )
26072586 . mockImplementationOnce ( ( ) => {
26082587 return Promise . resolve ( {
26092588 Payload : JSON . stringify ( successPayload ) ,
26102589 } )
26112590 } )
26122591
26132592 // Act
2614- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2593+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
26152594
26162595 // Assert
26172596 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2628,15 +2607,15 @@ describe('submission.service', () => {
26282607 body : '}' ,
26292608 }
26302609 const awsSpy = jest
2631- . spyOn ( aws . virusScannerLambda , 'invoke' )
2610+ . spyOn ( aws . guarddutyLambda , 'invoke' )
26322611 . mockImplementationOnce ( ( ) => {
26332612 return Promise . resolve ( {
26342613 Payload : JSON . stringify ( invalidSuccessPayload ) ,
26352614 } )
26362615 } )
26372616
26382617 // Act
2639- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2618+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
26402619
26412620 // Assert
26422621 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2656,15 +2635,15 @@ describe('submission.service', () => {
26562635 } ,
26572636 }
26582637 const awsSpy = jest
2659- . spyOn ( aws . virusScannerLambda , 'invoke' )
2638+ . spyOn ( aws . guarddutyLambda , 'invoke' )
26602639 . mockImplementationOnce ( ( ) => {
26612640 return Promise . resolve ( {
26622641 Payload : JSON . stringify ( invalidSuccessPayload ) ,
26632642 } )
26642643 } )
26652644
26662645 // Act
2667- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2646+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
26682647
26692648 // Assert
26702649 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2684,15 +2663,15 @@ describe('submission.service', () => {
26842663 } ,
26852664 }
26862665 const awsSpy = jest
2687- . spyOn ( aws . virusScannerLambda , 'invoke' )
2666+ . spyOn ( aws . guarddutyLambda , 'invoke' )
26882667 . mockImplementationOnce ( ( ) => {
26892668 return Promise . resolve ( {
26902669 Payload : JSON . stringify ( invalidSuccessPayload ) ,
26912670 } )
26922671 } )
26932672
26942673 // Act
2695- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2674+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
26962675
26972676 // Assert
26982677 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
@@ -2711,22 +2690,22 @@ describe('submission.service', () => {
27112690 } ) ,
27122691 }
27132692 const awsSpy = jest
2714- . spyOn ( aws . virusScannerLambda , 'invoke' )
2693+ . spyOn ( aws . guarddutyLambda , 'invoke' )
27152694 . mockImplementationOnce ( ( ) => {
27162695 return Promise . resolve ( {
27172696 Payload : JSON . stringify ( failurePayload ) ,
27182697 } )
27192698 } )
27202699
27212700 // Act
2722- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2701+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
27232702
27242703 // Assert
27252704 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
27262705 expect ( actualResult . isErr ( ) ) . toEqual ( true )
27272706 expect ( actualResult . _unsafeUnwrapErr ( ) ) . toEqual (
2728- new InvalidFileKeyError (
2729- 'Invalid file key - file key is not found in the quarantine bucket. The file must be uploaded first.' ,
2707+ new GuardDutyInvalidFileKeyError (
2708+ 'GUARDDUTY Invalid file key - file key is not found in the quarantine bucket. The file must be uploaded first.' ,
27302709 ) ,
27312710 )
27322711 } )
@@ -2740,15 +2719,15 @@ describe('submission.service', () => {
27402719 } ) ,
27412720 }
27422721 const awsSpy = jest
2743- . spyOn ( aws . virusScannerLambda , 'invoke' )
2722+ . spyOn ( aws . guarddutyLambda , 'invoke' )
27442723 . mockImplementationOnce ( ( ) => {
27452724 return Promise . resolve ( {
27462725 Payload : JSON . stringify ( failurePayload ) ,
27472726 } )
27482727 } )
27492728
27502729 // Act
2751- const actualResult = await triggerVirusScanning ( MOCK_VALID_FILE_KEY )
2730+ const actualResult = await triggerGuardDutyScanning ( MOCK_VALID_FILE_KEY )
27522731
27532732 // Assert
27542733 expect ( awsSpy ) . toHaveBeenCalledOnce ( )
0 commit comments