mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 07:06:56 +00:00
Retry on 412 status codes (#333)
* Retry on 412 status codes * Add retry tests
This commit is contained in:
parent
ad04ab9377
commit
55a11671e0
6 changed files with 956 additions and 2 deletions
|
|
@ -1,5 +1,9 @@
|
|||
## Unreleased
|
||||
|
||||
Bugs:
|
||||
|
||||
* Errors due to replication delay for tokens will now be retried [GH-333](https://github.com/hashicorp/vault-action/pull/333)
|
||||
|
||||
## 2.4.1 (April 28th, 2022)
|
||||
|
||||
Improvements:
|
||||
|
|
|
|||
873
package-lock.json
generated
873
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -58,6 +58,7 @@
|
|||
"@zeit/ncc": "^0.22.3",
|
||||
"jest": "^28.1.1",
|
||||
"jest-when": "^3.5.1",
|
||||
"mock-http-server": "^1.4.5",
|
||||
"semantic-release": "^19.0.3"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,15 @@ async function exportSecrets() {
|
|||
const defaultOptions = {
|
||||
prefixUrl: vaultUrl,
|
||||
headers: {},
|
||||
https: {}
|
||||
https: {},
|
||||
retry: {
|
||||
statusCodes: [
|
||||
...got.defaults.options.retry.statusCodes,
|
||||
// Vault returns 412 when the token in use hasn't yet been replicated
|
||||
// to the performance replica queried. See issue #332.
|
||||
412,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
const tlsSkipVerify = (core.getInput('tlsSkipVerify', { required: false }) || 'false').toLowerCase() != 'false';
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ const got = require('got');
|
|||
const {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseResponse,
|
||||
parseHeadersInput
|
||||
} = require('./action');
|
||||
|
||||
|
|
|
|||
69
src/retries.test.js
Normal file
69
src/retries.test.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
jest.mock('@actions/core');
|
||||
|
||||
const core = require('@actions/core');
|
||||
const ServerMock = require("mock-http-server");
|
||||
const { exportSecrets } = require("./action");
|
||||
const { when } = require('jest-when');
|
||||
|
||||
describe('exportSecrets retries', () => {
|
||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||
var calls = 0;
|
||||
|
||||
beforeEach((done) => {
|
||||
calls = 0;
|
||||
jest.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('token', expect.anything())
|
||||
.mockReturnValueOnce('EXAMPLE');
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('secrets', expect.anything())
|
||||
.mockReturnValueOnce("kv/mysecret key");
|
||||
|
||||
server.start(() => {
|
||||
expect(server.getHttpPort()).not.toBeNull();
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach((done) => {
|
||||
server.stop(done);
|
||||
});
|
||||
|
||||
function mockStatusCodes(statusCodes) {
|
||||
server.on({
|
||||
path: '/v1/kv/mysecret',
|
||||
reply: {
|
||||
status: function() {
|
||||
let status = statusCodes[calls];
|
||||
calls += 1;
|
||||
return status;
|
||||
},
|
||||
headers: { "content-type": "application/json" },
|
||||
body: function() {
|
||||
return JSON.stringify({ data: {"key": "value"} })
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it('retries on 412 status code', (done) => {
|
||||
mockStatusCodes([412, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('retries on 500 status code', (done) => {
|
||||
mockStatusCodes([500, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue