Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow BASIC authentication (all caps) #3471

Merged
merged 1 commit into from Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/main/src/plugin/image-registry.spec.ts
Expand Up @@ -106,6 +106,15 @@ test('Should extract auth registry with Amazon ECR registry', async () => {
expect(authInfo?.scope).toBeUndefined();
});

test('Should be able to use a local Sonatype Nexus instance that uses localhost and BASIC response', async () => {
const authInfo = imageRegistry.extractAuthData('BASIC realm="http://localhost:8082",service="test.sonatype.com"');
expect(authInfo).toBeDefined();
expect(authInfo?.authUrl).toBe('http://localhost:8082');
expect(authInfo?.scheme).toBe('BASIC');
expect(authInfo?.service).toBe('test.sonatype.com');
expect(authInfo?.scope).toBeUndefined();
});

test('Should extract auth registry with quay.io registry', async () => {
const authInfo = imageRegistry.extractAuthData('Bearer realm="https://quay.io/v2/auth",service="quay.io"');
expect(authInfo).toBeDefined();
Expand All @@ -115,6 +124,12 @@ test('Should extract auth registry with quay.io registry', async () => {
expect(authInfo?.scope).toBeUndefined();
});

test('Expect extractAuthData to fail since its not Bearer, Basic or BASIC. ', async () => {
const authInfo = imageRegistry.extractAuthData('Foobar realm="https://quay.io/v2/auth",service="quay.io"');
// Expect it to be undefined since its not Bearer, Basic or BASIC.
expect(authInfo).toBeUndefined();
});

test('should map short name to hub server', () => {
const registryServer = imageRegistry.extractRegistryServerFromImage('mysql');
expect(registryServer).toBe('docker.io');
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/plugin/image-registry.ts
Expand Up @@ -300,7 +300,7 @@ export class ImageRegistry {
// Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull,push"
// need to extract realm, service and scope parameters with a regexp
const WWW_AUTH_REGEXP =
/(?<scheme>Bearer|Basic) realm="(?<realm>[^"]+)"(,service="(?<service>[^"]+)")?(,scope="(?<scope>[^"]+)")?/;
/(?<scheme>Bearer|Basic|BASIC) realm="(?<realm>[^"]+)"(,service="(?<service>[^"]+)")?(,scope="(?<scope>[^"]+)")?/;

const parsed = WWW_AUTH_REGEXP.exec(wwwAuthenticate);
if (parsed?.groups) {
Expand Down