mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-09 16:16:55 +00:00
Add a test for Vault token retrieval retries
When the retryVaultTokenRetrieval option is set in the action we will now see HTTP errors when retrieving the Vault token retried. This adds a test block to test the client.post that is performed during the token retrieval is retried on an HTTP error, like a 500.
This commit is contained in:
parent
05074af563
commit
5fc6aa310b
1 changed files with 86 additions and 1 deletions
|
|
@ -66,4 +66,89 @@ describe('exportSecrets retries', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('exportSecrets retrieve token 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");
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('method', expect.anything())
|
||||||
|
.mockReturnValueOnce('approle')
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('roleId', expect.anything())
|
||||||
|
.mockReturnValueOnce('roleId')
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('secretId', expect.anything())
|
||||||
|
.mockReturnValueOnce('secretId')
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('retryVaultTokenRetrieval', expect.anything())
|
||||||
|
.mockReturnValueOnce('true')
|
||||||
|
|
||||||
|
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 mockKvRetrieval() {
|
||||||
|
server.on({
|
||||||
|
path: '/v1/kv/mysecret',
|
||||||
|
reply: {
|
||||||
|
status: 200,
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
body: function() {
|
||||||
|
return JSON.stringify({ data: {"key": "value"} })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockStatusCodes(statusCodes) {
|
||||||
|
server.on({
|
||||||
|
method: 'POST',
|
||||||
|
path: '/v1/auth/approle/login',
|
||||||
|
reply: {
|
||||||
|
status: function() {
|
||||||
|
let status = statusCodes[calls];
|
||||||
|
calls += 1;
|
||||||
|
return status;
|
||||||
|
},
|
||||||
|
body: function() {
|
||||||
|
return JSON.stringify({ auth: {"client_token": "token"} });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('retries on 500 status code', (done) => {
|
||||||
|
mockKvRetrieval()
|
||||||
|
mockStatusCodes([500, 201])
|
||||||
|
exportSecrets().then(() => {
|
||||||
|
expect(calls).toEqual(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue