2020-06-26 17:22:19 +01:00
"use strict" ;
2021-07-27 17:59:59 +01:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
Object . defineProperty ( o , k2 , { enumerable : true , get : function ( ) { return m [ k ] ; } } ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
2020-06-26 17:22:19 +01:00
var _ _importStar = ( this && this . _ _importStar ) || function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
2021-07-27 17:59:59 +01:00
if ( mod != null ) for ( var k in mod ) if ( k !== "default" && Object . prototype . hasOwnProperty . call ( mod , k ) ) _ _createBinding ( result , mod , k ) ;
_ _setModuleDefault ( result , mod ) ;
2020-06-26 17:22:19 +01:00
return result ;
} ;
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2022-06-27 16:01:48 +00:00
exports . stubToolRunnerConstructor = void 0 ;
2022-06-19 16:44:24 -07:00
const fs = _ _importStar ( require ( "fs" ) ) ;
2020-09-29 14:43:37 +01:00
const path = _ _importStar ( require ( "path" ) ) ;
2021-11-03 13:19:01 -07:00
const toolrunner = _ _importStar ( require ( "@actions/exec/lib/toolrunner" ) ) ;
2020-06-26 17:22:19 +01:00
const toolcache = _ _importStar ( require ( "@actions/tool-cache" ) ) ;
2022-12-02 14:05:21 +01:00
const safeWhich = _ _importStar ( require ( "@chrisgavin/safe-which" ) ) ;
2020-09-29 14:43:37 +01:00
const ava _1 = _ _importDefault ( require ( "ava" ) ) ;
2022-06-19 16:44:24 -07:00
const del _1 = _ _importDefault ( require ( "del" ) ) ;
const yaml = _ _importStar ( require ( "js-yaml" ) ) ;
2020-10-01 11:03:30 +01:00
const nock _1 = _ _importDefault ( require ( "nock" ) ) ;
2021-11-03 13:19:01 -07:00
const sinon = _ _importStar ( require ( "sinon" ) ) ;
2022-11-23 18:19:25 +00:00
const actionsUtil = _ _importStar ( require ( "./actions-util" ) ) ;
2020-10-01 11:03:30 +01:00
const codeql = _ _importStar ( require ( "./codeql" ) ) ;
const defaults = _ _importStar ( require ( "./defaults.json" ) ) ;
2022-05-09 12:02:19 +00:00
const feature _flags _1 = require ( "./feature-flags" ) ;
const languages _1 = require ( "./languages" ) ;
2020-08-25 16:19:15 +01:00
const logging _1 = require ( "./logging" ) ;
2020-06-26 17:22:19 +01:00
const testing _utils _1 = require ( "./testing-utils" ) ;
2020-10-01 11:03:30 +01:00
const util = _ _importStar ( require ( "./util" ) ) ;
2021-06-01 14:49:07 -07:00
const util _1 = require ( "./util" ) ;
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupTests ) ( ava _1 . default ) ;
2020-11-23 14:18:05 +00:00
const sampleApiDetails = {
auth : "token" ,
2020-11-24 11:10:25 +00:00
url : "https://github.com" ,
2022-08-10 21:11:50 +01:00
apiURL : undefined ,
2022-08-29 12:57:46 -07:00
registriesAuthTokens : undefined ,
2020-11-23 14:18:05 +00:00
} ;
2021-03-07 09:27:19 +00:00
const sampleGHAEApiDetails = {
auth : "token" ,
url : "https://example.githubenterprise.com" ,
2022-08-10 21:11:50 +01:00
apiURL : undefined ,
2022-08-29 12:57:46 -07:00
registriesAuthTokens : undefined ,
2021-03-07 09:27:19 +00:00
} ;
2022-06-19 16:44:24 -07:00
let stubConfig ;
2021-05-20 15:20:32 -07:00
ava _1 . default . beforeEach ( ( ) => {
2022-11-14 16:37:48 +00:00
( 0 , util _1 . initializeEnvironment ) ( "1.2.3" ) ;
2022-06-19 16:44:24 -07:00
stubConfig = {
languages : [ languages _1 . Language . cpp ] ,
queries : { } ,
pathsIgnore : [ ] ,
paths : [ ] ,
originalUserInput : { } ,
tempDir : "" ,
codeQLCmd : "" ,
gitHubVersion : {
type : util . GitHubVariant . DOTCOM ,
} ,
dbLocation : "" ,
packs : { } ,
debugMode : false ,
debugArtifactName : util . DEFAULT _DEBUG _ARTIFACT _NAME ,
debugDatabaseName : util . DEFAULT _DEBUG _DATABASE _NAME ,
augmentationProperties : {
injectedMlQueries : false ,
packsInputCombines : false ,
queriesInputCombines : false ,
} ,
2022-08-10 15:39:35 -07:00
trapCaches : { } ,
2022-08-15 14:44:43 +01:00
trapCacheDownloadTime : 0 ,
2022-06-19 16:44:24 -07:00
} ;
2021-05-20 15:20:32 -07:00
} ) ;
2022-11-23 14:53:40 -08:00
async function mockApiAndSetupCodeQL ( { apiDetails , bypassToolcache , isPinned , tmpDir , toolsInput , version , } ) {
2022-08-16 15:38:55 +01:00
var _a ;
const platform = process . platform === "win32"
? "win64"
: process . platform === "linux"
? "linux64"
: "osx64" ;
const baseUrl = ( _a = apiDetails === null || apiDetails === void 0 ? void 0 : apiDetails . url ) !== null && _a !== void 0 ? _a : "https://example.com" ;
const relativeUrl = apiDetails
? ` /github/codeql-action/releases/download/ ${ version } /codeql-bundle- ${ platform } .tar.gz `
: ` /download/codeql-bundle- ${ version } /codeql-bundle.tar.gz ` ;
( 0 , nock _1 . default ) ( baseUrl )
. get ( relativeUrl )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle ${ isPinned ? "-pinned" : "" } .tar.gz ` ) ) ;
2022-11-23 14:53:40 -08:00
return await codeql . setupCodeQL ( toolsInput ? toolsInput . input : ` ${ baseUrl } ${ relativeUrl } ` , apiDetails !== null && apiDetails !== void 0 ? apiDetails : sampleApiDetails , tmpDir , util . GitHubVariant . DOTCOM , ! ! bypassToolcache , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2022-08-16 15:38:55 +01:00
}
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "download codeql bundle cache" , async ( t ) => {
2020-06-26 17:22:19 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2020-09-14 10:44:43 +01:00
const versions = [ "20200601" , "20200610" ] ;
2020-06-26 17:22:19 +01:00
for ( let i = 0 ; i < versions . length ; i ++ ) {
const version = versions [ i ] ;
2022-10-05 09:16:42 -07:00
const codeQLConfig = await mockApiAndSetupCodeQL ( { version , tmpDir } ) ;
2020-09-14 10:44:43 +01:00
t . assert ( toolcache . find ( "CodeQL" , ` 0.0.0- ${ version } ` ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( codeQLConfig . toolsVersion , version ) ;
2020-06-26 17:22:19 +01:00
}
2022-08-16 15:38:55 +01:00
t . is ( toolcache . findAllVersions ( "CodeQL" ) . length , 2 ) ;
2020-09-22 14:38:27 +01:00
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "download codeql bundle cache explicitly requested with pinned different version cached" , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2022-10-05 09:16:42 -07:00
const pinnedCodeQLConfig = await mockApiAndSetupCodeQL ( {
2022-08-16 15:38:55 +01:00
version : "20200601" ,
isPinned : true ,
tmpDir ,
} ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( pinnedCodeQLConfig . toolsVersion , "20200601" ) ;
const unpinnedCodeQLConfig = await mockApiAndSetupCodeQL ( {
version : "20200610" ,
tmpDir ,
} ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200610" ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( unpinnedCodeQLConfig . toolsVersion , "20200610" ) ;
2020-09-22 14:38:27 +01:00
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "don't download codeql bundle cache with pinned different version cached" , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2022-10-05 09:16:42 -07:00
const pinnedCodeQLConfig = await mockApiAndSetupCodeQL ( {
2022-08-16 15:38:55 +01:00
version : "20200601" ,
isPinned : true ,
tmpDir ,
} ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( pinnedCodeQLConfig . toolsVersion , "20200601" ) ;
2022-11-23 14:53:40 -08:00
const codeQLConfig = await codeql . setupCodeQL ( undefined , sampleApiDetails , tmpDir , util . GitHubVariant . DOTCOM , false , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( codeQLConfig . toolsVersion , "0.0.0-20200601" ) ;
2020-09-22 14:38:27 +01:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 1 ) ;
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "download codeql bundle cache with different version cached (not pinned)" , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2022-10-05 09:16:42 -07:00
const cachedCodeQLConfig = await mockApiAndSetupCodeQL ( {
version : "20200601" ,
tmpDir ,
} ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( cachedCodeQLConfig . toolsVersion , "20200601" ) ;
const codeQLConfig = await mockApiAndSetupCodeQL ( {
2022-08-16 15:38:55 +01:00
version : defaults . bundleVersion ,
tmpDir ,
apiDetails : sampleApiDetails ,
toolsInput : { input : undefined } ,
} ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( codeQLConfig . toolsVersion , defaults . bundleVersion . replace ( "codeql-bundle-" , "" ) ) ;
2020-09-22 14:38:27 +01:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 2 ) ;
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( 'download codeql bundle cache with pinned different version cached if "latest" tools specified' , async ( t ) => {
2020-09-22 14:38:27 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2022-10-05 09:16:42 -07:00
const pinnedCodeQLConfig = await mockApiAndSetupCodeQL ( {
2022-08-16 15:38:55 +01:00
version : "20200601" ,
isPinned : true ,
tmpDir ,
} ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( pinnedCodeQLConfig . toolsVersion , "20200601" ) ;
const latestCodeQLConfig = await mockApiAndSetupCodeQL ( {
2022-08-16 15:38:55 +01:00
version : defaults . bundleVersion ,
apiDetails : sampleApiDetails ,
toolsInput : { input : "latest" } ,
tmpDir ,
} ) ;
2022-10-05 09:16:42 -07:00
t . deepEqual ( latestCodeQLConfig . toolsVersion , defaults . bundleVersion . replace ( "codeql-bundle-" , "" ) ) ;
2020-09-22 14:38:27 +01:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
2020-06-26 17:22:19 +01:00
t . is ( cachedVersions . length , 2 ) ;
} ) ;
} ) ;
2022-08-16 16:15:47 +01:00
const TOOLCACHE _BYPASS _TEST _CASES = [
[ true , undefined , true ] ,
[ false , undefined , false ] ,
[
true ,
"https://github.com/github/codeql-action/releases/download/codeql-bundle-20200601/codeql-bundle.tar.gz" ,
false ,
] ,
] ;
2022-10-11 10:39:40 -07:00
for ( const [ isFeatureEnabled , toolsInput , shouldToolcacheBeBypassed , ] of TOOLCACHE _BYPASS _TEST _CASES ) {
2022-10-11 18:56:15 +01:00
( 0 , ava _1 . default ) ( ` download codeql bundle ${ shouldToolcacheBeBypassed ? "bypasses" : "does not bypass" } toolcache when feature ${ isFeatureEnabled ? "enabled" : "disabled" } and tools: ${ toolsInput } passed ` , async ( t ) => {
2022-08-16 16:15:47 +01:00
await util . withTmpDir ( async ( tmpDir ) => {
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
await mockApiAndSetupCodeQL ( {
version : "codeql-bundle-20200601" ,
apiDetails : sampleApiDetails ,
isPinned : true ,
tmpDir ,
} ) ;
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
await mockApiAndSetupCodeQL ( {
version : defaults . bundleVersion ,
apiDetails : sampleApiDetails ,
2022-11-23 14:53:40 -08:00
bypassToolcache : isFeatureEnabled ,
2022-08-16 16:15:47 +01:00
toolsInput : { input : toolsInput } ,
tmpDir ,
} ) ;
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , shouldToolcacheBeBypassed ? 2 : 1 ) ;
} ) ;
} ) ;
}
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "download codeql bundle from github ae endpoint" , async ( t ) => {
2021-03-07 09:27:19 +00:00
await util . withTmpDir ( async ( tmpDir ) => {
2021-09-10 13:53:13 -07:00
( 0 , testing _utils _1 . setupActionsVars ) ( tmpDir , tmpDir ) ;
2021-03-07 09:27:19 +00:00
const bundleAssetID = 10 ;
const platform = process . platform === "win32"
? "win64"
: process . platform === "linux"
? "linux64"
: "osx64" ;
const codeQLBundleName = ` codeql-bundle- ${ platform } .tar.gz ` ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://example.githubenterprise.com" )
2021-03-07 09:27:19 +00:00
. get ( ` /api/v3/enterprise/code-scanning/codeql-bundle/find/ ${ defaults . bundleVersion } ` )
. reply ( 200 , {
assets : { [ codeQLBundleName ] : bundleAssetID } ,
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://example.githubenterprise.com" )
2021-03-07 09:27:19 +00:00
. get ( ` /api/v3/enterprise/code-scanning/codeql-bundle/download/ ${ bundleAssetID } ` )
. reply ( 200 , {
url : ` https://example.githubenterprise.com/github/codeql-action/releases/download/ ${ defaults . bundleVersion } / ${ codeQLBundleName } ` ,
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://example.githubenterprise.com" )
2021-03-07 09:27:19 +00:00
. get ( ` /github/codeql-action/releases/download/ ${ defaults . bundleVersion } / ${ codeQLBundleName } ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle-pinned.tar.gz ` ) ) ;
2022-11-23 14:53:40 -08:00
await codeql . setupCodeQL ( undefined , sampleGHAEApiDetails , tmpDir , util . GitHubVariant . GHAE , false , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2021-03-07 09:27:19 +00:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
t . is ( cachedVersions . length , 1 ) ;
} ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "parse codeql bundle url version" , ( t ) => {
2020-11-11 18:22:12 +00:00
t . deepEqual ( codeql . getCodeQLURLVersion ( "https://github.com/.../codeql-bundle-20200601/..." ) , "20200601" ) ;
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "convert to semver" , ( t ) => {
2020-06-26 17:22:19 +01:00
const tests = {
2020-09-14 10:44:43 +01:00
"20200601" : "0.0.0-20200601" ,
"20200601.0" : "0.0.0-20200601.0" ,
"20200601.0.0" : "20200601.0.0" ,
"1.2.3" : "1.2.3" ,
"1.2.3-alpha" : "1.2.3-alpha" ,
"1.2.3-beta.1" : "1.2.3-beta.1" ,
2020-06-26 17:22:19 +01:00
} ;
for ( const [ version , expectedVersion ] of Object . entries ( tests ) ) {
try {
2021-09-10 13:53:13 -07:00
const parsedVersion = codeql . convertToSemVer ( version , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2020-06-26 17:22:19 +01:00
t . deepEqual ( parsedVersion , expectedVersion ) ;
}
catch ( e ) {
2021-09-10 13:53:13 -07:00
t . fail ( e instanceof Error ? e . message : String ( e ) ) ;
2020-06-26 17:22:19 +01:00
}
}
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for explicit paths" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . deepEqual ( codeql . getExtraOptions ( { } , [ "foo" ] , [ ] ) , [ ] ) ;
t . deepEqual ( codeql . getExtraOptions ( { foo : [ 42 ] } , [ "foo" ] , [ ] ) , [ "42" ] ) ;
t . deepEqual ( codeql . getExtraOptions ( { foo : { bar : [ 42 ] } } , [ "foo" , "bar" ] , [ ] ) , [ "42" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for wildcards" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . deepEqual ( codeql . getExtraOptions ( { "*" : [ 42 ] } , [ "foo" ] , [ ] ) , [ "42" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions works for wildcards and explicit paths" , ( t ) => {
2020-09-14 10:44:43 +01:00
const o1 = { "*" : [ 42 ] , foo : [ 87 ] } ;
t . deepEqual ( codeql . getExtraOptions ( o1 , [ "foo" ] , [ ] ) , [ "42" , "87" ] ) ;
const o2 = { "*" : [ 42 ] , foo : [ 87 ] } ;
t . deepEqual ( codeql . getExtraOptions ( o2 , [ "foo" , "bar" ] , [ ] ) , [ "42" ] ) ;
const o3 = { "*" : [ 42 ] , foo : { "*" : [ 87 ] , bar : [ 99 ] } } ;
const p = [ "foo" , "bar" ] ;
t . deepEqual ( codeql . getExtraOptions ( o3 , p , [ ] ) , [ "42" , "87" , "99" ] ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getExtraOptions throws for bad content" , ( t ) => {
2020-09-14 10:44:43 +01:00
t . throws ( ( ) => codeql . getExtraOptions ( { "*" : 42 } , [ "foo" ] , [ ] ) ) ;
t . throws ( ( ) => codeql . getExtraOptions ( { foo : 87 } , [ "foo" ] , [ ] ) ) ;
t . throws ( ( ) => codeql . getExtraOptions ( { "*" : [ 42 ] , foo : { "*" : 87 , bar : [ 99 ] } } , [ "foo" , "bar" ] , [ ] ) ) ;
2020-08-10 09:25:14 +02:00
} ) ;
2021-09-10 13:53:13 -07:00
( 0 , ava _1 . default ) ( "getCodeQLActionRepository" , ( t ) => {
const logger = ( 0 , logging _1 . getRunnerLogger ) ( true ) ;
2022-11-14 16:37:48 +00:00
( 0 , util _1 . initializeEnvironment ) ( "1.2.3" ) ;
2021-05-20 15:20:32 -07:00
// isRunningLocalAction() === true
delete process . env [ "GITHUB_ACTION_REPOSITORY" ] ;
process . env [ "RUNNER_TEMP" ] = path . dirname ( _ _dirname ) ;
const repoLocalRunner = codeql . getCodeQLActionRepository ( logger ) ;
t . deepEqual ( repoLocalRunner , "github/codeql-action" ) ;
2022-11-23 18:19:25 +00:00
// isRunningLocalAction() === false
sinon . stub ( actionsUtil , "isRunningLocalAction" ) . returns ( false ) ;
2021-06-24 18:00:10 +01:00
process . env [ "GITHUB_ACTION_REPOSITORY" ] = "xxx/yyy" ;
const repoEnv = codeql . getCodeQLActionRepository ( logger ) ;
t . deepEqual ( repoEnv , "xxx/yyy" ) ;
2021-05-20 15:20:32 -07:00
} ) ;
2021-11-03 13:19:01 -07:00
( 0 , ava _1 . default ) ( "databaseInterpretResults() does not set --sarif-add-query-help for 2.7.0" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.7.0" ) ;
2022-12-02 14:05:21 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2022-12-05 14:10:06 +00:00
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "-v" , "" ) ;
2021-11-03 13:19:01 -07:00
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--sarif-add-query-help" ) , "--sarif-add-query-help should be absent, but it is present" ) ;
} ) ;
( 0 , ava _1 . default ) ( "databaseInterpretResults() sets --sarif-add-query-help for 2.7.1" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.7.1" ) ;
2022-12-02 14:05:21 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2022-12-05 14:10:06 +00:00
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "-v" , "" ) ;
2021-11-03 13:19:01 -07:00
t . true ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--sarif-add-query-help" ) , "--sarif-add-query-help should be present, but it is absent" ) ;
} ) ;
2022-06-19 16:44:24 -07:00
( 0 , ava _1 . default ) ( "databaseInitCluster() without injected codescanning config" , async ( t ) => {
await util . withTmpDir ( async ( tempDir ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.8.1" ) ;
2022-12-02 14:05:21 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2022-06-19 16:44:24 -07:00
const thisStubConfig = {
... stubConfig ,
tempDir ,
augmentationProperties : {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
} ,
} ;
2022-11-14 18:49:17 +00:00
await codeqlObject . databaseInitCluster ( thisStubConfig , "" , undefined , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2022-06-19 16:44:24 -07:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
// should NOT have used an config file
const configArg = args . find ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . falsy ( configArg , "Should have injected a codescanning config" ) ;
} ) ;
} ) ;
// Test macro for ensuring different variants of injected augmented configurations
const injectedConfigMacro = ava _1 . default . macro ( {
exec : async ( t , augmentationProperties , configOverride , expectedConfig ) => {
2022-10-05 15:54:07 -07:00
await util . withTmpDir ( async ( tempDir ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon
. stub ( codeqlObject , "getVersion" )
. resolves ( codeql . CODEQL _VERSION _CONFIG _FILES ) ;
const thisStubConfig = {
... stubConfig ,
... configOverride ,
tempDir ,
augmentationProperties ,
} ;
2022-11-14 18:49:17 +00:00
await codeqlObject . databaseInitCluster ( thisStubConfig , "" , undefined , ( 0 , testing _utils _1 . createFeatures ) ( [ feature _flags _1 . Feature . CliConfigFileEnabled ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2022-10-05 15:54:07 -07:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
// should have used an config file
const configArg = args . find ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . truthy ( configArg , "Should have injected a codescanning config" ) ;
const configFile = configArg . split ( "=" ) [ 1 ] ;
const augmentedConfig = yaml . load ( fs . readFileSync ( configFile , "utf8" ) ) ;
t . deepEqual ( augmentedConfig , expectedConfig ) ;
await ( 0 , del _1 . default ) ( configFile , { force : true } ) ;
} ) ;
2022-06-19 16:44:24 -07:00
} ,
title : ( providedTitle = "" ) => ` databaseInitCluster() injected config: ${ providedTitle } ` ,
} ) ;
( 0 , ava _1 . default ) ( "basic" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
} , { } , { } ) ;
( 0 , ava _1 . default ) ( "injected ML queries" , injectedConfigMacro , {
injectedMlQueries : true ,
queriesInputCombines : false ,
packsInputCombines : false ,
} , { } , {
2022-07-13 13:27:04 -07:00
packs : [ "codeql/javascript-experimental-atm-queries@~0.3.0" ] ,
2022-06-19 16:44:24 -07:00
} ) ;
( 0 , ava _1 . default ) ( "injected ML queries with existing packs" , injectedConfigMacro , {
injectedMlQueries : true ,
queriesInputCombines : false ,
packsInputCombines : false ,
} , {
originalUserInput : {
packs : { javascript : [ "codeql/something-else" ] } ,
} ,
} , {
packs : {
javascript : [
"codeql/something-else" ,
2022-07-13 13:27:04 -07:00
"codeql/javascript-experimental-atm-queries@~0.3.0" ,
2022-06-19 16:44:24 -07:00
] ,
} ,
} ) ;
( 0 , ava _1 . default ) ( "injected ML queries with existing packs of different language" , injectedConfigMacro , {
injectedMlQueries : true ,
queriesInputCombines : false ,
packsInputCombines : false ,
} , {
originalUserInput : {
packs : { cpp : [ "codeql/something-else" ] } ,
} ,
} , {
packs : {
cpp : [ "codeql/something-else" ] ,
2022-07-13 13:27:04 -07:00
javascript : [ "codeql/javascript-experimental-atm-queries@~0.3.0" ] ,
2022-06-19 16:44:24 -07:00
} ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
packsInput : [ "xxx" , "yyy" ] ,
} , { } , {
packs : [ "xxx" , "yyy" ] ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input with existing packs combines" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : true ,
packsInput : [ "xxx" , "yyy" ] ,
} , {
originalUserInput : {
packs : {
cpp : [ "codeql/something-else" ] ,
} ,
} ,
} , {
packs : {
cpp : [ "codeql/something-else" , "xxx" , "yyy" ] ,
} ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input with existing packs overrides" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
packsInput : [ "xxx" , "yyy" ] ,
} , {
originalUserInput : {
packs : {
cpp : [ "codeql/something-else" ] ,
} ,
} ,
} , {
packs : [ "xxx" , "yyy" ] ,
} ) ;
( 0 , ava _1 . default ) ( "injected packs from input with existing packs overrides and ML model inject" , injectedConfigMacro , {
injectedMlQueries : true ,
queriesInputCombines : false ,
packsInputCombines : false ,
packsInput : [ "xxx" , "yyy" ] ,
} , {
originalUserInput : {
packs : {
cpp : [ "codeql/something-else" ] ,
} ,
} ,
} , {
2022-07-13 13:27:04 -07:00
packs : [ "xxx" , "yyy" , "codeql/javascript-experimental-atm-queries@~0.3.0" ] ,
2022-06-19 16:44:24 -07:00
} ) ;
// similar, but with queries
( 0 , ava _1 . default ) ( "injected queries from input" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , { } , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input overrides" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : false ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , {
originalUserInput : {
queries : [ { uses : "zzz" } ] ,
} ,
} , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input combines" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : true ,
packsInputCombines : false ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , {
originalUserInput : {
queries : [ { uses : "zzz" } ] ,
} ,
} , {
queries : [
{
uses : "zzz" ,
} ,
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries from input combines 2" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : true ,
packsInputCombines : true ,
queriesInput : [ { uses : "xxx" } , { uses : "yyy" } ] ,
} , { } , {
queries : [
{
uses : "xxx" ,
} ,
{
uses : "yyy" ,
} ,
] ,
} ) ;
( 0 , ava _1 . default ) ( "injected queries and packs, but empty" , injectedConfigMacro , {
injectedMlQueries : false ,
queriesInputCombines : true ,
packsInputCombines : true ,
queriesInput : [ ] ,
packsInput : [ ] ,
} , {
originalUserInput : {
packs : [ ] ,
queries : [ ] ,
} ,
} , { } ) ;
2022-08-16 13:58:59 +01:00
( 0 , ava _1 . default ) ( "does not use injected config" , async ( t ) => {
2022-06-19 16:44:24 -07:00
const origCODEQL _PASS _CONFIG _TO _CLI = process . env . CODEQL _PASS _CONFIG _TO _CLI ;
process . env [ "CODEQL_PASS_CONFIG_TO_CLI" ] = "false" ;
try {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon
. stub ( codeqlObject , "getVersion" )
. resolves ( codeql . CODEQL _VERSION _CONFIG _FILES ) ;
2022-11-14 18:49:17 +00:00
await codeqlObject . databaseInitCluster ( stubConfig , "" , undefined , ( 0 , testing _utils _1 . createFeatures ) ( [ ] ) , ( 0 , logging _1 . getRunnerLogger ) ( true ) ) ;
2022-06-19 16:44:24 -07:00
const args = runnerConstructorStub . firstCall . args [ 1 ] ;
// should have used an config file
const configArg = args . find ( ( arg ) => arg . startsWith ( "--codescanning-config=" ) ) ;
t . falsy ( configArg , "Should NOT have injected a codescanning config" ) ;
}
finally {
process . env [ "CODEQL_PASS_CONFIG_TO_CLI" ] = origCODEQL _PASS _CONFIG _TO _CLI ;
}
} ) ;
2022-12-05 14:10:06 +00:00
( 0 , ava _1 . default ) ( "databaseInterpretResults() sets --sarif-add-baseline-file-info for 2.11.3" , async ( t ) => {
2022-10-26 16:14:02 +01:00
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2022-12-05 14:10:06 +00:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.11.3" ) ;
2022-12-02 14:05:21 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2022-12-05 14:10:06 +00:00
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "-v" , "" ) ;
2022-10-26 16:14:02 +01:00
t . true ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--sarif-add-baseline-file-info" ) , "--sarif-add-baseline-file-info should be present, but it is absent" ) ;
} ) ;
2022-12-05 14:10:06 +00:00
( 0 , ava _1 . default ) ( "databaseInterpretResults() does not set --sarif-add-baseline-file-info for 2.11.2" , async ( t ) => {
2022-10-26 16:14:02 +01:00
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
2022-12-05 14:10:06 +00:00
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.11.2" ) ;
2022-12-02 14:05:21 +01:00
// safeWhich throws because of the test CodeQL object.
sinon . stub ( safeWhich , "safeWhich" ) . resolves ( "" ) ;
2022-12-05 14:10:06 +00:00
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "-v" , "" ) ;
2022-10-26 16:14:02 +01:00
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--sarif-add-baseline-file-info" ) , "--sarif-add-baseline-file-info must be absent, but it is present" ) ;
} ) ;
2021-11-03 13:19:01 -07:00
function stubToolRunnerConstructor ( ) {
const runnerObjectStub = sinon . createStubInstance ( toolrunner . ToolRunner ) ;
runnerObjectStub . exec . resolves ( 0 ) ;
const runnerConstructorStub = sinon . stub ( toolrunner , "ToolRunner" ) ;
runnerConstructorStub . returns ( runnerObjectStub ) ;
return runnerConstructorStub ;
}
2022-06-27 16:01:48 +00:00
exports . stubToolRunnerConstructor = stubToolRunnerConstructor ;
2020-06-26 17:22:19 +01:00
//# sourceMappingURL=codeql.test.js.map