mirror of
https://github.com/github/codeql-action.git
synced 2026-04-03 02:02:17 +00:00
Skip checks for non-URLs for now
This commit is contained in:
23
lib/start-proxy-action.js
generated
23
lib/start-proxy-action.js
generated
@@ -121728,10 +121728,10 @@ var NetworkReachabilityBackend = class {
|
||||
this.agent = new import_https_proxy_agent.HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`);
|
||||
}
|
||||
agent;
|
||||
async checkConnection(registry) {
|
||||
async checkConnection(url) {
|
||||
return new Promise((resolve2, reject) => {
|
||||
const req = https.request(
|
||||
getAddressString(registry),
|
||||
url,
|
||||
{
|
||||
agent: this.agent,
|
||||
method: "HEAD",
|
||||
@@ -121768,21 +121768,24 @@ async function checkConnections(logger, proxy, backend) {
|
||||
}
|
||||
for (const registry of proxy.registries) {
|
||||
const address = getAddressString(registry);
|
||||
try {
|
||||
logger.debug(`Testing connection to ${address}...`);
|
||||
const statusCode = await backend.checkConnection(registry);
|
||||
const url = URL.parse(address);
|
||||
if (url === null) {
|
||||
logger.info(
|
||||
`Successfully tested connection to ${address} (${statusCode})`
|
||||
`Skipping check for ${address} since it is not a valid URL.`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
logger.debug(`Testing connection to ${url}...`);
|
||||
const statusCode = await backend.checkConnection(url);
|
||||
logger.info(`Successfully tested connection to ${url} (${statusCode})`);
|
||||
result.add(registry);
|
||||
} catch (e) {
|
||||
if (e instanceof ReachabilityError && e.statusCode !== void 0) {
|
||||
logger.error(
|
||||
`Connection test to ${address} failed. (${e.statusCode})`
|
||||
);
|
||||
logger.error(`Connection test to ${url} failed. (${e.statusCode})`);
|
||||
} else {
|
||||
logger.error(
|
||||
`Connection test to ${address} failed: ${getErrorMessage(e)}`
|
||||
`Connection test to ${url} failed: ${getErrorMessage(e)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import { ProxyInfo, Registry } from "./types";
|
||||
setupTests(test);
|
||||
|
||||
class MockReachabilityBackend implements ReachabilityBackend {
|
||||
public async checkConnection(_registry: Registry): Promise<number> {
|
||||
public async checkConnection(_url: URL): Promise<number> {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
@@ -94,3 +94,27 @@ test("checkConnections - handles other exceptions", async (t) => {
|
||||
`Finished testing connections`,
|
||||
]);
|
||||
});
|
||||
|
||||
test("checkConnections - handles invalid URLs", async (t) => {
|
||||
const backend = new MockReachabilityBackend();
|
||||
const messages = await withRecordingLoggerAsync(async (logger) => {
|
||||
const reachable = await checkConnections(
|
||||
logger,
|
||||
{
|
||||
...proxyInfo,
|
||||
registries: [
|
||||
{
|
||||
type: "nuget_feed",
|
||||
url: "localhost",
|
||||
},
|
||||
],
|
||||
},
|
||||
backend,
|
||||
);
|
||||
t.is(reachable.size, 0);
|
||||
});
|
||||
checkExpectedLogMessages(t, messages, [
|
||||
`Skipping check for localhost since it is not a valid URL.`,
|
||||
`Finished testing connections`,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -19,13 +19,13 @@ export class ReachabilityError extends Error {
|
||||
*/
|
||||
export interface ReachabilityBackend {
|
||||
/**
|
||||
* Performs a test HTTP request to the specified `registry`. Resolves to the status code,
|
||||
* Performs a test HTTP request to the specified `url`. Resolves to the status code,
|
||||
* if a successful status code was obtained. Otherwise throws
|
||||
*
|
||||
* @param registry The registry to try and reach.
|
||||
* @param url The URL of the registry to try and reach.
|
||||
* @returns The successful status code (in the `<400` range).
|
||||
*/
|
||||
checkConnection: (registry: Registry) => Promise<number>;
|
||||
checkConnection: (url: URL) => Promise<number>;
|
||||
}
|
||||
|
||||
class NetworkReachabilityBackend implements ReachabilityBackend {
|
||||
@@ -35,10 +35,10 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
|
||||
this.agent = new HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`);
|
||||
}
|
||||
|
||||
public async checkConnection(registry: Registry): Promise<number> {
|
||||
public async checkConnection(url: URL): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request(
|
||||
getAddressString(registry),
|
||||
url,
|
||||
{
|
||||
agent: this.agent,
|
||||
method: "HEAD",
|
||||
@@ -93,22 +93,27 @@ export async function checkConnections(
|
||||
|
||||
for (const registry of proxy.registries) {
|
||||
const address = getAddressString(registry);
|
||||
try {
|
||||
logger.debug(`Testing connection to ${address}...`);
|
||||
const statusCode = await backend.checkConnection(registry);
|
||||
const url = URL.parse(address);
|
||||
|
||||
if (url === null) {
|
||||
logger.info(
|
||||
`Successfully tested connection to ${address} (${statusCode})`,
|
||||
`Skipping check for ${address} since it is not a valid URL.`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
logger.debug(`Testing connection to ${url}...`);
|
||||
const statusCode = await backend.checkConnection(url);
|
||||
|
||||
logger.info(`Successfully tested connection to ${url} (${statusCode})`);
|
||||
result.add(registry);
|
||||
} catch (e) {
|
||||
if (e instanceof ReachabilityError && e.statusCode !== undefined) {
|
||||
logger.error(
|
||||
`Connection test to ${address} failed. (${e.statusCode})`,
|
||||
);
|
||||
logger.error(`Connection test to ${url} failed. (${e.statusCode})`);
|
||||
} else {
|
||||
logger.error(
|
||||
`Connection test to ${address} failed: ${getErrorMessage(e)}`,
|
||||
`Connection test to ${url} failed: ${getErrorMessage(e)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user