diff --git a/lib/entry-points.js b/lib/entry-points.js index 321b9ded49..0310338e16 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -161527,6 +161527,7 @@ function isPAT(value) { GITHUB_PAT_FINE_GRAINED_PATTERN ]); } +var ALWAYS_ENABLED_REGISTRY_TYPE = ["git_source"]; var LANGUAGE_TO_REGISTRY_TYPE = { actions: [], cpp: [], @@ -161591,7 +161592,7 @@ function getCredentials(logger, registrySecrets, registriesCredentials, language } const authConfig = getAuthConfig(e); const address = getRegistryAddress(e); - if (registryTypeForLanguage && !registryTypeForLanguage.some((t) => t === e.type)) { + if (!ALWAYS_ENABLED_REGISTRY_TYPE.some((t) => t === e.type) && registryTypeForLanguage && !registryTypeForLanguage.some((t) => t === e.type)) { continue; } const isPrintable2 = (str) => { diff --git a/src/start-proxy.test.ts b/src/start-proxy.test.ts index 6a905f16b7..178f7b4628 100644 --- a/src/start-proxy.test.ts +++ b/src/start-proxy.test.ts @@ -120,9 +120,14 @@ const mixedCredentials = [ { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, - { type: "git_source", host: "github.com/github", token: "mno" }, ]; +const gitSourceCredential = { + type: "git_source", + host: "github.com/github", + token: "mno", +}; + test("getCredentials prefers registriesCredentials over registrySecrets", async (t) => { const registryCredentials = Buffer.from( JSON.stringify([ @@ -241,7 +246,7 @@ test("getCredentials returns all for a language when specified", async (t) => { const credentials = startProxyExports.getCredentials( getRunnerLogger(true), undefined, - toEncodedJSON(mixedCredentials), + toEncodedJSON([...mixedCredentials, gitSourceCredential]), BuiltInLanguage.go, ); t.is(credentials.length, 2); @@ -284,7 +289,7 @@ test("getCredentials returns all maven_repositories for Java when specified", as host: "maven2.pkg.github.com", token: "token2", }, - { type: "git_source", host: "github.com/github", token: "mno" }, + { type: "goproxy_server", host: "github.com/github", token: "mno" }, ]; const credentials = startProxyExports.getCredentials( @@ -624,8 +629,11 @@ test("getCredentials validates 'replaces-base' correctly", async (t) => { ); }); -test("getCredentials returns no credentials for Actions", async (t) => { - const credentialsInput = toEncodedJSON(mixedCredentials); +test("getCredentials returns only ALWAYS_ENABLED_REGISTRY_TYPE credentials for Actions", async (t) => { + const credentialsInput = toEncodedJSON([ + ...mixedCredentials, + gitSourceCredential, + ]); const credentials = startProxyExports.getCredentials( getRunnerLogger(true), @@ -633,7 +641,41 @@ test("getCredentials returns no credentials for Actions", async (t) => { credentialsInput, BuiltInLanguage.actions, ); - t.deepEqual(credentials, []); + + for (const credential of credentials) { + t.true( + startProxyExports.ALWAYS_ENABLED_REGISTRY_TYPE.some( + (ty) => ty === credential.type, + ), + ); + } +}); + +test("getCredentials always returns ALWAYS_ENABLED_REGISTRY_TYPE credentials for all languages", async (t) => { + const alwaysEnabledCredentials: startProxyExports.Credential[] = []; + + for (const alwaysEnabled of startProxyExports.ALWAYS_ENABLED_REGISTRY_TYPE) { + alwaysEnabledCredentials.push({ + type: alwaysEnabled, + host: `host-${alwaysEnabled}`, + token: `bar-${alwaysEnabled}`, + url: `url-${alwaysEnabled}`, + }); + } + + const credentialsInput = toEncodedJSON(alwaysEnabledCredentials); + + // Test all languages. + for (const language of Object.values(BuiltInLanguage)) { + const credentials = startProxyExports.getCredentials( + getRunnerLogger(true), + undefined, + credentialsInput, + language, + ); + + t.deepEqual(credentials, alwaysEnabledCredentials); + } }); function mockGetApiClient(endpoints: any) { diff --git a/src/start-proxy.ts b/src/start-proxy.ts index 6b956d6473..03056ac4cb 100644 --- a/src/start-proxy.ts +++ b/src/start-proxy.ts @@ -187,9 +187,16 @@ function isPAT(value: string) { ]); } +/** + * A list of always-enabled registry types. The registry types in this list are always + * enabled, because generic CodeQL workflow components may use them rather than just + * language-specific components. + */ +export const ALWAYS_ENABLED_REGISTRY_TYPE = ["git_source"] as const; + type RegistryMapping = Partial>; -const LANGUAGE_TO_REGISTRY_TYPE: Required = { +export const LANGUAGE_TO_REGISTRY_TYPE: Required = { actions: [], cpp: [], java: ["maven_repository"], @@ -233,9 +240,11 @@ function getRegistryAddress( } } -// getCredentials returns registry credentials from action inputs. -// It prefers `registries_credentials` over `registry_secrets`. -// If neither is set, it returns an empty array. +/** + * Returns registry credentials from action inputs. + * It prefers `registriesCredentials` over `registrySecrets`. + * If neither is set, it returns an empty array. + */ export function getCredentials( logger: Logger, registrySecrets: string | undefined, @@ -291,8 +300,11 @@ export function getCredentials( const address = getRegistryAddress(e); // Filter credentials based on language if specified. `type` is the registry type. - // E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#. + // E.g., "maven_repository" for Java/Kotlin, "nuget_feed" for C#. + // We always allow types in `ALWAYS_ENABLED_REGISTRY_TYPE` since they can be used by + // other parts of the workflow. if ( + !ALWAYS_ENABLED_REGISTRY_TYPE.some((t) => t === e.type) && registryTypeForLanguage && !registryTypeForLanguage.some((t) => t === e.type) ) {