Skip to content
Merged
Show file tree
Hide file tree
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import {
ListCodeScanFindingsResponse,
pollScanJobStatus,
SecurityScanTimedOutError,
generateScanName,
} from 'aws-core-vscode/codewhisperer'
import { getStringHash, timeoutUtils } from 'aws-core-vscode/shared'
import { timeoutUtils } from 'aws-core-vscode/shared'
import assert from 'assert'
import sinon from 'sinon'
import * as vscode from 'vscode'
Expand Down Expand Up @@ -321,37 +320,4 @@ describe('securityScanHandler', function () {
await assert.rejects(() => pollPromise, SecurityScanTimedOutError)
})
})

describe('generateScanName', function () {
const clientId = 'ffffffff-ffff-ffff-ffff-ffffffffffff'

it('generates scan name for FILE_AUTO scope', function () {
const result = generateScanName(['/some/root/path'], CodeAnalysisScope.FILE_AUTO, '/path/to/some/file')
assert.strictEqual(result, getStringHash(`${clientId}::/path/to/some/file::FILE_AUTO`))
})

it('generates scan name for FILE_ON_DEMAND scope', function () {
const result = generateScanName(['/some/root/path'], CodeAnalysisScope.FILE_ON_DEMAND, '/path/to/some/file')
assert.strictEqual(result, getStringHash(`${clientId}::/path/to/some/file::FILE_ON_DEMAND`))
})

it('generates scan name for PROJECT scope with a single project root', function () {
const result = generateScanName(['/some/root/path'], CodeAnalysisScope.PROJECT)
assert.strictEqual(result, getStringHash(`${clientId}::/some/root/path::PROJECT`))
})

it('generates scan name for PROJECT scope with multiple project roots', function () {
const result = generateScanName(['/some/root/pathB', '/some/root/pathA'], CodeAnalysisScope.PROJECT)
assert.strictEqual(result, getStringHash(`${clientId}::/some/root/pathA,/some/root/pathB::PROJECT`))
})

it('does not exceed 126 characters', function () {
let reallyDeepFilePath = ''
for (let i = 0; i < 100; i++) {
reallyDeepFilePath += '/some/deep/path'
}
const result = generateScanName(['/some/root/path'], CodeAnalysisScope.FILE_ON_DEMAND, reallyDeepFilePath)
assert.ok(result.length <= 126)
})
})
})
4 changes: 2 additions & 2 deletions packages/core/src/codewhisperer/commands/startSecurityScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
listScanResults,
throwIfCancelled,
getLoggerForScope,
generateScanName,
} from '../service/securityScanHandler'
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
import {
Expand All @@ -39,6 +38,7 @@ import path from 'path'
import { ZipMetadata, ZipUtil } from '../util/zipUtil'
import { debounce } from 'lodash'
import { once } from '../../shared/utilities/functionUtils'
import { randomUUID } from '../../shared/crypto'
import { CodeAnalysisScope, ProjectSizeExceededErrorMessage, SecurityScanStep } from '../models/constants'
import {
CodeScanJobFailedError,
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function startSecurityScan(
}
let artifactMap: ArtifactMap = {}
const uploadStartTime = performance.now()
const scanName = generateScanName(projectPaths, scope, fileName)
const scanName = randomUUID()
try {
artifactMap = await getPresignedUrlAndUpload(client, zipMetadata, scope, scanName)
} finally {
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/codewhisperer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ export { DocumentChangedSource, KeyStrokeHandler, DefaultDocumentChangedType } f
export { ReferenceLogViewProvider } from './service/referenceLogViewProvider'
export { LicenseUtil } from './util/licenseUtil'
export { SecurityIssueProvider } from './service/securityIssueProvider'
export {
listScanResults,
mapToAggregatedList,
pollScanJobStatus,
generateScanName,
} from './service/securityScanHandler'
export { listScanResults, mapToAggregatedList, pollScanJobStatus } from './service/securityScanHandler'
export { CodeWhispererCodeCoverageTracker } from './tracker/codewhispererCodeCoverageTracker'
export { TelemetryHelper } from './util/telemetryHelper'
export { LineSelection, LineTracker } from './tracker/lineTracker'
Expand Down
21 changes: 0 additions & 21 deletions packages/core/src/codewhisperer/service/securityScanHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
import { FeatureUseCase } from '../models/constants'
import { UploadTestArtifactToS3Error } from '../../amazonqTest/error'
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
import { getStringHash } from '../../shared/utilities/textUtilities'
import { getClientId } from '../../shared/telemetry/util'
import globals from '../../shared/extensionGlobals'
import { AmazonqCreateUpload, Span, telemetry } from '../../shared/telemetry/telemetry'
import { AuthUtil } from '../util/authUtil'

Expand Down Expand Up @@ -436,21 +433,3 @@ function getPollingTimeoutMsForScope(scope: CodeWhispererConstants.CodeAnalysisS
? CodeWhispererConstants.expressScanTimeoutMs
: CodeWhispererConstants.standardScanTimeoutMs
}

/**
* Generates a scanName that unique identifies a user's workspace configuration for a Q code review.
*
* @param projectPaths List of project root paths
* @param scope {@link CodeWhispererConstants.CodeAnalysisScope} Scope of files included in the code review
* @param fileName File name of the file being reviewed, or pass undefined for workspace review
* @returns A string hash that uniquely identifies the workspace configuration
*/
export function generateScanName(
projectPaths: string[],
scope: CodeWhispererConstants.CodeAnalysisScope,
fileName?: string
) {
const clientId = getClientId(globals.globalState)
const projectId = fileName ?? projectPaths.sort((a, b) => a.localeCompare(b)).join(',')
return getStringHash(`${clientId}::${projectId}::${scope}`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
createScanJob,
pollScanJobStatus,
listScanResults,
generateScanName,
} from '../../codewhisperer/service/securityScanHandler'
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
import fs from '../../shared/fs/fs'
import { ZipUtil } from '../../codewhisperer/util/zipUtil'
import { randomUUID } from '../../shared/crypto'

const filePromptWithSecurityIssues = `from flask import app

Expand Down Expand Up @@ -95,7 +95,7 @@ describe('CodeWhisperer security scan', async function () {
const projectPaths = zipUtil.getProjectPaths()
const scope = CodeWhispererConstants.CodeAnalysisScope.PROJECT
const zipMetadata = await zipUtil.generateZip(uri, scope)
const codeScanName = generateScanName(projectPaths, scope)
const codeScanName = randomUUID()

let artifactMap
try {
Expand Down
Loading