-
Notifications
You must be signed in to change notification settings - Fork 5
/
secrets.test.js
54 lines (51 loc) · 2.47 KB
/
secrets.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
jest.mock('@actions/core');
jest.mock('./akeyless_api');
jest.mock('akeyless');
core = require('@actions/core');;
akeylessApi = require('./akeyless_api');
akeyless = require('akeyless');
secrets = require('./secrets');
test('export dynamic secrets', async () => {
const dynamicSecret = {
'access_key_id': 'aws-access-key',
'secret_access_key': 'aws-secret-key',
'session_token': 'aws-session-token',
}
core.setSecret = jest.fn(() => {});
core.setOutput = jest.fn(() => {});
core.exportVariable = jest.fn(() => {});
api = jest.fn(() => {});
api.getDynamicSecretValue = jest.fn(() => Promise.resolve(dynamicSecret));
akeylessApi.api = jest.fn(() => api);
akeyless.GetDynamicSecretValue.constructFromObject = jest.fn(() => 'get_dynamic_secret_body');
await secrets.exportDynamicSecrets('akeyless-token', {'/path/to/dynamic/producer': 'sup'}, 'https://api.akeyless.io', true, true);
expect(api.getDynamicSecretValue).toHaveBeenCalledWith('get_dynamic_secret_body');
expect(akeyless.GetDynamicSecretValue.constructFromObject).toHaveBeenCalledWith({
'token': 'akeyless-token',
'name': '/path/to/dynamic/producer',
});
expect(core.setSecret).toHaveBeenCalledWith('sup', dynamicSecret);
expect(core.setOutput).toHaveBeenCalledWith('sup', dynamicSecret);
expect(core.exportVariable).toHaveBeenCalledWith('sup', JSON.stringify(dynamicSecret));
});
test('export static secrets', async () => {
const staticSecret = {
'/path/to/static/secret': 'super secret',
}
core.setSecret = jest.fn(() => {});
core.setOutput = jest.fn(() => {});
core.exportVariable = jest.fn(() => {});
api = jest.fn(() => {});
api.getSecretValue = jest.fn(() => Promise.resolve(staticSecret));
akeylessApi.api = jest.fn(() => api);
akeyless.GetSecretValue.constructFromObject = jest.fn(() => 'get_static_secret_body');
await secrets.exportStaticSecrets('akeyless-token', {'/path/to/static/secret': 'sup'}, 'https://api.akeyless.io', true, true);
expect(api.getSecretValue).toHaveBeenCalledWith('get_static_secret_body');
expect(akeyless.GetSecretValue.constructFromObject).toHaveBeenCalledWith({
'token': 'akeyless-token',
'names': ['/path/to/static/secret'],
});
expect(core.setSecret).toHaveBeenCalledWith('super secret');
expect(core.setOutput).toHaveBeenCalledWith('sup', 'super secret');
expect(core.exportVariable).toHaveBeenCalledWith('sup', 'super secret');
});