Skip to content

Commit cf46341

Browse files
authored
Merge pull request #4007 from github/mbg/use-registry-proxy-for-repo-auth
Use private registry proxy for API requests when available
2 parents 7c4a258 + 7db34ae commit cf46341

12 files changed

Lines changed: 326 additions & 36 deletions

File tree

.github/workflows/__start-proxy.yml

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

lib/entry-points.js

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

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"long": "^5.3.2",
4545
"node-forge": "^1.4.0",
4646
"semver": "^7.8.5",
47-
"uuid": "^14.0.1"
47+
"uuid": "^14.0.1",
48+
"undici": "^6.24.0"
4849
},
4950
"devDependencies": {
5051
"@ava/typescript": "6.0.0",

pr-checks/checks/start-proxy.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ operatingSystems:
66
- windows
77
versions:
88
- linked
9+
env:
10+
CODEQL_ACTION_PROXY_API_REQUESTS: "true"
911
steps:
10-
- uses: ./../action/init
11-
with:
12-
languages: csharp
13-
tools: ${{ steps.prepare-test.outputs.tools-url }}
14-
1512
- name: Setup proxy for registries
1613
id: proxy
1714
uses: ./../action/start-proxy
1815
with:
16+
language: java
1917
registry_secrets: |
2018
[
2119
{
@@ -44,3 +42,14 @@ steps:
4442
|| !contains(steps.proxy.outputs.proxy_urls, 'https://repo.maven.apache.org/maven2/')
4543
|| !contains(steps.proxy.outputs.proxy_urls, 'https://repo1.maven.org/maven2')
4644
run: exit 1
45+
46+
- uses: ./../action/init
47+
env:
48+
CODEQL_PROXY_HOST: ${{ steps.proxy.outputs.proxy_host }}
49+
CODEQL_PROXY_PORT: ${{ steps.proxy.outputs.proxy_port }}
50+
CODEQL_PROXY_CA_CERTIFICATE: ${{ steps.proxy.outputs.proxy_ca_certificate }}
51+
CODEQL_ACTION_NEW_REMOTE_FILE_ADDRESSES: "true"
52+
with:
53+
languages: java
54+
tools: ${{ steps.prepare-test.outputs.tools-url }}
55+
config-file: codeql-action@main:tests/multi-language-repo/.github/codeql/custom-queries.yml

src/api-client.test.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as sinon from "sinon";
66
import * as actionsUtil from "./actions-util";
77
import * as api from "./api-client";
88
import { DO_NOT_RETRY_STATUSES } from "./api-client";
9-
import { ActionsEnvVars } from "./environment";
10-
import { getTestEnv, setupTests } from "./testing-utils";
9+
import { ActionsEnvVars, RegistryProxyVars } from "./environment";
10+
import { callee, getTestEnv, setupTests } from "./testing-utils";
1111
import * as util from "./util";
1212

1313
setupTests(test);
@@ -27,14 +27,17 @@ test.serial("getApiClient", async (t) => {
2727

2828
sinon.stub(actionsUtil, "getRequiredInput").withArgs("token").returns("xyz");
2929

30-
api.getApiClient(env);
30+
const apiClient = api.getApiClient(env);
31+
t.truthy(apiClient);
3132

33+
t.true(githubStub.calledOnce);
3234
t.assert(
3335
githubStub.calledOnceWithExactly({
3436
auth: "token xyz",
3537
baseUrl: "http://api.github.localhost",
3638
log: sinon.match.any,
3739
userAgent: `CodeQL-Action/${actionsUtil.getActionVersion()}`,
40+
request: sinon.match.any,
3841
retry: {
3942
doNotRetry: DO_NOT_RETRY_STATUSES,
4043
},
@@ -204,3 +207,47 @@ test.serial(
204207
}
205208
},
206209
);
210+
211+
test("getRegistryProxy - returns undefined if the proxy is not configured", async (t) => {
212+
const target = callee(api.getRegistryProxy).withArgs();
213+
214+
// Empty environment.
215+
await target.passes(t.is, undefined);
216+
// Only the host.
217+
await target
218+
.withEnv(getTestEnv({ [RegistryProxyVars.PROXY_HOST]: "localhost" }))
219+
.passes(t.is, undefined);
220+
// Only the port.
221+
await target
222+
.withEnv(getTestEnv({ [RegistryProxyVars.PROXY_PORT]: "1234" }))
223+
.passes(t.is, undefined);
224+
});
225+
226+
test("getRegistryProxy - returns value when both vars are set", async (t) => {
227+
await callee(api.getRegistryProxy)
228+
.withArgs()
229+
.withEnv(
230+
getTestEnv({
231+
[RegistryProxyVars.PROXY_HOST]: "localhost",
232+
[RegistryProxyVars.PROXY_PORT]: "1234",
233+
}),
234+
)
235+
.passes(t.truthy);
236+
});
237+
238+
test("getRegistryProxyConfig - gets the configuration from the env vars", async (t) => {
239+
const host = "localhost";
240+
const port = "1234";
241+
const ca = "cert";
242+
243+
await callee(api.getRegistryProxyConfig)
244+
.withArgs()
245+
.withEnv(
246+
getTestEnv({
247+
[RegistryProxyVars.PROXY_HOST]: host,
248+
[RegistryProxyVars.PROXY_PORT]: port,
249+
[RegistryProxyVars.PROXY_CA_CERTIFICATE]: ca,
250+
}),
251+
)
252+
.passes(t.like, { host, port, ca });
253+
});

0 commit comments

Comments
 (0)