Skip to content

Commit 9ac6701

Browse files
committed
Add more leniency towards registries that malform WWW-Authenticate.
Some OCI registries return a mangled WWW-Authenticate header. For example, versions of Sonatype Nexus Repository Manager return: WWW-Authenticate: BASIC realm="..." The current handling of the WWW-Authenticate header leaves the CLI to error when pushing to these registries. This commit adds more leniency and accepts weirdly capitalised versions of the header also.
1 parent cf9f0ea commit 9ac6701

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/spec-configuration/httpOCIRegistry.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ export async function requestEnsureAuthenticated(params: CommonParams, httpOptio
7070
return;
7171
}
7272

73-
switch (wwwAuthenticate.split(' ')[0]) {
73+
const authenticationMethod = wwwAuthenticate.split(' ')[0];
74+
switch (authenticationMethod.toLowerCase()) {
7475
// Basic realm="localhost"
75-
case 'Basic':
76+
case 'basic':
7677

7778
output.write(`[httpOci] Attempting to authenticate via 'Basic' auth.`, LogLevel.Trace);
7879

@@ -87,7 +88,7 @@ export async function requestEnsureAuthenticated(params: CommonParams, httpOptio
8788
break;
8889

8990
// Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull,push"
90-
case 'Bearer':
91+
case 'bearer':
9192

9293
output.write(`[httpOci] Attempting to authenticate via 'Bearer' auth.`, LogLevel.Trace);
9394

@@ -116,7 +117,7 @@ export async function requestEnsureAuthenticated(params: CommonParams, httpOptio
116117
break;
117118

118119
default:
119-
output.write(`[httpOci] ERR: Unsupported authentication mode '${wwwAuthenticate.split(' ')[0]}'`, LogLevel.Error);
120+
output.write(`[httpOci] ERR: Unsupported authentication mode '${authenticationMethod}'`, LogLevel.Error);
120121
return;
121122
}
122123

0 commit comments

Comments
 (0)