Skip to content

Commit 30e0f43

Browse files
committed
Use /v3/index.json for NuGet feed check
1 parent 6153577 commit 30e0f43

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

lib/start-proxy-action.js

Lines changed: 15 additions & 1 deletion
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "./../testing-utils";
99
import {
1010
checkConnections,
11+
connectionTestConfig,
1112
ReachabilityBackend,
1213
ReachabilityError,
1314
} from "./reachability";
@@ -118,3 +119,34 @@ test("checkConnections - handles invalid URLs", async (t) => {
118119
`Finished testing connections`,
119120
]);
120121
});
122+
123+
test("checkConnections - appends extra paths", async (t) => {
124+
const backend = new MockReachabilityBackend();
125+
const checkConnection = sinon.stub(backend, "checkConnection").resolves(200);
126+
127+
const messages = await withRecordingLoggerAsync(async (logger) => {
128+
const reachable = await checkConnections(
129+
logger,
130+
{
131+
...proxyInfo,
132+
registries: [{ ...nugetFeed, url: "https://api.nuget.org/" }],
133+
},
134+
backend,
135+
);
136+
});
137+
checkExpectedLogMessages(t, messages, [
138+
`Testing connection to https://api.nuget.org/`,
139+
`Successfully tested connection to https://api.nuget.org/`,
140+
`Finished testing connections`,
141+
]);
142+
143+
t.true(
144+
checkConnection.calledWith(
145+
sinon.match(
146+
new URL(
147+
`https://api.nuget.org/${connectionTestConfig["nuget_feed"]?.path}`,
148+
),
149+
),
150+
),
151+
);
152+
});

src/start-proxy/reachability.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@ import { getErrorMessage } from "../util";
77

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

10+
/** Represents registry-specific connection test configurations. */
11+
export interface ConnectionTestConfig {
12+
/** An optional path to append to the end of the base url. */
13+
path?: string;
14+
}
15+
16+
/** A partial mapping of registry types to extra connection test configurations. */
17+
export const connectionTestConfig: Partial<
18+
Record<string, ConnectionTestConfig>
19+
> = {
20+
nuget_feed: { path: "v3/index.json" },
21+
};
22+
23+
/**
24+
* Applies the registry-specific check configuration to the base URL, if any and applicable.
25+
*/
26+
export function makeTestUrl(
27+
config: ConnectionTestConfig | undefined,
28+
base: URL,
29+
): URL {
30+
if (config?.path === undefined) {
31+
return base;
32+
}
33+
if (base.pathname.endsWith(config.path)) {
34+
return base;
35+
}
36+
return new URL(config.path, base);
37+
}
38+
1039
export class ReachabilityError extends Error {
1140
constructor(public readonly statusCode?: number | undefined) {
1241
super();
@@ -92,6 +121,7 @@ export async function checkConnections(
92121
}
93122

94123
for (const registry of proxy.registries) {
124+
const config = connectionTestConfig[registry.type];
95125
const address = getAddressString(registry);
96126
const url = URL.parse(address);
97127

@@ -102,9 +132,11 @@ export async function checkConnections(
102132
continue;
103133
}
104134

135+
const testUrl = makeTestUrl(config, url);
136+
105137
try {
106138
logger.debug(`Testing connection to ${url}...`);
107-
const statusCode = await backend.checkConnection(url);
139+
const statusCode = await backend.checkConnection(testUrl);
108140

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

0 commit comments

Comments
 (0)