@@ -11,6 +11,14 @@ setupTests(test); |
11 | 11 | const toEncodedJSON = (data: any) => |
12 | 12 | Buffer.from(JSON.stringify(data)).toString("base64"); |
13 | 13 |
|
| 14 | +const mixedCredentials = [ |
| 15 | + { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, |
| 16 | + { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, |
| 17 | + { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, |
| 18 | + { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, |
| 19 | + { type: "git_source", host: "github.com/github", token: "mno" }, |
| 20 | +]; |
| 21 | + |
14 | 22 | test("getCredentials prefers registriesCredentials over registrySecrets", async (t) => { |
15 | 23 | const registryCredentials = Buffer.from( |
16 | 24 | JSON.stringify([ |
@@ -94,13 +102,6 @@ test("getCredentials throws error when credential missing host and url", async ( |
94 | 102 | }); |
95 | 103 |
|
96 | 104 | test("getCredentials filters by language when specified", async (t) => { |
97 | | - const mixedCredentials = [ |
98 | | - { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, |
99 | | - { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, |
100 | | - { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, |
101 | | - { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, |
102 | | - ]; |
103 | | - |
104 | 105 | const credentials = startProxyExports.getCredentials( |
105 | 106 | getRunnerLogger(true), |
106 | 107 | undefined, |
@@ -111,13 +112,21 @@ test("getCredentials filters by language when specified", async (t) => { |
111 | 112 | t.is(credentials[0].type, "maven_repository"); |
112 | 113 | }); |
113 | 114 |
|
| 115 | +test("getCredentials returns all for a language when specified", async (t) => { |
| 116 | + const credentials = startProxyExports.getCredentials( |
| 117 | + getRunnerLogger(true), |
| 118 | + undefined, |
| 119 | + toEncodedJSON(mixedCredentials), |
| 120 | + "go", |
| 121 | + ); |
| 122 | + t.is(credentials.length, 2); |
| 123 | + |
| 124 | + const credentialsTypes = credentials.map((c) => c.type); |
| 125 | + t.assert(credentialsTypes.includes("goproxy_server")); |
| 126 | + t.assert(credentialsTypes.includes("git_source")); |
| 127 | +}); |
| 128 | + |
114 | 129 | test("getCredentials returns all credentials when no language specified", async (t) => { |
115 | | - const mixedCredentials = [ |
116 | | - { type: "npm_registry", host: "npm.pkg.github.com", token: "abc" }, |
117 | | - { type: "maven_repository", host: "maven.pkg.github.com", token: "def" }, |
118 | | - { type: "nuget_feed", host: "nuget.pkg.github.com", token: "ghi" }, |
119 | | - { type: "goproxy_server", host: "goproxy.example.com", token: "jkl" }, |
120 | | - ]; |
121 | 130 | const credentialsInput = toEncodedJSON(mixedCredentials); |
122 | 131 |
|
123 | 132 | const credentials = startProxyExports.getCredentials( |
|