Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 1 addition & 135 deletions packages/core/src/test/codewhisperer/startSecurityScan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ import { assertTelemetry, closeAllEditors, getFetchStubWithResponse } from '../t
import { AWSError } from 'aws-sdk'
import { getTestWindow } from '../shared/vscode/window'
import { SeverityLevel } from '../shared/vscode/message'
import { cancel } from '../../shared/localizedText'
import {
showScannedFilesMessage,
stopScanMessage,
CodeAnalysisScope,
monthlyLimitReachedNotification,
scansLimitReachedErrorMessage,
} from '../../codewhisperer/models/constants'
import { showScannedFilesMessage, CodeAnalysisScope } from '../../codewhisperer/models/constants'
import * as model from '../../codewhisperer/models/model'
import * as errors from '../../shared/errors'
import * as timeoutUtils from '../../shared/utilities/timeoutUtils'
Expand Down Expand Up @@ -124,70 +117,6 @@ describe('startSecurityScan', function () {
})
})

it('Should stop security scan for project scans when confirmed', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
const securityScanRenderSpy = sinon.spy(diagnosticsProvider, 'initSecurityScanRender')
const securityScanStoppedErrorSpy = sinon.spy(model, 'CodeScanStoppedError')
const testWindow = getTestWindow()
testWindow.onDidShowMessage((message) => {
if (message.message === stopScanMessage) {
message.selectItem(startSecurityScan.stopScanButton)
}
})
model.codeScanState.setToRunning()
const scanPromise = startSecurityScan.startSecurityScan(
mockSecurityPanelViewProvider,
editor,
createClient(),
extensionContext,
CodeAnalysisScope.PROJECT,
false
)
await startSecurityScan.confirmStopSecurityScan(
model.codeScanState,
false,
CodeAnalysisScope.PROJECT,
undefined
)
await scanPromise
assert.ok(securityScanRenderSpy.notCalled)
assert.ok(securityScanStoppedErrorSpy.calledOnce)
const warnings = testWindow.shownMessages.filter((m) => m.severity === SeverityLevel.Warning)
assert.ok(warnings.map((m) => m.message).includes(stopScanMessage))
})

it('Should not stop security scan for project scans when not confirmed', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
const securityScanRenderSpy = sinon.spy(diagnosticsProvider, 'initSecurityScanRender')
const securityScanStoppedErrorSpy = sinon.spy(model, 'CodeScanStoppedError')
const testWindow = getTestWindow()
testWindow.onDidShowMessage((message) => {
if (message.message === stopScanMessage) {
message.selectItem(cancel)
}
})
model.codeScanState.setToRunning()
const scanPromise = startSecurityScan.startSecurityScan(
mockSecurityPanelViewProvider,
editor,
createClient(),
extensionContext,
CodeAnalysisScope.PROJECT,
false
)
await startSecurityScan.confirmStopSecurityScan(
model.codeScanState,
false,
CodeAnalysisScope.PROJECT,
undefined
)
await scanPromise
assert.ok(securityScanRenderSpy.calledOnce)
assert.ok(securityScanStoppedErrorSpy.notCalled)
const warnings = testWindow.shownMessages.filter((m) => m.severity === SeverityLevel.Warning)
assert.ok(warnings.map((m) => m.message).includes(stopScanMessage))
})

it('Should stop security scan for auto file scans if setting is disabled', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
const securityScanRenderSpy = sinon.spy(diagnosticsProvider, 'initSecurityScanRender')
Expand Down Expand Up @@ -272,39 +201,6 @@ describe('startSecurityScan', function () {
])
})

it('Should not cancel a project scan if a file scan has started', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
await model.CodeScansState.instance.setScansEnabled(true)

const scanPromise = startSecurityScan.startSecurityScan(
mockSecurityPanelViewProvider,
editor,
createClient(),
extensionContext,
CodeAnalysisScope.PROJECT,
false
)
await startSecurityScan.startSecurityScan(
mockSecurityPanelViewProvider,
editor,
createClient(),
extensionContext,
CodeAnalysisScope.FILE_AUTO,
false
)
await scanPromise
assertTelemetry('codewhisperer_securityScan', [
{
result: 'Succeeded',
codewhispererCodeScanScope: 'FILE_AUTO',
},
{
result: 'Succeeded',
codewhispererCodeScanScope: 'PROJECT',
},
])
})

it('Should handle failed scan job status', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })

Expand All @@ -330,36 +226,6 @@ describe('startSecurityScan', function () {
})
})

it('Should show notification when throttled for project scans', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
const mockClient = createClient()
mockClient.createCodeScan.throws({
code: 'ThrottlingException',
time: new Date(),
name: 'error name',
message: scansLimitReachedErrorMessage,
} satisfies AWSError)
sinon.stub(errors, 'isAwsError').returns(true)
const testWindow = getTestWindow()
await startSecurityScan.startSecurityScan(
mockSecurityPanelViewProvider,
editor,
mockClient,
extensionContext,
CodeAnalysisScope.PROJECT,
false
)

assert.ok(testWindow.shownMessages.map((m) => m.message).includes(monthlyLimitReachedNotification))
assertTelemetry('codewhisperer_securityScan', {
codewhispererCodeScanScope: 'PROJECT',
result: 'Failed',
reason: 'ThrottlingException',
reasonDesc: `ThrottlingException: Maximum com.amazon.aws.codewhisperer.StartCodeAnalysis reached for this month.`,
passive: false,
})
})

it('Should set monthly quota exceeded when throttled for auto file scans', async function () {
getFetchStubWithResponse({ status: 200, statusText: 'testing stub' })
await model.CodeScansState.instance.setScansEnabled(true)
Expand Down
Loading