@rockcarver/frodo-lib 0.17.2-0 → 0.17.3

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/cjs/api/AgentApi.js +1 -1
  3. package/cjs/api/AgentApi.js.map +1 -1
  4. package/cjs/api/AgentApi.test.js.map +1 -1
  5. package/cjs/api/ApiTypes.js +16 -16
  6. package/cjs/api/ApiTypes.js.map +1 -1
  7. package/cjs/api/AuthenticateApi.js +17 -12
  8. package/cjs/api/AuthenticateApi.js.map +1 -1
  9. package/cjs/api/AuthenticateApi.test.js.map +1 -1
  10. package/cjs/api/IdmConfigApi.js +28 -7
  11. package/cjs/api/IdmConfigApi.js.map +1 -1
  12. package/cjs/api/NodeApi.test.js.map +1 -1
  13. package/cjs/api/SecretsApi.test.js.map +1 -1
  14. package/cjs/api/SocialIdentityProvidersApi.js +22 -0
  15. package/cjs/api/SocialIdentityProvidersApi.js.map +1 -1
  16. package/cjs/api/TreeApi.test.js.map +1 -1
  17. package/cjs/api/VariablesApi.test.js.map +1 -1
  18. package/cjs/api/utils/ApiUtils.js +13 -4
  19. package/cjs/api/utils/ApiUtils.js.map +1 -1
  20. package/cjs/api/utils/ApiUtils.test.js.map +1 -1
  21. package/cjs/index.js +3 -1
  22. package/cjs/index.js.map +1 -1
  23. package/cjs/ops/AgentOps.test.js.map +1 -1
  24. package/cjs/ops/AuthenticateOps.js +0 -7
  25. package/cjs/ops/AuthenticateOps.js.map +1 -1
  26. package/cjs/ops/ConnectionProfileOps.test.js.map +1 -1
  27. package/cjs/ops/EmailTemplateOps.test.js.map +1 -1
  28. package/cjs/ops/IdmOps.test.js.map +1 -1
  29. package/cjs/ops/IdpOps.js +182 -275
  30. package/cjs/ops/IdpOps.js.map +1 -1
  31. package/cjs/ops/IdpOps.test.js.map +1 -1
  32. package/cjs/ops/SecretsOps.js +3 -3
  33. package/cjs/ops/SecretsOps.js.map +1 -1
  34. package/cjs/ops/VariablesOps.js +3 -3
  35. package/cjs/ops/VariablesOps.js.map +1 -1
  36. package/cjs/shared/State.js +1 -1
  37. package/cjs/shared/State.js.map +1 -1
  38. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_mytestrun_com.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent1.json} +0 -2
  39. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/{ig_chico.json → FrodoOpsTestGatewayAgent2.json} +0 -2
  40. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ig_chico.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent3.json} +0 -2
  41. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/{ig_mytestrun_com.json → FrodoOpsTestGatewayAgent4.json} +0 -2
  42. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/api_client.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent5.json} +0 -2
  43. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/{api_client.json → FrodoOpsTestGatewayAgent6.json} +0 -2
  44. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent7.json +20 -0
  45. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent8.json +20 -0
  46. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent9.json +30 -0
  47. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent1.json +30 -0
  48. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent2.json +20 -0
  49. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent3.json +20 -0
  50. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/{javaAgent.json → FrodoOpsTestJavaAgent1.json} +0 -2
  51. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/{tomcatagent.json → FrodoOpsTestJavaAgent2.json} +0 -2
  52. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/tomcatagent.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent3.json} +0 -2
  53. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/javaAgent.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent4.json} +0 -2
  54. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent5.json +621 -0
  55. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent6.json +628 -0
  56. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent7.json +628 -0
  57. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent8.json +628 -0
  58. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent9.json +628 -0
  59. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent1.json +621 -0
  60. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent2.json +628 -0
  61. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent3.json +628 -0
  62. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/apacheagent.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent1.json} +0 -2
  63. package/{esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/webserver.json → cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent2.json} +0 -2
  64. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/{webserver.json → FrodoOpsTestWebAgent3.json} +0 -2
  65. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/{apacheagent.json → FrodoOpsTestWebAgent4.json} +0 -2
  66. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent5.json +454 -0
  67. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent6.json +453 -0
  68. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent7.json +453 -0
  69. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent8.json +453 -0
  70. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent9.json +453 -0
  71. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent1.json +454 -0
  72. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent2.json +453 -0
  73. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent3.json +453 -0
  74. package/cjs/test/mocks/ForgeRockApiMockEngine.js +1 -108
  75. package/cjs/test/mocks/ForgeRockApiMockEngine.js.map +1 -1
  76. package/esm/api/AgentApi.mjs +1 -1
  77. package/esm/api/AgentApi.test.mjs +323 -246
  78. package/esm/api/ApiTypes.mjs +16 -16
  79. package/esm/api/AuthenticateApi.mjs +16 -12
  80. package/esm/api/AuthenticateApi.test.mjs +77 -35
  81. package/esm/api/IdmConfigApi.mjs +19 -4
  82. package/esm/api/NodeApi.test.mjs +248 -914
  83. package/esm/api/SecretsApi.test.mjs +252 -245
  84. package/esm/api/SocialIdentityProvidersApi.mjs +16 -0
  85. package/esm/api/TreeApi.test.mjs +190 -105
  86. package/esm/api/VariablesApi.test.mjs +108 -12
  87. package/esm/api/utils/ApiUtils.mjs +12 -4
  88. package/esm/api/utils/ApiUtils.test.mjs +80 -79
  89. package/esm/index.mjs +1 -0
  90. package/esm/ops/AgentOps.test.mjs +780 -1210
  91. package/esm/ops/AuthenticateOps.mjs +0 -7
  92. package/esm/ops/ConnectionProfileOps.test.mjs +94 -54
  93. package/esm/ops/EmailTemplateOps.test.mjs +140 -28
  94. package/esm/ops/IdmOps.test.mjs +159 -62
  95. package/esm/ops/IdpOps.mjs +139 -210
  96. package/esm/ops/IdpOps.test.mjs +651 -52
  97. package/esm/ops/SecretsOps.mjs +3 -3
  98. package/esm/ops/VariablesOps.mjs +3 -3
  99. package/esm/shared/State.mjs +1 -1
  100. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent1.json +30 -0
  101. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent2.json +20 -0
  102. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent3.json +20 -0
  103. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent4.json +30 -0
  104. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent5.json +20 -0
  105. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent6.json +20 -0
  106. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent7.json +20 -0
  107. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent8.json +20 -0
  108. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoOpsTestGatewayAgent9.json +30 -0
  109. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent1.json +30 -0
  110. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent2.json +20 -0
  111. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/FrodoTestGatewayAgent3.json +20 -0
  112. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent1.json +621 -0
  113. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent2.json +628 -0
  114. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent3.json +628 -0
  115. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent4.json +621 -0
  116. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent5.json +621 -0
  117. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent6.json +628 -0
  118. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent7.json +628 -0
  119. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent8.json +628 -0
  120. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoOpsTestJavaAgent9.json +628 -0
  121. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent1.json +621 -0
  122. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent2.json +628 -0
  123. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/J2EEAgent/FrodoTestJavaAgent3.json +628 -0
  124. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent1.json +454 -0
  125. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent2.json +453 -0
  126. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent3.json +453 -0
  127. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent4.json +454 -0
  128. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent5.json +454 -0
  129. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent6.json +453 -0
  130. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent7.json +453 -0
  131. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent8.json +453 -0
  132. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoOpsTestWebAgent9.json +453 -0
  133. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent1.json +454 -0
  134. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent2.json +453 -0
  135. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/WebAgent/FrodoTestWebAgent3.json +453 -0
  136. package/esm/test/mocks/ForgeRockApiMockEngine.mjs +1 -98
  137. package/package.json +1 -1
  138. package/types/api/AgentApi.d.ts.map +1 -1
  139. package/types/api/ApiTypes.d.ts +21 -21
  140. package/types/api/ApiTypes.d.ts.map +1 -1
  141. package/types/api/AuthenticateApi.d.ts +11 -2
  142. package/types/api/AuthenticateApi.d.ts.map +1 -1
  143. package/types/api/IdmConfigApi.d.ts +11 -5
  144. package/types/api/IdmConfigApi.d.ts.map +1 -1
  145. package/types/api/SocialIdentityProvidersApi.d.ts +7 -0
  146. package/types/api/SocialIdentityProvidersApi.d.ts.map +1 -1
  147. package/types/api/utils/ApiUtils.d.ts +7 -1
  148. package/types/api/utils/ApiUtils.d.ts.map +1 -1
  149. package/types/index.d.ts +1 -0
  150. package/types/index.d.ts.map +1 -1
  151. package/types/ops/AuthenticateOps.d.ts.map +1 -1
  152. package/types/ops/IdpOps.d.ts +31 -24
  153. package/types/ops/IdpOps.d.ts.map +1 -1
  154. package/types/ops/SecretsOps.d.ts.map +1 -1
  155. package/types/ops/VariablesOps.d.ts.map +1 -1
  156. package/types/shared/State.d.ts.map +1 -1
  157. package/types/test/mocks/ForgeRockApiMockEngine.d.ts +1 -11
  158. package/types/test/mocks/ForgeRockApiMockEngine.d.ts.map +1 -1
  159. package/cjs/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +0 -22
  160. package/esm/test/mocks/AgentApi/getAgentByTypeAndId/IdentityGatewayAgent/ajays_client.json +0 -22
@@ -398,17 +398,10 @@ export async function getTokens() {
398
398
  const token = await authenticate(state.getUsername(), state.getPassword());
399
399
  if (token) state.setCookieValue(token);
400
400
  await determineDeploymentTypeAndDefaultRealmAndVersion();
401
- debugMessage(`AuthenticateOps.getTokens: before bearer`);
402
- debugMessage(`AuthenticateOps.getTokens: cookie=${state.getCookieValue()}`);
403
- debugMessage(`AuthenticateOps.getTokens: bearer=${state.getBearerToken()}`);
404
- debugMessage(`AuthenticateOps.getTokens: type=${state.getDeploymentType()}`);
405
- debugMessage(`AuthenticateOps.getTokens: condition=${state.getCookieValue() && !state.getBearerToken() && (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY || state.getDeploymentType() === globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY)}`);
406
401
  if (state.getCookieValue() && !state.getBearerToken() && (state.getDeploymentType() === globalConfig.CLOUD_DEPLOYMENT_TYPE_KEY || state.getDeploymentType() === globalConfig.FORGEOPS_DEPLOYMENT_TYPE_KEY)) {
407
- debugMessage(`AuthenticateOps.getTokens: in bearer`);
408
402
  const accessToken = await getAccessTokenForUser();
409
403
  if (accessToken) state.setBearerToken(accessToken);
410
404
  }
411
- debugMessage(`AuthenticateOps.getTokens: after bearer`);
412
405
  }
413
406
  // incomplete or no credentials
414
407
  else {
@@ -3,62 +3,102 @@ import { homedir } from 'os';
3
3
  import { ConnectionProfile, state } from '../index';
4
4
  import { FRODO_CONNECTION_PROFILES_PATH_KEY, FRODO_MASTER_KEY_PATH_KEY, FRODO_MASTER_KEY_KEY } from '../storage/StaticStorage';
5
5
  describe('ConnectionProfileOps', () => {
6
- test('saveConnectionProfile() 1: Create connection profiles in location from state field', async () => {
7
- const host = 'https://openam-tenant-name.forgeblocks.com/am';
8
- const user = 'frodo.baggins@shire.me';
9
- const password = 'G@nd@lfTheW153';
10
- const connectionProfilePath = `${homedir()}/connections1.json`;
11
- state.setHost(host);
12
- state.setUsername(user);
13
- state.setPassword(password);
14
- state.setConnectionProfilesPath(connectionProfilePath);
15
- await ConnectionProfile.saveConnectionProfile(host);
16
- expect(fs.existsSync(connectionProfilePath)).toBeTruthy();
17
- const connections = JSON.parse(fs.readFileSync(connectionProfilePath, 'utf8'));
18
- expect(connections).toBeTruthy();
19
- expect(connections[host]).toBeTruthy();
20
- expect(connections[host].username).toEqual(user);
21
- expect(connections[host].encodedPassword).toBeTruthy();
6
+ const connectionProfilePath1 = `${homedir()}/connections1.json`;
7
+ const connectionProfilePath2 = `${homedir()}/connections2.json`;
8
+ const connectionProfilePath3 = `${homedir()}/connections3.json`;
9
+
10
+ // delete all connection profile files before running the tests
11
+ beforeAll(() => {
12
+ try {
13
+ fs.unlinkSync(connectionProfilePath1);
14
+ } catch (error) {
15
+ // ignore
16
+ }
17
+ try {
18
+ fs.unlinkSync(connectionProfilePath2);
19
+ } catch (error) {
20
+ // ignore
21
+ }
22
+ try {
23
+ fs.unlinkSync(connectionProfilePath3);
24
+ } catch (error) {
25
+ // ignore
26
+ }
22
27
  });
23
- test(`saveConnectionProfile() 2: Create connection profiles in location from env ${FRODO_MASTER_KEY_PATH_KEY}`, async () => {
24
- const host = 'https://openam-tenant-name.forgeblocks.com/am';
25
- const user = 'frodo.baggins@shire.me';
26
- const password = 'G@nd@lfTheW153';
27
- const connectionProfilePath = `${homedir()}/connections2.json`;
28
- // set the hard-coded master key
29
- process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] = connectionProfilePath;
30
- state.setHost(host);
31
- state.setUsername(user);
32
- state.setPassword(password);
33
- state.setConnectionProfilesPath('');
34
- await ConnectionProfile.saveConnectionProfile(host);
35
- expect(ConnectionProfile.getConnectionProfilesPath()).toEqual(connectionProfilePath);
36
- expect(fs.existsSync(connectionProfilePath)).toBeTruthy();
37
- const connections = JSON.parse(fs.readFileSync(connectionProfilePath, 'utf8'));
38
- expect(connections).toBeTruthy();
39
- expect(connections[host]).toBeTruthy();
40
- expect(connections[host].username).toEqual(user);
41
- expect(connections[host].encodedPassword).toBeTruthy();
28
+
29
+ // clean up all connection profile files after running the tests
30
+ afterAll(() => {
31
+ try {
32
+ fs.unlinkSync(connectionProfilePath1);
33
+ } catch (error) {
34
+ // ignore
35
+ }
36
+ try {
37
+ fs.unlinkSync(connectionProfilePath2);
38
+ } catch (error) {
39
+ // ignore
40
+ }
41
+ try {
42
+ fs.unlinkSync(connectionProfilePath3);
43
+ } catch (error) {
44
+ // ignore
45
+ }
42
46
  });
43
- test(`saveConnectionProfile() 3: Use Master Key from env ${FRODO_MASTER_KEY_KEY}`, async () => {
44
- const host = 'https://openam-tenant-name.forgeblocks.com/am';
45
- const user = 'frodo.baggins@shire.me';
46
- const password = 'G@nd@lfTheW153';
47
- const connectionProfilePath = `${homedir()}/connections3.json`;
48
- const masterKey = 'bxnQlhcU5VfyDs+BBPhRhK09yHaNtdIIk85HUMKBnqg=';
49
- // set the hard-coded master key
50
- process.env[FRODO_MASTER_KEY_KEY] = masterKey;
51
- state.setHost(host);
52
- state.setUsername(user);
53
- state.setPassword(password);
54
- state.setConnectionProfilesPath(connectionProfilePath);
55
- await ConnectionProfile.saveConnectionProfile(host);
56
- expect(fs.existsSync(connectionProfilePath)).toBeTruthy();
57
- const connections = JSON.parse(fs.readFileSync(connectionProfilePath, 'utf8'));
58
- expect(connections).toBeTruthy();
59
- expect(connections[host]).toBeTruthy();
60
- expect(connections[host].username).toEqual(user);
61
- expect(connections[host].encodedPassword).toBeTruthy();
47
+ describe('saveConnectionProfile()', () => {
48
+ test('1: Create connection profiles in location from state field', async () => {
49
+ const host = 'https://openam-tenant-name.forgeblocks.com/am';
50
+ const user = 'frodo.baggins@shire.me';
51
+ const password = 'G@nd@lfTheW153';
52
+ state.setHost(host);
53
+ state.setUsername(user);
54
+ state.setPassword(password);
55
+ state.setConnectionProfilesPath(connectionProfilePath1);
56
+ await ConnectionProfile.saveConnectionProfile(host);
57
+ expect(fs.existsSync(connectionProfilePath1)).toBeTruthy();
58
+ const connections = JSON.parse(fs.readFileSync(connectionProfilePath1, 'utf8'));
59
+ expect(connections).toBeTruthy();
60
+ expect(connections[host]).toBeTruthy();
61
+ expect(connections[host].username).toEqual(user);
62
+ expect(connections[host].encodedPassword).toBeTruthy();
63
+ });
64
+ test(`2: Create connection profiles in location from env ${FRODO_MASTER_KEY_PATH_KEY}`, async () => {
65
+ const host = 'https://openam-tenant-name.forgeblocks.com/am';
66
+ const user = 'frodo.baggins@shire.me';
67
+ const password = 'G@nd@lfTheW153';
68
+ // set the hard-coded master key
69
+ process.env[FRODO_CONNECTION_PROFILES_PATH_KEY] = connectionProfilePath2;
70
+ state.setHost(host);
71
+ state.setUsername(user);
72
+ state.setPassword(password);
73
+ state.setConnectionProfilesPath('');
74
+ await ConnectionProfile.saveConnectionProfile(host);
75
+ expect(ConnectionProfile.getConnectionProfilesPath()).toEqual(connectionProfilePath2);
76
+ expect(fs.existsSync(connectionProfilePath2)).toBeTruthy();
77
+ const connections = JSON.parse(fs.readFileSync(connectionProfilePath2, 'utf8'));
78
+ expect(connections).toBeTruthy();
79
+ expect(connections[host]).toBeTruthy();
80
+ expect(connections[host].username).toEqual(user);
81
+ expect(connections[host].encodedPassword).toBeTruthy();
82
+ });
83
+ test(`3: Use Master Key from env ${FRODO_MASTER_KEY_KEY}`, async () => {
84
+ const host = 'https://openam-tenant-name.forgeblocks.com/am';
85
+ const user = 'frodo.baggins@shire.me';
86
+ const password = 'G@nd@lfTheW153';
87
+ const masterKey = 'bxnQlhcU5VfyDs+BBPhRhK09yHaNtdIIk85HUMKBnqg=';
88
+ // set the hard-coded master key
89
+ process.env[FRODO_MASTER_KEY_KEY] = masterKey;
90
+ state.setHost(host);
91
+ state.setUsername(user);
92
+ state.setPassword(password);
93
+ state.setConnectionProfilesPath(connectionProfilePath3);
94
+ await ConnectionProfile.saveConnectionProfile(host);
95
+ expect(fs.existsSync(connectionProfilePath3)).toBeTruthy();
96
+ const connections = JSON.parse(fs.readFileSync(connectionProfilePath3, 'utf8'));
97
+ expect(connections).toBeTruthy();
98
+ expect(connections[host]).toBeTruthy();
99
+ expect(connections[host].username).toEqual(user);
100
+ expect(connections[host].encodedPassword).toBeTruthy();
101
+ });
62
102
  });
63
103
  });
64
104
  //# sourceMappingURL=ConnectionProfileOps.test.js.map
@@ -1,34 +1,146 @@
1
- import axios from 'axios';
2
- import MockAdapter from 'axios-mock-adapter';
3
- import { EmailTemplate, state } from '../index';
4
- import * as global from '../storage/StaticStorage';
5
- import { mockGetConfigEntitiesByType } from '../test/mocks/ForgeRockApiMockEngine';
6
- const mock = new MockAdapter(axios);
7
- state.setHost('https://openam-frodo-dev.forgeblocks.com/am');
8
- state.setRealm('alpha');
9
- state.setCookieName('cookieName');
10
- state.setCookieValue('cookieValue');
11
- state.setDeploymentType(global.CLOUD_DEPLOYMENT_TYPE_KEY);
12
- describe('EmailTemplateOps - getEmailTemplate()', () => {
13
- test('getEmailTemplate() 0: Method is implemented', async () => {
14
- expect(EmailTemplate.getEmailTemplate).toBeDefined();
1
+ /**
2
+ * To record and update snapshots, you must perform 3 steps in order:
3
+ *
4
+ * 1. Record API responses & update ESM snapshots
5
+ *
6
+ * To record and update ESM snapshots, you must call the test:record
7
+ * script and override all the connection state variables required
8
+ * to connect to the env to record from:
9
+ *
10
+ * FRODO_DEBUG=1 FRODO_HOST=frodo-dev npm run test:record EmailTemplateOps
11
+ *
12
+ * The above command assumes that you have a connection profile for
13
+ * 'frodo-dev' on your development machine.
14
+ *
15
+ * 2. Update CJS snapshots
16
+ *
17
+ * After recording, the ESM snapshots will already be updated as that happens
18
+ * in one go, but you musty manually update the CJS snapshots by running:
19
+ *
20
+ * FRODO_DEBUG=1 npm run test:update EmailTemplateOps
21
+ *
22
+ * 3. Test your changes
23
+ *
24
+ * If 1 and 2 didn't produce any errors, you are ready to run the tests in
25
+ * replay mode and make sure they all succeed as well:
26
+ *
27
+ * npm run test:only EmailTemplateOps
28
+ *
29
+ * Note: FRODO_DEBUG=1 is optional and enables debug logging for some output
30
+ * in case things don't function as expected
31
+ */
32
+ import { EmailTemplate, IdmConfigRaw } from '../index';
33
+ import { autoSetupPolly } from '../utils/AutoSetupPolly';
34
+ autoSetupPolly();
35
+ const {
36
+ EMAIL_TEMPLATE_TYPE
37
+ } = EmailTemplate;
38
+ async function stageTemplate(template, create = true) {
39
+ // delete if exists, then create
40
+ try {
41
+ await IdmConfigRaw.getConfigEntity(`${EMAIL_TEMPLATE_TYPE}/${template.id}`);
42
+ await IdmConfigRaw.deleteConfigEntity(`${EMAIL_TEMPLATE_TYPE}/${template.id}`);
43
+ } catch (error) {
44
+ // ignore
45
+ } finally {
46
+ if (create) {
47
+ await IdmConfigRaw.putConfigEntity(`${EMAIL_TEMPLATE_TYPE}/${template.id}`, template.data);
48
+ }
49
+ }
50
+ }
51
+ describe('EmailTemplateOps', () => {
52
+ const template1 = {
53
+ id: 'FrodoTestEmailTemplate1',
54
+ data: {
55
+ defaultLocale: 'en',
56
+ displayName: 'Frodo Test Email Template One',
57
+ enabled: true,
58
+ from: '',
59
+ message: {
60
+ en: '<h3>Click to reset your password</h3><h4><a href="{{object.resumeURI}}">Password reset link</a></h4>',
61
+ fr: '<h3>Cliquez pour réinitialiser votre mot de passe</h3><h4><a href="{{object.resumeURI}}">Mot de passe lien de réinitialisation</a></h4>'
62
+ },
63
+ mimeType: 'text/html',
64
+ subject: {
65
+ en: 'Reset your password',
66
+ fr: 'Réinitialisez votre mot de passe'
67
+ }
68
+ }
69
+ };
70
+ const template2 = {
71
+ id: 'FrodoTestEmailTemplate2',
72
+ data: {
73
+ defaultLocale: 'en',
74
+ displayName: 'Frodo Test Email Template Two',
75
+ enabled: true,
76
+ from: '',
77
+ message: {
78
+ en: '<h3>This is your one-time password:</h3><h4>{{object.description}}</a></h4>'
79
+ },
80
+ mimeType: 'text/html',
81
+ subject: {
82
+ en: 'One-Time Password for login'
83
+ }
84
+ }
85
+ };
86
+ const template3 = {
87
+ id: 'FrodoTestEmailTemplate3',
88
+ data: {
89
+ defaultLocale: 'en',
90
+ displayName: 'Frodo Test Email Template Three',
91
+ enabled: true,
92
+ from: '',
93
+ message: {
94
+ en: '<html><body><h3>You started a login or profile update that requires MFA. </h3><h4><a href="{{object.resumeURI}}">Click to Proceed</a></h4></body></html>'
95
+ },
96
+ mimeType: 'text/html',
97
+ subject: {
98
+ en: 'Multi-Factor Email for Identity Cloud login'
99
+ }
100
+ }
101
+ };
102
+ // in recording mode, setup test data before recording
103
+ beforeAll(async () => {
104
+ if (process.env.FRODO_POLLY_MODE === 'record') {
105
+ await stageTemplate(template1);
106
+ await stageTemplate(template2);
107
+ await stageTemplate(template3, false);
108
+ }
15
109
  });
16
- });
17
- describe('EmailTemplateOps - getEmailTemplates()', () => {
18
- test('getEmailTemplates() 0: Method is implemented', async () => {
19
- expect(EmailTemplate.getEmailTemplates).toBeDefined();
110
+ // in recording mode, remove test data after recording
111
+ afterAll(async () => {
112
+ if (process.env.FRODO_POLLY_MODE === 'record') {
113
+ await stageTemplate(template1, false);
114
+ await stageTemplate(template2, false);
115
+ await stageTemplate(template3, false);
116
+ }
20
117
  });
21
- test('getEmailTemplates() 1: Get email templates', async () => {
22
- mockGetConfigEntitiesByType(mock);
23
- expect.assertions(2);
24
- const emailTemplates = await EmailTemplate.getEmailTemplates();
25
- expect(emailTemplates).toBeTruthy();
26
- expect(emailTemplates.result.length).toBe(17);
118
+ describe('getEmailTemplate()', () => {
119
+ test('0: Method is implemented', async () => {
120
+ expect(EmailTemplate.getEmailTemplate).toBeDefined();
121
+ });
122
+ test(`1: Get email template '${template1.id}'`, async () => {
123
+ const response = await EmailTemplate.getEmailTemplate(template1.id);
124
+ expect(response).toMatchSnapshot();
125
+ });
27
126
  });
28
- });
29
- describe('EmailTemplateOps - putEmailTemplate()', () => {
30
- test('putEmailTemplate() 0: Method is implemented', async () => {
31
- expect(EmailTemplate.putEmailTemplate).toBeDefined();
127
+ describe('getEmailTemplates()', () => {
128
+ test('0: Method is implemented', async () => {
129
+ expect(EmailTemplate.getEmailTemplates).toBeDefined();
130
+ });
131
+ test('1: Get all email templates', async () => {
132
+ const response = await EmailTemplate.getEmailTemplates();
133
+ expect(response).toMatchSnapshot();
134
+ });
135
+ });
136
+ describe('putEmailTemplate()', () => {
137
+ test('0: Method is implemented', async () => {
138
+ expect(EmailTemplate.putEmailTemplate).toBeDefined();
139
+ });
140
+ test(`1: Create email template '${template3.id}'`, async () => {
141
+ const response = await EmailTemplate.putEmailTemplate(template3.id, template3.data);
142
+ expect(response).toMatchSnapshot();
143
+ });
32
144
  });
33
145
  });
34
146
  //# sourceMappingURL=EmailTemplateOps.test.js.map
@@ -1,72 +1,169 @@
1
- import fs from 'fs';
2
- import axios from 'axios';
3
- import MockAdapter from 'axios-mock-adapter';
4
- import { fileURLToPath } from 'url';
5
- import { Idm, state } from '../index';
6
- import * as global from '../storage/StaticStorage';
7
- import { mockGetAllConfigEntities, mockPutConfigEntity, mockGetConfigEntity, mockGetConfigEntitiesByType } from '../test/mocks/ForgeRockApiMockEngine';
8
- import path from 'path';
9
- const mock = new MockAdapter(axios);
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- state.setHost('https://openam-frodo-dev.forgeblocks.com/am');
12
- state.setRealm('alpha');
13
- state.setCookieName('cookieName');
14
- state.setCookieValue('cookieValue');
15
- state.setDeploymentType(global.CLOUD_DEPLOYMENT_TYPE_KEY);
16
- describe('IdmOps - getAllConfigEntities()', () => {
17
- test('getAllConfigEntities() 0: Method is implemented', async () => {
18
- expect(Idm.getAllConfigEntities).toBeDefined();
1
+ /**
2
+ * To record and update snapshots, you must perform 3 steps in order:
3
+ *
4
+ * 1. Record API responses & update ESM snapshots
5
+ *
6
+ * To record and update ESM snapshots, you must call the test:record
7
+ * script and override all the connection state variables required
8
+ * to connect to the env to record from:
9
+ *
10
+ * FRODO_DEBUG=1 FRODO_HOST=frodo-dev npm run test:record IdmOps
11
+ *
12
+ * The above command assumes that you have a connection profile for
13
+ * 'frodo-dev' on your development machine.
14
+ *
15
+ * 2. Update CJS snapshots
16
+ *
17
+ * After recording, the ESM snapshots will already be updated as that happens
18
+ * in one go, but you musty manually update the CJS snapshots by running:
19
+ *
20
+ * FRODO_DEBUG=1 npm run test:update IdmOps
21
+ *
22
+ * 3. Test your changes
23
+ *
24
+ * If 1 and 2 didn't produce any errors, you are ready to run the tests in
25
+ * replay mode and make sure they all succeed as well:
26
+ *
27
+ * npm run test:only IdmOps
28
+ *
29
+ * Note: FRODO_DEBUG=1 is optional and enables debug logging for some output
30
+ * in case things don't function as expected
31
+ */
32
+ import { Idm, IdmConfigRaw } from '../index';
33
+ import { autoSetupPolly } from '../utils/AutoSetupPolly';
34
+ autoSetupPolly();
35
+ async function stageConfigEntity(configEntity, create = true) {
36
+ // delete if exists, then create
37
+ try {
38
+ await IdmConfigRaw.getConfigEntity(configEntity.id);
39
+ await IdmConfigRaw.deleteConfigEntity(configEntity.id);
40
+ } catch (error) {
41
+ // ignore
42
+ } finally {
43
+ if (create) {
44
+ await IdmConfigRaw.putConfigEntity(configEntity.id, configEntity.data);
45
+ }
46
+ }
47
+ }
48
+ describe('IdmOps', () => {
49
+ const configEntity1 = {
50
+ id: 'emailTemplate/FrodoTestConfigEntity1',
51
+ data: {
52
+ defaultLocale: 'en',
53
+ displayName: 'Frodo Test Email Template One',
54
+ enabled: true,
55
+ from: '',
56
+ message: {
57
+ en: '<h3>Click to reset your password</h3><h4><a href="{{object.resumeURI}}">Password reset link</a></h4>',
58
+ fr: '<h3>Cliquez pour réinitialiser votre mot de passe</h3><h4><a href="{{object.resumeURI}}">Mot de passe lien de réinitialisation</a></h4>'
59
+ },
60
+ mimeType: 'text/html',
61
+ subject: {
62
+ en: 'Reset your password',
63
+ fr: 'Réinitialisez votre mot de passe'
64
+ }
65
+ }
66
+ };
67
+ const configEntity2 = {
68
+ id: 'emailTemplate/FrodoTestConfigEntity2',
69
+ data: {
70
+ defaultLocale: 'en',
71
+ displayName: 'Frodo Test Email Template Two',
72
+ enabled: true,
73
+ from: '',
74
+ message: {
75
+ en: '<h3>This is your one-time password:</h3><h4>{{object.description}}</a></h4>'
76
+ },
77
+ mimeType: 'text/html',
78
+ subject: {
79
+ en: 'One-Time Password for login'
80
+ }
81
+ }
82
+ };
83
+ const configEntity3 = {
84
+ id: 'emailTemplate/FrodoTestConfigEntity3',
85
+ data: {
86
+ defaultLocale: 'en',
87
+ displayName: 'Frodo Test Email Template Three',
88
+ enabled: true,
89
+ from: '',
90
+ message: {
91
+ en: '<html><body><h3>You started a login or profile update that requires MFA. </h3><h4><a href="{{object.resumeURI}}">Click to Proceed</a></h4></body></html>'
92
+ },
93
+ mimeType: 'text/html',
94
+ subject: {
95
+ en: 'Multi-Factor Email for Identity Cloud login'
96
+ }
97
+ }
98
+ };
99
+ // in recording mode, setup test data before recording
100
+ beforeAll(async () => {
101
+ if (process.env.FRODO_POLLY_MODE === 'record') {
102
+ await stageConfigEntity(configEntity1);
103
+ await stageConfigEntity(configEntity2);
104
+ await stageConfigEntity(configEntity3, false);
105
+ }
19
106
  });
20
- test('getAllConfigEntities() 1: get all config entities', async () => {
21
- mockGetAllConfigEntities(mock);
22
- expect.assertions(2);
23
- const configEntities = await Idm.getAllConfigEntities();
24
- expect(configEntities).toBeTruthy();
25
- expect(configEntities.configurations.length).toBeGreaterThan(0);
107
+ // in recording mode, remove test data after recording
108
+ afterAll(async () => {
109
+ if (process.env.FRODO_POLLY_MODE === 'record') {
110
+ await stageConfigEntity(configEntity1, false);
111
+ await stageConfigEntity(configEntity2, false);
112
+ await stageConfigEntity(configEntity3, false);
113
+ }
26
114
  });
27
- });
28
- describe('IdmOps - getConfigEntitiesByType()', () => {
29
- test('getConfigEntitiesByType() 0: Method is implemented', async () => {
30
- expect(Idm.getConfigEntitiesByType).toBeDefined();
31
- });
32
- test('getConfigEntitiesByType() 1: Get config entity by type', async () => {
33
- mockGetConfigEntitiesByType(mock);
34
- expect.assertions(2);
35
- const configEntity = await Idm.getConfigEntitiesByType('emailTemplate');
36
- expect(configEntity).toBeTruthy();
37
- expect(configEntity).toMatchSnapshot();
38
- });
39
- });
40
- describe('IdmOps - getConfigEntity()', () => {
41
- test('getConfigEntity() 0: Method is implemented', async () => {
42
- expect(Idm.getConfigEntity).toBeDefined();
115
+ describe('getAllConfigEntities()', () => {
116
+ test('0: Method is implemented', async () => {
117
+ expect(Idm.getAllConfigEntities).toBeDefined();
118
+ });
119
+ test('1: get all config entities', async () => {
120
+ const response = await Idm.getAllConfigEntities();
121
+ expect(response).toMatchSnapshot();
122
+ });
43
123
  });
44
- test('getConfigEntity() 1: Get config entity by Id', async () => {
45
- mockGetConfigEntity(mock);
46
- // expect.assertions(2);
47
- const configEntity = await Idm.getConfigEntity('managed');
48
- expect(configEntity).toBeTruthy();
49
- expect(configEntity).toMatchSnapshot();
124
+ describe('getConfigEntitiesByType()', () => {
125
+ test('0: Method is implemented', async () => {
126
+ expect(Idm.getConfigEntitiesByType).toBeDefined();
127
+ });
128
+ test('1: Get config entity by type (emailTemplate)', async () => {
129
+ const response = await Idm.getConfigEntitiesByType('emailTemplate');
130
+ expect(response).toMatchSnapshot();
131
+ });
132
+ test('2: Get config entity by type (managed)', async () => {
133
+ const response = await Idm.getConfigEntitiesByType('managed');
134
+ expect(response).toMatchSnapshot();
135
+ });
50
136
  });
51
- });
52
- describe('IdmOps - putConfigEntity()', () => {
53
- test('putConfigEntity() 0: Method is implemented', async () => {
54
- expect(Idm.putConfigEntity).toBeDefined();
137
+ describe('getConfigEntity()', () => {
138
+ test('0: Method is implemented', async () => {
139
+ expect(Idm.getConfigEntity).toBeDefined();
140
+ });
141
+ test(`1: Get config entity '${configEntity1.id}'`, async () => {
142
+ const response = await Idm.getConfigEntity(configEntity1.id);
143
+ expect(response).toMatchSnapshot();
144
+ });
145
+ test("2: Get config entity 'managed'", async () => {
146
+ const response = await Idm.getConfigEntity('managed');
147
+ expect(response).toMatchSnapshot();
148
+ });
55
149
  });
56
- test('putConfigEntity() 1: Put a config entity', async () => {
57
- const templateData = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../test/mocks/IdmConfigApi/getConfigEntity/emailTemplate/welcome.json'), 'utf8'));
58
- let uploaded = null;
59
- mockPutConfigEntity(mock, (id, data) => {
60
- uploaded = data;
150
+ describe('putConfigEntity()', () => {
151
+ test('0: Method is implemented', async () => {
152
+ expect(Idm.putConfigEntity).toBeDefined();
153
+ });
154
+ test(`1: Put a config entity '${configEntity3.id}'`, async () => {
155
+ const response = await Idm.putConfigEntity(configEntity3.id, configEntity3.data);
156
+ expect(response).toMatchSnapshot();
61
157
  });
62
- await Idm.putConfigEntity('emailTemplate/welcome', templateData);
63
- expect(uploaded).toBeDefined();
64
- expect(uploaded).toMatchSnapshot();
65
158
  });
66
- });
67
- describe('IdmOps - queryAllManagedObjectsByType()', () => {
68
- test('queryAllManagedObjectsByType() 0: Method is implemented', async () => {
69
- expect(Idm.queryAllManagedObjectsByType).toBeDefined();
159
+ describe('queryAllManagedObjectsByType()', () => {
160
+ test('0: Method is implemented', async () => {
161
+ expect(Idm.queryAllManagedObjectsByType).toBeDefined();
162
+ });
163
+ test(`1: Query managed objects of type 'alpha_user'`, async () => {
164
+ const response = await Idm.queryAllManagedObjectsByType('alpha_user', ['*'], null);
165
+ expect(response).toMatchSnapshot();
166
+ });
70
167
  });
71
168
  });
72
169
  //# sourceMappingURL=IdmOps.test.js.map