Sitelet https://github.com/github/codeql-action/pull/3853/commits/30e0f4391d8c181f5d82c2b34c870a0f13849cb0
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use /v3/index.json for NuGet feed check
  • Loading branch information
mbg committed Apr 28, 2026
commit 30e0f4391d8c181f5d82c2b34c870a0f13849cb0
16 changes: 15 additions & 1 deletion lib/start-proxy-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/start-proxy/reachability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "./../testing-utils";
import {
checkConnections,
connectionTestConfig,
ReachabilityBackend,
ReachabilityError,
} from "./reachability";
Expand Down Expand Up @@ -118,3 +119,34 @@ test("checkConnections - handles invalid URLs", async (t) => {
`Finished testing connections`,
]);
});

test("checkConnections - appends extra paths", async (t) => {
const backend = new MockReachabilityBackend();
const checkConnection = sinon.stub(backend, "checkConnection").resolves(200);

const messages = await withRecordingLoggerAsync(async (logger) => {
const reachable = await checkConnections(
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
logger,
{
...proxyInfo,
registries: [{ ...nugetFeed, url: "https://api.nuget.org/" }],
},
backend,
);
});
checkExpectedLogMessages(t, messages, [
`Testing connection to https://api.nuget.org/`,
`Successfully tested connection to https://api.nuget.org/`,
`Finished testing connections`,
]);

t.true(
checkConnection.calledWith(
sinon.match(
new URL(
`https://api.nuget.org/${connectionTestConfig["nuget_feed"]?.path}`,
),
),
),
);
});
34 changes: 33 additions & 1 deletion src/start-proxy/reachability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ import { getErrorMessage } from "../util";

import { getAddressString, ProxyInfo, Registry } from "./types";

/** Represents registry-specific connection test configurations. */
export interface ConnectionTestConfig {
Comment thread
mbg marked this conversation as resolved.
/** An optional path to append to the end of the base url. */
path?: string;
}

/** A partial mapping of registry types to extra connection test configurations. */
export const connectionTestConfig: Partial<
Record<string, ConnectionTestConfig>
> = {
nuget_feed: { path: "v3/index.json" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume v3 is old enough that we can rely on this existing / the proxy only supports v3 anyway?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK nothing else exists. I.e. I am not aware that v2/index.json was ever a thing. See also https://learn.microsoft.com/en-us/nuget/api/service-index#versioning

};

/**
* Applies the registry-specific check configuration to the base URL, if any and applicable.
*/
export function makeTestUrl(
config: ConnectionTestConfig | undefined,
base: URL,
): URL {
if (config?.path === undefined) {
return base;
}
if (base.pathname.endsWith(config.path)) {
return base;
}
return new url(/sitelet?url=https%3A%2F%2Fgithub.com%2Fgithub%2Fcodeql-action%2Fpull%2F3853%2Fcommits%2Fconfig.path%2C%2520base);
}

export class ReachabilityError extends Error {
constructor(public readonly statusCode?: number | undefined) {
super();
Expand Down Expand Up @@ -92,6 +121,7 @@ export async function checkConnections(
}

for (const registry of proxy.registries) {
const config = connectionTestConfig[registry.type];
const address = getAddressString(registry);
const url = URL.parse(address);

Expand All @@ -102,9 +132,11 @@ export async function checkConnections(
continue;
}

const testUrl = makeTesturl(/sitelet?url=https%3A%2F%2Fgithub.com%2Fgithub%2Fcodeql-action%2Fpull%2F3853%2Fcommits%2Fconfig%2C%2520url);

try {
logger.debug(`Testing connection to ${url}...`);
const statusCode = await backend.checkConnection(url);
const statusCode = await backend.checkConnection(testUrl);

logger.info(`Successfully tested connection to ${url} (${statusCode})`);
result.add(registry);
Expand Down