3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { PromiseResult } from 'aws-sdk/lib/request'
7
- import { Stub , stub } from 'aws-core-vscode/test'
6
+ import { PromiseResult , Request } from 'aws-sdk/lib/request'
7
+ import { createMockDocument } from './testUtil'
8
+ import { Stub , stub } from '../utilities/stubber'
8
9
import { AWSError , HttpResponse } from 'aws-sdk'
9
10
import {
10
11
CodeAnalysisScope ,
@@ -15,12 +16,13 @@ import {
15
16
ListCodeScanFindingsResponse ,
16
17
pollScanJobStatus ,
17
18
SecurityScanTimedOutError ,
18
- } from 'aws-core-vscode /codewhisperer'
19
- import { timeoutUtils } from 'aws-core-vscode /shared'
19
+ } from '../.. /codewhisperer'
20
+ import { timeoutUtils } from '../.. /shared'
20
21
import assert from 'assert'
21
- import sinon from 'sinon'
22
+ import * as sinon from 'sinon'
22
23
import * as vscode from 'vscode'
23
24
import fs from 'fs' // eslint-disable-line no-restricted-imports
25
+ import { GetCodeScanResponse } from '../../codewhisperer/client/codewhispererclient'
24
26
25
27
const buildRawCodeScanIssue = ( params ?: Partial < RawCodeScanIssue > ) : RawCodeScanIssue => ( {
26
28
filePath : 'workspaceFolder/python3.7-plain-sam-app/hello_world/app.py' ,
@@ -72,6 +74,8 @@ describe('securityScanHandler', function () {
72
74
mockClient = stub ( DefaultCodeWhispererClient )
73
75
sinon . stub ( fs , 'existsSync' ) . returns ( true )
74
76
sinon . stub ( fs , 'statSync' ) . returns ( { isFile : ( ) => true } as fs . Stats )
77
+ const textDocumentMock = createMockDocument ( 'first line\n second line\n fourth line' )
78
+ sinon . stub ( vscode . workspace , 'openTextDocument' ) . resolves ( textDocumentMock )
75
79
} )
76
80
77
81
afterEach ( function ( ) {
@@ -290,16 +294,64 @@ describe('securityScanHandler', function () {
290
294
it ( 'should return status when scan completes successfully' , async function ( ) {
291
295
mockClient . getCodeScan
292
296
. onFirstCall ( )
293
- . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
297
+ . resolves ( {
298
+ status : 'Pending' ,
299
+ $response : {
300
+ requestId : 'req1' ,
301
+ hasNextPage : function ( ) : boolean {
302
+ throw new Error ( 'Function not implemented.' )
303
+ } ,
304
+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
305
+ throw new Error ( 'Function not implemented.' )
306
+ } ,
307
+ data : undefined ,
308
+ error : undefined ,
309
+ redirectCount : 0 ,
310
+ retryCount : 0 ,
311
+ httpResponse : new HttpResponse ( ) ,
312
+ } ,
313
+ } )
294
314
. onSecondCall ( )
295
- . resolves ( { status : 'Completed' , $response : { requestId : 'req2' } } )
315
+ . resolves ( {
316
+ status : 'Completed' ,
317
+ $response : {
318
+ requestId : 'req2' ,
319
+ hasNextPage : function ( ) : boolean {
320
+ throw new Error ( 'Function not implemented.' )
321
+ } ,
322
+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
323
+ throw new Error ( 'Function not implemented.' )
324
+ } ,
325
+ data : undefined ,
326
+ error : undefined ,
327
+ redirectCount : 0 ,
328
+ retryCount : 0 ,
329
+ httpResponse : new HttpResponse ( ) ,
330
+ } ,
331
+ } )
296
332
297
333
const result = await pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . FILE_AUTO , mockStartTime )
298
334
assert . strictEqual ( result , 'Completed' )
299
335
} )
300
336
301
337
it ( 'should throw SecurityScanTimedOutError when polling exceeds timeout for express scans' , async function ( ) {
302
- mockClient . getCodeScan . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
338
+ mockClient . getCodeScan . resolves ( {
339
+ status : 'Pending' ,
340
+ $response : {
341
+ requestId : 'req1' ,
342
+ hasNextPage : function ( ) : boolean {
343
+ throw new Error ( 'Function not implemented.' )
344
+ } ,
345
+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
346
+ throw new Error ( 'Function not implemented.' )
347
+ } ,
348
+ data : undefined ,
349
+ error : undefined ,
350
+ redirectCount : 0 ,
351
+ retryCount : 0 ,
352
+ httpResponse : new HttpResponse ( ) ,
353
+ } ,
354
+ } )
303
355
304
356
const pollPromise = pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . FILE_AUTO , mockStartTime )
305
357
@@ -310,7 +362,23 @@ describe('securityScanHandler', function () {
310
362
} )
311
363
312
364
it ( 'should throw SecurityScanTimedOutError when polling exceeds timeout for standard scans' , async function ( ) {
313
- mockClient . getCodeScan . resolves ( { status : 'Pending' , $response : { requestId : 'req1' } } )
365
+ mockClient . getCodeScan . resolves ( {
366
+ status : 'Pending' ,
367
+ $response : {
368
+ requestId : 'req1' ,
369
+ hasNextPage : function ( ) : boolean {
370
+ throw new Error ( 'Function not implemented.' )
371
+ } ,
372
+ nextPage : function ( ) : Request < GetCodeScanResponse , AWSError > | null {
373
+ throw new Error ( 'Function not implemented.' )
374
+ } ,
375
+ data : undefined ,
376
+ error : undefined ,
377
+ redirectCount : 0 ,
378
+ retryCount : 0 ,
379
+ httpResponse : new HttpResponse ( ) ,
380
+ } ,
381
+ } )
314
382
315
383
const pollPromise = pollScanJobStatus ( mockClient , mockJobId , CodeAnalysisScope . PROJECT , mockStartTime )
316
384
0 commit comments