Skip to content

Commit 6085805

Browse files
committed
Append / to end of registries url
Avoids a bug in 2.10.4. Also, add some better handling for invalid registries blocks.
1 parent 5974446 commit 6085805

File tree

7 files changed

+119
-30
lines changed

7 files changed

+119
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ No user facing changes.
4242
## 2.1.15 - 28 Jun 2022
4343

4444
- CodeQL query packs listed in the `packs` configuration field will be skipped if their target language is not being analyzed in the current Actions job. Previously, this would throw an error. [#1116](https://github.com/github/codeql-action/pull/1116)
45-
- The combination of python2 and poetry is no longer supported. See https://github.com/actions/setup-python/issues/374 for more details. [#1124](https://github.com/github/codeql-action/pull/1124)
45+
- The combination of python2 and poetry is no longer supported. See <https://github.com/actions/setup-python/issues/374> for more details. [#1124](https://github.com/github/codeql-action/pull/1124)
4646
- Update default CodeQL bundle version to 2.10.0. [#1123](https://github.com/github/codeql-action/pull/1123)
4747

4848
## 2.1.14 - 22 Jun 2022

lib/config-utils.js

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

lib/config-utils.js.map

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

lib/config-utils.test.js

Lines changed: 36 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

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

src/config-utils.test.ts

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,17 +2277,25 @@ test("downloadPacks-with-registries", async (t) => {
22772277

22782278
const registries = [
22792279
{
2280+
// no slash
22802281
url: "http://ghcr.io",
22812282
packages: ["codeql/*", "dsp-testing/*"],
22822283
token: "not-a-token",
22832284
},
22842285
{
2286+
// with slash
22852287
url: "https://containers.GHEHOSTNAME1/v2/",
22862288
packages: "semmle/*",
22872289
token: "still-not-a-token",
22882290
},
22892291
];
22902292

2293+
// append a slash to the first url
2294+
const expectedRegistries = registries.map((r, i) => ({
2295+
packages: r.packages,
2296+
url: i === 0 ? `${r.url}/` : r.url,
2297+
}));
2298+
22912299
const expectedConfigFile = path.join(tmpDir, "qlconfig.yml");
22922300
const packDownloadStub = sinon.stub();
22932301
packDownloadStub.callsFake((packs, configFile) => {
@@ -2303,10 +2311,7 @@ test("downloadPacks-with-registries", async (t) => {
23032311
const config = yaml.load(fs.readFileSync(configFile, "utf8")) as {
23042312
registries: configUtils.RegistryConfigNoCredentials[];
23052313
};
2306-
t.deepEqual(
2307-
config.registries,
2308-
registries.map((r) => ({ url: r.url, packages: r.packages }))
2309-
);
2314+
t.deepEqual(config.registries, expectedRegistries);
23102315
return {
23112316
packs,
23122317
};
@@ -2375,24 +2380,61 @@ test("downloadPacks-with-registries fails on 2.10.3", async (t) => {
23752380
getVersion: () => Promise.resolve("2.10.3"),
23762381
});
23772382
await t.throwsAsync(
2378-
async () =>
2379-
// packs are supplied for go, java, and python
2380-
// analyzed languages are java, javascript, and python
2381-
{
2382-
/* packs are supplied for go, java, and python*/
2383-
/* analyzed languages are java, javascript, and python*/
2384-
return await configUtils.downloadPacks(
2385-
codeQL,
2386-
[Language.javascript, Language.java, Language.python],
2387-
{},
2388-
registries,
2389-
sampleApiDetails,
2390-
tmpDir,
2391-
logger
2392-
);
2393-
},
2383+
async () => {
2384+
return await configUtils.downloadPacks(
2385+
codeQL,
2386+
[Language.javascript, Language.java, Language.python],
2387+
{},
2388+
registries,
2389+
sampleApiDetails,
2390+
tmpDir,
2391+
logger
2392+
);
2393+
},
2394+
{ instanceOf: Error },
2395+
"'registries' input is not supported on CodeQL versions less than 2.10.4."
2396+
);
2397+
});
2398+
});
2399+
2400+
test("downloadPacks-with-registries fails with invalid registries block", async (t) => {
2401+
// same thing, but this time include a registries block and
2402+
// associated env vars
2403+
return await util.withTmpDir(async (tmpDir) => {
2404+
process.env.GITHUB_TOKEN = "not-a-token";
2405+
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
2406+
const logger = getRunnerLogger(true);
2407+
2408+
const registries = [
2409+
{
2410+
// missing url property
2411+
packages: ["codeql/*", "dsp-testing/*"],
2412+
token: "not-a-token",
2413+
},
2414+
{
2415+
url: "https://containers.GHEHOSTNAME1/v2/",
2416+
packages: "semmle/*",
2417+
token: "still-not-a-token",
2418+
},
2419+
];
2420+
2421+
const codeQL = setCodeQL({
2422+
getVersion: () => Promise.resolve("2.10.4"),
2423+
});
2424+
await t.throwsAsync(
2425+
async () => {
2426+
return await configUtils.downloadPacks(
2427+
codeQL,
2428+
[Language.javascript, Language.java, Language.python],
2429+
{},
2430+
registries as any,
2431+
sampleApiDetails,
2432+
tmpDir,
2433+
logger
2434+
);
2435+
},
23942436
{ instanceOf: Error },
2395-
"'registries' input is not supported on CodeQL versions less than 2.10.5."
2437+
"Invalid 'registries' input. Must be an array of objects with 'url' and 'packages' properties."
23962438
);
23972439
});
23982440
});

src/config-utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,9 +1900,19 @@ export async function downloadPacks(
19001900
function createRegistriesBlock(registries: RegistryConfigWithCredentials[]): {
19011901
registries: RegistryConfigNoCredentials[];
19021902
} {
1903+
if (
1904+
!Array.isArray(registries) ||
1905+
registries.some((r) => !r.url || !r.packages)
1906+
) {
1907+
throw new Error(
1908+
"Invalid 'registries' input. Must be an array of objects with 'url' and 'packages' properties."
1909+
);
1910+
}
1911+
19031912
// be sure to remove the `token` field from the registry before writing it to disk.
19041913
const safeRegistries = registries.map((registry) => ({
1905-
url: registry.url,
1914+
// ensure the url ends with a slash to avoid a bug in the CLI 2.10.4
1915+
url: !registry?.url.endsWith("/") ? `${registry.url}/` : registry.url,
19061916
packages: registry.packages,
19071917
}));
19081918
const qlconfig = {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy