@northern.tech/testing 0.8.3 → 0.9.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.
Files changed (101) hide show
  1. package/dist/chunk-CKQMccvm.cjs +28 -0
  2. package/dist/mockData.cjs +1288 -953
  3. package/dist/mockData.cjs.map +1 -1
  4. package/dist/mockData.d.cts +595 -569
  5. package/dist/mockData.d.ts +595 -569
  6. package/dist/mockData.js +1278 -45
  7. package/dist/mockData.js.map +1 -1
  8. package/dist/openapi.yaml.d.cjs +0 -0
  9. package/dist/openapi.yaml.d.cts +4 -0
  10. package/dist/openapi.yaml.d.ts +5 -0
  11. package/dist/requestHandlers/deploymentHandlers.cjs +181 -1031
  12. package/dist/requestHandlers/deploymentHandlers.cjs.map +1 -1
  13. package/dist/requestHandlers/deploymentHandlers.d.cts +5 -3
  14. package/dist/requestHandlers/deploymentHandlers.d.ts +5 -3
  15. package/dist/requestHandlers/deploymentHandlers.js +190 -6
  16. package/dist/requestHandlers/deploymentHandlers.js.map +1 -1
  17. package/dist/requestHandlers/deviceHandlers.cjs +427 -1090
  18. package/dist/requestHandlers/deviceHandlers.cjs.map +1 -1
  19. package/dist/requestHandlers/deviceHandlers.d.cts +17 -15
  20. package/dist/requestHandlers/deviceHandlers.d.ts +17 -15
  21. package/dist/requestHandlers/deviceHandlers.js +427 -10
  22. package/dist/requestHandlers/deviceHandlers.js.map +1 -1
  23. package/dist/requestHandlers/monitorHandlers.cjs +21 -831
  24. package/dist/requestHandlers/monitorHandlers.cjs.map +1 -1
  25. package/dist/requestHandlers/monitorHandlers.d.cts +5 -3
  26. package/dist/requestHandlers/monitorHandlers.d.ts +5 -3
  27. package/dist/requestHandlers/monitorHandlers.js +21 -7
  28. package/dist/requestHandlers/monitorHandlers.js.map +1 -1
  29. package/dist/requestHandlers/organizationHandlers.cjs +296 -1113
  30. package/dist/requestHandlers/organizationHandlers.cjs.map +1 -1
  31. package/dist/requestHandlers/organizationHandlers.d.cts +5 -3
  32. package/dist/requestHandlers/organizationHandlers.d.ts +5 -3
  33. package/dist/requestHandlers/organizationHandlers.js +308 -6
  34. package/dist/requestHandlers/organizationHandlers.js.map +1 -1
  35. package/dist/requestHandlers/releaseHandlers.cjs +157 -960
  36. package/dist/requestHandlers/releaseHandlers.cjs.map +1 -1
  37. package/dist/requestHandlers/releaseHandlers.d.cts +5 -3
  38. package/dist/requestHandlers/releaseHandlers.d.ts +5 -3
  39. package/dist/requestHandlers/releaseHandlers.js +158 -6
  40. package/dist/requestHandlers/releaseHandlers.js.map +1 -1
  41. package/dist/requestHandlers/requestHandlers.cjs +26 -2000
  42. package/dist/requestHandlers/requestHandlers.cjs.map +1 -1
  43. package/dist/requestHandlers/requestHandlers.d.cts +5 -4
  44. package/dist/requestHandlers/requestHandlers.d.ts +5 -3
  45. package/dist/requestHandlers/requestHandlers.js +24 -32
  46. package/dist/requestHandlers/requestHandlers.js.map +1 -1
  47. package/dist/requestHandlers/userHandlers.cjs +139 -990
  48. package/dist/requestHandlers/userHandlers.cjs.map +1 -1
  49. package/dist/requestHandlers/userHandlers.d.cts +5 -3
  50. package/dist/requestHandlers/userHandlers.d.ts +5 -3
  51. package/dist/requestHandlers/userHandlers.js +139 -7
  52. package/dist/requestHandlers/userHandlers.js.map +1 -1
  53. package/dist/requestHandlers/validation.cjs +4 -0
  54. package/dist/requestHandlers/validation.d.cts +6 -0
  55. package/dist/requestHandlers/validation.d.ts +6 -0
  56. package/dist/requestHandlers/validation.js +2 -0
  57. package/dist/setupTests.cjs +148 -992
  58. package/dist/setupTests.cjs.map +1 -1
  59. package/dist/setupTests.d.cts +68 -66
  60. package/dist/setupTests.d.ts +68 -66
  61. package/dist/setupTests.js +114 -117
  62. package/dist/setupTests.js.map +1 -1
  63. package/dist/theme/light.cjs +7 -39
  64. package/dist/theme/light.cjs.map +1 -1
  65. package/dist/theme/light.d.cts +5 -10
  66. package/dist/theme/light.d.ts +5 -10
  67. package/dist/theme/light.js +7 -6
  68. package/dist/theme/light.js.map +1 -1
  69. package/dist/theme/mui.d.cjs +0 -0
  70. package/dist/theme/mui.d.cts +11 -0
  71. package/dist/theme/mui.d.ts +11 -0
  72. package/dist/utils.cjs +18 -68
  73. package/dist/utils.cjs.map +1 -1
  74. package/dist/utils.d.cts +6 -67
  75. package/dist/utils.d.ts +6 -67
  76. package/dist/utils.js +16 -10
  77. package/dist/utils.js.map +1 -1
  78. package/dist/validation-CsEFO-Cv.cjs +77 -0
  79. package/dist/validation-CsEFO-Cv.cjs.map +1 -0
  80. package/dist/validation-JDM_vsFz.js +64 -0
  81. package/dist/validation-JDM_vsFz.js.map +1 -0
  82. package/package.json +8 -6
  83. package/dist/chunk-3CVNBMEF.js +0 -161
  84. package/dist/chunk-3CVNBMEF.js.map +0 -1
  85. package/dist/chunk-7GNK7IRV.js +0 -29
  86. package/dist/chunk-7GNK7IRV.js.map +0 -1
  87. package/dist/chunk-AP4MOFMD.js +0 -239
  88. package/dist/chunk-AP4MOFMD.js.map +0 -1
  89. package/dist/chunk-DOHA53UH.js +0 -301
  90. package/dist/chunk-DOHA53UH.js.map +0 -1
  91. package/dist/chunk-H4J7L3HX.js +0 -188
  92. package/dist/chunk-H4J7L3HX.js.map +0 -1
  93. package/dist/chunk-HRGVXWMH.js +0 -17
  94. package/dist/chunk-HRGVXWMH.js.map +0 -1
  95. package/dist/chunk-KCLTR6QS.js +0 -34
  96. package/dist/chunk-KCLTR6QS.js.map +0 -1
  97. package/dist/chunk-M2TKDOPD.js +0 -266
  98. package/dist/chunk-M2TKDOPD.js.map +0 -1
  99. package/dist/chunk-O42KIJXJ.js +0 -933
  100. package/dist/chunk-O42KIJXJ.js.map +0 -1
  101. /package/dist/{baseTestConfig.json → public/baseTestConfig.json} +0 -0
@@ -1,993 +1,142 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/requestHandlers/userHandlers.ts
21
- var userHandlers_exports = {};
22
- __export(userHandlers_exports, {
23
- userHandlers: () => userHandlers
24
- });
25
- module.exports = __toCommonJS(userHandlers_exports);
26
- var import_constants2 = require("@northern.tech/utils/constants");
27
- var import_msw = require("msw");
28
-
29
- // src/mockData.ts
30
- var import_constants = require("@northern.tech/utils/constants");
31
- var TEST_SESSION_DATETIME = "2019-01-13T13:00:00.000Z";
32
- var testDate = new Date(TEST_SESSION_DATETIME);
33
- var mockDate = new Date(testDate.setMilliseconds(testDate.getMilliseconds() + import_constants.maxSessionAge));
34
- var defaultPassword = "mysecretpassword!123";
35
- var defaultCreationDate = "2019-01-13T06:25:00.000Z";
36
- var defaultMacAddress = "dc:a6:32:12:ad:bf";
37
- var testSsoId = "sso_id";
38
- var permissionSetObjectTypes = {
39
- any: "Any",
40
- artifacts: "Artifacts",
41
- empty: "",
42
- groups: "Device groups",
43
- releases: "Releases",
44
- tenantManagement: "Tenant management",
45
- userManagement: "User management"
46
- };
47
- var commonEndpoints = {
48
- artifacts: "^/api/management/v1/deployments/artifacts",
49
- artifactDetails: "^/api/management/v1/deployments/artifacts/[^/]+",
50
- deviceManagement: "^/api/management/(v[1-9])/(devauth|inventory)/"
51
- };
52
- var token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjZTNkMGY4Yy1hZWRlLTQwMzAtYjM5MS03ZDUwMjBlYjg3M2UiLCJzdWIiOiJhMzBhNzgwYi1iODQzLTUzNDQtODBlMy0wZmQ5NWE0ZjZmYzMiLCJleHAiOjE2MDY4MTUzNjksImlhdCI6MTYwNjIxMDU2OSwibWVuZGVyLnRlbmFudCI6IjVmODVjMTdiY2U2MmI3ZmE3ZjVmNzA0MCIsIm1lbmRlci51c2VyIjp0cnVlLCJpc3MiOiJNZW5kZXIgVXNlcnMiLCJzY3AiOiJtZW5kZXIuKiIsIm1lbmRlci5wbGFuIjoicHJvZmVzc2lvbmFsIiwibmJmIjoxNjA2MjEwNTY5fQ.qVgYdCzLTf8OdK9uUctqqaY_HWkIiwpekuGvuGQAXCEgOv4bRNDlZRN_ZRSbxQoARG3pquhScbQrjBV9tcF4irTUPlTn3yrsXNO17DpcbTVeKRkb88RDtIKiRw3orVZ_GlIb-ckTQ5dS-Nqlyyf3Fmrhca-gwt6m_xv2UrmJK6eYYTMfggdRRWb-4u7mEkBI_pHPMTQrT8kJ2BeX-vHgazH9AoH0k85LHtFZQXD7pXHlDZRnLxJXukncwMGDmF17374gavYAIyDIzcC8sEBMDnVXgpikeA1sauzirqix6mAVs6XmxdQO7aF0wfXO1_PTYUA3Nk1oQfMYNlEI3U9uLRJRZIq2L8fmrrBryhstKd4y0KlBbGAQrx8NtRkgajjd1ljMfPBUEZrb7uSerVjneiO-aIBO76CuH0zdklphIjpGJeogkBhe8pAYNggp1XsZHgpZfl7IE5faKaDkMGnutaea--Czor6bhqUNCuY4tR0cpQJbNwy6LS9o1CFy4Log";
53
- var accessTokens = [
54
- { id: "some-id-1", expiration_date: "2022-06-02T11:11:21.725Z", name: "some-name-1" },
55
- { id: "some-id-2", expiration_date: "2022-06-02T11:11:21.725Z", last_used: "2022-06-02T11:05:21.725Z", name: "some-name-2" }
56
- ];
57
- var userId = "a30a780b-b843-5344-80e3-0fd95a4f6fc3";
58
- var defaultUser = {
59
- created_ts: "2019-01-01T10:30:00.000Z",
60
- email: "a@b.com",
61
- id: "a1",
62
- roles: ["RBAC_ROLE_PERMIT_ALL"],
63
- tfa_status: "enabled",
64
- verified: true
65
- };
66
- var deviceTypes = { qemu: "qemux86-64" };
67
- var checkInTimeRounded = "2019-01-01T00:00:00.000Z";
68
- var checkInTimeExact = "2019-01-01T10:25:00.000Z";
69
- var mockApiResponses = {
70
- deployments: {
71
- byId: {
72
- d1: {
73
- id: "d1",
74
- name: "test deployment",
75
- created: "2019-01-01T12:30:00.000Z",
76
- devices: {
77
- a1: {
78
- id: "a1",
79
- status: "installing",
80
- attributes: {},
81
- image: { size: 123 }
82
- }
83
- },
84
- statistics: {
85
- status: {
86
- "already-installed": 0,
87
- decommissioned: 0,
88
- downloading: 0,
89
- failure: 0,
90
- installing: 1,
91
- noartifact: 0,
92
- pending: 0,
93
- rebooting: 0,
94
- success: 0
95
- },
96
- total_size: 1234
97
- }
98
- },
99
- d2: {
100
- id: "d2",
101
- name: "test deployment 2",
102
- artifact_name: "r1",
103
- artifacts: ["123"],
104
- created: "2019-01-01T12:25:00.000Z",
105
- device_count: 1,
106
- devices: {
107
- b1: {
108
- attributes: {},
109
- id: "b1",
110
- status: "pending"
111
- }
112
- },
113
- filter: void 0,
114
- group: void 0,
115
- statistics: {
116
- status: {
117
- downloading: 0,
118
- decommissioned: 0,
119
- failure: 0,
120
- installing: 0,
121
- noartifact: 0,
122
- pending: 1,
123
- rebooting: 0,
124
- success: 0,
125
- "already-installed": 0
126
- }
127
- }
128
- },
129
- d3: {
130
- id: "d3",
131
- name: "Test",
132
- phases: [
133
- { id: "0", batch_size: 2, device_count: 2 },
134
- { id: "1", start_ts: "2019-02-04T11:45:10.002Z", batch_size: 3, device_count: 3 },
135
- { id: "2", start_ts: "2019-02-05T11:45:10.002Z", batch_size: 5, device_count: 5 },
136
- { id: "3", start_ts: "2019-02-06T11:45:10.002Z", batch_size: 5, device_count: 5 },
137
- { id: "4", start_ts: "2019-02-21T11:45:10.002Z", batch_size: 5, device_count: 0 }
138
- ],
139
- max_devices: 0,
140
- created: "2019-01-31T12:59:30.020Z",
141
- devices: {},
142
- filter: void 0,
143
- group: void 0,
144
- stats: {
145
- pending: 3,
146
- decommissioned: 0,
147
- failure: 23,
148
- pause_before_committing: 0,
149
- pause_before_rebooting: 0,
150
- installing: 0,
151
- rebooting: 0,
152
- "already-installed": 0,
153
- pause_before_installing: 0,
154
- downloading: 0,
155
- success: 6,
156
- aborted: 0,
157
- noartifact: 0
158
- },
159
- statistics: { total_size: "1234" },
160
- status: "inprogress",
161
- active: true,
162
- device_count: 100,
163
- retries: "0",
164
- type: "software"
165
- }
166
- },
167
- byStatus: {
168
- pending: { deploymentIds: ["d2"] },
169
- inprogress: { deploymentIds: ["d3"] }
170
- }
171
- },
172
- devices: {
173
- byId: {
174
- a1: {
175
- id: "a1",
176
- auth_sets: [
177
- {
178
- id: "auth1",
179
- identity_data: { mac: defaultMacAddress },
180
- pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
181
- status: "accepted",
182
- ts: defaultCreationDate
183
- }
184
- ],
185
- updated_ts: "2019-01-01T09:25:00.000Z"
186
- },
187
- b1: {
188
- id: "b1",
189
- attributes: {
190
- ipv4_wlan0: "192.168.10.141/24",
191
- device_type: [deviceTypes.qemu]
192
- },
193
- system: {
194
- check_in_time: checkInTimeRounded
195
- },
196
- check_in_time: checkInTimeExact,
197
- check_in_time_exact: checkInTimeExact,
198
- check_in_time_rounded: checkInTimeRounded,
199
- identity_data: { mac: defaultMacAddress },
200
- status: "accepted",
201
- decommissioning: false,
202
- created_ts: defaultCreationDate,
203
- updated_ts: "2019-01-01T09:25:00.000Z",
204
- auth_sets: [
205
- {
206
- id: "auth1",
207
- identity_data: { mac: defaultMacAddress },
208
- pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
209
- ts: defaultCreationDate,
210
- status: "accepted"
211
- }
212
- ]
213
- }
214
- },
215
- groups: {
216
- byId: {
217
- testGroup: {
218
- deviceIds: ["a1", "b1"],
219
- filters: [],
220
- total: 2
221
- },
222
- testGroupDynamic: {
223
- id: "filter1",
224
- name: "filter1",
225
- filters: [{ scope: "system", key: "group", operator: "$eq", value: "things" }]
226
- }
227
- }
228
- },
229
- limits: { standard: 500, micro: 0, system: 0 },
230
- byStatus: {
231
- accepted: { deviceIds: ["a1", "b1"], total: 2 },
232
- active: { deviceIds: [], total: 0 },
233
- inactive: { deviceIds: [], total: 0 },
234
- pending: { deviceIds: ["c1"], total: 1 },
235
- preauthorized: { deviceIds: [], total: 0 },
236
- rejected: { deviceIds: [], total: 0 }
237
- }
238
- },
239
- organization: {
240
- organization: {
241
- id: "1",
242
- addons: [],
243
- name: "test",
244
- plan: "os",
245
- trial: false
246
- },
247
- products: [
248
- {
249
- name: "mender_standard",
250
- billing_unit: "devices",
251
- prices: [
252
- {
253
- plan: "os",
254
- constraints: {
255
- min: 50,
256
- max: 1e3,
257
- div: 50
258
- }
259
- },
260
- {
261
- plan: "professional",
262
- constraints: {
263
- min: 250,
264
- max: 1e4,
265
- div: 50
266
- }
267
- }
268
- ],
269
- addons: [
270
- {
271
- name: "troubleshoot",
272
- prices: [{ plan: "os" }, { plan: "professional" }]
273
- },
274
- {
275
- name: "configure",
276
- prices: [{ plan: "os" }, { plan: "professional" }]
277
- },
278
- {
279
- name: "monitor",
280
- prices: [{ plan: "professional" }]
281
- }
282
- ]
283
- },
284
- {
285
- name: "mender_micro",
286
- billing_unit: "devices",
287
- prices: [
288
- {
289
- plan: "os",
290
- constraints: {
291
- min: 50,
292
- max: 5e3,
293
- div: 50
294
- }
295
- },
296
- {
297
- plan: "professional",
298
- constraints: {
299
- min: 500,
300
- max: 1e5,
301
- div: 50
302
- }
303
- }
304
- ]
305
- }
306
- ],
307
- intentId: "testIntent",
308
- auditlog: {
309
- events: [
310
- {
311
- actor: {
312
- id: "string",
313
- type: "user",
314
- email: "string@example.com"
315
- },
316
- time: "2019-01-01T12:10:22.667Z",
317
- action: "create",
318
- object: {
319
- id: "string",
320
- type: "user",
321
- user: {
322
- email: "user@acme.com"
323
- }
324
- },
325
- change: "change1"
326
- },
327
- {
328
- actor: {
329
- id: "string",
330
- type: "user",
331
- email: "string",
332
- identity_data: "string"
333
- },
334
- time: "2019-01-01T12:16:22.667Z",
335
- action: "create",
336
- object: {
337
- id: "string",
338
- type: "deployment",
339
- deployment: {
340
- name: "production",
341
- artifact_name: "Application 0.0.1"
342
- }
343
- },
344
- change: "change2"
345
- },
346
- {
347
- actor: {
348
- id: "string",
349
- type: "user",
350
- email: "string@example.com"
351
- },
352
- time: "2019-01-01T12:10:22.669Z",
353
- action: "open_terminal",
354
- meta: {
355
- session_id: ["abd313a8-ee88-48ab-9c99-fbcd80048e6e"]
356
- },
357
- object: {
358
- id: "a1",
359
- type: "device"
360
- },
361
- change: "change3"
362
- }
363
- ]
364
- }
365
- },
366
- releases: {
367
- byId: {
368
- r1: {
369
- name: "r1",
370
- artifacts: [
371
- {
372
- id: "art1",
373
- description: "test description",
374
- device_types_compatible: [deviceTypes.qemu],
375
- modified: "2020-09-10T12:16:22.667Z",
376
- updates: [{ type_info: { type: "testtype" } }],
377
- artifact_depends: {
378
- device_type: [deviceTypes.qemu]
379
- },
380
- artifact_provides: {
381
- artifact_name: "myapp",
382
- "data-partition.myapp.version": "v2020.10",
383
- list_of_fancy: [deviceTypes.qemu, "x172"]
384
- },
385
- clears_artifact_provides: ["data-partition.myapp.*"]
386
- }
387
- ],
388
- device_types_compatible: [deviceTypes.qemu],
389
- modified: "2020-09-10T12:16:22.667Z",
390
- metaData: {}
391
- }
392
- }
393
- },
394
- users: {
395
- byId: {
396
- a1: defaultUser,
397
- [userId]: { ...defaultUser, id: userId, email: "a2@b.com", created_ts: "2019-01-01T12:30:00.000Z" }
398
- },
399
- rolesById: {
400
- admin: {
401
- name: "admin",
402
- description: "Administrator role",
403
- permissions: []
404
- },
405
- test: { name: "test", description: "test description", permissions: [] }
406
- },
407
- globalSettings: {
408
- "2fa": "enabled",
409
- id_attribute: void 0,
410
- previousFilters: []
411
- },
412
- userSettings: {
413
- "2fa": "disabled",
414
- columnSelection: [],
415
- onboarding: { something: "here" },
416
- tooltips: {},
417
- previousFilters: []
418
- }
419
- }
420
- };
421
- var releasesList = Array.from({ length: 5e3 }, (x, i) => ({
422
- artifacts: [
423
- {
424
- id: "art1",
425
- description: "test description",
426
- device_types_compatible: [deviceTypes.qemu],
427
- modified: "2020-09-10T12:16:22.667Z",
428
- updates: [{ type_info: { type: "testtype" } }],
429
- artifact_depends: {
430
- device_type: [deviceTypes.qemu]
431
- },
432
- artifact_provides: {
433
- artifact_name: "myapp",
434
- "data-partition.myapp.version": "v2020.10",
435
- list_of_fancy: [deviceTypes.qemu, "x172"]
436
- },
437
- clears_artifact_provides: ["data-partition.myapp.*"]
438
- }
439
- ],
440
- device_types_compatible: [deviceTypes.qemu],
441
- metaData: {},
442
- name: `release-${i + 1}`,
443
- modified: i
444
- }));
445
- var permissionSets = [
446
- {
447
- ...import_constants.defaultPermissionSets.Basic,
448
- object: permissionSetObjectTypes.empty,
449
- description: "Set containing basic permissions.",
450
- permissions: [
451
- { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/settings$" } },
452
- { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/users/me$" } },
453
- { action: "http", object: { type: "any", value: "^/api/management/1.0/auth/verify$" } },
454
- { action: "http", object: { type: "PUT", value: "^/api/management/v1/useradm/2faverify$" } },
455
- { action: "http", object: { type: "POST", value: "^/api/management/v1/useradm/users/me/2fa/(enable|disable)$" } },
456
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/roles" } },
457
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/user/tenant" } }
458
- ]
459
- },
460
- {
461
- ...import_constants.defaultPermissionSets.ManageReleases,
462
- action: import_constants.uiPermissionsById.manage.title,
463
- object: permissionSetObjectTypes.releases,
464
- description: "Set of permissions which allows user to manage releases",
465
- permissions: [
466
- { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
467
- { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
468
- { action: "http", object: { type: "PUT", value: commonEndpoints.artifactDetails } },
469
- { action: "http", object: { type: "DELETE", value: commonEndpoints.artifactDetails } },
470
- { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
471
- ]
472
- },
473
- {
474
- ...import_constants.defaultPermissionSets.ReadUsers,
475
- action: import_constants.uiPermissionsById.read.title,
476
- object: permissionSetObjectTypes.userManagement,
477
- description: "Set of permissions which allows user to view other users",
478
- permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/" } }]
479
- },
480
- {
481
- ...import_constants.defaultPermissionSets.ManageUsers,
482
- action: import_constants.uiPermissionsById.manage.title,
483
- object: permissionSetObjectTypes.userManagement,
484
- description: "Set of permissions which allows user manage other user accounts",
485
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/" } }]
486
- },
487
- {
488
- ...import_constants.defaultPermissionSets.ReadTenants,
489
- action: import_constants.uiPermissionsById.read.title,
490
- object: permissionSetObjectTypes.tenantManagement,
491
- description: "Set of permissions which allows user to list other tenants and their config",
492
- permissions: [
493
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
494
- { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } }
495
- ]
496
- },
497
- {
498
- ...import_constants.defaultPermissionSets.ManageTenants,
499
- action: import_constants.uiPermissionsById.manage.title,
500
- object: permissionSetObjectTypes.tenantManagement,
501
- description: "Set of permissions which allows user to manage other tenants and their config",
502
- permissions: [
503
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
504
- { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } },
505
- { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9])/tenantadm/" } }
506
- ]
507
- },
508
- {
509
- ...import_constants.defaultPermissionSets.ReadAuditLogs,
510
- action: import_constants.uiPermissionsById.read.title,
511
- object: "System Audit Log",
512
- description: "Set of permissions which allows user to view system audit log",
513
- permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/auditlogs/logs" } }]
514
- },
515
- {
516
- ...import_constants.defaultPermissionSets.DeployToDevices,
517
- action: "Deploy",
518
- object: permissionSetObjectTypes.groups,
519
- description: "Set of permissions which allows user to deploy to devices",
520
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/(deployments|deviceconfig)/" } }],
521
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
522
- },
523
- {
524
- ...import_constants.defaultPermissionSets.ConfigureDevices,
525
- action: "Configure",
526
- object: permissionSetObjectTypes.groups,
527
- description: "Set of permissions which allows user to manage configuration of the devices",
528
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/" } }],
529
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
530
- },
531
- {
532
- ...import_constants.defaultPermissionSets.ConnectToDevices,
533
- action: "Connect",
534
- object: permissionSetObjectTypes.groups,
535
- description: "Set of permissions which allows user to use remote terminal and file transfer",
536
- permissions: [
537
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/connect$" } },
538
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/download\\?path=[^&]+$" } },
539
- { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/upload$" } }
540
- ],
541
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
542
- },
543
- {
544
- ...import_constants.defaultPermissionSets.SuperUser,
545
- action: "Any",
546
- object: permissionSetObjectTypes.any,
547
- description: "Set of permissions which allows user to do anything",
548
- permissions: [{ action: "any", object: { type: "any", value: "any" } }]
549
- },
550
- {
551
- ...import_constants.defaultPermissionSets.UploadArtifacts,
552
- action: "Upload",
553
- object: permissionSetObjectTypes.artifacts,
554
- description: "Set of permissions which allows user to upload artifacts",
555
- permissions: [
556
- { action: "http", object: { type: "POST", value: commonEndpoints.artifacts } },
557
- { action: "http", object: { type: "POST", value: "^/api/management/v1/deployments/artifacts/generate" } }
558
- ]
559
- },
560
- {
561
- ...import_constants.defaultPermissionSets.ReadDevices,
562
- action: import_constants.uiPermissionsById.read.title,
563
- object: permissionSetObjectTypes.groups,
564
- description: "Set of permissions which allows user to view devices",
565
- permissions: [
566
- { action: "http", object: { type: "POST", value: "^/api/management/v2/inventory/filters/search" } },
567
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/(deployments|devauth|inventory|deviceconfig|devicemonitor)/" } },
568
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+$" } }
569
- ],
570
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
571
- },
572
- {
573
- ...import_constants.defaultPermissionSets.ManageDevices,
574
- action: import_constants.uiPermissionsById.manage.title,
575
- object: permissionSetObjectTypes.groups,
576
- description: "Set of permissions which allows user to manage devices",
577
- permissions: [
578
- { action: "http", object: { type: "POST", value: commonEndpoints.deviceManagement } },
579
- { action: "http", object: { type: "PUT", value: commonEndpoints.deviceManagement } },
580
- { action: "http", object: { type: "DELETE", value: commonEndpoints.deviceManagement } }
581
- ],
582
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
583
- },
584
- {
585
- ...import_constants.defaultPermissionSets.ReadReleases,
586
- action: import_constants.uiPermissionsById.read.title,
587
- object: permissionSetObjectTypes.releases,
588
- description: "Set of permissions which allows user to view releases",
589
- permissions: [
590
- { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
591
- { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
592
- { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
593
- ]
594
- },
595
- {
596
- name: "almostAdmin",
597
- object: permissionSetObjectTypes.empty,
598
- description: "Set containing all the permissions.",
599
- permissions: [
600
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/auditlogs/.*" } },
601
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/.*" } },
602
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/config/.*" } },
603
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/.*" } },
604
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/releases/.*" } },
605
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/devauth/.*" } },
606
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/.*" } },
607
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/.*" } },
608
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/devices" } },
609
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/inventory/.*" } },
610
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/iot-manager/.*" } },
611
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/monitor/.*" } },
612
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/.*" } }
613
- ]
614
- }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../chunk-CKQMccvm.cjs");
3
+ const require_mockData = require("../mockData.cjs");
4
+ const require_validation = require("../validation-CsEFO-Cv.cjs");
5
+ let _northern_tech_utils_constants = require("@northern.tech/utils/constants");
6
+ let msw = require("msw");
7
+ //#region src/requestHandlers/userHandlers.ts
8
+ const userHandlers = [
9
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/auth/login`, ({ request }) => {
10
+ const authHeader = request.headers.get("authorization");
11
+ const [user, password] = atob(authHeader?.split(" ")[1]).split(":");
12
+ if (!password) return msw.HttpResponse.json({
13
+ id: require_mockData.testSsoId,
14
+ kind: "sso/saml"
15
+ });
16
+ else if (password !== "mysecretpassword!123") return new msw.HttpResponse(null, { status: 401 });
17
+ else if (user.includes("limited")) return new msw.HttpResponse("limitedToken", { headers: { "Content-Type": _northern_tech_utils_constants.APPLICATION_JWT_CONTENT_TYPE } });
18
+ else if (user.includes("2fa")) return new msw.HttpResponse(JSON.stringify({ error: "2fa needed" }), { status: 401 });
19
+ return new msw.HttpResponse(require_mockData.token, { headers: { "Content-Type": _northern_tech_utils_constants.APPLICATION_JWT_CONTENT_TYPE } });
20
+ }),
21
+ msw.http.get(`https://hosted.mender.io${_northern_tech_utils_constants.useradmApiUrl}/auth/magic/:id`, ({ params: { id } }) => {
22
+ if (id) return new msw.HttpResponse("test", { headers: { "Set-Cookie": "JWT=test" } });
23
+ return new msw.HttpResponse(null, { status: 400 });
24
+ }),
25
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/auth/logout`, () => new msw.HttpResponse(null, { status: 200 })),
26
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/auth/password-reset/:status`, require_validation.validated(async ({ params: { status }, request }) => {
27
+ const { email, secret_hash, password } = await request.json();
28
+ if (!["start", "complete"].includes(status) && ![
29
+ email,
30
+ secret_hash,
31
+ password
32
+ ].some((item) => item)) return new msw.HttpResponse(null, { status: 560 });
33
+ if (status === "start" && email) return new msw.HttpResponse(null, { status: 200 });
34
+ if (status === "complete" && secret_hash && password) return new msw.HttpResponse(null, { status: 200 });
35
+ return new msw.HttpResponse(null, { status: 561 });
36
+ })),
37
+ msw.http.put(`${_northern_tech_utils_constants.useradmApiUrl}/2faverify`, require_validation.validated(async ({ request }) => {
38
+ const { token2fa } = await request.json();
39
+ if (!token2fa) return new msw.HttpResponse(null, { status: 562 });
40
+ return new msw.HttpResponse(null, { status: 200 });
41
+ })),
42
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/users`, () => msw.HttpResponse.json(Object.values(require_mockData.mockApiResponses.users.byId))),
43
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/users/me`, ({ request }) => {
44
+ if (request.headers.get("authorization")?.includes("limited")) return new msw.HttpResponse(JSON.stringify({ error: "forbidden by role-based access control" }), { status: 403 });
45
+ return msw.HttpResponse.json(require_mockData.mockApiResponses.users.byId[require_mockData.userId]);
46
+ }),
47
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/users/exists`, ({ request }) => {
48
+ const email = new URL(request.url).searchParams.get("email");
49
+ if (!decodeURIComponent(email).includes("child+123")) return new msw.HttpResponse(null, { status: 578 });
50
+ return msw.HttpResponse.json({ exists: true });
51
+ }),
52
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId`, ({ params: { userId: userId$1 } }) => {
53
+ if (userId$1 === "me" || require_mockData.mockApiResponses.users.byId[userId$1]) {
54
+ const user = userId$1 === "me" ? require_mockData.userId : userId$1;
55
+ return msw.HttpResponse.json(require_mockData.mockApiResponses.users.byId[user]);
56
+ }
57
+ return new msw.HttpResponse(null, { status: 563 });
58
+ }),
59
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/users`, require_validation.validated(async ({ request }) => {
60
+ const { email, password } = await request.json();
61
+ if (email === "test@test.com" || [email, password].every((value) => value)) return msw.HttpResponse.json(require_mockData.mockApiResponses.users.byId.a1);
62
+ return new msw.HttpResponse(null, { status: 564 });
63
+ })),
64
+ msw.http.put(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId`, require_validation.validated(async ({ params: { userId }, request }) => {
65
+ const { email, password, current_password } = await request.json();
66
+ if (current_password === "bad_password") return new msw.HttpResponse(null, { status: 401 });
67
+ if (require_mockData.mockApiResponses.users.byId[userId] && [email, password].some((value) => Object.values(require_mockData.mockApiResponses.users.byId[userId]).includes(value)) || email === "test@test.com") return new msw.HttpResponse(null, { status: 200 });
68
+ return new msw.HttpResponse(null, { status: 565 });
69
+ })),
70
+ msw.http.delete(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId`, ({ params: { userId } }) => new msw.HttpResponse(null, { status: require_mockData.mockApiResponses.users.byId[userId] ? 200 : 566 })),
71
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/roles`, () => msw.HttpResponse.json(require_mockData.rbacRoles)),
72
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/roles`, require_validation.validated(async ({ request }) => {
73
+ const { name, permissions } = await request.json();
74
+ if ([name, permissions].every((value) => value) && permissions.every((permission) => permission.action && permission.object && permission.object.type && permission.object.value)) return new msw.HttpResponse(null, { status: 200 });
75
+ return new msw.HttpResponse(null, { status: 567 });
76
+ })),
77
+ msw.http.put(`${_northern_tech_utils_constants.useradmApiUrl}/roles/:roleId`, require_validation.validated(async ({ params: { roleId }, request }) => {
78
+ const { description, name, permissions } = await request.json();
79
+ if (require_mockData.mockApiResponses.users.rolesById[roleId] && [
80
+ description,
81
+ name,
82
+ permissions
83
+ ].some((value) => value)) return new msw.HttpResponse(null, { status: 200 });
84
+ return new msw.HttpResponse(null, { status: 568 });
85
+ })),
86
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrlv2}/support/feedback/product`, async () => new msw.HttpResponse(null, { status: 200 })),
87
+ msw.http.delete(`${_northern_tech_utils_constants.useradmApiUrl}/roles/:roleId`, ({ params: { roleId } }) => new msw.HttpResponse(null, { status: require_mockData.mockApiResponses.users.rolesById[roleId] ? 200 : 569 })),
88
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrlv2}/roles`, () => msw.HttpResponse.json(require_mockData.rbacRoles)),
89
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrlv2}/roles/:roleId`, async ({ params: { roleId } }) => {
90
+ if (require_mockData.mockApiResponses.users.rolesById[roleId]) return msw.HttpResponse.json(require_mockData.mockApiResponses.users.rolesById[roleId]);
91
+ return new msw.HttpResponse(null, { status: 571 });
92
+ }),
93
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrlv2}/roles`, require_validation.validated(async ({ request }) => {
94
+ const { name, permission_sets_with_scope } = await request.json();
95
+ if (!!name && permission_sets_with_scope.every((permission) => permission.name && require_mockData.permissionSets.find((permissionSet) => permissionSet.name === permission.name))) return new msw.HttpResponse(null, { status: 200 });
96
+ return new msw.HttpResponse(null, { status: 572 });
97
+ })),
98
+ msw.http.put(`${_northern_tech_utils_constants.useradmApiUrlv2}/roles/:roleId`, require_validation.validated(async ({ params: { roleId }, request }) => {
99
+ const { description, name, permission_sets_with_scope } = await request.json();
100
+ if (require_mockData.mockApiResponses.users.rolesById[roleId] && [
101
+ description,
102
+ name,
103
+ permission_sets_with_scope
104
+ ].some((value) => value)) return new msw.HttpResponse(null, { status: 200 });
105
+ return new msw.HttpResponse(null, { status: 573 });
106
+ })),
107
+ msw.http.delete(`${_northern_tech_utils_constants.useradmApiUrlv2}/roles/:roleId`, ({ params: { roleId } }) => {
108
+ if (require_mockData.mockApiResponses.users.rolesById[roleId]) return new msw.HttpResponse(null, { status: 200 });
109
+ return new msw.HttpResponse(null, { status: 574 });
110
+ }),
111
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/settings`, () => msw.HttpResponse.json(require_mockData.mockApiResponses.users.globalSettings)),
112
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/settings`, () => new msw.HttpResponse(null, { status: 200 })),
113
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/settings/me`, () => msw.HttpResponse.json(require_mockData.mockApiResponses.users.userSettings)),
114
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/settings/me`, () => new msw.HttpResponse(null, { status: 200 })),
115
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/settings/tokens`, () => msw.HttpResponse.json(require_mockData.accessTokens)),
116
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/settings/tokens`, () => msw.HttpResponse.json("aNewToken")),
117
+ msw.http.delete(`${_northern_tech_utils_constants.useradmApiUrl}/settings/tokens/:tokenId`, ({ params: { tokenId } }) => new msw.HttpResponse(null, { status: tokenId === "some-id-1" ? 200 : 577 })),
118
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/2faqr`, () => msw.HttpResponse.json({ qr: btoa("test") })),
119
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId/2fa/enable`, ({ params: { userId } }) => {
120
+ if (require_mockData.mockApiResponses.users.byId[userId] || userId === "me") return new msw.HttpResponse(null, { status: 200 });
121
+ return new msw.HttpResponse(null, { status: 570 });
122
+ }),
123
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId/2fa/disable`, ({ params: { userId } }) => {
124
+ if (require_mockData.mockApiResponses.users.byId[userId] || userId === "me") return new msw.HttpResponse(null, { status: 200 });
125
+ return new msw.HttpResponse(null, { status: 571 });
126
+ }),
127
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/auth/verify-email/start`, () => new msw.HttpResponse(null, { status: 200 })),
128
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/auth/verify-email/complete`, require_validation.validated(async ({ request }) => {
129
+ const { secret_hash } = await request.json();
130
+ return new msw.HttpResponse(null, { status: secret_hash === "superSecret" ? 200 : 576 });
131
+ })),
132
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrlv2}/permission_sets`, () => msw.HttpResponse.json(require_mockData.permissionSets)),
133
+ msw.http.post(`${_northern_tech_utils_constants.useradmApiUrl}/users/:userId/assign`, require_validation.validated(async ({ request }) => {
134
+ const { tenant_ids } = await request.json();
135
+ return new msw.HttpResponse(null, { status: tenant_ids.length ? 200 : 577 });
136
+ })),
137
+ msw.http.get(`${_northern_tech_utils_constants.useradmApiUrl}/users/tenants/:tenantId/token`, () => msw.HttpResponse.text("differentToken"))
615
138
  ];
616
- var rbacRoles = [
617
- {
618
- name: "dyn",
619
- description: "",
620
- permissions: [
621
- { action: "CREATE_DEPLOYMENT", object: { type: "DEVICE_GROUP", value: "dyn" } },
622
- { action: "VIEW_DEVICE", object: { type: "DEVICE_GROUP", value: "dyn" } }
623
- ]
624
- },
625
- { name: "asdasd", description: "123", permissions: [{ action: "http", object: { type: "any", value: "/api/management/v1/useradm/.*" } }] },
626
- {
627
- name: "141sasd",
628
- description: "1313adg",
629
- permission_sets_with_scope: [
630
- { ...import_constants.defaultPermissionSets.ReadDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
631
- { ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
632
- { ...import_constants.defaultPermissionSets.ManageUsers }
633
- ]
634
- },
635
- {
636
- name: "kljlkk",
637
- description: "lkl",
638
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } }]
639
- },
640
- {
641
- name: "yyyyy",
642
- description: "asd",
643
- permission_sets_with_scope: [
644
- { ...import_constants.defaultPermissionSets.ManageDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["dockerclient"] } },
645
- { ...import_constants.defaultPermissionSets.ManageReleases }
646
- ]
647
- },
648
- {
649
- name: "RBAC_ROLE_DEPLOYMENTS_MANAGER",
650
- description: "Intended for users responsible for managing deployments, this role can create and abort deployments",
651
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.DeployToDevices }]
652
- },
653
- {
654
- name: "RBAC_ROLE_REMOTE_TERMINAL",
655
- description: `Intended for tech support accounts, this role can access the devices' Remote Terminal.`,
656
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices }]
657
- },
658
- { name: "RBAC_ROLE_PERMIT_ALL", description: "", permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.SuperUser }] },
659
- {
660
- name: "RBAC_ROLE_OBSERVER",
661
- description: "Intended for team leaders or limited tech support accounts, this role can see all Devices, Artifacts and Deployment reports but not make any changes.",
662
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ReadReleases }, { ...import_constants.defaultPermissionSets.ReadDevices }]
663
- },
664
- {
665
- name: "RBAC_ROLE_CI",
666
- description: "Intended for automation accounts building software (e.g. CI/CD systems), this role can only manage Artifacts, including upload new Artifacts and delete Artifacts. It does not have access to Devices or Deployments.",
667
- permission_sets_with_scope: [
668
- { ...import_constants.defaultPermissionSets.ReadReleases },
669
- { ...import_constants.defaultPermissionSets.ManageReleases },
670
- { ...import_constants.defaultPermissionSets.UploadArtifacts }
671
- ]
672
- },
673
- {
674
- name: "almostAdmin",
675
- description: "almost admin rights",
676
- permissions: permissionSets.find((item) => item.name === "almostAdmin")?.permissions
677
- },
678
- {
679
- name: "almostAdminNew",
680
- description: "almost admin rights",
681
- permission_sets_with_scope: Object.values(import_constants.defaultPermissionSets)
682
- }
683
- ];
684
- var expectedParsedRoles = {
685
- "141sasd": {
686
- editable: true,
687
- isCustom: void 0,
688
- uiPermissions: {
689
- ...import_constants.emptyUiPermissions,
690
- groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] },
691
- userManagement: [import_constants.uiPermissionsById.manage.value]
692
- }
693
- },
694
- asdasd: {
695
- editable: false,
696
- isCustom: true,
697
- uiPermissions: { ...import_constants.emptyUiPermissions, userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] }
698
- },
699
- dyn: {
700
- editable: false,
701
- isCustom: true,
702
- uiPermissions: {
703
- ...import_constants.emptyUiPermissions,
704
- deployments: [import_constants.uiPermissionsById.deploy.value],
705
- groups: { dyn: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value] }
706
- }
707
- },
708
- kljlkk: {
709
- editable: true,
710
- isCustom: false,
711
- uiPermissions: { ...import_constants.emptyUiPermissions, groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] } }
712
- },
713
- yyyyy: {
714
- editable: true,
715
- isCustom: void 0,
716
- uiPermissions: {
717
- ...import_constants.emptyUiPermissions,
718
- groups: { dockerclient: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] },
719
- releases: { [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value] }
720
- }
721
- },
722
- almostAdmin: {
723
- editable: false,
724
- isCustom: true,
725
- uiPermissions: {
726
- ...import_constants.emptyUiPermissions,
727
- auditlog: [import_constants.uiPermissionsById.read.value],
728
- deployments: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.read.value],
729
- groups: {
730
- [import_constants.ALL_DEVICES]: [
731
- import_constants.uiPermissionsById.read.value,
732
- // we can't assign deployment permissions to devices here, since the old path based rbac controls don't allow the scoped permissions
733
- // uiPermissionsById.deploy.value,
734
- import_constants.uiPermissionsById.manage.value,
735
- import_constants.uiPermissionsById.connect.value,
736
- import_constants.uiPermissionsById.configure.value
737
- ]
738
- },
739
- releases: {
740
- [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.manage.value]
741
- },
742
- userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
743
- }
744
- },
745
- almostAdminNew: {
746
- editable: true,
747
- isCustom: void 0,
748
- uiPermissions: {
749
- ...import_constants.emptyUiPermissions,
750
- auditlog: [import_constants.uiPermissionsById.read.value],
751
- deployments: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.manage.value],
752
- groups: {
753
- [import_constants.ALL_DEVICES]: [
754
- import_constants.uiPermissionsById.read.value,
755
- import_constants.uiPermissionsById.manage.value,
756
- import_constants.uiPermissionsById.deploy.value,
757
- import_constants.uiPermissionsById.connect.value,
758
- import_constants.uiPermissionsById.configure.value
759
- ]
760
- },
761
- releases: {
762
- [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.read.value]
763
- },
764
- tenantManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value],
765
- userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
766
- }
767
- }
768
- };
769
- var defaultRolesById = {
770
- ...import_constants.rolesById,
771
- test: {
772
- ...import_constants.emptyRole,
773
- name: "test",
774
- description: "test description",
775
- editable: true,
776
- uiPermissions: {
777
- ...import_constants.emptyUiPermissions,
778
- groups: { testGroup: [import_constants.uiPermissionsById.read.value] },
779
- releases: { bar: [import_constants.uiPermissionsById.read.value] }
780
- }
781
- }
782
- };
783
- var receivedRoles = rbacRoles.reduce(
784
- (accu, role) => {
785
- const { name, description, ...roleRemainder } = role;
786
- if (name.startsWith("RBAC")) {
787
- accu[name] = {
788
- ...defaultRolesById[name],
789
- ...roleRemainder,
790
- editable: false,
791
- isCustom: false,
792
- description: defaultRolesById[name].description ? defaultRolesById[name].description : description
793
- };
794
- } else {
795
- const result = expectedParsedRoles[name] ?? {};
796
- accu[name] = {
797
- ...import_constants.emptyRole,
798
- ...role,
799
- ...result,
800
- name
801
- };
802
- }
803
- return accu;
804
- },
805
- { ...defaultRolesById }
806
- );
807
- var receivedPermissionSets = permissionSets.reduce((accu, set) => {
808
- const result = import_constants.defaultPermissionSets[set.name]?.result ?? {};
809
- accu[set.name] = {
810
- ...set,
811
- result: {
812
- ...import_constants.emptyUiPermissions,
813
- ...result
814
- }
815
- };
816
- return accu;
817
- }, {});
139
+ //#endregion
140
+ exports.userHandlers = userHandlers;
818
141
 
819
- // src/requestHandlers/userHandlers.ts
820
- var userHandlers = [
821
- import_msw.http.post(`${import_constants2.useradmApiUrl}/auth/login`, ({ request }) => {
822
- const authHeader = request.headers.get("authorization");
823
- const authInfo = atob(authHeader?.split(" ")[1]);
824
- const [user, password] = authInfo.split(":");
825
- if (!password) {
826
- return import_msw.HttpResponse.json({ id: testSsoId, kind: "sso/saml" });
827
- } else if (password !== defaultPassword) {
828
- return new import_msw.HttpResponse(null, { status: 401 });
829
- } else if (user.includes("limited")) {
830
- return new import_msw.HttpResponse("limitedToken", { headers: { "Content-Type": import_constants2.APPLICATION_JWT_CONTENT_TYPE } });
831
- } else if (user.includes("2fa")) {
832
- return new import_msw.HttpResponse(JSON.stringify({ error: "2fa needed" }), { status: 401 });
833
- }
834
- return new import_msw.HttpResponse(token, { headers: { "Content-Type": import_constants2.APPLICATION_JWT_CONTENT_TYPE } });
835
- }),
836
- import_msw.http.get(`https://hosted.mender.io${import_constants2.useradmApiUrl}/auth/magic/:id`, ({ params: { id } }) => {
837
- if (id) {
838
- return new import_msw.HttpResponse("test", { headers: { "Set-Cookie": "JWT=test" } });
839
- }
840
- return new import_msw.HttpResponse(null, { status: 400 });
841
- }),
842
- import_msw.http.post(`${import_constants2.useradmApiUrl}/auth/logout`, () => new import_msw.HttpResponse(null, { status: 200 })),
843
- import_msw.http.post(`${import_constants2.useradmApiUrl}/auth/password-reset/:status`, async ({ params: { status }, request }) => {
844
- const { email, secret_hash, password } = await request.json();
845
- if (!["start", "complete"].includes(status) && ![email, secret_hash, password].some((item) => item)) {
846
- return new import_msw.HttpResponse(null, { status: 560 });
847
- }
848
- if (status === "start" && email) {
849
- return new import_msw.HttpResponse(null, { status: 200 });
850
- }
851
- if (status === "complete" && secret_hash && password) {
852
- return new import_msw.HttpResponse(null, { status: 200 });
853
- }
854
- return new import_msw.HttpResponse(null, { status: 561 });
855
- }),
856
- import_msw.http.put(`${import_constants2.useradmApiUrl}/2faverify`, async ({ request }) => {
857
- const { token2fa } = await request.json();
858
- if (!token2fa) {
859
- return new import_msw.HttpResponse(null, { status: 562 });
860
- }
861
- return new import_msw.HttpResponse(null, { status: 200 });
862
- }),
863
- import_msw.http.get(`${import_constants2.useradmApiUrl}/users`, () => import_msw.HttpResponse.json(Object.values(mockApiResponses.users.byId))),
864
- import_msw.http.get(`${import_constants2.useradmApiUrl}/users/me`, ({ request }) => {
865
- const authHeader = request.headers.get("authorization");
866
- if (authHeader?.includes("limited")) {
867
- return new import_msw.HttpResponse(JSON.stringify({ error: "forbidden by role-based access control" }), { status: 403 });
868
- }
869
- return import_msw.HttpResponse.json(mockApiResponses.users.byId[userId]);
870
- }),
871
- import_msw.http.get(`${import_constants2.useradmApiUrl}/users/exists`, ({ request }) => {
872
- const url = new URL(request.url);
873
- const email = url.searchParams.get("email");
874
- if (!decodeURIComponent(email).includes("child+123")) {
875
- return new import_msw.HttpResponse(null, { status: 578 });
876
- }
877
- return import_msw.HttpResponse.json({ exists: true });
878
- }),
879
- import_msw.http.get(`${import_constants2.useradmApiUrl}/users/:userId`, ({ params: { userId: userId2 } }) => {
880
- if (userId2 === "me" || mockApiResponses.users.byId[userId2]) {
881
- const user = userId2 === "me" ? userId : userId2;
882
- return import_msw.HttpResponse.json(mockApiResponses.users.byId[user]);
883
- }
884
- return new import_msw.HttpResponse(null, { status: 563 });
885
- }),
886
- import_msw.http.post(`${import_constants2.useradmApiUrl}/users`, async ({ request }) => {
887
- const { email, password } = await request.json();
888
- if (email === "test@test.com" || [email, password].every((value) => value)) {
889
- return import_msw.HttpResponse.json(mockApiResponses.users.byId.a1);
890
- }
891
- return new import_msw.HttpResponse(null, { status: 564 });
892
- }),
893
- import_msw.http.put(`${import_constants2.useradmApiUrl}/users/:userId`, async ({ params: { userId: userId2 }, request }) => {
894
- const { email, password, current_password } = await request.json();
895
- if (current_password === "bad_password") {
896
- return new import_msw.HttpResponse(null, { status: 401 });
897
- }
898
- if (mockApiResponses.users.byId[userId2] && [email, password].some((value) => Object.values(mockApiResponses.users.byId[userId2]).includes(value)) || email === "test@test.com") {
899
- return new import_msw.HttpResponse(null, { status: 200 });
900
- }
901
- return new import_msw.HttpResponse(null, { status: 565 });
902
- }),
903
- import_msw.http.delete(
904
- `${import_constants2.useradmApiUrl}/users/:userId`,
905
- ({ params: { userId: userId2 } }) => new import_msw.HttpResponse(null, { status: mockApiResponses.users.byId[userId2] ? 200 : 566 })
906
- ),
907
- import_msw.http.get(`${import_constants2.useradmApiUrl}/roles`, () => import_msw.HttpResponse.json(rbacRoles)),
908
- import_msw.http.post(`${import_constants2.useradmApiUrl}/roles`, async ({ request }) => {
909
- const { name, permissions } = await request.json();
910
- if ([name, permissions].every((value) => value) && permissions.every((permission) => permission.action && permission.object && permission.object.type && permission.object.value)) {
911
- return new import_msw.HttpResponse(null, { status: 200 });
912
- }
913
- return new import_msw.HttpResponse(null, { status: 567 });
914
- }),
915
- import_msw.http.put(`${import_constants2.useradmApiUrl}/roles/:roleId`, async ({ params: { roleId }, request }) => {
916
- const { description, name, permissions } = await request.json();
917
- if (mockApiResponses.users.rolesById[roleId] && [description, name, permissions].some((value) => value)) {
918
- return new import_msw.HttpResponse(null, { status: 200 });
919
- }
920
- return new import_msw.HttpResponse(null, { status: 568 });
921
- }),
922
- import_msw.http.post(`${import_constants2.useradmApiUrlv2}/support/feedback/product`, async () => new import_msw.HttpResponse(null, { status: 200 })),
923
- import_msw.http.delete(
924
- `${import_constants2.useradmApiUrl}/roles/:roleId`,
925
- ({ params: { roleId } }) => new import_msw.HttpResponse(null, { status: mockApiResponses.users.rolesById[roleId] ? 200 : 569 })
926
- ),
927
- import_msw.http.get(`${import_constants2.useradmApiUrlv2}/roles`, () => import_msw.HttpResponse.json(rbacRoles)),
928
- import_msw.http.get(`${import_constants2.useradmApiUrlv2}/roles/:roleId`, async ({ params: { roleId } }) => {
929
- if (mockApiResponses.users.rolesById[roleId]) {
930
- return import_msw.HttpResponse.json(mockApiResponses.users.rolesById[roleId]);
931
- }
932
- return new import_msw.HttpResponse(null, { status: 571 });
933
- }),
934
- import_msw.http.post(`${import_constants2.useradmApiUrlv2}/roles`, async ({ request }) => {
935
- const { name, permission_sets_with_scope } = await request.json();
936
- if (!!name && permission_sets_with_scope.every((permission) => permission.name && permissionSets.find((permissionSet) => permissionSet.name === permission.name))) {
937
- return new import_msw.HttpResponse(null, { status: 200 });
938
- }
939
- return new import_msw.HttpResponse(null, { status: 572 });
940
- }),
941
- import_msw.http.put(`${import_constants2.useradmApiUrlv2}/roles/:roleId`, async ({ params: { roleId }, request }) => {
942
- const { description, name, permission_sets_with_scope } = await request.json();
943
- if (mockApiResponses.users.rolesById[roleId] && [description, name, permission_sets_with_scope].some((value) => value)) {
944
- return new import_msw.HttpResponse(null, { status: 200 });
945
- }
946
- return new import_msw.HttpResponse(null, { status: 573 });
947
- }),
948
- import_msw.http.delete(`${import_constants2.useradmApiUrlv2}/roles/:roleId`, ({ params: { roleId } }) => {
949
- if (mockApiResponses.users.rolesById[roleId]) {
950
- return new import_msw.HttpResponse(null, { status: 200 });
951
- }
952
- return new import_msw.HttpResponse(null, { status: 574 });
953
- }),
954
- import_msw.http.get(`${import_constants2.useradmApiUrl}/settings`, () => import_msw.HttpResponse.json(mockApiResponses.users.globalSettings)),
955
- import_msw.http.post(`${import_constants2.useradmApiUrl}/settings`, () => new import_msw.HttpResponse(null, { status: 200 })),
956
- import_msw.http.get(`${import_constants2.useradmApiUrl}/settings/me`, () => import_msw.HttpResponse.json(mockApiResponses.users.userSettings)),
957
- import_msw.http.post(`${import_constants2.useradmApiUrl}/settings/me`, () => new import_msw.HttpResponse(null, { status: 200 })),
958
- import_msw.http.get(`${import_constants2.useradmApiUrl}/settings/tokens`, () => import_msw.HttpResponse.json(accessTokens)),
959
- import_msw.http.post(`${import_constants2.useradmApiUrl}/settings/tokens`, () => import_msw.HttpResponse.json("aNewToken")),
960
- import_msw.http.delete(
961
- `${import_constants2.useradmApiUrl}/settings/tokens/:tokenId`,
962
- ({ params: { tokenId } }) => new import_msw.HttpResponse(null, { status: tokenId === "some-id-1" ? 200 : 577 })
963
- ),
964
- import_msw.http.get(`${import_constants2.useradmApiUrl}/2faqr`, () => import_msw.HttpResponse.json({ qr: btoa("test") })),
965
- import_msw.http.post(`${import_constants2.useradmApiUrl}/users/:userId/2fa/enable`, ({ params: { userId: userId2 } }) => {
966
- if (mockApiResponses.users.byId[userId2] || userId2 === "me") {
967
- return new import_msw.HttpResponse(null, { status: 200 });
968
- }
969
- return new import_msw.HttpResponse(null, { status: 570 });
970
- }),
971
- import_msw.http.post(`${import_constants2.useradmApiUrl}/users/:userId/2fa/disable`, ({ params: { userId: userId2 } }) => {
972
- if (mockApiResponses.users.byId[userId2] || userId2 === "me") {
973
- return new import_msw.HttpResponse(null, { status: 200 });
974
- }
975
- return new import_msw.HttpResponse(null, { status: 571 });
976
- }),
977
- import_msw.http.post(`${import_constants2.useradmApiUrl}/auth/verify-email/start`, () => new import_msw.HttpResponse(null, { status: 200 })),
978
- import_msw.http.post(`${import_constants2.useradmApiUrl}/auth/verify-email/complete`, async ({ request }) => {
979
- const { secret_hash } = await request.json();
980
- return new import_msw.HttpResponse(null, { status: secret_hash === "superSecret" ? 200 : 576 });
981
- }),
982
- import_msw.http.get(`${import_constants2.useradmApiUrlv2}/permission_sets`, () => import_msw.HttpResponse.json(permissionSets)),
983
- import_msw.http.post(`${import_constants2.useradmApiUrl}/users/:userId/assign`, async ({ request }) => {
984
- const { tenant_ids } = await request.json();
985
- return new import_msw.HttpResponse(null, { status: tenant_ids.length ? 200 : 577 });
986
- }),
987
- import_msw.http.get(`${import_constants2.useradmApiUrl}/users/tenants/:tenantId/token`, () => import_msw.HttpResponse.text("differentToken"))
988
- ];
989
- // Annotate the CommonJS export names for ESM import in node:
990
- 0 && (module.exports = {
991
- userHandlers
992
- });
993
142
  //# sourceMappingURL=userHandlers.cjs.map