Skip to content

Commit ef79560

Browse files
committed
Always enable git_source registries
1 parent 0e974e6 commit ef79560

3 files changed

Lines changed: 66 additions & 11 deletions

File tree

lib/entry-points.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/start-proxy.test.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ const mixedCredentials = [
120120
{ type: "maven_repository", host: "maven.pkg.github.com", token: "def" },
121121
{ type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" },
122122
{ type: "goproxy_server", host: "goproxy.example.com", token: "jkl" },
123-
{ type: "git_source", host: "github.com/github", token: "mno" },
124123
];
125124

125+
const gitSourceCredential = {
126+
type: "git_source",
127+
host: "github.com/github",
128+
token: "mno",
129+
};
130+
126131
test("getCredentials prefers registriesCredentials over registrySecrets", async (t) => {
127132
const registryCredentials = Buffer.from(
128133
JSON.stringify([
@@ -241,7 +246,7 @@ test("getCredentials returns all for a language when specified", async (t) => {
241246
const credentials = startProxyExports.getCredentials(
242247
getRunnerLogger(true),
243248
undefined,
244-
toEncodedJSON(mixedCredentials),
249+
toEncodedJSON([...mixedCredentials, gitSourceCredential]),
245250
BuiltInLanguage.go,
246251
);
247252
t.is(credentials.length, 2);
@@ -284,7 +289,7 @@ test("getCredentials returns all maven_repositories for Java when specified", as
284289
host: "maven2.pkg.github.com",
285290
token: "token2",
286291
},
287-
{ type: "git_source", host: "github.com/github", token: "mno" },
292+
{ type: "goproxy_server", host: "github.com/github", token: "mno" },
288293
];
289294

290295
const credentials = startProxyExports.getCredentials(
@@ -624,16 +629,53 @@ test("getCredentials validates 'replaces-base' correctly", async (t) => {
624629
);
625630
});
626631

627-
test("getCredentials returns no credentials for Actions", async (t) => {
628-
const credentialsInput = toEncodedJSON(mixedCredentials);
632+
test("getCredentials returns only ALWAYS_ENABLED_REGISTRY_TYPE credentials for Actions", async (t) => {
633+
const credentialsInput = toEncodedJSON([
634+
...mixedCredentials,
635+
gitSourceCredential,
636+
]);
629637

630638
const credentials = startProxyExports.getCredentials(
631639
getRunnerLogger(true),
632640
undefined,
633641
credentialsInput,
634642
BuiltInLanguage.actions,
635643
);
636-
t.deepEqual(credentials, []);
644+
645+
for (const credential of credentials) {
646+
t.true(
647+
startProxyExports.ALWAYS_ENABLED_REGISTRY_TYPE.some(
648+
(ty) => ty === credential.type,
649+
),
650+
);
651+
}
652+
});
653+
654+
test("getCredentials always returns ALWAYS_ENABLED_REGISTRY_TYPE credentials for all languages", async (t) => {
655+
const alwaysEnabledCredentials: startProxyExports.Credential[] = [];
656+
657+
for (const alwaysEnabled of startProxyExports.ALWAYS_ENABLED_REGISTRY_TYPE) {
658+
alwaysEnabledCredentials.push({
659+
type: alwaysEnabled,
660+
host: `host-${alwaysEnabled}`,
661+
token: `bar-${alwaysEnabled}`,
662+
url: `url-${alwaysEnabled}`,
663+
});
664+
}
665+
666+
const credentialsInput = toEncodedJSON(alwaysEnabledCredentials);
667+
668+
// Test all languages.
669+
for (const language of Object.values(BuiltInLanguage)) {
670+
const credentials = startProxyExports.getCredentials(
671+
getRunnerLogger(true),
672+
undefined,
673+
credentialsInput,
674+
language,
675+
);
676+
677+
t.deepEqual(credentials, alwaysEnabledCredentials);
678+
}
637679
});
638680

639681
function mockGetApiClient(endpoints: any) {

src/start-proxy.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,16 @@ function isPAT(value: string) {
187187
]);
188188
}
189189

190+
/**
191+
* A list of always-enabled registry types. The registry types in this list are always
192+
* enabled, because generic CodeQL workflow components may use them rather than just
193+
* language-specific components.
194+
*/
195+
export const ALWAYS_ENABLED_REGISTRY_TYPE = ["git_source"];
196+
190197
type RegistryMapping = Partial<Record<BuiltInLanguage, string[]>>;
191198

192-
const LANGUAGE_TO_REGISTRY_TYPE: Required<RegistryMapping> = {
199+
export const LANGUAGE_TO_REGISTRY_TYPE: Required<RegistryMapping> = {
193200
actions: [],
194201
cpp: [],
195202
java: ["maven_repository"],
@@ -233,9 +240,11 @@ function getRegistryAddress(
233240
}
234241
}
235242

236-
// getCredentials returns registry credentials from action inputs.
237-
// It prefers `registries_credentials` over `registry_secrets`.
238-
// If neither is set, it returns an empty array.
243+
/**
244+
* Returns registry credentials from action inputs.
245+
* It prefers `registriesCredentials` over `registrySecrets`.
246+
* If neither is set, it returns an empty array.
247+
*/
239248
export function getCredentials(
240249
logger: Logger,
241250
registrySecrets: string | undefined,
@@ -292,7 +301,10 @@ export function getCredentials(
292301

293302
// Filter credentials based on language if specified. `type` is the registry type.
294303
// E.g., "maven_feed" for Java/Kotlin, "nuget_repository" for C#.
304+
// We always allow types in `ALWAYS_ENABLED_REGISTRY_TYPE` since they can be used by
305+
// other parts of the workflow.
295306
if (
307+
!ALWAYS_ENABLED_REGISTRY_TYPE.some((t) => t === e.type) &&
296308
registryTypeForLanguage &&
297309
!registryTypeForLanguage.some((t) => t === e.type)
298310
) {

0 commit comments

Comments
 (0)