mirror of
https://github.com/docker/login-action.git
synced 2026-07-27 18:55:23 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f9303b0b21 |
@@ -35,12 +35,12 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_VERSION }}
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
-
|
-
|
||||||
name: Initialize CodeQL
|
name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@e0647621c2984b5ed2f768cb892365bf2a616ad1 # v4.37.2
|
uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
|
||||||
with:
|
with:
|
||||||
languages: javascript-typescript
|
languages: javascript-typescript
|
||||||
build-mode: none
|
build-mode: none
|
||||||
-
|
-
|
||||||
name: Perform CodeQL Analysis
|
name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@e0647621c2984b5ed2f768cb892365bf2a616ad1 # v4.37.2
|
uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
|
||||||
with:
|
with:
|
||||||
category: "/language:javascript-typescript"
|
category: "/language:javascript-typescript"
|
||||||
|
|||||||
@@ -126,14 +126,8 @@ describe('getOIDCToken', () => {
|
|||||||
expect(core.info).toHaveBeenCalledWith('Docker Hub OIDC token request rate limited, retrying in 0ms (attempt 1/5)');
|
expect(core.info).toHaveBeenCalledWith('Docker Hub OIDC token request rate limited, retrying in 0ms (attempt 1/5)');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws Docker Hub OIDC error responses', async () => {
|
test('throws Docker Hub API errors', async () => {
|
||||||
postSpy.mockResolvedValue(httpResponse(400, JSON.stringify({error: 'invalid_request', error_description: 'bad connection', error_uri: 'https://docs.docker.com'})));
|
postSpy.mockResolvedValue(httpResponse(400, JSON.stringify({description: 'bad connection'})));
|
||||||
await expect(dockerhub.getOIDCToken('docker.io', 'dbowie')).rejects.toThrow('Docker Hub API: bad status code 400: {"error":"invalid_request","error_description":"bad connection","error_uri":"https://docs.docker.com"}');
|
await expect(dockerhub.getOIDCToken('docker.io', 'dbowie')).rejects.toThrow('Docker Hub API: bad status code 400: bad connection');
|
||||||
});
|
|
||||||
|
|
||||||
test('throws rate limited Docker Hub OIDC error response after retries', async () => {
|
|
||||||
postSpy.mockResolvedValue(httpResponse(429, JSON.stringify({error: 'rate_limited', error_description: 'slow down'}), {'retry-after': '0'}));
|
|
||||||
await expect(dockerhub.getOIDCToken('docker.io', 'dbowie')).rejects.toThrow('Docker Hub API: bad status code 429: {"error":"rate_limited","error_description":"slow down"}');
|
|
||||||
expect(postSpy).toHaveBeenCalledTimes(6);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+26
-26
File diff suppressed because one or more lines are too long
+3
-3
File diff suppressed because one or more lines are too long
+16
-11
@@ -108,19 +108,24 @@ const handleResponse = async (resp: httpm.HttpClientResponse): Promise<string> =
|
|||||||
};
|
};
|
||||||
|
|
||||||
const parseError = (statusCode: number, body: string): Error => {
|
const parseError = (statusCode: number, body: string): Error => {
|
||||||
if (body) {
|
|
||||||
let errResp: unknown;
|
|
||||||
try {
|
|
||||||
errResp = JSON.parse(body);
|
|
||||||
} catch {
|
|
||||||
errResp = undefined;
|
|
||||||
}
|
|
||||||
if (errResp !== undefined) {
|
|
||||||
throw new Error(`Docker Hub API: bad status code ${statusCode}: ${JSON.stringify(errResp)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (statusCode === 401) {
|
if (statusCode === 401) {
|
||||||
throw new Error(`Docker Hub API: operation not permitted`);
|
throw new Error(`Docker Hub API: operation not permitted`);
|
||||||
}
|
}
|
||||||
|
if (body) {
|
||||||
|
const errResp = parseErrorBody(body);
|
||||||
|
for (const k of ['description', 'message', 'detail', 'error']) {
|
||||||
|
if (errResp[k]) {
|
||||||
|
throw new Error(`Docker Hub API: bad status code ${statusCode}: ${errResp[k]}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
throw new Error(`Docker Hub API: bad status code ${statusCode}`);
|
throw new Error(`Docker Hub API: bad status code ${statusCode}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseErrorBody = (body: string): Record<string, string> => {
|
||||||
|
try {
|
||||||
|
return <Record<string, string>>JSON.parse(body);
|
||||||
|
} catch {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user