@rockcarver/frodo-lib 0.12.1 → 0.12.2-0
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.
- package/CHANGELOG.md +5 -1
- package/cjs/api/BaseApi.js +36 -8
- package/cjs/api/BaseApi.js.map +1 -1
- package/cjs/api/NodeApi.js +190 -0
- package/cjs/api/NodeApi.js.map +1 -0
- package/cjs/api/NodeApi.test.js.map +1 -0
- package/cjs/api/StartupApi.js +21 -8
- package/cjs/api/StartupApi.js.map +1 -1
- package/cjs/api/StartupApi.test.js.map +1 -0
- package/cjs/api/TreeApi.js +28 -161
- package/cjs/api/TreeApi.js.map +1 -1
- package/cjs/api/TreeApi.test.js.map +1 -0
- package/cjs/index.js +15 -5
- package/cjs/index.js.map +1 -1
- package/cjs/ops/IdpOps.js +1 -1
- package/cjs/ops/IdpOps.js.map +1 -1
- package/cjs/ops/JourneyOps.js +202 -203
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/StartupOps.js +61 -71
- package/cjs/ops/StartupOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +3 -2
- package/cjs/ops/utils/Console.js.map +1 -1
- package/esm/api/BaseApi.mjs +35 -7
- package/esm/api/NodeApi.mjs +114 -0
- package/esm/api/NodeApi.test.mjs +105 -0
- package/esm/api/StartupApi.mjs +18 -8
- package/esm/api/StartupApi.test.mjs +56 -0
- package/esm/api/TreeApi.mjs +27 -99
- package/esm/api/TreeApi.test.mjs +175 -0
- package/esm/index.mjs +7 -5
- package/esm/ops/IdpOps.mjs +1 -1
- package/esm/ops/JourneyOps.mjs +165 -154
- package/esm/ops/StartupOps.mjs +59 -62
- package/esm/ops/utils/Console.mjs +3 -2
- package/package.json +7 -4
- package/types/api/AuthenticateApi.d.ts +2 -0
- package/types/api/AuthenticateApi.d.ts.map +1 -0
- package/types/api/BaseApi.d.ts +50 -0
- package/types/api/BaseApi.d.ts.map +1 -0
- package/types/api/CirclesOfTrustApi.d.ts +24 -0
- package/types/api/CirclesOfTrustApi.d.ts.map +1 -0
- package/types/api/EmailTemplateApi.d.ts +22 -0
- package/types/api/EmailTemplateApi.d.ts.map +1 -0
- package/types/api/IdmConfigApi.d.ts +39 -0
- package/types/api/IdmConfigApi.d.ts.map +1 -0
- package/types/api/LogApi.d.ts +4 -0
- package/types/api/LogApi.d.ts.map +1 -0
- package/types/api/ManagedObjectApi.d.ts +21 -0
- package/types/api/ManagedObjectApi.d.ts.map +1 -0
- package/types/api/NodeApi.d.ts +38 -0
- package/types/api/NodeApi.d.ts.map +1 -0
- package/types/api/OAuth2ClientApi.d.ts +18 -0
- package/types/api/OAuth2ClientApi.d.ts.map +1 -0
- package/types/api/OAuth2OIDCApi.d.ts +22 -0
- package/types/api/OAuth2OIDCApi.d.ts.map +1 -0
- package/types/api/OAuth2ProviderApi.d.ts +5 -0
- package/types/api/OAuth2ProviderApi.d.ts.map +1 -0
- package/types/api/RealmApi.d.ts +30 -0
- package/types/api/RealmApi.d.ts.map +1 -0
- package/types/api/Saml2Api.d.ts +52 -0
- package/types/api/Saml2Api.d.ts.map +1 -0
- package/types/api/ScriptApi.d.ts +24 -0
- package/types/api/ScriptApi.d.ts.map +1 -0
- package/types/api/SecretsApi.d.ts +10 -0
- package/types/api/SecretsApi.d.ts.map +1 -0
- package/types/api/ServerInfoApi.d.ts +10 -0
- package/types/api/ServerInfoApi.d.ts.map +1 -0
- package/types/api/SocialIdentityProvidersApi.d.ts +31 -0
- package/types/api/SocialIdentityProvidersApi.d.ts.map +1 -0
- package/types/api/StartupApi.d.ts +14 -0
- package/types/api/StartupApi.d.ts.map +1 -0
- package/types/api/ThemeApi.d.ts +54 -0
- package/types/api/ThemeApi.d.ts.map +1 -0
- package/types/api/TreeApi.d.ts +24 -0
- package/types/api/TreeApi.d.ts.map +1 -0
- package/types/api/VariablesApi.d.ts +32 -0
- package/types/api/VariablesApi.d.ts.map +1 -0
- package/types/api/utils/ApiUtils.d.ts +29 -0
- package/types/api/utils/ApiUtils.d.ts.map +1 -0
- package/types/api/utils/Base64.d.ts +30 -0
- package/types/api/utils/Base64.d.ts.map +1 -0
- package/types/index.d.ts +26 -0
- package/types/index.d.ts.map +1 -0
- package/types/ops/AdminOps.d.ts +11 -0
- package/types/ops/AdminOps.d.ts.map +1 -0
- package/types/ops/AuthenticateOps.d.ts +6 -0
- package/types/ops/AuthenticateOps.d.ts.map +1 -0
- package/types/ops/CirclesOfTrustOps.d.ts +40 -0
- package/types/ops/CirclesOfTrustOps.d.ts.map +1 -0
- package/types/ops/ConnectionProfileOps.d.ts +47 -0
- package/types/ops/ConnectionProfileOps.d.ts.map +1 -0
- package/types/ops/EmailTemplateOps.d.ts +40 -0
- package/types/ops/EmailTemplateOps.d.ts.map +1 -0
- package/types/ops/IdmOps.d.ts +27 -0
- package/types/ops/IdmOps.d.ts.map +1 -0
- package/types/ops/IdpOps.d.ts +45 -0
- package/types/ops/IdpOps.d.ts.map +1 -0
- package/types/ops/JourneyOps.d.ts +145 -0
- package/types/ops/JourneyOps.d.ts.map +1 -0
- package/types/ops/LogOps.d.ts +5 -0
- package/types/ops/LogOps.d.ts.map +1 -0
- package/types/ops/ManagedObjectOps.d.ts +14 -0
- package/types/ops/ManagedObjectOps.d.ts.map +1 -0
- package/types/ops/OAuth2ClientOps.d.ts +24 -0
- package/types/ops/OAuth2ClientOps.d.ts.map +1 -0
- package/types/ops/OrganizationOps.d.ts +11 -0
- package/types/ops/OrganizationOps.d.ts.map +1 -0
- package/types/ops/RealmOps.d.ts +22 -0
- package/types/ops/RealmOps.d.ts.map +1 -0
- package/types/ops/SamlOps.d.ts +51 -0
- package/types/ops/SamlOps.d.ts.map +1 -0
- package/types/ops/ScriptOps.d.ts +30 -0
- package/types/ops/ScriptOps.d.ts.map +1 -0
- package/types/ops/SecretsOps.d.ts +63 -0
- package/types/ops/SecretsOps.d.ts.map +1 -0
- package/types/ops/StartupOps.d.ts +25 -0
- package/types/ops/StartupOps.d.ts.map +1 -0
- package/types/ops/ThemeOps.d.ts +66 -0
- package/types/ops/ThemeOps.d.ts.map +1 -0
- package/types/ops/VariablesOps.d.ts +39 -0
- package/types/ops/VariablesOps.d.ts.map +1 -0
- package/types/ops/utils/Console.d.ts +63 -0
- package/types/ops/utils/Console.d.ts.map +1 -0
- package/types/ops/utils/DataProtection.d.ts +6 -0
- package/types/ops/utils/DataProtection.d.ts.map +1 -0
- package/types/ops/utils/ExportImportUtils.d.ts +22 -0
- package/types/ops/utils/ExportImportUtils.d.ts.map +1 -0
- package/types/ops/utils/OpsUtils.d.ts +27 -0
- package/types/ops/utils/OpsUtils.d.ts.map +1 -0
- package/types/ops/utils/Wordwrap.d.ts +1 -0
- package/types/ops/utils/Wordwrap.d.ts.map +1 -0
- package/types/storage/SessionStorage.d.ts +47 -0
- package/types/storage/SessionStorage.d.ts.map +1 -0
- package/types/storage/StaticStorage.d.ts +14 -0
- package/types/storage/StaticStorage.d.ts.map +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
+
import { NodeRaw, 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('');
|
|
12
|
+
state.default.session.setRealm('alpha');
|
|
13
|
+
state.default.session.setCookieName('cookieName');
|
|
14
|
+
state.default.session.setCookieValue('cookieValue');
|
|
15
|
+
describe('NodeApi - getNodeTypes()', () => {
|
|
16
|
+
test('getNodeTypes() 1: Get all node types', async () => {
|
|
17
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/getNodeTypes/types.json'), 'utf8'));
|
|
18
|
+
mock.onPost('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes?_action=getAllTypes').reply(200, response);
|
|
19
|
+
const types = await NodeRaw.getNodeTypes();
|
|
20
|
+
expect(types).toBeTruthy();
|
|
21
|
+
expect(types.length).toBe(99);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('NodeApi - getNodesByType()', () => {
|
|
25
|
+
test('getNodesByType() 1: Get all page nodes', async () => {
|
|
26
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/getNodesByType/PageNode.json'), 'utf8'));
|
|
27
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode?_queryFilter=true').reply(200, response);
|
|
28
|
+
const nodes = await NodeRaw.getNodesByType('PageNode');
|
|
29
|
+
expect(nodes).toBeTruthy();
|
|
30
|
+
expect(nodes.length).toBe(161);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('NodeApi - getNode()', () => {
|
|
34
|
+
test('getNode() 1: Get existing page node [1aea363f-d8d2-4711-b88d-d58fff92dbae]', async () => {
|
|
35
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/getNode/PageNode_1aea363f-d8d2-4711-b88d-d58fff92dbae.json'), 'utf8'));
|
|
36
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/1aea363f-d8d2-4711-b88d-d58fff92dbae').reply(200, response);
|
|
37
|
+
const node = await NodeRaw.getNode('1aea363f-d8d2-4711-b88d-d58fff92dbae', 'PageNode');
|
|
38
|
+
expect(node).toBeTruthy();
|
|
39
|
+
expect(node).toMatchObject(response);
|
|
40
|
+
});
|
|
41
|
+
test('getNode() 2: Get non-existing page node [00000000-0000-0000-0000-000000000000]', async () => {
|
|
42
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/00000000-0000-0000-0000-000000000000').reply(404, {
|
|
43
|
+
code: 404,
|
|
44
|
+
reason: 'Not Found',
|
|
45
|
+
message: 'Not Found'
|
|
46
|
+
});
|
|
47
|
+
expect.assertions(2);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
await NodeRaw.getNode('00000000-0000-0000-0000-000000000000', 'PageNode');
|
|
51
|
+
} catch (error) {
|
|
52
|
+
expect(error.response).toBeTruthy();
|
|
53
|
+
expect(error.response.data).toMatchObject({
|
|
54
|
+
code: 404,
|
|
55
|
+
reason: 'Not Found',
|
|
56
|
+
message: 'Not Found'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('NodeApi - putNode()', () => {
|
|
62
|
+
test('putNode() 1: Create page node [0ad90971-d08a-4af3-86f3-01729572dc8f]', async () => {
|
|
63
|
+
const nodeData = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/putNode/PageNode_0ad90971-d08a-4af3-86f3-01729572dc8f.json'), 'utf8'));
|
|
64
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/0ad90971-d08a-4af3-86f3-01729572dc8f').reply(201, nodeData);
|
|
65
|
+
const node = await NodeRaw.putNode('0ad90971-d08a-4af3-86f3-01729572dc8f', 'PageNode', nodeData);
|
|
66
|
+
expect(node).toBeTruthy();
|
|
67
|
+
expect(node).toMatchObject(nodeData);
|
|
68
|
+
});
|
|
69
|
+
test('putNode() 1: Update existing page node [1aea363f-d8d2-4711-b88d-d58fff92dbae]', async () => {
|
|
70
|
+
const nodeData = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/putNode/PageNode_1aea363f-d8d2-4711-b88d-d58fff92dbae.json'), 'utf8'));
|
|
71
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/1aea363f-d8d2-4711-b88d-d58fff92dbae').reply(200, nodeData);
|
|
72
|
+
const node = await NodeRaw.putNode('1aea363f-d8d2-4711-b88d-d58fff92dbae', 'PageNode', nodeData);
|
|
73
|
+
expect(node).toBeTruthy();
|
|
74
|
+
expect(node).toMatchObject(nodeData);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('NodeApi - deleteNode()', () => {
|
|
78
|
+
test('deleteNode() 1: Delete existing node [1aea363f-d8d2-4711-b88d-d58fff92dbae]', async () => {
|
|
79
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/NodeApi/deleteNode/PageNode_1aea363f-d8d2-4711-b88d-d58fff92dbae.json'), 'utf8'));
|
|
80
|
+
mock.onDelete('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/1aea363f-d8d2-4711-b88d-d58fff92dbae').reply(200, response);
|
|
81
|
+
const node = await NodeRaw.deleteNode('1aea363f-d8d2-4711-b88d-d58fff92dbae', 'PageNode');
|
|
82
|
+
expect(node).toBeTruthy();
|
|
83
|
+
expect(node._id).toEqual('1aea363f-d8d2-4711-b88d-d58fff92dbae');
|
|
84
|
+
});
|
|
85
|
+
test('deleteNode() 2: Delete non-existing node [00000000-0000-0000-0000-000000000000]', async () => {
|
|
86
|
+
mock.onDelete('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/nodes/PageNode/00000000-0000-0000-0000-000000000000').reply(404, {
|
|
87
|
+
code: 404,
|
|
88
|
+
reason: 'Not Found',
|
|
89
|
+
message: 'Not Found'
|
|
90
|
+
});
|
|
91
|
+
expect.assertions(2);
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
await NodeRaw.deleteNode('00000000-0000-0000-0000-000000000000', 'PageNode');
|
|
95
|
+
} catch (error) {
|
|
96
|
+
expect(error.response).toBeTruthy();
|
|
97
|
+
expect(error.response.data).toMatchObject({
|
|
98
|
+
code: 404,
|
|
99
|
+
reason: 'Not Found',
|
|
100
|
+
message: 'Not Found'
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=NodeApi.test.js.map
|
package/esm/api/StartupApi.mjs
CHANGED
|
@@ -10,33 +10,43 @@ const getApiConfig = () => ({
|
|
|
10
10
|
path: `/environment/startup`,
|
|
11
11
|
apiVersion
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
export let RestartStatus;
|
|
13
15
|
/**
|
|
14
16
|
* Get status
|
|
15
|
-
* @returns {Promise} a promise that resolves to a status
|
|
17
|
+
* @returns {Promise<RestartStatus>} a promise that resolves to a string indicating status
|
|
16
18
|
*/
|
|
17
19
|
|
|
20
|
+
(function (RestartStatus) {
|
|
21
|
+
RestartStatus["restarting"] = "restarting";
|
|
22
|
+
RestartStatus["ready"] = "ready";
|
|
23
|
+
})(RestartStatus || (RestartStatus = {}));
|
|
18
24
|
|
|
19
25
|
export async function getStatus() {
|
|
20
26
|
const urlString = util.format(startupURLTemplate, getTenantURL(storage.session.getTenant()));
|
|
21
|
-
|
|
27
|
+
const {
|
|
28
|
+
data
|
|
29
|
+
} = await generateESVApi(getApiConfig()).get(urlString, {
|
|
22
30
|
withCredentials: true
|
|
23
31
|
});
|
|
32
|
+
return data.restartStatus;
|
|
24
33
|
}
|
|
25
34
|
/**
|
|
26
35
|
* Initiate restart
|
|
27
|
-
* @returns {Promise} a promise that resolves to a status
|
|
36
|
+
* @returns {Promise<string>} a promise that resolves to a string indicating status
|
|
28
37
|
*/
|
|
29
38
|
|
|
30
39
|
export async function initiateRestart() {
|
|
31
|
-
const
|
|
32
|
-
restartStatus
|
|
33
|
-
} = (await getStatus()).data;
|
|
40
|
+
const restartStatus = await getStatus();
|
|
34
41
|
|
|
35
|
-
if (restartStatus ===
|
|
42
|
+
if (restartStatus === RestartStatus.ready) {
|
|
36
43
|
const urlString = util.format(startupInitiateRestartURLTemplate, getTenantURL(storage.session.getTenant()));
|
|
37
|
-
|
|
44
|
+
const {
|
|
45
|
+
data
|
|
46
|
+
} = await generateESVApi(getApiConfig()).post(urlString, null, {
|
|
38
47
|
withCredentials: true
|
|
39
48
|
});
|
|
49
|
+
return data.restartStatus;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
throw new Error(`Not ready! Current status: ${restartStatus}`);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
+
import { StartupRaw, 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('StartupApi - getStatus()', () => {
|
|
16
|
+
test('getStatus() 1: Get restart status - expect "ready"', async () => {
|
|
17
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/getStatus/ready.json'), 'utf8'));
|
|
18
|
+
mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/startup').reply(200, response);
|
|
19
|
+
const status = await StartupRaw.getStatus();
|
|
20
|
+
expect(status in StartupRaw.RestartStatus).toBeTruthy();
|
|
21
|
+
expect(status).toBe(StartupRaw.RestartStatus.ready);
|
|
22
|
+
});
|
|
23
|
+
test('getStatus() 2: Get restart status - expect "restarting"', async () => {
|
|
24
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/getStatus/restarting.json'), 'utf8'));
|
|
25
|
+
mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/startup').reply(200, response);
|
|
26
|
+
const status = await StartupRaw.getStatus();
|
|
27
|
+
expect(status in StartupRaw.RestartStatus).toBeTruthy();
|
|
28
|
+
expect(status).toBe(StartupRaw.RestartStatus.restarting);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('StartupApi - initiateRestart()', () => {
|
|
32
|
+
test('initiateRestart() 1: Initiate restart - expect "ready" -> "restarting"', async () => {
|
|
33
|
+
const response1 = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/getStatus/ready.json'), 'utf8'));
|
|
34
|
+
mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/startup').reply(200, response1);
|
|
35
|
+
const response2 = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/initiateRestart/restarting.json'), 'utf8'));
|
|
36
|
+
mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/startup?_action=restart').reply(200, response2);
|
|
37
|
+
const status = await StartupRaw.initiateRestart();
|
|
38
|
+
expect(status in StartupRaw.RestartStatus).toBeTruthy();
|
|
39
|
+
expect(status).toBe(StartupRaw.RestartStatus.restarting);
|
|
40
|
+
});
|
|
41
|
+
test('initiateRestart() 2: Initiate restart - expect "restarting" -> exception', async () => {
|
|
42
|
+
const response1 = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/getStatus/restarting.json'), 'utf8'));
|
|
43
|
+
mock.onGet('https://openam-frodo-dev.forgeblocks.com/environment/startup').reply(200, response1);
|
|
44
|
+
const response2 = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/StartupApi/initiateRestart/restarting.json'), 'utf8'));
|
|
45
|
+
mock.onPost('https://openam-frodo-dev.forgeblocks.com/environment/startup?_action=restart').reply(200, response2);
|
|
46
|
+
expect.assertions(2);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await StartupRaw.initiateRestart();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
expect(error).toBeTruthy();
|
|
52
|
+
expect(error.message).toBe('Not ready! Current status: restarting');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=StartupApi.test.js.map
|
package/esm/api/TreeApi.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import util from 'util';
|
|
2
|
-
import {
|
|
2
|
+
import { getCurrentRealmPath } from './utils/ApiUtils';
|
|
3
3
|
import { generateAmApi } from './BaseApi';
|
|
4
4
|
import storage from '../storage/SessionStorage';
|
|
5
|
-
const nodeURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/nodes/%s/%s';
|
|
6
|
-
const queryAllNodesByTypeURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/nodes/%s?_queryFilter=true';
|
|
7
|
-
const queryAllNodesURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/nodes?_action=nextdescendents';
|
|
8
|
-
const queryAllNodeTypesURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/nodes?_action=getAllTypes';
|
|
9
5
|
const treeByIdURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/trees/%s';
|
|
10
6
|
const queryAllTreesURLTemplate = '%s/json%s/realm-config/authentication/authenticationtrees/trees?_queryFilter=true';
|
|
11
7
|
const apiVersion = 'protocol=2.1,resource=1.0';
|
|
@@ -17,131 +13,63 @@ const getTreeApiConfig = () => {
|
|
|
17
13
|
apiVersion
|
|
18
14
|
};
|
|
19
15
|
};
|
|
20
|
-
|
|
21
|
-
export async function getNodeTypes() {
|
|
22
|
-
const urlString = util.format(queryAllNodeTypesURLTemplate, storage.session.getTenant(), getCurrentRealmPath());
|
|
23
|
-
return generateAmApi(getTreeApiConfig()).post(urlString, {}, {
|
|
24
|
-
withCredentials: true,
|
|
25
|
-
headers: {
|
|
26
|
-
'Accept-Encoding': 'gzip, deflate, br'
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Get all nodes
|
|
32
|
-
* @returns {Promise} a promise that resolves to an object containing an array of all node objects
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export async function getNodes() {
|
|
36
|
-
const urlString = util.format(queryAllNodesURLTemplate, storage.session.getTenant(), getCurrentRealmPath());
|
|
37
|
-
return generateAmApi(getTreeApiConfig()).post(urlString, {}, {
|
|
38
|
-
withCredentials: true,
|
|
39
|
-
headers: {
|
|
40
|
-
'Accept-Encoding': 'gzip, deflate, br'
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Get all nodes by type
|
|
46
|
-
* @param {*} type node type
|
|
47
|
-
* @returns {Promise} a promise that resolves to an object containing an array of node objects of the requested type
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export async function getNodesByType(type) {
|
|
51
|
-
const urlString = util.format(queryAllNodesByTypeURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), type);
|
|
52
|
-
return generateAmApi(getTreeApiConfig()).get(urlString, {
|
|
53
|
-
withCredentials: true
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get node by uuid and type
|
|
58
|
-
* @param {String} id node uuid
|
|
59
|
-
* @param {String} nodeType node type
|
|
60
|
-
* @returns {Promise} a promise that resolves to an object containing a node object
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
export async function getNode(id, nodeType) {
|
|
64
|
-
const urlString = util.format(nodeURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), nodeType, id);
|
|
65
|
-
return generateAmApi(getTreeApiConfig()).get(urlString, {
|
|
66
|
-
withCredentials: true
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Put node by uuid and type
|
|
71
|
-
* @param {String} id node uuid
|
|
72
|
-
* @param {String} nodeType node type
|
|
73
|
-
* @param {Object} data node object
|
|
74
|
-
* @returns {Promise} a promise that resolves to an object containing a node object
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
export async function putNode(id, nodeType, nodeData) {
|
|
78
|
-
// until we figure out a way to use transport keys in Frodo,
|
|
79
|
-
// we'll have to drop those encrypted attributes.
|
|
80
|
-
const data = deleteDeepByKey(nodeData, '-encrypted');
|
|
81
|
-
const urlString = util.format(nodeURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), nodeType, id);
|
|
82
|
-
return generateAmApi(getTreeApiConfig()).put(urlString, data, {
|
|
83
|
-
withCredentials: true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Delete node by uuid and type
|
|
88
|
-
* @param {String} id node uuid
|
|
89
|
-
* @param {String} nodeType node type
|
|
90
|
-
* @returns {Promise} a promise that resolves to an object containing a node object
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
export async function deleteNode(id, nodeType) {
|
|
94
|
-
const urlString = util.format(nodeURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), nodeType, id);
|
|
95
|
-
return generateAmApi(getTreeApiConfig()).delete(urlString, {
|
|
96
|
-
withCredentials: true
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
16
|
/**
|
|
100
17
|
* Get all trees
|
|
101
|
-
* @returns {Promise} a promise that resolves to an
|
|
18
|
+
* @returns {Promise} a promise that resolves to an array of tree objects
|
|
102
19
|
*/
|
|
103
20
|
|
|
21
|
+
|
|
104
22
|
export async function getTrees() {
|
|
105
23
|
const urlString = util.format(queryAllTreesURLTemplate, storage.session.getTenant(), getCurrentRealmPath());
|
|
106
|
-
|
|
24
|
+
const response = await generateAmApi(getTreeApiConfig()).get(urlString, {
|
|
107
25
|
withCredentials: true
|
|
108
26
|
});
|
|
27
|
+
return response.data.result;
|
|
109
28
|
}
|
|
110
29
|
/**
|
|
111
30
|
* Get tree by id/name
|
|
112
31
|
* @param {String} id tree id/name
|
|
113
|
-
* @returns {Promise} a promise that resolves to
|
|
32
|
+
* @returns {Promise} a promise that resolves to a tree object
|
|
114
33
|
*/
|
|
115
34
|
|
|
116
35
|
export async function getTree(id) {
|
|
117
36
|
const urlString = util.format(treeByIdURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), id);
|
|
118
|
-
|
|
37
|
+
const {
|
|
38
|
+
data
|
|
39
|
+
} = await generateAmApi(getTreeApiConfig()).get(urlString, {
|
|
119
40
|
withCredentials: true
|
|
120
41
|
});
|
|
42
|
+
return data;
|
|
121
43
|
}
|
|
122
44
|
/**
|
|
123
45
|
* Put tree by id/name
|
|
124
|
-
* @param {String}
|
|
125
|
-
* @param {Object}
|
|
126
|
-
* @returns {Promise} a promise that resolves to
|
|
46
|
+
* @param {String} treeId tree id/name
|
|
47
|
+
* @param {Object} treeData tree object
|
|
48
|
+
* @returns {Promise} a promise that resolves to a tree object
|
|
127
49
|
*/
|
|
128
50
|
|
|
129
|
-
export async function putTree(
|
|
130
|
-
const urlString = util.format(treeByIdURLTemplate, storage.session.getTenant(), getCurrentRealmPath(),
|
|
131
|
-
|
|
51
|
+
export async function putTree(treeId, treeData) {
|
|
52
|
+
const urlString = util.format(treeByIdURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), treeId);
|
|
53
|
+
const {
|
|
54
|
+
data
|
|
55
|
+
} = await generateAmApi(getTreeApiConfig()).put(urlString, treeData, {
|
|
132
56
|
withCredentials: true
|
|
133
57
|
});
|
|
58
|
+
return data;
|
|
134
59
|
}
|
|
135
60
|
/**
|
|
136
61
|
* Delete tree by id/name
|
|
137
|
-
* @param {String}
|
|
138
|
-
* @returns {Promise} a promise that resolves to
|
|
62
|
+
* @param {String} treeId tree id/name
|
|
63
|
+
* @returns {Promise} a promise that resolves to a tree object
|
|
139
64
|
*/
|
|
140
65
|
|
|
141
|
-
export async function deleteTree(
|
|
142
|
-
const urlString = util.format(treeByIdURLTemplate, storage.session.getTenant(), getCurrentRealmPath(),
|
|
143
|
-
|
|
66
|
+
export async function deleteTree(treeId) {
|
|
67
|
+
const urlString = util.format(treeByIdURLTemplate, storage.session.getTenant(), getCurrentRealmPath(), treeId);
|
|
68
|
+
const {
|
|
69
|
+
data
|
|
70
|
+
} = await generateAmApi(getTreeApiConfig()).delete(urlString, {
|
|
144
71
|
withCredentials: true
|
|
145
72
|
});
|
|
73
|
+
return data;
|
|
146
74
|
}
|
|
147
75
|
//# sourceMappingURL=TreeApi.js.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
+
import { TreeRaw, 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('');
|
|
12
|
+
state.default.session.setRealm('alpha');
|
|
13
|
+
state.default.session.setCookieName('cookieName');
|
|
14
|
+
state.default.session.setCookieValue('cookieValue');
|
|
15
|
+
describe('TreeApi - getTrees()', () => {
|
|
16
|
+
test('getTrees() 1: Get all trees', async () => {
|
|
17
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/getTrees/trees.json'), 'utf8'));
|
|
18
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees?_queryFilter=true').reply(200, response);
|
|
19
|
+
const trees = await TreeRaw.getTrees();
|
|
20
|
+
expect(trees).toBeTruthy();
|
|
21
|
+
expect(trees.length).toBe(92);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('TreeApi - getTree()', () => {
|
|
25
|
+
test('getTree() 1: Get existing tree', async () => {
|
|
26
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/getTree/FrodoTest.json'), 'utf8'));
|
|
27
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/FrodoTest').reply(200, response);
|
|
28
|
+
const tree = await TreeRaw.getTree('FrodoTest');
|
|
29
|
+
expect(tree).toBeTruthy();
|
|
30
|
+
expect(tree._id).toEqual('FrodoTest');
|
|
31
|
+
});
|
|
32
|
+
test('getTree() 2: Get non-existing tree', async () => {
|
|
33
|
+
mock.onGet('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/DoesNotExist').reply(404, {
|
|
34
|
+
code: 404,
|
|
35
|
+
reason: 'Not Found',
|
|
36
|
+
message: 'Not Found'
|
|
37
|
+
});
|
|
38
|
+
expect.assertions(2);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
await TreeRaw.getTree('DoesNotExist');
|
|
42
|
+
} catch (error) {
|
|
43
|
+
expect(error.response).toBeTruthy();
|
|
44
|
+
expect(error.response.data).toMatchObject({
|
|
45
|
+
code: 404,
|
|
46
|
+
reason: 'Not Found',
|
|
47
|
+
message: 'Not Found'
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('TreeApi - putTree()', () => {
|
|
53
|
+
test('putTree() 1: Put valid tree', async () => {
|
|
54
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/putTree/FrodoTest.json'), 'utf8'));
|
|
55
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/FrodoTest').reply(201, response);
|
|
56
|
+
const tree = await TreeRaw.putTree('FrodoTest', response);
|
|
57
|
+
expect(tree).toBeTruthy();
|
|
58
|
+
expect(tree._id).toEqual('FrodoTest');
|
|
59
|
+
});
|
|
60
|
+
test('putTree() 2: Put invalid tree [trailing data]', async () => {
|
|
61
|
+
const request = fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/putTree/Invalid_trailing-data.txt'), 'utf8');
|
|
62
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/Invalid').reply(400, {
|
|
63
|
+
code: 400,
|
|
64
|
+
reason: 'Bad Request',
|
|
65
|
+
message: 'The request could not be processed because there is trailing data after the JSON content'
|
|
66
|
+
});
|
|
67
|
+
expect.assertions(2);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
await TreeRaw.putTree('Invalid', request);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
expect(error.response).toBeTruthy();
|
|
73
|
+
expect(error.response.data).toMatchObject({
|
|
74
|
+
code: 400,
|
|
75
|
+
reason: 'Bad Request',
|
|
76
|
+
message: 'The request could not be processed because there is trailing data after the JSON content'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
test('putTree() 3: Put invalid tree [invalid attribute]', async () => {
|
|
81
|
+
const request = fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/putTree/Invalid_invalid-attribute.json'), 'utf8');
|
|
82
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/Invalid').reply(400, {
|
|
83
|
+
code: 400,
|
|
84
|
+
reason: 'Bad Request',
|
|
85
|
+
message: 'Invalid attribute specified.',
|
|
86
|
+
detail: {
|
|
87
|
+
validAttributes: ['description', 'enabled', 'entryNodeId', 'identityResource', 'nodes', 'staticNodes', 'uiConfig']
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
expect.assertions(2);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
await TreeRaw.putTree('Invalid', request);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
expect(error.response).toBeTruthy();
|
|
96
|
+
expect(error.response.data).toMatchObject({
|
|
97
|
+
code: 400,
|
|
98
|
+
reason: 'Bad Request',
|
|
99
|
+
message: 'Invalid attribute specified.',
|
|
100
|
+
detail: {
|
|
101
|
+
validAttributes: ['description', 'enabled', 'entryNodeId', 'identityResource', 'nodes', 'staticNodes', 'uiConfig']
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
test('putTree() 4: Put invalid tree [no entry node]', async () => {
|
|
107
|
+
const request = fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/putTree/Invalid_no-entry-node.json'), 'utf8');
|
|
108
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/Invalid').reply(400, {
|
|
109
|
+
code: 400,
|
|
110
|
+
reason: 'Bad Request',
|
|
111
|
+
message: 'Node with ID entryNodeId must exist in the tree.'
|
|
112
|
+
});
|
|
113
|
+
expect.assertions(2);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
await TreeRaw.putTree('Invalid', request);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
expect(error.response).toBeTruthy();
|
|
119
|
+
expect(error.response.data).toMatchObject({
|
|
120
|
+
code: 400,
|
|
121
|
+
reason: 'Bad Request',
|
|
122
|
+
message: 'Node with ID entryNodeId must exist in the tree.'
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
test('putTree() 5: Put invalid tree [invalid nodes]', async () => {
|
|
127
|
+
const request = fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/putTree/Invalid_invalid-nodes.json'), 'utf8');
|
|
128
|
+
mock.onPut('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/Invalid').reply(400, {
|
|
129
|
+
code: 400,
|
|
130
|
+
reason: 'Bad Request',
|
|
131
|
+
message: 'Node with ID entryNodeId must exist in the tree.'
|
|
132
|
+
});
|
|
133
|
+
expect.assertions(2);
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
await TreeRaw.putTree('Invalid', request);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
expect(error.response).toBeTruthy();
|
|
139
|
+
expect(error.response.data).toMatchObject({
|
|
140
|
+
code: 400,
|
|
141
|
+
reason: 'Bad Request',
|
|
142
|
+
message: 'Node with ID entryNodeId must exist in the tree.'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('TreeApi - deleteTree()', () => {
|
|
148
|
+
test('deleteTree() 1: Delete existing tree', async () => {
|
|
149
|
+
const response = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../test/mocks/TreeApi/deleteTree/FrodoTest.json'), 'utf8'));
|
|
150
|
+
mock.onDelete('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/FrodoTest').reply(200, response);
|
|
151
|
+
const tree = await TreeRaw.deleteTree('FrodoTest');
|
|
152
|
+
expect(tree).toBeTruthy();
|
|
153
|
+
expect(tree._id).toEqual('FrodoTest');
|
|
154
|
+
});
|
|
155
|
+
test('deleteTree() 2: Delete non-existing tree', async () => {
|
|
156
|
+
mock.onDelete('/json/realms/root/realms/alpha/realm-config/authentication/authenticationtrees/trees/DoesNotExist').reply(404, {
|
|
157
|
+
code: 404,
|
|
158
|
+
reason: 'Not Found',
|
|
159
|
+
message: 'Not Found'
|
|
160
|
+
});
|
|
161
|
+
expect.assertions(2);
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await TreeRaw.deleteTree('DoesNotExist');
|
|
165
|
+
} catch (error) {
|
|
166
|
+
expect(error.response).toBeTruthy();
|
|
167
|
+
expect(error.response.data).toMatchObject({
|
|
168
|
+
code: 404,
|
|
169
|
+
reason: 'Not Found',
|
|
170
|
+
message: 'Not Found'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=TreeApi.test.js.map
|
package/esm/index.mjs
CHANGED
|
@@ -4,13 +4,15 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
|
|
7
|
-
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'));
|
|
8
|
-
// fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')
|
|
9
|
-
// );
|
|
10
|
-
|
|
7
|
+
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'));
|
|
11
8
|
export function getVersion() {
|
|
12
9
|
return `v${pkg.version}`;
|
|
13
|
-
}
|
|
10
|
+
} // Api Layer
|
|
11
|
+
|
|
12
|
+
export * as NodeRaw from './api/NodeApi';
|
|
13
|
+
export * as TreeRaw from './api/TreeApi';
|
|
14
|
+
export * as StartupRaw from './api/StartupApi'; // Ops Layer
|
|
15
|
+
|
|
14
16
|
export * as Admin from './ops/AdminOps';
|
|
15
17
|
export * as Authenticate from './ops/AuthenticateOps';
|
|
16
18
|
export * as CirclesOfTrust from './ops/CirclesOfTrustOps';
|
package/esm/ops/IdpOps.mjs
CHANGED
|
@@ -78,7 +78,7 @@ export async function exportProvider(id, file = '') {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
saveJsonToFile(fileData, fileName);
|
|
81
|
-
stopProgressIndicator(`Exported ${id
|
|
81
|
+
stopProgressIndicator(`Exported ${id['brightCyan']} to ${fileName['brightCyan']}.`);
|
|
82
82
|
} catch (err) {
|
|
83
83
|
stopProgressIndicator(`${err}`);
|
|
84
84
|
printMessage(`${err}`, 'error');
|