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 ;
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" ) ) ;
2020-09-29 14:43:37 +01:00
const ava _1 = _ _importDefault ( require ( "ava" ) ) ;
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" ) ) ;
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" ,
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" ,
} ;
2021-05-20 15:20:32 -07:00
ava _1 . default . beforeEach ( ( ) => {
2021-09-10 13:53:13 -07:00
( 0 , util _1 . initializeEnvironment ) ( util _1 . Mode . actions , "1.2.3" ) ;
2021-05-20 15:20:32 -07: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 ] ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://example.com" )
2020-06-26 17:22:19 +01:00
. get ( ` /download/codeql-bundle- ${ version } /codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( ` https://example.com/download/codeql-bundle- ${ version } /codeql-bundle.tar.gz ` , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-14 10:44:43 +01:00
t . assert ( toolcache . find ( "CodeQL" , ` 0.0.0- ${ version } ` ) ) ;
2020-06-26 17:22:19 +01:00
}
2020-09-14 10:44:43 +01:00
const cachedVersions = toolcache . findAllVersions ( "CodeQL" ) ;
2020-09-22 14:38:27 +01:00
t . is ( cachedVersions . length , 2 ) ;
} ) ;
} ) ;
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 ) ;
( 0 , nock _1 . default ) ( "https://example.com" )
2020-09-22 14:38:27 +01:00
. get ( ` /download/codeql-bundle-20200601/codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle-pinned.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://example.com" )
2020-09-22 14:38:27 +01:00
. get ( ` /download/codeql-bundle-20200610/codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "https://example.com/download/codeql-bundle-20200610/codeql-bundle.tar.gz" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200610" ) ) ;
} ) ;
} ) ;
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 ) ;
( 0 , nock _1 . default ) ( "https://example.com" )
2020-09-22 14:38:27 +01:00
. get ( ` /download/codeql-bundle-20200601/codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle-pinned.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( undefined , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
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 ) ;
( 0 , nock _1 . default ) ( "https://example.com" )
2020-09-22 14:38:27 +01:00
. get ( ` /download/codeql-bundle-20200601/codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2020-09-30 16:17:07 +02:00
const platform = process . platform === "win32"
? "win64"
: process . platform === "linux"
? "linux64"
: "osx64" ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://github.com" )
2020-09-30 16:17:07 +02:00
. get ( ` /github/codeql-action/releases/download/ ${ defaults . bundleVersion } /codeql-bundle- ${ platform } .tar.gz ` )
2020-09-22 14:38:27 +01:00
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( undefined , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
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 ) ;
( 0 , nock _1 . default ) ( "https://example.com" )
2020-09-22 14:38:27 +01:00
. get ( ` /download/codeql-bundle-20200601/codeql-bundle.tar.gz ` )
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle-pinned.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
2020-09-22 14:38:27 +01:00
t . assert ( toolcache . find ( "CodeQL" , "0.0.0-20200601" ) ) ;
2020-09-30 16:17:07 +02:00
const platform = process . platform === "win32"
? "win64"
: process . platform === "linux"
? "linux64"
: "osx64" ;
2021-09-10 13:53:13 -07:00
( 0 , nock _1 . default ) ( "https://github.com" )
2020-09-30 16:17:07 +02:00
. get ( ` /github/codeql-action/releases/download/ ${ defaults . bundleVersion } /codeql-bundle- ${ platform } .tar.gz ` )
2020-09-22 14:38:27 +01:00
. replyWithFile ( 200 , path . join ( _ _dirname , ` /../src/testdata/codeql-bundle.tar.gz ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( "latest" , sampleApiDetails , tmpDir , tmpDir , util . GitHubVariant . DOTCOM , ( 0 , logging _1 . getRunnerLogger ) ( true ) , false ) ;
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 ) ;
} ) ;
} ) ;
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 ` ) ) ;
2021-09-10 13:53:13 -07:00
await codeql . setupCodeQL ( undefined , sampleGHAEApiDetails , tmpDir , tmpDir , util . GitHubVariant . GHAE , ( 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 ) ;
( 0 , util _1 . initializeEnvironment ) ( util _1 . Mode . runner , "1.2.3" ) ;
2021-05-20 15:20:32 -07:00
const repoActions = codeql . getCodeQLActionRepository ( logger ) ;
t . deepEqual ( repoActions , "github/codeql-action" ) ;
2021-09-10 13:53:13 -07:00
( 0 , util _1 . initializeEnvironment ) ( util _1 . Mode . actions , "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" ) ;
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" ) ;
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "" ) ;
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" ) ;
await codeqlObject . databaseInterpretResults ( "" , [ ] , "" , "" , "" , "" ) ;
t . true ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--sarif-add-query-help" ) , "--sarif-add-query-help should be present, but it is absent" ) ;
} ) ;
2022-05-09 12:02:19 +00:00
const stubConfig = {
languages : [ languages _1 . Language . cpp ] ,
queries : { } ,
pathsIgnore : [ ] ,
paths : [ ] ,
originalUserInput : { } ,
tempDir : "" ,
toolCacheDir : "" ,
codeQLCmd : "" ,
gitHubVersion : {
type : util . GitHubVariant . DOTCOM ,
} ,
dbLocation : "" ,
packs : { } ,
debugMode : false ,
debugArtifactName : util . DEFAULT _DEBUG _ARTIFACT _NAME ,
debugDatabaseName : util . DEFAULT _DEBUG _DATABASE _NAME ,
injectedMlQueries : false ,
} ;
( 0 , ava _1 . default ) ( "databaseInitCluster() Lua feature flag enabled, but old CLI" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.9.0" ) ;
await codeqlObject . databaseInitCluster ( stubConfig , "" , undefined , undefined , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ feature _flags _1 . FeatureFlag . LuaTracerConfigEnabled ] ) ) ;
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--internal-use-lua-tracing" ) , "--internal-use-lua-tracing should be absent, but it is present" ) ;
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--no-internal-use-lua-tracing" ) , "--no-internal-use-lua-tracing should be absent, but it is present" ) ;
} ) ;
( 0 , ava _1 . default ) ( "databaseInitCluster() Lua feature flag disabled, with old CLI" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.9.0" ) ;
await codeqlObject . databaseInitCluster ( stubConfig , "" , undefined , undefined , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) ) ;
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--internal-use-lua-tracing" ) , "--internal-use-lua-tracing should be absent, but it is present" ) ;
t . false ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--no-internal-use-lua-tracing" ) , "--no-internal-use-lua-tracing should be absent, but it is present" ) ;
} ) ;
( 0 , ava _1 . default ) ( "databaseInitCluster() Lua feature flag enabled, compatible CLI" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.10.0" ) ;
await codeqlObject . databaseInitCluster ( stubConfig , "" , undefined , undefined , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ feature _flags _1 . FeatureFlag . LuaTracerConfigEnabled ] ) ) ;
t . true ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--internal-use-lua-tracing" ) , "--internal-use-lua-tracing should be present, but it is absent" ) ;
} ) ;
( 0 , ava _1 . default ) ( "databaseInitCluster() Lua feature flag disabled, compatible CLI" , async ( t ) => {
const runnerConstructorStub = stubToolRunnerConstructor ( ) ;
const codeqlObject = await codeql . getCodeQLForTesting ( ) ;
sinon . stub ( codeqlObject , "getVersion" ) . resolves ( "2.10.0" ) ;
await codeqlObject . databaseInitCluster ( stubConfig , "" , undefined , undefined , ( 0 , feature _flags _1 . createFeatureFlags ) ( [ ] ) ) ;
t . true ( runnerConstructorStub . firstCall . args [ 1 ] . includes ( "--no-internal-use-lua-tracing" ) , "--no-internal-use-lua-tracing should be present, but it is absent" ) ;
} ) ;
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