@@ -11,6 +11,14 @@ setupTests(test);
1111const toEncodedJSON = ( data :any ) =>
1212Buffer . from ( JSON . stringify ( data ) ) . toString ( "base64" ) ;
1313
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+
1422test ( "getCredentials prefers registriesCredentials over registrySecrets" , async ( t ) => {
1523const registryCredentials = Buffer . from (
1624JSON . stringify ( [
@@ -94,13 +102,6 @@ test("getCredentials throws error when credential missing host and url", async (
94102} ) ;
95103
96104test ( "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-
104105const credentials = startProxyExports . getCredentials (
105106getRunnerLogger ( true ) ,
106107undefined ,
@@ -111,13 +112,21 @@ test("getCredentials filters by language when specified", async (t) => {
111112t . is ( credentials [ 0 ] . type , "maven_repository" ) ;
112113} ) ;
113114
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+
114129test ( "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- ] ;
121130const credentialsInput = toEncodedJSON ( mixedCredentials ) ;
122131
123132const credentials = startProxyExports . getCredentials (