mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-14 18:13:45 +00:00
Set default role, stop mocks conflicting across tests, cache generated test JWT
This commit is contained in:
parent
4bd533450e
commit
e3eff1b249
1 changed files with 17 additions and 9 deletions
|
|
@ -51,6 +51,9 @@ function mockGithubOIDCResponse(aud= "https://github.com/hashicorp/vault-action"
|
||||||
return rsasign.KJUR.jws.JWS.sign(alg, JSON.stringify(header), JSON.stringify(payload), decryptedKey);
|
return rsasign.KJUR.jws.JWS.sign(alg, JSON.stringify(header), JSON.stringify(payload), decryptedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The sign call inside this function takes a while to run, so cache the default JWT in a constant.
|
||||||
|
const defaultGithubJwt = mockGithubOIDCResponse();
|
||||||
|
|
||||||
describe('jwt auth', () => {
|
describe('jwt auth', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Verify Connection
|
// Verify Connection
|
||||||
|
|
@ -99,7 +102,8 @@ describe('jwt auth', () => {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
json: {
|
json: {
|
||||||
jwt_validation_pubkeys: publicRsaKey
|
jwt_validation_pubkeys: publicRsaKey,
|
||||||
|
default_role: "default"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -198,20 +202,20 @@ describe('jwt auth', () => {
|
||||||
.calledWith('jwtPrivateKey')
|
.calledWith('jwtPrivateKey')
|
||||||
.mockReturnValueOnce('');
|
.mockReturnValueOnce('');
|
||||||
|
|
||||||
when(core.getInput)
|
|
||||||
.calledWith('role')
|
|
||||||
.mockReturnValueOnce('default');
|
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('secrets')
|
.calledWith('secrets')
|
||||||
.mockReturnValueOnce('secret/data/test secret');
|
.mockReturnValueOnce('secret/data/test secret');
|
||||||
|
|
||||||
when(core.getIDToken)
|
|
||||||
.calledWith()
|
|
||||||
.mockReturnValueOnce(mockGithubOIDCResponse());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('successfully authenticates', async () => {
|
it('successfully authenticates', async () => {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('role')
|
||||||
|
.mockReturnValueOnce('default');
|
||||||
|
|
||||||
|
when(core.getIDToken)
|
||||||
|
.calledWith()
|
||||||
|
.mockReturnValueOnce(defaultGithubJwt);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||||
});
|
});
|
||||||
|
|
@ -238,6 +242,10 @@ describe('jwt auth', () => {
|
||||||
.calledWith('role')
|
.calledWith('role')
|
||||||
.mockReturnValueOnce(null);
|
.mockReturnValueOnce(null);
|
||||||
|
|
||||||
|
when(core.getIDToken)
|
||||||
|
.calledWith()
|
||||||
|
.mockReturnValueOnce(defaultGithubJwt);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue