Skip to content

Commit efb92e2

Browse files
committed
Skip checks for non-URLs for now
1 parent 2b5b614 commit efb92e2

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

lib/start-proxy-action.js

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

src/start-proxy/reachability.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ProxyInfo, Registry } from "./types";
1616
setupTests(test);
1717

1818
class MockReachabilityBackend implements ReachabilityBackend {
19-
public async checkConnection(_registry: Registry): Promise<number> {
19+
public async checkConnection(_url: URL): Promise<number> {
2020
return 200;
2121
}
2222
}
@@ -94,3 +94,27 @@ test("checkConnections - handles other exceptions", async (t) => {
9494
`Finished testing connections`,
9595
]);
9696
});
97+
98+
test("checkConnections - handles invalid URLs", async (t) => {
99+
const backend = new MockReachabilityBackend();
100+
const messages = await withRecordingLoggerAsync(async (logger) => {
101+
const reachable = await checkConnections(
102+
logger,
103+
{
104+
...proxyInfo,
105+
registries: [
106+
{
107+
type: "nuget_feed",
108+
url: "localhost",
109+
},
110+
],
111+
},
112+
backend,
113+
);
114+
t.is(reachable.size, 0);
115+
});
116+
checkExpectedLogMessages(t, messages, [
117+
`Skipping check for localhost since it is not a valid URL.`,
118+
`Finished testing connections`,
119+
]);
120+
});

src/start-proxy/reachability.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class ReachabilityError extends Error {
1919
*/
2020
export interface ReachabilityBackend {
2121
/**
22-
* Performs a test HTTP request to the specified `registry`. Resolves to the status code,
22+
* Performs a test HTTP request to the specified `url`. Resolves to the status code,
2323
* if a successful status code was obtained. Otherwise throws
2424
*
25-
* @param registry The registry to try and reach.
25+
* @param url The URL of the registry to try and reach.
2626
* @returns The successful status code (in the `<400` range).
2727
*/
28-
checkConnection: (registry: Registry) => Promise<number>;
28+
checkConnection: (url: URL) => Promise<number>;
2929
}
3030

3131
class NetworkReachabilityBackend implements ReachabilityBackend {
@@ -35,10 +35,10 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
3535
this.agent = new HttpsProxyAgent(`http://${proxy.host}:${proxy.port}`);
3636
}
3737

38-
public async checkConnection(registry: Registry): Promise<number> {
38+
public async checkConnection(url: URL): Promise<number> {
3939
return new Promise((resolve, reject) => {
4040
const req = https.request(
41-
getAddressString(registry),
41+
url,
4242
{
4343
agent: this.agent,
4444
method: "HEAD",
@@ -93,22 +93,27 @@ export async function checkConnections(
9393

9494
for (const registry of proxy.registries) {
9595
const address = getAddressString(registry);
96-
try {
97-
logger.debug(`Testing connection to ${address}...`);
98-
const statusCode = await backend.checkConnection(registry);
96+
const url = URL.parse(address);
9997

98+
if (url === null) {
10099
logger.info(
101-
`Successfully tested connection to ${address} (${statusCode})`,
100+
`Skipping check for ${address} since it is not a valid URL.`,
102101
);
102+
continue;
103+
}
104+
105+
try {
106+
logger.debug(`Testing connection to ${url}...`);
107+
const statusCode = await backend.checkConnection(url);
108+
109+
logger.info(`Successfully tested connection to ${url} (${statusCode})`);
103110
result.add(registry);
104111
} catch (e) {
105112
if (e instanceof ReachabilityError && e.statusCode !== undefined) {
106-
logger.error(
107-
`Connection test to ${address} failed. (${e.statusCode})`,
108-
);
113+
logger.error(`Connection test to ${url} failed. (${e.statusCode})`);
109114
} else {
110115
logger.error(
111-
`Connection test to ${address} failed: ${getErrorMessage(e)}`,
116+
`Connection test to ${url} failed: ${getErrorMessage(e)}`,
112117
);
113118
}
114119
}

0 commit comments

Comments
 (0)