@rockcarver/frodo-lib 0.12.2-2 → 0.12.2-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,283 @@
1
+ import axios from 'axios';
2
+ import MockAdapter from 'axios-mock-adapter';
3
+ import { SecretsRaw, state } from '../index';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ const mock = new MockAdapter(axios);
11
+ state.default.session.setTenant('https://openam-frodo-dev.forgeblocks.com/am');
12
+ state.default.session.setRealm('alpha');
13
+ state.default.session.setCookieName('cookieName');
14
+ state.default.session.setCookieValue('cookieValue');
15
+ describe('SecretsApi - getSecrets()', () => {
16
+ test('getSecrets() 1: Get all secrets - success', async () => {
17
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecrets/secrets.json'), 'utf8'));
18
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets').reply(200, mockResponse);
19
+ const response = await SecretsRaw.getSecrets();
20
+ expect(response).toBeTruthy();
21
+ expect(response).toMatchObject(mockResponse);
22
+ });
23
+ test('getSecrets() 2: Get all secrets - error', async () => {
24
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecrets/error.json'), 'utf8'));
25
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets').reply(500, mockResponse);
26
+ expect.assertions(4);
27
+
28
+ try {
29
+ await SecretsRaw.getSecrets();
30
+ } catch (error) {
31
+ // console.dir(error);
32
+ expect(error).toBeTruthy();
33
+ expect(error.response.status).toBe(500);
34
+ expect(error.response.data.code).toBe(500);
35
+ expect(error.response.data.message).toBe('Server Error');
36
+ }
37
+ });
38
+ });
39
+ describe('SecretsApi - getSecret()', () => {
40
+ test('getSecret() 1: Get existing secret: esv-volkerstestsecret1', async () => {
41
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecret/esv-volkerstestsecret1.json'), 'utf8'));
42
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1').reply(200, mockResponse);
43
+ const response = await SecretsRaw.getSecret('esv-volkerstestsecret1');
44
+ expect(response).toBeTruthy();
45
+ expect(response).toMatchObject(mockResponse);
46
+ });
47
+ test('getSecret() 2: Get non-existing secret: esv-does-not-exist', async () => {
48
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecret/esv-does-not-exist.json'), 'utf8'));
49
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-does-not-exist').reply(404, mockResponse);
50
+ expect.assertions(4);
51
+
52
+ try {
53
+ await SecretsRaw.getSecret('esv-does-not-exist');
54
+ } catch (error) {
55
+ // console.dir(error);
56
+ expect(error).toBeTruthy();
57
+ expect(error.response.status).toBe(404);
58
+ expect(error.response.data.code).toBe(404);
59
+ expect(error.response.data.message).toBe('The secret does not exist or does not have a version');
60
+ }
61
+ });
62
+ });
63
+ describe('SecretsApi - putSecret()', () => {
64
+ test('putSecret() 1: Create secret: esv-volkerstestsecret1 - success', async () => {
65
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/putSecret/esv-volkerstestsecret1.json'), 'utf8'));
66
+ mock.onPut('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1').reply(200, mockResponse);
67
+ const response = await SecretsRaw.putSecret('esv-volkerstestsecret1', "Volker's Test Secret Value", "Volker's Test Secret Description", 'generic', true);
68
+ expect(response).toBeTruthy();
69
+ expect(response).toMatchObject(mockResponse);
70
+ });
71
+ test('putSecret() 2: Create secret: esv-volkerstestsecret1 - error', async () => {
72
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/putSecret/error.json'), 'utf8'));
73
+ mock.onPut('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1').reply(500, mockResponse);
74
+ expect.assertions(4);
75
+
76
+ try {
77
+ await SecretsRaw.putSecret('esv-volkerstestsecret1', "Volker's Test Secret Value", "Volker's Test Secret Description", 'generic', true);
78
+ } catch (error) {
79
+ // console.dir(error);
80
+ expect(error).toBeTruthy();
81
+ expect(error.response.status).toBe(500);
82
+ expect(error.response.data.code).toBe(500);
83
+ expect(error.response.data.message).toBe('Server Error');
84
+ }
85
+ });
86
+ });
87
+ describe('SecretsApi - setSecretDescription()', () => {
88
+ test('setSecretDescription() 1: Set secret description: esv-volkerstestsecret1 - success', async () => {
89
+ const mockResponse = '';
90
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1?_action=setDescription').reply(200, mockResponse);
91
+ const response = await SecretsRaw.setSecretDescription('esv-volkerstestsecret1', "Volker's Updated Test Secret Description");
92
+ expect(response).toBe('');
93
+ });
94
+ test('setSecretDescription() 2: Set secret description: esv-volkerstestsecret1 - error', async () => {
95
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/setSecretDescription/error.json'), 'utf8'));
96
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1?_action=setDescription').reply(500, mockResponse);
97
+ expect.assertions(4);
98
+
99
+ try {
100
+ await SecretsRaw.setSecretDescription('esv-volkerstestsecret1', "Volker's Updated Test Secret Description");
101
+ } catch (error) {
102
+ // console.dir(error);
103
+ expect(error).toBeTruthy();
104
+ expect(error.response.status).toBe(500);
105
+ expect(error.response.data.code).toBe(500);
106
+ expect(error.response.data.message).toBe('Server Error');
107
+ }
108
+ });
109
+ });
110
+ describe('SecretsApi - deleteSecret()', () => {
111
+ test('deleteSecret() 1: Delete secret: esv-volkerstestsecret1 - success', async () => {
112
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/deleteSecret/esv-volkerstestsecret1.json'), 'utf8'));
113
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1').reply(200, mockResponse);
114
+ const response = await SecretsRaw.deleteSecret('esv-volkerstestsecret1');
115
+ expect(response).toBeTruthy();
116
+ expect(response).toMatchObject(mockResponse);
117
+ });
118
+ test('deleteSecret() 2: Delete secret: esv-volkerstestsecret1 - error', async () => {
119
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/deleteSecret/error.json'), 'utf8'));
120
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1').reply(500, mockResponse);
121
+ expect.assertions(4);
122
+
123
+ try {
124
+ await SecretsRaw.deleteSecret('esv-volkerstestsecret1');
125
+ } catch (error) {
126
+ // console.dir(error);
127
+ expect(error).toBeTruthy();
128
+ expect(error.response.status).toBe(500);
129
+ expect(error.response.data.code).toBe(500);
130
+ expect(error.response.data.message).toBe('Server Error');
131
+ }
132
+ });
133
+ });
134
+ describe('SecretsApi - getSecretVersions()', () => {
135
+ test('getSecretVersions() 1: Get versions of existing secret: esv-volkerstestsecret1', async () => {
136
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecretVersions/esv-volkerstestsecret1.json'), 'utf8'));
137
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions').reply(200, mockResponse);
138
+ const response = await SecretsRaw.getSecretVersions('esv-volkerstestsecret1');
139
+ expect(response).toBeTruthy();
140
+ expect(response).toMatchObject(mockResponse);
141
+ });
142
+ test('getSecretVersions() 2: Get versions of non-existing secret: esv-does-not-exist', async () => {
143
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getSecretVersions/esv-does-not-exist.json'), 'utf8'));
144
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-does-not-exist/versions').reply(404, mockResponse);
145
+ expect.assertions(4);
146
+
147
+ try {
148
+ await SecretsRaw.getSecretVersions('esv-does-not-exist');
149
+ } catch (error) {
150
+ // console.dir(error);
151
+ expect(error).toBeTruthy();
152
+ expect(error.response.status).toBe(404);
153
+ expect(error.response.data.code).toBe(404);
154
+ expect(error.response.data.message).toBe('The secret does not exist or does not have a version');
155
+ }
156
+ });
157
+ });
158
+ describe('SecretsApi - createNewVersionOfSecret()', () => {
159
+ test('createNewVersionOfSecret() 1: Create new version of existing secret: esv-volkerstestsecret1 - success', async () => {
160
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/createNewVersionOfSecret/esv-volkerstestsecret1.json'), 'utf8'));
161
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions?_action=create').reply(200, mockResponse);
162
+ const response = await SecretsRaw.createNewVersionOfSecret('esv-volkerstestsecret1', "Volker's Test Secret Value");
163
+ expect(response).toBeTruthy();
164
+ expect(response).toMatchObject(mockResponse);
165
+ });
166
+ test('createNewVersionOfSecret() 2: Create new version of existing secret: esv-volkerstestsecret1 - error', async () => {
167
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/createNewVersionOfSecret/error.json'), 'utf8'));
168
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions?_action=create').reply(500, mockResponse);
169
+ expect.assertions(4);
170
+
171
+ try {
172
+ await SecretsRaw.createNewVersionOfSecret('esv-volkerstestsecret1', "Volker's Test Secret Value");
173
+ } catch (error) {
174
+ // console.dir(error);
175
+ expect(error).toBeTruthy();
176
+ expect(error.response.status).toBe(500);
177
+ expect(error.response.data.code).toBe(500);
178
+ expect(error.response.data.message).toBe('Server Error');
179
+ }
180
+ });
181
+ test('createNewVersionOfSecret() 3: Create new version of non-existing secret: esv-does-not-exist - error', async () => {
182
+ const mockResponse = fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/createNewVersionOfSecret/esv-does-not-exist.txt'), 'utf8');
183
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions?_action=create').reply(500, mockResponse);
184
+ expect.assertions(3);
185
+
186
+ try {
187
+ await SecretsRaw.createNewVersionOfSecret('esv-volkerstestsecret1', "Volker's Test Secret Value");
188
+ } catch (error) {
189
+ // console.dir(error);
190
+ expect(error).toBeTruthy();
191
+ expect(error.response.status).toBe(500);
192
+ expect(error.response.data).toBe(mockResponse);
193
+ }
194
+ });
195
+ });
196
+ describe('SecretsApi - getVersionOfSecret()', () => {
197
+ test('getVersionOfSecret() 1: Get version 2 of existing secret: esv-volkerstestsecret1', async () => {
198
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getVersionOfSecret/esv-volkerstestsecret1_v2.json'), 'utf8'));
199
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions/2').reply(200, mockResponse);
200
+ const response = await SecretsRaw.getVersionOfSecret('esv-volkerstestsecret1', '2');
201
+ expect(response).toBeTruthy();
202
+ expect(response).toMatchObject(mockResponse);
203
+ });
204
+ test('getVersionOfSecret() 2: Get version 2 of non-existing secret: esv-does-not-exist', async () => {
205
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/getVersionOfSecret/esv-does-not-exist_v2.json'), 'utf8'));
206
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-does-not-exist/versions/2').reply(500, mockResponse);
207
+ expect.assertions(4);
208
+
209
+ try {
210
+ await SecretsRaw.getVersionOfSecret('esv-does-not-exist', '2');
211
+ } catch (error) {
212
+ // console.dir(error);
213
+ expect(error).toBeTruthy();
214
+ expect(error.response.status).toBe(500);
215
+ expect(error.response.data.code).toBe(500);
216
+ expect(error.response.data.message).toBe('Failed to update secret version');
217
+ }
218
+ });
219
+ });
220
+ describe('SecretsApi - setStatusOfVersionOfSecret()', () => {
221
+ test('setStatusOfVersionOfSecret() 1: Disable version 2 of existing secret: esv-volkerstestsecret1 - success', async () => {
222
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/setStatusOfVersionOfSecret/esv-volkerstestsecret1_v2_DISABLED.json'), 'utf8'));
223
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions/2?_action=changestatus').reply(200, mockResponse);
224
+ const response = await SecretsRaw.setStatusOfVersionOfSecret('esv-volkerstestsecret1', '2', SecretsRaw.VersionOfSecretStatus.DISABLED);
225
+ expect(response).toBeTruthy();
226
+ expect(response).toMatchObject(mockResponse);
227
+ });
228
+ test('setStatusOfVersionOfSecret() 2: Disable version 2 of existing secret: esv-volkerstestsecret1 - error', async () => {
229
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/setStatusOfVersionOfSecret/error.json'), 'utf8'));
230
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions/2?_action=changestatus').reply(500, mockResponse);
231
+ expect.assertions(4);
232
+
233
+ try {
234
+ await SecretsRaw.setStatusOfVersionOfSecret('esv-volkerstestsecret1', '2', SecretsRaw.VersionOfSecretStatus.DISABLED);
235
+ } catch (error) {
236
+ // console.dir(error);
237
+ expect(error).toBeTruthy();
238
+ expect(error.response.status).toBe(500);
239
+ expect(error.response.data.code).toBe(500);
240
+ expect(error.response.data.message).toBe('Server Error');
241
+ }
242
+ });
243
+ test('setStatusOfVersionOfSecret() 3: Disable version 2 of non-existing secret: esv-does-not-exist - error', async () => {
244
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/setStatusOfVersionOfSecret/esv-does-not-exist_v2_DISABLED.json'), 'utf8'));
245
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-does-not-exist/versions/2?_action=changestatus').reply(404, mockResponse);
246
+ expect.assertions(4);
247
+
248
+ try {
249
+ await SecretsRaw.setStatusOfVersionOfSecret('esv-does-not-exist', '2', SecretsRaw.VersionOfSecretStatus.DISABLED);
250
+ } catch (error) {
251
+ // console.dir(error);
252
+ expect(error).toBeTruthy();
253
+ expect(error.response.status).toBe(404);
254
+ expect(error.response.data.code).toBe(404);
255
+ expect(error.response.data.message).toBe('The secret does not exist or does not have a version');
256
+ }
257
+ });
258
+ });
259
+ describe('SecretsApi - deleteVersionOfSecret()', () => {
260
+ test('deleteVersionOfSecret() 1: Delete version 2 of secret: esv-volkerstestsecret1 - success', async () => {
261
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/deleteVersionOfSecret/esv-volkerstestsecret1_v2.json'), 'utf8'));
262
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions/2').reply(200, mockResponse);
263
+ const response = await SecretsRaw.deleteVersionOfSecret('esv-volkerstestsecret1', '2');
264
+ expect(response).toBeTruthy();
265
+ expect(response).toMatchObject(mockResponse);
266
+ });
267
+ test('deleteVersionOfSecret() 2: Delete version 2 of secret: esv-volkerstestsecret1 - error', async () => {
268
+ const mockResponse = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/SecretsApi/deleteVersionOfSecret/error.json'), 'utf8'));
269
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/secrets/esv-volkerstestsecret1/versions/2').reply(500, mockResponse);
270
+ expect.assertions(4);
271
+
272
+ try {
273
+ await SecretsRaw.deleteVersionOfSecret('esv-volkerstestsecret1', '2');
274
+ } catch (error) {
275
+ // console.dir(error);
276
+ expect(error).toBeTruthy();
277
+ expect(error.response.status).toBe(500);
278
+ expect(error.response.data.code).toBe(500);
279
+ expect(error.response.data.message).toBe('Server Error');
280
+ }
281
+ });
282
+ });
283
+ //# sourceMappingURL=SecretsApi.test.js.map
@@ -17,7 +17,7 @@ const getApiConfig = () => {
17
17
  };
18
18
  /**
19
19
  * Get all variables
20
- * @returns {Promise} a promise that resolves to an object containing an array of variable objects
20
+ * @returns {Promise<unknown[]>} a promise that resolves to an array of variable objects
21
21
  */
22
22
 
23
23
 
@@ -28,12 +28,12 @@ export async function getVariables() {
28
28
  } = await generateESVApi(getApiConfig()).get(urlString, {
29
29
  withCredentials: true
30
30
  });
31
- return data.result;
31
+ return data;
32
32
  }
33
33
  /**
34
34
  * Get variable by id/name
35
- * @param {String} variableId variable id/name
36
- * @returns {Promise} a promise that resolves to an object containing a variable object
35
+ * @param {string} variableId variable id/name
36
+ * @returns {Promise<unknown>} a promise that resolves to a variable object
37
37
  */
38
38
 
39
39
  export async function getVariable(variableId) {
@@ -47,10 +47,10 @@ export async function getVariable(variableId) {
47
47
  }
48
48
  /**
49
49
  * Put variable by id/name
50
- * @param {String} variableId variable id/name
51
- * @param {String} value variable value
52
- * @param {String} description variable description
53
- * @returns {Promise} a promise that resolves to an object containing a variable object
50
+ * @param {string} variableId variable id/name
51
+ * @param {string} value variable value
52
+ * @param {string} description variable description
53
+ * @returns {Promise<unknown>} a promise that resolves to a variable object
54
54
  */
55
55
 
56
56
  export async function putVariable(variableId, value, description) {
@@ -67,9 +67,9 @@ export async function putVariable(variableId, value, description) {
67
67
  }
68
68
  /**
69
69
  * Set variable description
70
- * @param {*} variableId variable id/name
71
- * @param {*} description variable description
72
- * @returns {Promise} a promise that resolves to an object containing a status object
70
+ * @param {string} variableId variable id/name
71
+ * @param {string} description variable description
72
+ * @returns {Promise<unknown>} a promise that resolves to a status object
73
73
  */
74
74
 
75
75
  export async function setVariableDescription(variableId, description) {
@@ -85,8 +85,8 @@ export async function setVariableDescription(variableId, description) {
85
85
  }
86
86
  /**
87
87
  * Delete variable by id/name
88
- * @param {String} variableId variable id/name
89
- * @returns {Promise} a promise that resolves to an object containing a variable object
88
+ * @param {string} variableId variable id/name
89
+ * @returns {Promise<unknown>} a promise that resolves to a variable object
90
90
  */
91
91
 
92
92
  export async function deleteVariable(variableId) {
@@ -0,0 +1,229 @@
1
+ import axios from 'axios';
2
+ import MockAdapter from 'axios-mock-adapter';
3
+ import { VariablesRaw, state } from '../index';
4
+ const mock = new MockAdapter(axios);
5
+ state.default.session.setTenant('https://openam-frodo-dev.forgeblocks.com/am');
6
+ state.default.session.setRealm('alpha');
7
+ state.default.session.setCookieName('cookieName');
8
+ state.default.session.setCookieValue('cookieValue');
9
+ describe('VariablesApi - getVariables()', () => {
10
+ test('getVariables() 0: Method is implemented', async () => {
11
+ expect(VariablesRaw.getVariables).toBeDefined();
12
+ });
13
+ test('getVariables() 1: Get all variables - success', async () => {
14
+ const mockResponse = {
15
+ pagedResultsCookie: null,
16
+ remainingPagedResults: -1,
17
+ result: [{
18
+ _id: 'esv-twilio-phone-number',
19
+ description: 'Twilio phone number. Get your own at: https://twilio.com',
20
+ expressionType: '',
21
+ lastChangeDate: '2022-08-12T21:27:18.560Z',
22
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
23
+ loaded: true,
24
+ valueBase64: 'KzEzMTc2NDQzMTA3'
25
+ }, {
26
+ _id: 'esv-461016d8d2-configurationpropertiescredentials',
27
+ description: 'Configuration parameter /configurationProperties/credentials in file idm/conf/provisioner.openicf-OUD.json',
28
+ expressionType: '',
29
+ lastChangeDate: '2021-12-09T16:48:18.482Z',
30
+ lastChangedBy: 'forgerock-automation',
31
+ loaded: true,
32
+ valueBase64: 'RnJkcC0yMDEw'
33
+ }, {
34
+ _id: 'esv-twilio-account-sid',
35
+ description: 'Twilio account SID. Get your own at: https://twilio.com',
36
+ expressionType: '',
37
+ lastChangeDate: '2022-08-12T21:26:32.688Z',
38
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
39
+ loaded: true,
40
+ valueBase64: 'QUM3NTA0MTVlMzE2M2EyZTU3YjdhZWVhN2VlZDgyZDk0NA=='
41
+ }, {
42
+ _id: 'esv-ipv4-cidr-access-rules',
43
+ description: 'IPv4 CIDR access rules: { "allow": [ "address/mask" ] }',
44
+ expressionType: '',
45
+ lastChangeDate: '2022-08-25T20:16:54.243Z',
46
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
47
+ loaded: true,
48
+ valueBase64: 'eyAiYWxsb3ciOiBbICIxNDUuMTE4LjAuMC8xNiIsICIxMzIuMzUuMC4wLzE2IiwgIjEwMS4yMjYuMC4wLzE2IiwgIjk5LjcyLjI4LjE4Mi8zMiIgXSB9'
49
+ }, {
50
+ _id: 'esv-volkerstestvariable1',
51
+ description: "Volker's Updated Test Variable Description",
52
+ expressionType: '',
53
+ lastChangeDate: '2022-04-10T20:55:39.746Z',
54
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
55
+ loaded: true,
56
+ valueBase64: 'Vm9sa2VyJ3MgVGVzdCBWYXJpYWJsZSBWYWx1ZQo='
57
+ }],
58
+ resultCount: 5,
59
+ totalPagedResults: -1,
60
+ totalPagedResultsPolicy: 'NONE'
61
+ };
62
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/variables').reply(200, mockResponse);
63
+ const response = await VariablesRaw.getVariables();
64
+ expect(response).toBeTruthy();
65
+ expect(response).toMatchObject(mockResponse);
66
+ });
67
+ test('getVariables() 2: Get all variables - error', async () => {
68
+ const mockResponse = {
69
+ message: 'Server Error',
70
+ code: 500
71
+ };
72
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/variables').reply(500, mockResponse);
73
+ expect.assertions(4);
74
+
75
+ try {
76
+ await VariablesRaw.getVariables();
77
+ } catch (error) {
78
+ // console.dir(error);
79
+ expect(error).toBeTruthy();
80
+ expect(error.response.status).toBe(500);
81
+ expect(error.response.data.code).toBe(500);
82
+ expect(error.response.data.message).toBe('Server Error');
83
+ }
84
+ });
85
+ });
86
+ describe('VariablesApi - getVariable()', () => {
87
+ test('getVariable() 0: Method is implemented', async () => {
88
+ expect(VariablesRaw.getVariable).toBeDefined();
89
+ });
90
+ test('getVariable() 1: Get existing variable: esv-volkerstestvariable1', async () => {
91
+ const mockResponse = {
92
+ _id: 'esv-volkerstestvariable1',
93
+ description: "Volker's Updated Test Variable Description",
94
+ expressionType: '',
95
+ lastChangeDate: '2022-04-10T20:55:39.746Z',
96
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
97
+ loaded: true,
98
+ valueBase64: 'Vm9sa2VyJ3MgVGVzdCBWYXJpYWJsZSBWYWx1ZQo='
99
+ };
100
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1').reply(200, mockResponse);
101
+ const response = await VariablesRaw.getVariable('esv-volkerstestvariable1');
102
+ expect(response).toBeTruthy();
103
+ expect(response).toMatchObject(mockResponse);
104
+ });
105
+ test('getVariable() 2: Get non-existing variable: esv-does-not-exist', async () => {
106
+ const mockResponse = {
107
+ code: 404,
108
+ message: 'The variable does not exist'
109
+ };
110
+ mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-does-not-exist').reply(404, mockResponse);
111
+ expect.assertions(4);
112
+
113
+ try {
114
+ await VariablesRaw.getVariable('esv-does-not-exist');
115
+ } catch (error) {
116
+ // console.dir(error);
117
+ expect(error).toBeTruthy();
118
+ expect(error.response.status).toBe(404);
119
+ expect(error.response.data.code).toBe(404);
120
+ expect(error.response.data.message).toBe('The variable does not exist');
121
+ }
122
+ });
123
+ });
124
+ describe('VariablesApi - putVariable()', () => {
125
+ test('putVariable() 0: Method is implemented', async () => {
126
+ expect(VariablesRaw.putVariable).toBeDefined();
127
+ });
128
+ test('putVariable() 1: Create variable: esv-volkerstestvariable1 - success', async () => {
129
+ const mockResponse = {
130
+ _id: 'esv-volkerstestvariable1',
131
+ description: "Volker's Updated Test Variable Description",
132
+ expressionType: '',
133
+ lastChangeDate: '2022-04-10T20:55:39.746Z',
134
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
135
+ loaded: true,
136
+ valueBase64: 'Vm9sa2VyJ3MgVGVzdCBWYXJpYWJsZSBWYWx1ZQo='
137
+ };
138
+ mock.onPut('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1').reply(200, mockResponse);
139
+ const response = await VariablesRaw.putVariable('esv-volkerstestvariable1', "Volker's Test Variable Value", "Volker's Test Variable Description");
140
+ expect(response).toBeTruthy();
141
+ expect(response).toMatchObject(mockResponse);
142
+ });
143
+ test('putVariable() 2: Create variable: esv-volkerstestvariable1 - error', async () => {
144
+ const mockResponse = {
145
+ code: 500,
146
+ message: 'Server Error'
147
+ };
148
+ mock.onPut('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1').reply(500, mockResponse);
149
+ expect.assertions(4);
150
+
151
+ try {
152
+ await VariablesRaw.putVariable('esv-volkerstestvariable1', "Volker's Test Variable Value", "Volker's Test Variable Description");
153
+ } catch (error) {
154
+ // console.dir(error);
155
+ expect(error).toBeTruthy();
156
+ expect(error.response.status).toBe(500);
157
+ expect(error.response.data.code).toBe(500);
158
+ expect(error.response.data.message).toBe('Server Error');
159
+ }
160
+ });
161
+ });
162
+ describe('VariablesApi - setVariableDescription()', () => {
163
+ test('setVariableDescription() 0: Method is implemented', async () => {
164
+ expect(VariablesRaw.setVariableDescription).toBeDefined();
165
+ });
166
+ test('setVariableDescription() 1: Set variable description: esv-volkerstestvariable1 - success', async () => {
167
+ const mockResponse = '';
168
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1?_action=setDescription').reply(200, mockResponse);
169
+ const response = await VariablesRaw.setVariableDescription('esv-volkerstestvariable1', "Volker's Updated Test Secret Description");
170
+ expect(response).toBe('');
171
+ });
172
+ test('setVariableDescription() 2: Set variable description: esv-volkerstestvariable1 - error', async () => {
173
+ const mockResponse = {
174
+ code: 500,
175
+ message: 'Server Error'
176
+ };
177
+ mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1?_action=setDescription').reply(500, mockResponse);
178
+ expect.assertions(4);
179
+
180
+ try {
181
+ await VariablesRaw.setVariableDescription('esv-volkerstestvariable1', "Volker's Updated Test Secret Description");
182
+ } catch (error) {
183
+ // console.dir(error);
184
+ expect(error).toBeTruthy();
185
+ expect(error.response.status).toBe(500);
186
+ expect(error.response.data.code).toBe(500);
187
+ expect(error.response.data.message).toBe('Server Error');
188
+ }
189
+ });
190
+ });
191
+ describe('VariablesApi - deleteVariable()', () => {
192
+ test('deleteVariable() 0: Method is implemented', async () => {
193
+ expect(VariablesRaw.deleteVariable).toBeDefined();
194
+ });
195
+ test('deleteVariable() 1: Delete variable: esv-volkerstestvariable1 - success', async () => {
196
+ const mockResponse = {
197
+ _id: 'esv-volkerstestvariable1',
198
+ description: "Volker's Updated Test Variable Description",
199
+ expressionType: '',
200
+ lastChangeDate: '2022-04-10T20:55:39.746Z',
201
+ lastChangedBy: 'c5f3cf35-4cc1-42f9-80b3-59e1ca842510',
202
+ loaded: true,
203
+ valueBase64: 'Vm9sa2VyJ3MgVGVzdCBWYXJpYWJsZSBWYWx1ZQo='
204
+ };
205
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1').reply(200, mockResponse);
206
+ const response = await VariablesRaw.deleteVariable('esv-volkerstestvariable1');
207
+ expect(response).toBeTruthy();
208
+ expect(response).toMatchObject(mockResponse);
209
+ });
210
+ test('deleteVariable() 2: Delete variable: esv-volkerstestvariable1 - error', async () => {
211
+ const mockResponse = {
212
+ code: 500,
213
+ message: 'Cannot delete a variable that has an existing config placeholder'
214
+ };
215
+ mock.onDelete('https://openam-frodo-dev.forgeblocks.com/environment/variables/esv-volkerstestvariable1').reply(500, mockResponse);
216
+ expect.assertions(4);
217
+
218
+ try {
219
+ await VariablesRaw.deleteVariable('esv-volkerstestvariable1');
220
+ } catch (error) {
221
+ // console.dir(error);
222
+ expect(error).toBeTruthy();
223
+ expect(error.response.status).toBe(500);
224
+ expect(error.response.data.code).toBe(500);
225
+ expect(error.response.data.message).toBe('Cannot delete a variable that has an existing config placeholder');
226
+ }
227
+ });
228
+ });
229
+ //# sourceMappingURL=VariablesApi.test.js.map
package/esm/index.mjs CHANGED
@@ -11,7 +11,9 @@ export function getVersion() {
11
11
 
12
12
  export * as NodeRaw from './api/NodeApi';
13
13
  export * as TreeRaw from './api/TreeApi';
14
- export * as StartupRaw from './api/StartupApi'; // Ops Layer
14
+ export * as StartupRaw from './api/StartupApi';
15
+ export * as SecretsRaw from './api/SecretsApi';
16
+ export * as VariablesRaw from './api/VariablesApi'; // Ops Layer
15
17
 
16
18
  export * as Admin from './ops/AdminOps';
17
19
  export * as Authenticate from './ops/AuthenticateOps';
@@ -1,5 +1,5 @@
1
1
  import { createKeyValueTable, createProgressIndicator, createTable, printMessage, stopProgressIndicator, updateProgressIndicator } from './utils/Console';
2
- import { createNewVersionOfSecret, deleteSecret, deleteVersionOfSecret, getSecret, getSecrets, getSecretVersions, putSecret, setSecretDescription, setStatusOfVersionOfSecret } from '../api/SecretsApi';
2
+ import { createNewVersionOfSecret, deleteSecret, deleteVersionOfSecret, getSecret, getSecrets, getSecretVersions, putSecret, setSecretDescription, setStatusOfVersionOfSecret, VersionOfSecretStatus } from '../api/SecretsApi';
3
3
  import wordwrap from './utils/Wordwrap';
4
4
  import { resolveUserName } from './ManagedObjectOps';
5
5
  /**
@@ -11,7 +11,7 @@ export async function listSecrets(long) {
11
11
  let secrets = [];
12
12
 
13
13
  try {
14
- secrets = await getSecrets();
14
+ secrets = (await getSecrets()).result;
15
15
  } catch (error) {
16
16
  printMessage(`${error.message}`, 'error');
17
17
  printMessage(error.response.data, 'error');
@@ -101,7 +101,7 @@ export async function deleteSecretCmd(secretId) {
101
101
 
102
102
  export async function deleteSecretsCmd() {
103
103
  try {
104
- const secrets = await getSecrets();
104
+ const secrets = (await getSecrets()).result;
105
105
  createProgressIndicator(secrets.length, `Deleting secrets...`);
106
106
 
107
107
  for (const secret of secrets) {
@@ -202,7 +202,7 @@ export async function activateVersionOfSecret(secretId, version) {
202
202
  createProgressIndicator(undefined, `Activating version ${version} of secret ${secretId}...`, 'indeterminate');
203
203
 
204
204
  try {
205
- await setStatusOfVersionOfSecret(secretId, version, 'ENABLED');
205
+ await setStatusOfVersionOfSecret(secretId, version, VersionOfSecretStatus.ENABLED);
206
206
  stopProgressIndicator(`Activated version ${version} of secret ${secretId}`, 'success');
207
207
  } catch (error) {
208
208
  stopProgressIndicator(`Error: ${error.response.data.code} - ${error.response.data.message}`, 'fail');
@@ -218,7 +218,7 @@ export async function deactivateVersionOfSecret(secretId, version) {
218
218
  createProgressIndicator(undefined, `Deactivating version ${version} of secret ${secretId}...`, 'indeterminate');
219
219
 
220
220
  try {
221
- await setStatusOfVersionOfSecret(secretId, version, 'DISABLED');
221
+ await setStatusOfVersionOfSecret(secretId, version, VersionOfSecretStatus.DISABLED);
222
222
  stopProgressIndicator(`Deactivated version ${version} of secret ${secretId}`, 'success');
223
223
  } catch (error) {
224
224
  stopProgressIndicator(`Error: ${error.response.data.code} - ${error.response.data.message}`, 'fail');
@@ -20,8 +20,8 @@ export async function checkForUpdates() {
20
20
  createProgressIndicator(undefined, `Checking for updates to apply...`, 'indeterminate');
21
21
 
22
22
  try {
23
- updates.secrets = (await getSecrets()).filter(secret => !secret.loaded);
24
- updates.variables = (await getVariables()).filter(variable => !variable.loaded);
23
+ updates.secrets = (await getSecrets()).result.filter(secret => !secret.loaded);
24
+ updates.variables = (await getVariables()).result.filter(variable => !variable.loaded);
25
25
  } catch (error) {
26
26
  stopProgressIndicator(`Error: ${error.response.data.code} - ${error.response.data.message}`, 'fail');
27
27
  }
@@ -12,7 +12,7 @@ export async function listVariables(long) {
12
12
  let variables = [];
13
13
 
14
14
  try {
15
- variables = await getVariables();
15
+ variables = (await getVariables()).result;
16
16
  } catch (error) {
17
17
  printMessage(`${error.message}`, 'error');
18
18
  printMessage(error.response.data, 'error');
@@ -105,7 +105,7 @@ export async function deleteVariableCmd(variableId) {
105
105
 
106
106
  export async function deleteVariablesCmd() {
107
107
  try {
108
- const variables = await getVariables();
108
+ const variables = (await getVariables()).result;
109
109
  createProgressIndicator(variables.length, `Deleting variable...`);
110
110
 
111
111
  for (const variable of variables) {