@sasjs/api 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/build/browser.js +1663 -1606
- package/build/cjs/corpus/drive.js +4 -1
- package/build/cjs/corpus/identity.js +17 -13
- package/build/cjs/corpus/records.js +46 -26
- package/build/cjs/drive/memory-store.js +17 -1
- package/build/cjs/drive/service.js +7 -1
- package/build/cjs/identity/fixture.js +6 -6
- package/build/cjs/index.js +21 -8
- package/build/esm/corpus/drive.d.ts.map +1 -1
- package/build/esm/corpus/drive.js +4 -1
- package/build/esm/corpus/identity.d.ts.map +1 -1
- package/build/esm/corpus/identity.js +17 -13
- package/build/esm/corpus/records.d.ts.map +1 -1
- package/build/esm/corpus/records.js +46 -26
- package/build/esm/drive/memory-store.d.ts +10 -0
- package/build/esm/drive/memory-store.d.ts.map +1 -1
- package/build/esm/drive/memory-store.js +17 -1
- package/build/esm/drive/service.d.ts.map +1 -1
- package/build/esm/drive/service.js +7 -1
- package/build/esm/identity/fixture.js +6 -6
- package/build/esm/index.d.ts +6 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +3 -0
- package/build/esm/types.d.ts +14 -0
- package/build/esm/types.d.ts.map +1 -1
- package/package.json +1 -1
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.23.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
|
|
2
2
|
"use strict";
|
|
3
3
|
var SASjsApi = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -33,6 +33,7 @@ var SASjsApi = (() => {
|
|
|
33
33
|
CODE_DEBUG: () => CODE_DEBUG,
|
|
34
34
|
DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
|
|
35
35
|
DEFAULT_IDENTITY: () => DEFAULT_IDENTITY,
|
|
36
|
+
DEFAULT_LOG_LINES: () => DEFAULT_LOG_LINES,
|
|
36
37
|
DEFAULT_SESSIONS: () => DEFAULT_SESSIONS,
|
|
37
38
|
DEPLOY_CORPUS: () => DEPLOY_CORPUS,
|
|
38
39
|
DEPLOY_LIMITS: () => DEPLOY_LIMITS,
|
|
@@ -46,6 +47,7 @@ var SASjsApi = (() => {
|
|
|
46
47
|
IDENTITY_CORPUS: () => IDENTITY_CORPUS,
|
|
47
48
|
IDENTITY_FORMAT: () => IDENTITY_FORMAT,
|
|
48
49
|
INFO_CORPUS: () => INFO_CORPUS,
|
|
50
|
+
MAX_LOG_LINES: () => MAX_LOG_LINES,
|
|
49
51
|
MemoryAppStreamRegistry: () => MemoryAppStreamRegistry,
|
|
50
52
|
MemoryDriveStore: () => MemoryDriveStore,
|
|
51
53
|
MemoryIdentityStore: () => MemoryIdentityStore,
|
|
@@ -63,6 +65,10 @@ var SASjsApi = (() => {
|
|
|
63
65
|
TOP_LEVEL_ROUTES: () => TOP_LEVEL_ROUTES,
|
|
64
66
|
basename: () => basename,
|
|
65
67
|
checkDeployTree: () => checkDeployTree,
|
|
68
|
+
checkLogFileName: () => checkLogFileName,
|
|
69
|
+
createAdminService: () => createAdminService,
|
|
70
|
+
createAuthConfigService: () => createAuthConfigService,
|
|
71
|
+
createDirectoryService: () => createDirectoryService,
|
|
66
72
|
createDriveService: () => createDriveService,
|
|
67
73
|
createHomeService: () => createHomeService,
|
|
68
74
|
createIdentityService: () => createIdentityService,
|
|
@@ -80,9 +86,13 @@ var SASjsApi = (() => {
|
|
|
80
86
|
isDeployTree: () => isDeployTree,
|
|
81
87
|
isRoot: () => isRoot,
|
|
82
88
|
isRouteGranted: () => isRouteGranted,
|
|
89
|
+
logLines: () => logLines,
|
|
83
90
|
measureDeployTree: () => measureDeployTree,
|
|
91
|
+
normaliseAuthConfig: () => normaliseAuthConfig,
|
|
92
|
+
normaliseDiagnostics: () => normaliseDiagnostics,
|
|
84
93
|
normaliseDrivePath: () => normaliseDrivePath,
|
|
85
94
|
normaliseInfo: () => normaliseInfo,
|
|
95
|
+
normaliseLogFiles: () => normaliseLogFiles,
|
|
86
96
|
parseIdentity: () => parseIdentity,
|
|
87
97
|
routeById: () => routeById,
|
|
88
98
|
runCase: () => runCase,
|
|
@@ -336,10 +346,14 @@ var SASjsApi = (() => {
|
|
|
336
346
|
);
|
|
337
347
|
}
|
|
338
348
|
for (const file of listing.files) {
|
|
349
|
+
const relativePath = path === "/" ? "/" + file : path + "/" + file;
|
|
350
|
+
const stat = await store.stat(relativePath);
|
|
339
351
|
children.push({
|
|
340
352
|
name: file,
|
|
341
|
-
relativePath
|
|
353
|
+
relativePath,
|
|
342
354
|
isFolder: false,
|
|
355
|
+
...stat.modified ? { modified: stat.modified } : {},
|
|
356
|
+
...stat.created ? { created: stat.created } : {},
|
|
343
357
|
children: []
|
|
344
358
|
});
|
|
345
359
|
}
|
|
@@ -460,6 +474,14 @@ var SASjsApi = (() => {
|
|
|
460
474
|
constructor(seed = {}) {
|
|
461
475
|
this.files = /* @__PURE__ */ new Map();
|
|
462
476
|
this.folders = /* @__PURE__ */ new Set(["/"]);
|
|
477
|
+
/**
|
|
478
|
+
* When each entry was first written and last written, ISO strings.
|
|
479
|
+
*
|
|
480
|
+
* A Map has no clock of its own, so the store keeps one: a seeded drive is
|
|
481
|
+
* created when the store is, and a write moves `modified` while `created`
|
|
482
|
+
* stays. A host with real file metadata reports its own instead.
|
|
483
|
+
*/
|
|
484
|
+
this.times = /* @__PURE__ */ new Map();
|
|
463
485
|
for (const [path, contents] of Object.entries(seed)) {
|
|
464
486
|
this.putSync(path, contents);
|
|
465
487
|
}
|
|
@@ -476,6 +498,12 @@ var SASjsApi = (() => {
|
|
|
476
498
|
path,
|
|
477
499
|
typeof contents === "string" ? contents : contents.slice()
|
|
478
500
|
);
|
|
501
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
502
|
+
const existing = this.times.get(path);
|
|
503
|
+
this.times.set(path, {
|
|
504
|
+
created: existing?.created ?? now,
|
|
505
|
+
modified: now
|
|
506
|
+
});
|
|
479
507
|
}
|
|
480
508
|
mkdirpSync(path) {
|
|
481
509
|
const parts = path.split("/").filter(Boolean);
|
|
@@ -517,9 +545,11 @@ var SASjsApi = (() => {
|
|
|
517
545
|
return { directory: true, size: 0 };
|
|
518
546
|
const contents = this.files.get(path);
|
|
519
547
|
if (contents === void 0) throw new ApiError(404, `File doesn't exist.`);
|
|
548
|
+
const times = this.times.get(path);
|
|
520
549
|
return {
|
|
521
550
|
directory: false,
|
|
522
|
-
size: typeof contents === "string" ? contents.length : contents.length
|
|
551
|
+
size: typeof contents === "string" ? contents.length : contents.length,
|
|
552
|
+
...times ? { modified: times.modified, created: times.created } : {}
|
|
523
553
|
};
|
|
524
554
|
}
|
|
525
555
|
async list(path) {
|
|
@@ -4578,915 +4608,1292 @@ var SASjsApi = (() => {
|
|
|
4578
4608
|
};
|
|
4579
4609
|
};
|
|
4580
4610
|
|
|
4581
|
-
// src/
|
|
4582
|
-
var
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
isAdmin: false,
|
|
4604
|
-
isActive: true,
|
|
4605
|
-
needsToUpdatePassword: false
|
|
4606
|
-
}
|
|
4607
|
-
],
|
|
4608
|
-
groups: [
|
|
4609
|
-
{
|
|
4610
|
-
uid: "group-data-controller",
|
|
4611
|
-
name: "DCGroup",
|
|
4612
|
-
description: "Data Controller users",
|
|
4613
|
-
isActive: true,
|
|
4614
|
-
users: ["user2"]
|
|
4615
|
-
},
|
|
4616
|
-
{
|
|
4617
|
-
uid: "group-admins",
|
|
4618
|
-
name: "Admins",
|
|
4619
|
-
description: "Everything the API offers",
|
|
4620
|
-
isActive: true,
|
|
4621
|
-
users: ["admin"]
|
|
4622
|
-
}
|
|
4623
|
-
],
|
|
4624
|
-
permissions: [
|
|
4625
|
-
{
|
|
4626
|
-
uid: "rule-routes",
|
|
4627
|
-
path: "/SASjsApi/drive/file",
|
|
4628
|
-
type: "Route",
|
|
4629
|
-
setting: "Grant",
|
|
4630
|
-
group: "group-data-controller"
|
|
4631
|
-
},
|
|
4632
|
-
{
|
|
4633
|
-
uid: "rule-execute",
|
|
4634
|
-
path: "/SASjsApi/stp/execute",
|
|
4635
|
-
type: "Route",
|
|
4636
|
-
setting: "Grant",
|
|
4637
|
-
group: "group-data-controller"
|
|
4638
|
-
},
|
|
4639
|
-
{
|
|
4640
|
-
uid: "rule-code",
|
|
4641
|
-
path: "/SASjsApi/code/execute",
|
|
4642
|
-
type: "Route",
|
|
4643
|
-
setting: "Deny",
|
|
4644
|
-
user: "user-restricted"
|
|
4645
|
-
}
|
|
4646
|
-
],
|
|
4647
|
-
clients: [
|
|
4648
|
-
{
|
|
4649
|
-
clientId: "web_app",
|
|
4650
|
-
clientSecret: "web_app",
|
|
4651
|
-
accessTokenExpiration: SECONDS_IN_A_DAY2,
|
|
4652
|
-
refreshTokenExpiration: SECONDS_IN_A_DAY2 * 30
|
|
4653
|
-
},
|
|
4654
|
-
{
|
|
4655
|
-
clientId: "sasjs",
|
|
4656
|
-
clientSecret: "sasjs",
|
|
4657
|
-
accessTokenExpiration: 3600,
|
|
4658
|
-
refreshTokenExpiration: SECONDS_IN_A_DAY2
|
|
4659
|
-
}
|
|
4660
|
-
]
|
|
4661
|
-
};
|
|
4662
|
-
var parseIdentity = (raw) => {
|
|
4663
|
-
const fixture = raw;
|
|
4664
|
-
if (!fixture || typeof fixture !== "object")
|
|
4665
|
-
throw new Error("The identity fixture is not an object.");
|
|
4666
|
-
if (fixture.format !== IDENTITY_FORMAT)
|
|
4611
|
+
// src/authconfig/service.ts
|
|
4612
|
+
var LDAP_FIELDS = [
|
|
4613
|
+
"url",
|
|
4614
|
+
"bindDn",
|
|
4615
|
+
"usersBaseDn",
|
|
4616
|
+
"groupsBaseDn",
|
|
4617
|
+
"bindPasswordSet"
|
|
4618
|
+
];
|
|
4619
|
+
var OIDC_FIELDS = [
|
|
4620
|
+
"providerName",
|
|
4621
|
+
"issuerUrl",
|
|
4622
|
+
"clientId",
|
|
4623
|
+
"redirectUri",
|
|
4624
|
+
"scope",
|
|
4625
|
+
"signingAlg",
|
|
4626
|
+
"usernameClaim",
|
|
4627
|
+
"jitProvision",
|
|
4628
|
+
"clientSecretSet"
|
|
4629
|
+
];
|
|
4630
|
+
var SECRET = /(password|secret|passwd|token)/i;
|
|
4631
|
+
var checkProvider = (name, block, fields, booleans) => {
|
|
4632
|
+
if (!block || typeof block !== "object")
|
|
4667
4633
|
throw new Error(
|
|
4668
|
-
`The
|
|
4634
|
+
`The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`
|
|
4669
4635
|
);
|
|
4670
|
-
for (const key of
|
|
4671
|
-
if (!
|
|
4672
|
-
throw new Error(`The identity fixture has no \`${key}\` array.`);
|
|
4673
|
-
for (const token of fixture.tokens || [])
|
|
4674
|
-
if (!token.accessToken || !token.refreshToken)
|
|
4636
|
+
for (const key of Object.keys(block)) {
|
|
4637
|
+
if (!fields.includes(key))
|
|
4675
4638
|
throw new Error(
|
|
4676
|
-
`The
|
|
4639
|
+
SECRET.test(key) ? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.` : `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`
|
|
4677
4640
|
);
|
|
4678
|
-
|
|
4641
|
+
}
|
|
4642
|
+
for (const key of fields) {
|
|
4643
|
+
if (!(key in block))
|
|
4644
|
+
throw new Error(
|
|
4645
|
+
`The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`
|
|
4646
|
+
);
|
|
4647
|
+
const value = block[key];
|
|
4648
|
+
if (booleans.includes(key)) {
|
|
4649
|
+
if (typeof value !== "boolean")
|
|
4650
|
+
throw new Error(
|
|
4651
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`
|
|
4652
|
+
);
|
|
4653
|
+
} else if (typeof value !== "string")
|
|
4654
|
+
throw new Error(
|
|
4655
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`
|
|
4656
|
+
);
|
|
4657
|
+
}
|
|
4658
|
+
};
|
|
4659
|
+
var normaliseAuthConfig = (config) => {
|
|
4660
|
+
if (!config || typeof config !== "object")
|
|
4661
|
+
throw new Error("The auth configuration is not an object.");
|
|
4662
|
+
for (const key of Object.keys(config))
|
|
4663
|
+
if (key !== "ldap" && key !== "oidc")
|
|
4664
|
+
throw new Error(
|
|
4665
|
+
SECRET.test(key) ? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.` : `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`
|
|
4666
|
+
);
|
|
4667
|
+
const answer = {};
|
|
4668
|
+
if (config.ldap !== void 0) {
|
|
4669
|
+
checkProvider("ldap", config.ldap, LDAP_FIELDS, ["bindPasswordSet"]);
|
|
4670
|
+
answer.ldap = {
|
|
4671
|
+
LDAP_URL: config.ldap.url,
|
|
4672
|
+
LDAP_BIND_DN: config.ldap.bindDn,
|
|
4673
|
+
LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
|
|
4674
|
+
LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
|
|
4675
|
+
LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
|
|
4676
|
+
};
|
|
4677
|
+
}
|
|
4678
|
+
if (config.oidc !== void 0) {
|
|
4679
|
+
checkProvider("oidc", config.oidc, OIDC_FIELDS, ["clientSecretSet"]);
|
|
4680
|
+
answer.oidc = {
|
|
4681
|
+
OIDC_PROVIDER_NAME: config.oidc.providerName,
|
|
4682
|
+
OIDC_ISSUER_URL: config.oidc.issuerUrl,
|
|
4683
|
+
OIDC_CLIENT_ID: config.oidc.clientId,
|
|
4684
|
+
OIDC_REDIRECT_URI: config.oidc.redirectUri,
|
|
4685
|
+
OIDC_SCOPE: config.oidc.scope,
|
|
4686
|
+
OIDC_SIGNING_ALG: config.oidc.signingAlg,
|
|
4687
|
+
OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
|
|
4688
|
+
OIDC_JIT_PROVISION: config.oidc.jitProvision,
|
|
4689
|
+
OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
|
|
4690
|
+
};
|
|
4691
|
+
}
|
|
4692
|
+
return answer;
|
|
4693
|
+
};
|
|
4694
|
+
var createAuthConfigService = (config) => {
|
|
4695
|
+
const read = () => typeof config === "function" ? config() : config;
|
|
4696
|
+
return {
|
|
4697
|
+
async authConfig() {
|
|
4698
|
+
return normaliseAuthConfig(read());
|
|
4699
|
+
}
|
|
4700
|
+
};
|
|
4701
|
+
};
|
|
4702
|
+
|
|
4703
|
+
// src/admin/service.ts
|
|
4704
|
+
var DEFAULT_LOG_LINES = 200;
|
|
4705
|
+
var MAX_LOG_LINES = 5e3;
|
|
4706
|
+
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
4707
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
4708
|
+
var isString = (value) => typeof value === "string";
|
|
4709
|
+
var requireString = (holder, key, where) => {
|
|
4710
|
+
if (!isString(holder[key]))
|
|
4679
4711
|
throw new Error(
|
|
4680
|
-
|
|
4712
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`
|
|
4681
4713
|
);
|
|
4682
|
-
return fixture;
|
|
4683
4714
|
};
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
const source = globalThis.crypto;
|
|
4689
|
-
if (!source)
|
|
4690
|
-
throw new ApiError(
|
|
4691
|
-
500,
|
|
4692
|
-
"This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
|
|
4715
|
+
var requireNumber = (holder, key, where) => {
|
|
4716
|
+
if (!isNumber(holder[key]))
|
|
4717
|
+
throw new Error(
|
|
4718
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
|
|
4693
4719
|
);
|
|
4694
|
-
const buffer = new Uint8Array(bytes3);
|
|
4695
|
-
source.getRandomValues(buffer);
|
|
4696
|
-
return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
4697
|
-
""
|
|
4698
|
-
);
|
|
4699
4720
|
};
|
|
4700
|
-
var
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
setting: permission.setting,
|
|
4765
|
-
user: permission.user ? this.userList.find((user3) => user3.uid === permission.user)?.uid : void 0,
|
|
4766
|
-
group: permission.group ? this.groupList.get(permission.group)?.uid : void 0
|
|
4767
|
-
});
|
|
4768
|
-
}
|
|
4769
|
-
for (const token of fixture.tokens || []) {
|
|
4770
|
-
const user3 = this.userList.find(
|
|
4771
|
-
(candidate) => candidate.username === token.username
|
|
4721
|
+
var requireObject = (holder, key, where) => {
|
|
4722
|
+
const value = holder[key];
|
|
4723
|
+
if (!isObject(value))
|
|
4724
|
+
throw new Error(
|
|
4725
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
|
|
4726
|
+
);
|
|
4727
|
+
return value;
|
|
4728
|
+
};
|
|
4729
|
+
var normaliseDiagnostics = (report) => {
|
|
4730
|
+
if (!isObject(report))
|
|
4731
|
+
throw new Error("The diagnostics report is not an object.");
|
|
4732
|
+
const build = requireObject(
|
|
4733
|
+
report,
|
|
4734
|
+
"build",
|
|
4735
|
+
"diagnostics"
|
|
4736
|
+
);
|
|
4737
|
+
requireString(build, "version", "diagnostics build");
|
|
4738
|
+
requireString(build, "gitHash", "diagnostics build");
|
|
4739
|
+
if (!(build.buildDate === null || isString(build.buildDate)))
|
|
4740
|
+
throw new Error(
|
|
4741
|
+
`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
|
|
4742
|
+
);
|
|
4743
|
+
const server = requireObject(
|
|
4744
|
+
report,
|
|
4745
|
+
"server",
|
|
4746
|
+
"diagnostics"
|
|
4747
|
+
);
|
|
4748
|
+
requireString(server, "mode", "diagnostics server");
|
|
4749
|
+
requireString(server, "startedAt", "diagnostics server");
|
|
4750
|
+
requireString(server, "nodeVersion", "diagnostics server");
|
|
4751
|
+
requireString(server, "platform", "diagnostics server");
|
|
4752
|
+
requireString(server, "arch", "diagnostics server");
|
|
4753
|
+
requireString(server, "cpuModel", "diagnostics server");
|
|
4754
|
+
requireString(server, "sasjsRoot", "diagnostics server");
|
|
4755
|
+
requireNumber(server, "uptimeSeconds", "diagnostics server");
|
|
4756
|
+
requireNumber(server, "pid", "diagnostics server");
|
|
4757
|
+
requireNumber(server, "cpuCount", "diagnostics server");
|
|
4758
|
+
if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
|
|
4759
|
+
throw new Error(
|
|
4760
|
+
"The diagnostics server report states `loadAverage` as something other than an array of numbers."
|
|
4761
|
+
);
|
|
4762
|
+
if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
|
|
4763
|
+
throw new Error(
|
|
4764
|
+
"The diagnostics server report states `runTimes` as something other than an array of strings."
|
|
4765
|
+
);
|
|
4766
|
+
const memory = requireObject(
|
|
4767
|
+
report,
|
|
4768
|
+
"memory",
|
|
4769
|
+
"diagnostics"
|
|
4770
|
+
);
|
|
4771
|
+
for (const key of [
|
|
4772
|
+
"rssBytes",
|
|
4773
|
+
"heapTotalBytes",
|
|
4774
|
+
"heapUsedBytes",
|
|
4775
|
+
"externalBytes",
|
|
4776
|
+
"systemTotalBytes",
|
|
4777
|
+
"systemFreeBytes"
|
|
4778
|
+
])
|
|
4779
|
+
requireNumber(memory, key, "diagnostics memory");
|
|
4780
|
+
const filesystem = report.filesystem;
|
|
4781
|
+
if (filesystem !== null) {
|
|
4782
|
+
if (!isObject(filesystem))
|
|
4783
|
+
throw new Error(
|
|
4784
|
+
`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
|
|
4772
4785
|
);
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
for (const code of fixture.codes || []) {
|
|
4784
|
-
const user3 = this.userList.find(
|
|
4785
|
-
(candidate) => candidate.username === code.username
|
|
4786
|
+
requireString(
|
|
4787
|
+
filesystem,
|
|
4788
|
+
"path",
|
|
4789
|
+
"diagnostics filesystem"
|
|
4790
|
+
);
|
|
4791
|
+
for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
|
|
4792
|
+
requireNumber(
|
|
4793
|
+
filesystem,
|
|
4794
|
+
key,
|
|
4795
|
+
"diagnostics filesystem"
|
|
4786
4796
|
);
|
|
4787
|
-
if (!user3) continue;
|
|
4788
|
-
this.codes.set(code.code, {
|
|
4789
|
-
subject: { userId: user3.uid, clientId: code.clientId }
|
|
4790
|
-
});
|
|
4791
|
-
}
|
|
4792
4797
|
}
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4798
|
+
if (!Array.isArray(report.folders))
|
|
4799
|
+
throw new Error(
|
|
4800
|
+
"The diagnostics report states `folders` as something other than an array."
|
|
4796
4801
|
);
|
|
4797
|
-
|
|
4802
|
+
for (const folder of report.folders) {
|
|
4803
|
+
if (!isObject(folder))
|
|
4804
|
+
throw new Error(
|
|
4805
|
+
"The diagnostics report carries a folder that is not an object."
|
|
4806
|
+
);
|
|
4807
|
+
const entry = folder;
|
|
4808
|
+
requireString(entry, "label", "diagnostics folder");
|
|
4809
|
+
requireString(entry, "path", "diagnostics folder");
|
|
4810
|
+
requireNumber(entry, "bytes", "diagnostics folder");
|
|
4811
|
+
requireNumber(entry, "files", "diagnostics folder");
|
|
4812
|
+
if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
|
|
4813
|
+
throw new Error(
|
|
4814
|
+
"The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
|
|
4815
|
+
);
|
|
4798
4816
|
}
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4817
|
+
const logs = requireObject(
|
|
4818
|
+
report,
|
|
4819
|
+
"logs",
|
|
4820
|
+
"diagnostics"
|
|
4821
|
+
);
|
|
4822
|
+
requireString(logs, "folder", "diagnostics logs");
|
|
4823
|
+
requireNumber(logs, "fileCount", "diagnostics logs");
|
|
4824
|
+
requireNumber(logs, "totalBytes", "diagnostics logs");
|
|
4825
|
+
for (const key of ["newestFile", "newestModified"])
|
|
4826
|
+
if (!(logs[key] === null || isString(logs[key])))
|
|
4827
|
+
throw new Error(
|
|
4828
|
+
`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
|
|
4829
|
+
);
|
|
4830
|
+
return report;
|
|
4831
|
+
};
|
|
4832
|
+
var normaliseLogFiles = (files) => {
|
|
4833
|
+
if (!Array.isArray(files))
|
|
4834
|
+
throw new Error("The log report is not an array of files.");
|
|
4835
|
+
return files.map((file) => {
|
|
4836
|
+
if (!isObject(file))
|
|
4837
|
+
throw new Error("The log report carries an entry that is not an object.");
|
|
4838
|
+
const entry = file;
|
|
4839
|
+
requireString(entry, "name", "logs");
|
|
4840
|
+
requireString(entry, "modified", "logs");
|
|
4841
|
+
requireNumber(entry, "sizeBytes", "logs");
|
|
4842
|
+
return file;
|
|
4843
|
+
});
|
|
4844
|
+
};
|
|
4845
|
+
var checkLogFileName = (fileName) => {
|
|
4846
|
+
if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
|
|
4847
|
+
throw new ApiError(400, "Invalid log file name.");
|
|
4848
|
+
return fileName;
|
|
4849
|
+
};
|
|
4850
|
+
var logLines = (lines) => {
|
|
4851
|
+
if (lines === void 0 || lines === null || lines === "")
|
|
4852
|
+
return DEFAULT_LOG_LINES;
|
|
4853
|
+
const wanted = Number(lines);
|
|
4854
|
+
if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
|
|
4855
|
+
return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
|
|
4856
|
+
};
|
|
4857
|
+
var normaliseLogTail = (tail) => {
|
|
4858
|
+
if (!isObject(tail)) throw new Error("The log tail report is not an object.");
|
|
4859
|
+
const entry = tail;
|
|
4860
|
+
requireString(entry, "fileName", "log tail");
|
|
4861
|
+
requireString(entry, "content", "log tail");
|
|
4862
|
+
requireNumber(entry, "lines", "log tail");
|
|
4863
|
+
requireNumber(entry, "bytesRead", "log tail");
|
|
4864
|
+
if (typeof entry.truncated !== "boolean")
|
|
4865
|
+
throw new Error(
|
|
4866
|
+
"The log tail report states `truncated` as something other than a boolean."
|
|
4867
|
+
);
|
|
4868
|
+
return tail;
|
|
4869
|
+
};
|
|
4870
|
+
var createAdminService = (reports) => ({
|
|
4871
|
+
async diagnostics() {
|
|
4872
|
+
return normaliseDiagnostics(await reports.diagnostics());
|
|
4873
|
+
},
|
|
4874
|
+
async logs() {
|
|
4875
|
+
return normaliseLogFiles(await reports.logs());
|
|
4876
|
+
},
|
|
4877
|
+
async logTail(fileName, lines) {
|
|
4878
|
+
const name = checkLogFileName(fileName);
|
|
4879
|
+
const tail = await reports.logTail(name, logLines(lines));
|
|
4880
|
+
if (tail === void 0) throw new ApiError(404, "Log file not found.");
|
|
4881
|
+
return normaliseLogTail(tail);
|
|
4802
4882
|
}
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4883
|
+
});
|
|
4884
|
+
|
|
4885
|
+
// src/directory/service.ts
|
|
4886
|
+
var isNonEmptyString3 = (value) => typeof value === "string" && value.length > 0;
|
|
4887
|
+
var usersOf = (users) => {
|
|
4888
|
+
if (!Array.isArray(users))
|
|
4889
|
+
throw new Error("The directory answer has no users array.");
|
|
4890
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4891
|
+
for (const user3 of users) {
|
|
4892
|
+
if (!isNonEmptyString3(user3?.username) || !isNonEmptyString3(user3?.displayName))
|
|
4893
|
+
throw new Error(
|
|
4894
|
+
`The directory answer carries a user without a username or displayName: ${JSON.stringify(user3)}. Both are what the API keys an account on, so the import cannot guess them.`
|
|
4895
|
+
);
|
|
4896
|
+
if (seen.has(user3.username))
|
|
4897
|
+
throw new Error(
|
|
4898
|
+
`The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
|
|
4899
|
+
);
|
|
4900
|
+
seen.add(user3.username);
|
|
4806
4901
|
}
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
});
|
|
4824
|
-
return pair;
|
|
4825
|
-
}
|
|
4826
|
-
/**
|
|
4827
|
-
* A token names its subject only while that subject's CURRENT pair holds it.
|
|
4828
|
-
* The server verifies a token against the pair saved for the user and client,
|
|
4829
|
-
* so a logged-out or rotated token stops working there too; without the same
|
|
4830
|
-
* check here, the browser host would honour a token the server had revoked.
|
|
4831
|
-
*/
|
|
4832
|
-
async readAccess(token) {
|
|
4833
|
-
return this.current(token, this.access, "accessToken");
|
|
4834
|
-
}
|
|
4835
|
-
async readRefresh(token) {
|
|
4836
|
-
return this.current(token, this.refresh, "refreshToken");
|
|
4837
|
-
}
|
|
4838
|
-
current(token, issued, kind) {
|
|
4839
|
-
const entry = issued.get(token);
|
|
4840
|
-
if (!entry) return void 0;
|
|
4841
|
-
const subject = live(entry, Date.now());
|
|
4842
|
-
if (!subject) return void 0;
|
|
4843
|
-
const pair = this.pairs.get(keyOf(subject));
|
|
4844
|
-
return pair && pair[kind] === token ? subject : void 0;
|
|
4845
|
-
}
|
|
4846
|
-
/**
|
|
4847
|
-
* The subject's saved pair, while both of its tokens are still live.
|
|
4848
|
-
*
|
|
4849
|
-
* An exchange hands a saved pair back rather than rotating a second tab's
|
|
4850
|
-
* tokens. That is only an answer if the pair can still be used: a saved pair
|
|
4851
|
-
* whose access token has aged out would sign the caller in and then refuse
|
|
4852
|
-
* every request it makes, so an aged-out pair is reported as absent and the
|
|
4853
|
-
* exchange mints a fresh one. `live()` reads the issue-time expiry, which a
|
|
4854
|
-
* seeded token does not carry - a seeded pair therefore never ages out here.
|
|
4855
|
-
*/
|
|
4856
|
-
async pairFor(subject) {
|
|
4857
|
-
const pair = this.pairs.get(keyOf(subject));
|
|
4858
|
-
if (!pair) return void 0;
|
|
4859
|
-
const now = Date.now();
|
|
4860
|
-
const access = this.access.get(pair.accessToken);
|
|
4861
|
-
const refresh = this.refresh.get(pair.refreshToken);
|
|
4862
|
-
return live(access, now) && live(refresh, now) ? pair : void 0;
|
|
4863
|
-
}
|
|
4864
|
-
async savePair(subject, pair) {
|
|
4865
|
-
this.pairs.set(keyOf(subject), pair);
|
|
4866
|
-
}
|
|
4867
|
-
async deletePair(subject) {
|
|
4868
|
-
this.pairs.delete(keyOf(subject));
|
|
4869
|
-
}
|
|
4870
|
-
async issueCode(subject) {
|
|
4871
|
-
const code = `code-${randomHex(16)}`;
|
|
4872
|
-
this.codes.set(code, {
|
|
4873
|
-
subject,
|
|
4874
|
-
expiresAt: Date.now() + CODE_LIFETIME_SECONDS * 1e3
|
|
4875
|
-
});
|
|
4876
|
-
return code;
|
|
4877
|
-
}
|
|
4878
|
-
async readCode(code) {
|
|
4879
|
-
return live(this.codes.get(code), Date.now());
|
|
4880
|
-
}
|
|
4881
|
-
async claimCode(code) {
|
|
4882
|
-
if (this.claimed.has(code) || !this.codes.has(code)) return false;
|
|
4883
|
-
this.claimed.add(code);
|
|
4884
|
-
return true;
|
|
4885
|
-
}
|
|
4886
|
-
// ---------------------------------------------------------------- records
|
|
4887
|
-
async users() {
|
|
4888
|
-
return this.userList.map((user3) => this.recordOf(user3));
|
|
4889
|
-
}
|
|
4890
|
-
/** A user as the administration routes report one: groups derived, not stored. */
|
|
4891
|
-
recordOf(user3) {
|
|
4892
|
-
return {
|
|
4893
|
-
...user3,
|
|
4894
|
-
groups: [...this.groupList.values()].filter((group) => group.users.includes(user3.uid)).map((group) => group.uid)
|
|
4895
|
-
};
|
|
4896
|
-
}
|
|
4897
|
-
async createUser(input) {
|
|
4898
|
-
const user3 = {
|
|
4899
|
-
uid: `user-${randomHex(6)}`,
|
|
4900
|
-
username: input.username,
|
|
4901
|
-
displayName: input.displayName,
|
|
4902
|
-
isAdmin: input.isAdmin,
|
|
4903
|
-
isActive: input.isActive,
|
|
4904
|
-
needsToUpdatePassword: false,
|
|
4905
|
-
autoExec: input.autoExec,
|
|
4906
|
-
authProvider: input.authProvider
|
|
4907
|
-
};
|
|
4908
|
-
this.userList.push(user3);
|
|
4909
|
-
return this.recordOf(user3);
|
|
4910
|
-
}
|
|
4911
|
-
async updateUser(uid, change) {
|
|
4912
|
-
const user3 = this.userList.find((candidate) => candidate.uid === uid);
|
|
4913
|
-
if (!user3) return void 0;
|
|
4914
|
-
if (change.username !== void 0) user3.username = change.username;
|
|
4915
|
-
if (change.displayName !== void 0) user3.displayName = change.displayName;
|
|
4916
|
-
if (change.isAdmin !== void 0) user3.isAdmin = change.isAdmin;
|
|
4917
|
-
if (change.isActive !== void 0) user3.isActive = change.isActive;
|
|
4918
|
-
if (change.needsToUpdatePassword !== void 0)
|
|
4919
|
-
user3.needsToUpdatePassword = change.needsToUpdatePassword;
|
|
4920
|
-
if (change.autoExec !== void 0) user3.autoExec = change.autoExec;
|
|
4921
|
-
return this.recordOf(user3);
|
|
4922
|
-
}
|
|
4923
|
-
async deleteUser(uid) {
|
|
4924
|
-
const index = this.userList.findIndex((user3) => user3.uid === uid);
|
|
4925
|
-
if (index === -1) return;
|
|
4926
|
-
this.userList.splice(index, 1);
|
|
4927
|
-
this.passwords.delete(uid);
|
|
4928
|
-
for (const group of this.groupList.values())
|
|
4929
|
-
group.users = group.users.filter((member) => member !== uid);
|
|
4930
|
-
for (const [key, permission] of this.permissionList)
|
|
4931
|
-
if (permission.user === uid) this.permissionList.delete(key);
|
|
4932
|
-
for (const key of this.pairs.keys())
|
|
4933
|
-
if (key.startsWith(`${uid}|`)) this.pairs.delete(key);
|
|
4934
|
-
}
|
|
4935
|
-
async setPassword(uid, password) {
|
|
4936
|
-
this.passwords.set(uid, password);
|
|
4937
|
-
}
|
|
4938
|
-
async groups() {
|
|
4939
|
-
return [...this.groupList.values()];
|
|
4940
|
-
}
|
|
4941
|
-
async groupById(uid) {
|
|
4942
|
-
return this.groupList.get(uid);
|
|
4943
|
-
}
|
|
4944
|
-
async groupByName(name) {
|
|
4945
|
-
return [...this.groupList.values()].find((group) => group.name === name);
|
|
4946
|
-
}
|
|
4947
|
-
async createGroup(input) {
|
|
4948
|
-
const group = {
|
|
4949
|
-
uid: `group-${randomHex(6)}`,
|
|
4950
|
-
name: input.name,
|
|
4951
|
-
description: input.description,
|
|
4952
|
-
isActive: input.isActive,
|
|
4953
|
-
users: [],
|
|
4954
|
-
...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
|
|
4955
|
-
};
|
|
4956
|
-
this.groupList.set(group.uid, group);
|
|
4957
|
-
return group;
|
|
4958
|
-
}
|
|
4959
|
-
async deleteGroup(uid) {
|
|
4960
|
-
this.groupList.delete(uid);
|
|
4961
|
-
for (const [key, permission] of this.permissionList)
|
|
4962
|
-
if (permission.group === uid) this.permissionList.delete(key);
|
|
4963
|
-
}
|
|
4964
|
-
async addToGroup(groupUid, userUid) {
|
|
4965
|
-
const group = this.groupList.get(groupUid);
|
|
4966
|
-
if (!group) return void 0;
|
|
4967
|
-
if (!group.users.includes(userUid)) group.users.push(userUid);
|
|
4968
|
-
return group;
|
|
4969
|
-
}
|
|
4970
|
-
async removeFromGroup(groupUid, userUid) {
|
|
4971
|
-
const group = this.groupList.get(groupUid);
|
|
4972
|
-
if (!group) return void 0;
|
|
4973
|
-
group.users = group.users.filter((member) => member !== userUid);
|
|
4974
|
-
return group;
|
|
4975
|
-
}
|
|
4976
|
-
async permissions() {
|
|
4977
|
-
return [...this.permissionList.values()];
|
|
4978
|
-
}
|
|
4979
|
-
async permissionById(uid) {
|
|
4980
|
-
return this.permissionList.get(uid);
|
|
4981
|
-
}
|
|
4982
|
-
async createPermission(input) {
|
|
4983
|
-
const permission = {
|
|
4984
|
-
uid: `rule-${randomHex(6)}`,
|
|
4985
|
-
path: input.path,
|
|
4986
|
-
type: input.type,
|
|
4987
|
-
setting: input.setting,
|
|
4988
|
-
user: input.user,
|
|
4989
|
-
group: input.group
|
|
4990
|
-
};
|
|
4991
|
-
this.permissionList.set(permission.uid, permission);
|
|
4992
|
-
return permission;
|
|
4993
|
-
}
|
|
4994
|
-
async setPermissionSetting(uid, setting) {
|
|
4995
|
-
const permission = this.permissionList.get(uid);
|
|
4996
|
-
if (!permission) return void 0;
|
|
4997
|
-
permission.setting = setting;
|
|
4998
|
-
return permission;
|
|
4999
|
-
}
|
|
5000
|
-
async deletePermission(uid) {
|
|
5001
|
-
this.permissionList.delete(uid);
|
|
5002
|
-
}
|
|
5003
|
-
async clients() {
|
|
5004
|
-
return [...this.clientRecords.values()];
|
|
5005
|
-
}
|
|
5006
|
-
async createClient(input) {
|
|
5007
|
-
this.clientRecords.set(input.clientId, input);
|
|
5008
|
-
this.clientMap.set(input.clientId, {
|
|
5009
|
-
clientId: input.clientId,
|
|
5010
|
-
accessTokenExpiration: input.accessTokenExpiration,
|
|
5011
|
-
refreshTokenExpiration: input.refreshTokenExpiration
|
|
5012
|
-
});
|
|
5013
|
-
return input;
|
|
4902
|
+
return users;
|
|
4903
|
+
};
|
|
4904
|
+
var groupsOf = (groups) => {
|
|
4905
|
+
if (!Array.isArray(groups))
|
|
4906
|
+
throw new Error("The directory answer has no groups array.");
|
|
4907
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4908
|
+
for (const group of groups) {
|
|
4909
|
+
if (!isNonEmptyString3(group?.name))
|
|
4910
|
+
throw new Error(
|
|
4911
|
+
`The directory answer carries a group without a name: ${JSON.stringify(group)}.`
|
|
4912
|
+
);
|
|
4913
|
+
if (seen.has(group.name))
|
|
4914
|
+
throw new Error(
|
|
4915
|
+
`The directory answer names the group ${group.name} twice, which would apply its members twice.`
|
|
4916
|
+
);
|
|
4917
|
+
seen.add(group.name);
|
|
5014
4918
|
}
|
|
4919
|
+
return groups;
|
|
4920
|
+
};
|
|
4921
|
+
var createDirectoryService = (store, source, options = {}) => {
|
|
4922
|
+
const provider = options.provider || "ldap";
|
|
4923
|
+
return {
|
|
4924
|
+
async synchronise() {
|
|
4925
|
+
const directoryUsers = usersOf(await source.users());
|
|
4926
|
+
const directoryGroups = groupsOf(await source.groups());
|
|
4927
|
+
const existingUsers = await store.users();
|
|
4928
|
+
const existingGroups = await store.groups();
|
|
4929
|
+
const userByName = new Map(
|
|
4930
|
+
existingUsers.map((user3) => [user3.username, user3])
|
|
4931
|
+
);
|
|
4932
|
+
const groupByName = new Map(
|
|
4933
|
+
existingGroups.map((group) => [group.name, group])
|
|
4934
|
+
);
|
|
4935
|
+
const imported = [];
|
|
4936
|
+
for (const user3 of directoryUsers) {
|
|
4937
|
+
if (userByName.has(user3.username)) continue;
|
|
4938
|
+
const created = await store.createUser({
|
|
4939
|
+
username: user3.username,
|
|
4940
|
+
displayName: user3.displayName,
|
|
4941
|
+
isAdmin: false,
|
|
4942
|
+
isActive: true,
|
|
4943
|
+
authProvider: provider
|
|
4944
|
+
});
|
|
4945
|
+
userByName.set(created.username, created);
|
|
4946
|
+
imported.push(created);
|
|
4947
|
+
}
|
|
4948
|
+
const importedGroups = [];
|
|
4949
|
+
for (const group of directoryGroups) {
|
|
4950
|
+
if (groupByName.has(group.name)) continue;
|
|
4951
|
+
const created = await store.createGroup({
|
|
4952
|
+
name: group.name,
|
|
4953
|
+
description: "",
|
|
4954
|
+
isActive: true,
|
|
4955
|
+
authProvider: provider
|
|
4956
|
+
});
|
|
4957
|
+
groupByName.set(created.name, created);
|
|
4958
|
+
importedGroups.push(created);
|
|
4959
|
+
}
|
|
4960
|
+
const membersOf = /* @__PURE__ */ new Map();
|
|
4961
|
+
const note = (groupName, username) => {
|
|
4962
|
+
const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
|
|
4963
|
+
members.add(username);
|
|
4964
|
+
membersOf.set(groupName, members);
|
|
4965
|
+
};
|
|
4966
|
+
for (const group of directoryGroups)
|
|
4967
|
+
for (const member of group.members || []) note(group.name, member);
|
|
4968
|
+
for (const user3 of directoryUsers)
|
|
4969
|
+
for (const groupName of user3.groups || [])
|
|
4970
|
+
note(groupName, user3.username);
|
|
4971
|
+
for (const group of importedGroups)
|
|
4972
|
+
for (const username of membersOf.get(group.name) || []) {
|
|
4973
|
+
const user3 = userByName.get(username);
|
|
4974
|
+
if (user3) await store.addToGroup(group.uid, user3.uid);
|
|
4975
|
+
}
|
|
4976
|
+
return { userCount: imported.length, groupCount: importedGroups.length };
|
|
4977
|
+
}
|
|
4978
|
+
};
|
|
5015
4979
|
};
|
|
5016
4980
|
|
|
5017
|
-
// src/
|
|
5018
|
-
var
|
|
5019
|
-
var
|
|
5020
|
-
var
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
},
|
|
5034
|
-
expect: { status: 200, body: success2 }
|
|
5035
|
-
},
|
|
5036
|
-
{
|
|
5037
|
-
id: "create-file-at-form-path",
|
|
5038
|
-
route: "POST /SASjsApi/drive/file",
|
|
5039
|
-
description: "takes the destination from the form field when the query has none",
|
|
5040
|
-
request: {
|
|
5041
|
-
file: { name: "x.csv", contents: "x" },
|
|
5042
|
-
body: { filePath: "/data/from-form.csv" }
|
|
5043
|
-
},
|
|
5044
|
-
expect: { status: 200, body: success2 }
|
|
5045
|
-
},
|
|
5046
|
-
{
|
|
5047
|
-
id: "create-file-over-existing",
|
|
5048
|
-
route: "POST /SASjsApi/drive/file",
|
|
5049
|
-
description: "refuses a create over a file that exists, as 409",
|
|
5050
|
-
seed: { "/data/exists.csv": "a" },
|
|
5051
|
-
request: {
|
|
5052
|
-
query: { _filePath: "/data/exists.csv" },
|
|
5053
|
-
file: { name: "x", contents: "b" }
|
|
5054
|
-
},
|
|
5055
|
-
expect: { status: 409, error: "File already exists." }
|
|
5056
|
-
},
|
|
5057
|
-
{
|
|
5058
|
-
id: "create-file-blocked-extension",
|
|
5059
|
-
route: "POST /SASjsApi/drive/file",
|
|
5060
|
-
description: "refuses a refused extension before touching the drive",
|
|
5061
|
-
request: {
|
|
5062
|
-
query: { _filePath: "/data/run.sh" },
|
|
5063
|
-
file: { name: "run.sh", contents: "x" }
|
|
4981
|
+
// src/identity/fixture.ts
|
|
4982
|
+
var IDENTITY_FORMAT = 1;
|
|
4983
|
+
var SECONDS_IN_A_DAY2 = 86400;
|
|
4984
|
+
var DEFAULT_IDENTITY = {
|
|
4985
|
+
format: IDENTITY_FORMAT,
|
|
4986
|
+
users: [
|
|
4987
|
+
{
|
|
4988
|
+
uid: "user-admin",
|
|
4989
|
+
username: "sasjsadmin",
|
|
4990
|
+
displayName: "Demo Admin",
|
|
4991
|
+
// long enough to pass the API's own password rule (six characters), so a
|
|
4992
|
+
// demo can sign in against a real server as well as a mock
|
|
4993
|
+
password: "Orion123",
|
|
4994
|
+
isAdmin: true,
|
|
4995
|
+
isActive: true,
|
|
4996
|
+
needsToUpdatePassword: false
|
|
5064
4997
|
},
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
4998
|
+
{
|
|
4999
|
+
uid: "user-restricted",
|
|
5000
|
+
username: "sasjsuser",
|
|
5001
|
+
displayName: "Demo User",
|
|
5002
|
+
password: "Orion123",
|
|
5003
|
+
isAdmin: false,
|
|
5004
|
+
isActive: true,
|
|
5005
|
+
needsToUpdatePassword: false
|
|
5006
|
+
}
|
|
5007
|
+
],
|
|
5008
|
+
groups: [
|
|
5009
|
+
{
|
|
5010
|
+
uid: "group-data-controller",
|
|
5011
|
+
name: "DCGroup",
|
|
5012
|
+
description: "Data Controller users",
|
|
5013
|
+
isActive: true,
|
|
5014
|
+
users: ["sasjsuser"]
|
|
5074
5015
|
},
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
},
|
|
5091
|
-
{
|
|
5092
|
-
id: "replace-file",
|
|
5093
|
-
route: "PATCH /SASjsApi/drive/file",
|
|
5094
|
-
description: "replaces the contents of a file that exists",
|
|
5095
|
-
seed: { "/data/keep.csv": "old" },
|
|
5096
|
-
request: {
|
|
5097
|
-
query: { _filePath: "/data/keep.csv" },
|
|
5098
|
-
file: { name: "keep.csv", contents: "new" }
|
|
5016
|
+
{
|
|
5017
|
+
uid: "group-admins",
|
|
5018
|
+
name: "Admins",
|
|
5019
|
+
description: "Everything the API offers",
|
|
5020
|
+
isActive: true,
|
|
5021
|
+
users: ["sasjsadmin"]
|
|
5022
|
+
}
|
|
5023
|
+
],
|
|
5024
|
+
permissions: [
|
|
5025
|
+
{
|
|
5026
|
+
uid: "rule-routes",
|
|
5027
|
+
path: "/SASjsApi/drive/file",
|
|
5028
|
+
type: "Route",
|
|
5029
|
+
setting: "Grant",
|
|
5030
|
+
group: "group-data-controller"
|
|
5099
5031
|
},
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
request: {
|
|
5107
|
-
query: { _filePath: "/data/missing.csv" },
|
|
5108
|
-
file: { name: "x", contents: "x" }
|
|
5032
|
+
{
|
|
5033
|
+
uid: "rule-execute",
|
|
5034
|
+
path: "/SASjsApi/stp/execute",
|
|
5035
|
+
type: "Route",
|
|
5036
|
+
setting: "Grant",
|
|
5037
|
+
group: "group-data-controller"
|
|
5109
5038
|
},
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5039
|
+
{
|
|
5040
|
+
uid: "rule-code",
|
|
5041
|
+
path: "/SASjsApi/code/execute",
|
|
5042
|
+
type: "Route",
|
|
5043
|
+
setting: "Deny",
|
|
5044
|
+
user: "user-restricted"
|
|
5045
|
+
}
|
|
5046
|
+
],
|
|
5047
|
+
clients: [
|
|
5048
|
+
{
|
|
5049
|
+
clientId: "web_app",
|
|
5050
|
+
clientSecret: "web_app",
|
|
5051
|
+
accessTokenExpiration: SECONDS_IN_A_DAY2,
|
|
5052
|
+
refreshTokenExpiration: SECONDS_IN_A_DAY2 * 30
|
|
5119
5053
|
},
|
|
5120
|
-
expect: { status: 400, error: "Can't modify file outside drive." }
|
|
5121
|
-
},
|
|
5122
|
-
{
|
|
5123
|
-
id: "read-file",
|
|
5124
|
-
route: "GET /SASjsApi/drive/file",
|
|
5125
|
-
description: "answers with the file contents",
|
|
5126
|
-
seed: { "/data/keep.csv": "a,b\n1,2\n" },
|
|
5127
|
-
request: { query: { _filePath: "/data/keep.csv" } },
|
|
5128
|
-
expect: { status: 200, contents: "a,b\n1,2\n" }
|
|
5129
|
-
},
|
|
5130
|
-
{
|
|
5131
|
-
id: "read-file-missing",
|
|
5132
|
-
route: "GET /SASjsApi/drive/file",
|
|
5133
|
-
description: "refuses a read of a file that is not there",
|
|
5134
|
-
request: { query: { _filePath: "/data/missing.csv" } },
|
|
5135
|
-
expect: { status: 404, error: `File doesn't exist.` }
|
|
5136
|
-
},
|
|
5137
|
-
{
|
|
5138
|
-
id: "read-file-outside-drive",
|
|
5139
|
-
route: "GET /SASjsApi/drive/file",
|
|
5140
|
-
description: "refuses a read of a path that climbs out of the drive",
|
|
5141
|
-
request: { query: { _filePath: "/../escape.csv" } },
|
|
5142
|
-
expect: { status: 400, error: "Can't get file outside drive." }
|
|
5143
|
-
},
|
|
5144
|
-
{
|
|
5145
|
-
id: "delete-file",
|
|
5146
|
-
route: "DELETE /SASjsApi/drive/file",
|
|
5147
|
-
description: "deletes a file that exists",
|
|
5148
|
-
seed: { "/data/keep.csv": "a" },
|
|
5149
|
-
request: { query: { _filePath: "/data/keep.csv" } },
|
|
5150
|
-
expect: { status: 200, body: success2 }
|
|
5151
|
-
},
|
|
5152
|
-
{
|
|
5153
|
-
id: "delete-file-missing",
|
|
5154
|
-
route: "DELETE /SASjsApi/drive/file",
|
|
5155
|
-
description: "refuses a delete of a file that is not there",
|
|
5156
|
-
request: { query: { _filePath: "/data/missing.csv" } },
|
|
5157
|
-
expect: { status: 404, error: `File doesn't exist.` }
|
|
5158
|
-
},
|
|
5159
|
-
{
|
|
5160
|
-
id: "delete-file-outside-drive",
|
|
5161
|
-
route: "DELETE /SASjsApi/drive/file",
|
|
5162
|
-
description: "refuses a delete of a path that climbs out of the drive",
|
|
5163
|
-
request: { query: { _filePath: "/../escape.csv" } },
|
|
5164
|
-
expect: { status: 400, error: "Can't delete file outside drive." }
|
|
5165
|
-
},
|
|
5166
|
-
{
|
|
5167
|
-
id: "list-folder",
|
|
5168
|
-
route: "GET /SASjsApi/drive/folder",
|
|
5169
|
-
description: "lists the files and folders of a folder",
|
|
5170
|
-
seed: { "/data/a.csv": "a", "/data/reports/b.csv": "b" },
|
|
5171
|
-
request: { query: { _folderPath: "/data" } },
|
|
5172
|
-
expect: { status: 200, body: { files: ["a.csv"], folders: ["reports"] } }
|
|
5173
|
-
},
|
|
5174
|
-
{
|
|
5175
|
-
id: "list-folder-missing",
|
|
5176
|
-
route: "GET /SASjsApi/drive/folder",
|
|
5177
|
-
description: "refuses a listing of a folder that is not there",
|
|
5178
|
-
request: { query: { _folderPath: "/nope" } },
|
|
5179
|
-
expect: { status: 404, error: `Folder doesn't exist.` }
|
|
5180
|
-
},
|
|
5181
|
-
{
|
|
5182
|
-
id: "list-folder-outside-drive",
|
|
5183
|
-
route: "GET /SASjsApi/drive/folder",
|
|
5184
|
-
description: "refuses a listing of a path that climbs out of the drive",
|
|
5185
|
-
request: { query: { _folderPath: "/../escape" } },
|
|
5186
|
-
expect: { status: 400, error: "Can't get folder outside drive." }
|
|
5187
|
-
},
|
|
5188
|
-
{
|
|
5189
|
-
id: "delete-folder-without-path",
|
|
5190
|
-
route: "DELETE /SASjsApi/drive/folder",
|
|
5191
|
-
description: "answers for a missing folder path, because the table marks it required",
|
|
5192
|
-
request: {},
|
|
5193
|
-
expect: { status: 400, error: '"_folderPath" is required' }
|
|
5194
|
-
},
|
|
5195
|
-
{
|
|
5196
|
-
id: "create-folder-without-path",
|
|
5197
|
-
route: "POST /SASjsApi/drive/folder",
|
|
5198
|
-
description: "answers for a missing folder path in the body",
|
|
5199
|
-
request: { body: {} },
|
|
5200
|
-
expect: { status: 400, error: '"folderPath" is required' }
|
|
5201
|
-
},
|
|
5202
|
-
{
|
|
5203
|
-
id: "create-folder",
|
|
5204
|
-
route: "POST /SASjsApi/drive/folder",
|
|
5205
|
-
description: "creates a folder",
|
|
5206
|
-
request: { body: { folderPath: "/data/reports" } },
|
|
5207
|
-
expect: { status: 200, body: success2 }
|
|
5208
|
-
},
|
|
5209
|
-
{
|
|
5210
|
-
id: "create-folder-existing",
|
|
5211
|
-
route: "POST /SASjsApi/drive/folder",
|
|
5212
|
-
description: "refuses a folder that already exists, as 409",
|
|
5213
|
-
seed: { "/data/reports/a.csv": "a" },
|
|
5214
|
-
request: { body: { folderPath: "/data/reports" } },
|
|
5215
|
-
expect: { status: 409, error: "Folder already exists." }
|
|
5216
|
-
},
|
|
5217
|
-
{
|
|
5218
|
-
id: "delete-folder",
|
|
5219
|
-
route: "DELETE /SASjsApi/drive/folder",
|
|
5220
|
-
description: "deletes a folder with everything under it",
|
|
5221
|
-
seed: { "/data/reports/a.csv": "a", "/data/reports/nested/b.csv": "b" },
|
|
5222
|
-
request: { query: { _folderPath: "/data/reports" } },
|
|
5223
|
-
expect: { status: 200, body: success2 }
|
|
5224
|
-
},
|
|
5225
|
-
{
|
|
5226
|
-
id: "delete-folder-missing",
|
|
5227
|
-
route: "DELETE /SASjsApi/drive/folder",
|
|
5228
|
-
description: "refuses a delete of a folder that is not there",
|
|
5229
|
-
request: { query: { _folderPath: "/nope" } },
|
|
5230
|
-
expect: { status: 404, error: `Folder doesn't exist.` }
|
|
5231
|
-
},
|
|
5232
|
-
{
|
|
5233
|
-
id: "rename-file",
|
|
5234
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5235
|
-
description: "moves a file to a new path",
|
|
5236
|
-
seed: { "/data/old.csv": "r" },
|
|
5237
|
-
request: { body: { oldPath: "/data/old.csv", newPath: "/data/new.csv" } },
|
|
5238
|
-
expect: { status: 200, body: success2 }
|
|
5239
|
-
},
|
|
5240
|
-
{
|
|
5241
|
-
id: "rename-onto-existing",
|
|
5242
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5243
|
-
description: "refuses a move onto something that exists",
|
|
5244
|
-
seed: { "/data/a.csv": "a", "/data/b.csv": "b" },
|
|
5245
|
-
request: { body: { oldPath: "/data/a.csv", newPath: "/data/b.csv" } },
|
|
5246
|
-
expect: { status: 409, error: "File with new name already exists." }
|
|
5247
|
-
},
|
|
5248
|
-
{
|
|
5249
|
-
id: "rename-missing",
|
|
5250
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5251
|
-
description: "refuses a move of something that is not there",
|
|
5252
|
-
request: { body: { oldPath: "/data/nope.csv", newPath: "/data/x.csv" } },
|
|
5253
|
-
expect: { status: 404, error: "No file/folder found for provided path." }
|
|
5254
|
-
},
|
|
5255
|
-
{
|
|
5256
|
-
id: "rename-file-to-blocked-extension",
|
|
5257
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5258
|
-
description: "refuses a rename that would produce a name the file routes refuse",
|
|
5259
|
-
seed: { "/data/report.csv": "a,b" },
|
|
5260
|
-
request: {
|
|
5261
|
-
body: { oldPath: "/data/report.csv", newPath: "/data/report.sh" }
|
|
5262
|
-
},
|
|
5263
|
-
expect: { status: 400, error: "Invalid file extension" }
|
|
5264
|
-
},
|
|
5265
|
-
{
|
|
5266
|
-
id: "rename-folder-to-dotted-name",
|
|
5267
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5268
|
-
description: "renames a folder whose new name carries a blocked suffix",
|
|
5269
|
-
seed: { "/data/reports/a.csv": "a" },
|
|
5270
|
-
request: {
|
|
5271
|
-
body: { oldPath: "/data/reports", newPath: "/data/reports.sh" }
|
|
5272
|
-
},
|
|
5273
|
-
expect: { status: 200, body: { status: "success" } }
|
|
5274
|
-
},
|
|
5275
|
-
{
|
|
5276
|
-
id: "rename-folder-into-itself",
|
|
5277
|
-
route: "POST /SASjsApi/drive/rename",
|
|
5278
|
-
description: "refuses a folder moved inside itself, which the server loses at the filesystem",
|
|
5279
|
-
seed: { "/data/reports/a.csv": "a" },
|
|
5280
|
-
request: {
|
|
5281
|
-
body: { oldPath: "/data/reports", newPath: "/data/reports/nested" }
|
|
5282
|
-
},
|
|
5283
|
-
expect: {
|
|
5284
|
-
status: 400,
|
|
5285
|
-
error: "New path can't be inside the folder being moved."
|
|
5286
|
-
}
|
|
5287
|
-
},
|
|
5288
|
-
{
|
|
5289
|
-
id: "tree",
|
|
5290
|
-
route: "GET /SASjsApi/drive/filetree",
|
|
5291
|
-
description: "answers with the drive tree",
|
|
5292
|
-
seed: { "/data/a.csv": "a" },
|
|
5293
|
-
request: { query: { _folderPath: "/data" } },
|
|
5294
|
-
expect: {
|
|
5295
|
-
status: 200,
|
|
5296
|
-
body: {
|
|
5297
|
-
status: "success",
|
|
5298
|
-
tree: {
|
|
5299
|
-
name: "data",
|
|
5300
|
-
relativePath: "/data",
|
|
5301
|
-
isFolder: true,
|
|
5302
|
-
children: [
|
|
5303
|
-
{
|
|
5304
|
-
name: "a.csv",
|
|
5305
|
-
relativePath: "/data/a.csv",
|
|
5306
|
-
isFolder: false,
|
|
5307
|
-
children: []
|
|
5308
|
-
}
|
|
5309
|
-
]
|
|
5310
|
-
}
|
|
5311
|
-
}
|
|
5312
|
-
}
|
|
5313
|
-
},
|
|
5314
|
-
{
|
|
5315
|
-
id: "deploy-tree",
|
|
5316
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5317
|
-
description: "writes a whole tree under the appLoc it names",
|
|
5318
|
-
request: {
|
|
5319
|
-
body: {
|
|
5320
|
-
appLoc: "/Public/apps/demo",
|
|
5321
|
-
fileTree: {
|
|
5322
|
-
members: [
|
|
5323
|
-
{
|
|
5324
|
-
name: "services",
|
|
5325
|
-
type: "folder",
|
|
5326
|
-
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
5327
|
-
},
|
|
5328
|
-
{ name: "index.html", type: "file", code: "PGgxPkhlbGxvPC9oMT4=" }
|
|
5329
|
-
]
|
|
5330
|
-
}
|
|
5331
|
-
}
|
|
5332
|
-
},
|
|
5333
|
-
expect: {
|
|
5334
|
-
status: 200,
|
|
5335
|
-
body: {
|
|
5336
|
-
status: "success",
|
|
5337
|
-
message: "Files deployed successfully to @sasjs/server."
|
|
5338
|
-
}
|
|
5339
|
-
}
|
|
5340
|
-
},
|
|
5341
|
-
{
|
|
5342
|
-
id: "deploy-refused-by-entry-count",
|
|
5343
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5344
|
-
description: "refuses a tree over the entry cap, naming the figure and the cap",
|
|
5345
|
-
request: {
|
|
5346
|
-
body: {
|
|
5347
|
-
appLoc: "/Public/apps/many",
|
|
5348
|
-
fileTree: { members: manyMembers(10001) }
|
|
5349
|
-
}
|
|
5350
|
-
},
|
|
5351
|
-
expect: {
|
|
5352
|
-
status: 413,
|
|
5353
|
-
body: {
|
|
5354
|
-
status: "failure",
|
|
5355
|
-
message: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
|
|
5356
|
-
},
|
|
5357
|
-
error: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
|
|
5358
|
-
}
|
|
5359
|
-
},
|
|
5360
|
-
{
|
|
5361
|
-
id: "deploy-refused-by-name",
|
|
5362
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5363
|
-
description: "refuses a member name that would escape the deployment root",
|
|
5364
|
-
request: {
|
|
5365
|
-
body: {
|
|
5366
|
-
appLoc: "/Public/apps/hostile",
|
|
5367
|
-
fileTree: {
|
|
5368
|
-
members: [{ name: "../escape", type: "service", code: "%put hi;" }]
|
|
5369
|
-
}
|
|
5370
|
-
}
|
|
5371
|
-
},
|
|
5372
|
-
expect: {
|
|
5373
|
-
status: 400,
|
|
5374
|
-
body: {
|
|
5375
|
-
status: "failure",
|
|
5376
|
-
message: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
|
|
5377
|
-
},
|
|
5378
|
-
error: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
|
|
5379
|
-
}
|
|
5380
|
-
},
|
|
5381
|
-
{
|
|
5382
|
-
id: "deploy-refused-by-shape",
|
|
5383
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5384
|
-
description: "refuses a fileTree that is not a tree, in the routes own envelope",
|
|
5385
|
-
request: { body: { appLoc: "/Public/apps/bad", fileTree: { members: 1 } } },
|
|
5386
|
-
expect: {
|
|
5387
|
-
status: 400,
|
|
5388
|
-
body: {
|
|
5389
|
-
status: "failure",
|
|
5390
|
-
message: "Provided not supported data format."
|
|
5391
|
-
},
|
|
5392
|
-
error: "Provided not supported data format."
|
|
5393
|
-
}
|
|
5394
|
-
},
|
|
5395
|
-
{
|
|
5396
|
-
id: "deploy-refused-by-store",
|
|
5397
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5398
|
-
description: "answers the routes 500 when the drive refuses the write",
|
|
5399
|
-
unwritable: true,
|
|
5400
|
-
request: {
|
|
5401
|
-
body: {
|
|
5402
|
-
appLoc: "/Public/apps/demo",
|
|
5403
|
-
fileTree: {
|
|
5404
|
-
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
},
|
|
5408
|
-
expect: {
|
|
5409
|
-
status: 500,
|
|
5410
|
-
body: { status: "failure", message: "Deployment failed!" },
|
|
5411
|
-
error: "Deployment failed!"
|
|
5412
|
-
}
|
|
5413
|
-
},
|
|
5414
|
-
{
|
|
5415
|
-
id: "deploy-refused-outside-drive",
|
|
5416
|
-
route: "POST /SASjsApi/drive/deploy",
|
|
5417
|
-
description: "refuses an appLoc that resolves outside the drive",
|
|
5418
|
-
request: {
|
|
5419
|
-
body: { appLoc: "/../outside", fileTree: { members: [] } }
|
|
5420
|
-
},
|
|
5421
|
-
expect: {
|
|
5422
|
-
status: 400,
|
|
5423
|
-
body: { status: "failure", message: "appLoc cannot be outside drive." },
|
|
5424
|
-
error: "appLoc cannot be outside drive."
|
|
5425
|
-
}
|
|
5426
|
-
},
|
|
5427
|
-
{
|
|
5428
|
-
id: "bytes-round-trip",
|
|
5429
|
-
route: "GET /SASjsApi/drive/file",
|
|
5430
|
-
description: "keeps a byte file as bytes",
|
|
5431
|
-
seed: { "/data/pack.zip": bytes(80, 75, 3, 4) },
|
|
5432
|
-
request: { query: { _filePath: "/data/pack.zip" } },
|
|
5433
|
-
expect: { status: 200, contents: bytes(80, 75, 3, 4) }
|
|
5434
|
-
}
|
|
5435
|
-
];
|
|
5436
|
-
|
|
5437
|
-
// src/corpus/identity.ts
|
|
5438
|
-
var SIGNED_IN = {
|
|
5439
|
-
...DEFAULT_IDENTITY,
|
|
5440
|
-
tokens: [
|
|
5441
|
-
{
|
|
5442
|
-
username: "user2",
|
|
5443
|
-
clientId: "web_app",
|
|
5444
|
-
accessToken: "seed-access",
|
|
5445
|
-
refreshToken: "seed-refresh"
|
|
5446
|
-
},
|
|
5447
|
-
{
|
|
5448
|
-
username: "admin",
|
|
5449
|
-
clientId: "removed_client",
|
|
5450
|
-
accessToken: "seed-access-orphan",
|
|
5451
|
-
refreshToken: "seed-refresh-orphan"
|
|
5452
|
-
}
|
|
5453
|
-
],
|
|
5454
|
-
codes: [
|
|
5455
|
-
{ code: "seed-code", username: "user2", clientId: "web_app" },
|
|
5456
|
-
{ code: "seed-orphan-code", username: "user2", clientId: "removed_client" },
|
|
5457
|
-
// the same shape with a pair already issued: the exchange must still refuse,
|
|
5458
|
-
// rather than handing back tokens that belong to a client that is gone
|
|
5459
5054
|
{
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5055
|
+
clientId: "sasjs",
|
|
5056
|
+
clientSecret: "sasjs",
|
|
5057
|
+
accessTokenExpiration: 3600,
|
|
5058
|
+
refreshTokenExpiration: SECONDS_IN_A_DAY2
|
|
5463
5059
|
}
|
|
5464
5060
|
]
|
|
5465
5061
|
};
|
|
5466
|
-
var
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
)
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5062
|
+
var parseIdentity = (raw) => {
|
|
5063
|
+
const fixture = raw;
|
|
5064
|
+
if (!fixture || typeof fixture !== "object")
|
|
5065
|
+
throw new Error("The identity fixture is not an object.");
|
|
5066
|
+
if (fixture.format !== IDENTITY_FORMAT)
|
|
5067
|
+
throw new Error(
|
|
5068
|
+
`The identity fixture states format ${String(fixture.format)}, and this build reads format ${IDENTITY_FORMAT}. Rebuild the site, or replace mock-identity.json with one this version wrote.`
|
|
5069
|
+
);
|
|
5070
|
+
for (const key of ["users", "groups", "permissions", "clients"])
|
|
5071
|
+
if (!Array.isArray(fixture[key]))
|
|
5072
|
+
throw new Error(`The identity fixture has no \`${key}\` array.`);
|
|
5073
|
+
for (const token of fixture.tokens || [])
|
|
5074
|
+
if (!token.accessToken || !token.refreshToken)
|
|
5075
|
+
throw new Error(
|
|
5076
|
+
`The identity fixture declares a half pair for ${token.username}/${token.clientId}: a seeded token needs both an accessToken and a refreshToken, because a token only authenticates while the subject's pair holds it.`
|
|
5077
|
+
);
|
|
5078
|
+
if (!fixture.users.some((user3) => user3.isAdmin))
|
|
5079
|
+
throw new Error(
|
|
5080
|
+
"The identity fixture declares no administrator: a demo with nobody able to administer it cannot exercise the admin routes."
|
|
5081
|
+
);
|
|
5082
|
+
return fixture;
|
|
5083
|
+
};
|
|
5084
|
+
|
|
5085
|
+
// src/identity/memory-store.ts
|
|
5086
|
+
var keyOf = (subject) => `${subject.userId}|${subject.clientId}`;
|
|
5087
|
+
var randomHex = (bytes3) => {
|
|
5088
|
+
const source = globalThis.crypto;
|
|
5089
|
+
if (!source)
|
|
5090
|
+
throw new ApiError(
|
|
5091
|
+
500,
|
|
5092
|
+
"This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
|
|
5093
|
+
);
|
|
5094
|
+
const buffer = new Uint8Array(bytes3);
|
|
5095
|
+
source.getRandomValues(buffer);
|
|
5096
|
+
return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
5097
|
+
""
|
|
5098
|
+
);
|
|
5099
|
+
};
|
|
5100
|
+
var CODE_LIFETIME_SECONDS = 30;
|
|
5101
|
+
var live = (issued, now) => issued && (issued.expiresAt === void 0 || issued.expiresAt > now) ? issued.subject : void 0;
|
|
5102
|
+
var MemoryIdentityStore = class {
|
|
5103
|
+
constructor(fixture = DEFAULT_IDENTITY) {
|
|
5104
|
+
this.userList = [];
|
|
5105
|
+
this.passwords = /* @__PURE__ */ new Map();
|
|
5106
|
+
this.groupList = /* @__PURE__ */ new Map();
|
|
5107
|
+
this.permissionList = /* @__PURE__ */ new Map();
|
|
5108
|
+
this.clientRecords = /* @__PURE__ */ new Map();
|
|
5109
|
+
this.clientMap = /* @__PURE__ */ new Map();
|
|
5110
|
+
this.pairs = /* @__PURE__ */ new Map();
|
|
5111
|
+
this.access = /* @__PURE__ */ new Map();
|
|
5112
|
+
this.refresh = /* @__PURE__ */ new Map();
|
|
5113
|
+
this.codes = /* @__PURE__ */ new Map();
|
|
5114
|
+
this.claimed = /* @__PURE__ */ new Set();
|
|
5115
|
+
if (fixture.format !== IDENTITY_FORMAT)
|
|
5116
|
+
throw new ApiError(
|
|
5117
|
+
500,
|
|
5118
|
+
`The identity fixture states format ${String(fixture.format)}; this store reads ${IDENTITY_FORMAT}.`
|
|
5119
|
+
);
|
|
5120
|
+
for (const user3 of fixture.users) {
|
|
5121
|
+
this.userList.push({
|
|
5122
|
+
uid: user3.uid,
|
|
5123
|
+
username: user3.username,
|
|
5124
|
+
displayName: user3.displayName,
|
|
5125
|
+
isAdmin: user3.isAdmin,
|
|
5126
|
+
isActive: user3.isActive,
|
|
5127
|
+
needsToUpdatePassword: user3.needsToUpdatePassword,
|
|
5128
|
+
authProvider: user3.authProvider,
|
|
5129
|
+
autoExec: user3.autoExec
|
|
5130
|
+
});
|
|
5131
|
+
this.passwords.set(user3.uid, user3.password);
|
|
5132
|
+
}
|
|
5133
|
+
for (const client of fixture.clients) {
|
|
5134
|
+
this.clientMap.set(client.clientId, {
|
|
5135
|
+
clientId: client.clientId,
|
|
5136
|
+
accessTokenExpiration: client.accessTokenExpiration,
|
|
5137
|
+
refreshTokenExpiration: client.refreshTokenExpiration
|
|
5138
|
+
});
|
|
5139
|
+
this.clientRecords.set(client.clientId, {
|
|
5140
|
+
clientId: client.clientId,
|
|
5141
|
+
clientSecret: client.clientSecret,
|
|
5142
|
+
accessTokenExpiration: client.accessTokenExpiration,
|
|
5143
|
+
refreshTokenExpiration: client.refreshTokenExpiration
|
|
5144
|
+
});
|
|
5145
|
+
}
|
|
5146
|
+
for (const group of fixture.groups) {
|
|
5147
|
+
const uid = group.uid;
|
|
5148
|
+
this.groupList.set(uid, {
|
|
5149
|
+
uid,
|
|
5150
|
+
name: group.name,
|
|
5151
|
+
description: group.description,
|
|
5152
|
+
isActive: group.isActive,
|
|
5153
|
+
authProvider: group.authProvider,
|
|
5154
|
+
users: group.users.map(
|
|
5155
|
+
(username) => this.userList.find((user3) => user3.username === username)?.uid
|
|
5156
|
+
).filter((member) => member !== void 0)
|
|
5157
|
+
});
|
|
5158
|
+
}
|
|
5159
|
+
for (const permission of fixture.permissions) {
|
|
5160
|
+
this.permissionList.set(permission.uid, {
|
|
5161
|
+
uid: permission.uid,
|
|
5162
|
+
path: permission.path,
|
|
5163
|
+
type: permission.type,
|
|
5164
|
+
setting: permission.setting,
|
|
5165
|
+
user: permission.user ? this.userList.find((user3) => user3.uid === permission.user)?.uid : void 0,
|
|
5166
|
+
group: permission.group ? this.groupList.get(permission.group)?.uid : void 0
|
|
5167
|
+
});
|
|
5168
|
+
}
|
|
5169
|
+
for (const token of fixture.tokens || []) {
|
|
5170
|
+
const user3 = this.userList.find(
|
|
5171
|
+
(candidate) => candidate.username === token.username
|
|
5172
|
+
);
|
|
5173
|
+
if (!user3) continue;
|
|
5174
|
+
const subject = { userId: user3.uid, clientId: token.clientId };
|
|
5175
|
+
if (token.accessToken) this.access.set(token.accessToken, { subject });
|
|
5176
|
+
if (token.refreshToken) this.refresh.set(token.refreshToken, { subject });
|
|
5177
|
+
if (token.accessToken && token.refreshToken)
|
|
5178
|
+
this.pairs.set(keyOf(subject), {
|
|
5179
|
+
accessToken: token.accessToken,
|
|
5180
|
+
refreshToken: token.refreshToken
|
|
5181
|
+
});
|
|
5182
|
+
}
|
|
5183
|
+
for (const code of fixture.codes || []) {
|
|
5184
|
+
const user3 = this.userList.find(
|
|
5185
|
+
(candidate) => candidate.username === code.username
|
|
5186
|
+
);
|
|
5187
|
+
if (!user3) continue;
|
|
5188
|
+
this.codes.set(code.code, {
|
|
5189
|
+
subject: { userId: user3.uid, clientId: code.clientId }
|
|
5190
|
+
});
|
|
5191
|
+
}
|
|
5192
|
+
}
|
|
5193
|
+
async userByName(username) {
|
|
5194
|
+
const user3 = this.userList.find(
|
|
5195
|
+
(candidate) => candidate.username === username
|
|
5196
|
+
);
|
|
5197
|
+
return user3 ? this.recordOf(user3) : void 0;
|
|
5198
|
+
}
|
|
5199
|
+
async userById(uid) {
|
|
5200
|
+
const user3 = this.userList.find((candidate) => candidate.uid === uid);
|
|
5201
|
+
return user3 ? this.recordOf(user3) : void 0;
|
|
5202
|
+
}
|
|
5203
|
+
/** A fixture holds the password in clear, so the check is an equality. */
|
|
5204
|
+
async passwordMatches(user3, password) {
|
|
5205
|
+
return this.passwords.get(user3.uid) === password;
|
|
5206
|
+
}
|
|
5207
|
+
async client(clientId) {
|
|
5208
|
+
return this.clientMap.get(clientId);
|
|
5209
|
+
}
|
|
5210
|
+
async issue(subject, client) {
|
|
5211
|
+
const issuedAt = Date.now();
|
|
5212
|
+
const pair = {
|
|
5213
|
+
accessToken: `access-${randomHex(16)}`,
|
|
5214
|
+
refreshToken: `refresh-${randomHex(16)}`
|
|
5215
|
+
};
|
|
5216
|
+
this.access.set(pair.accessToken, {
|
|
5217
|
+
subject,
|
|
5218
|
+
expiresAt: issuedAt + client.accessTokenExpiration * 1e3
|
|
5219
|
+
});
|
|
5220
|
+
this.refresh.set(pair.refreshToken, {
|
|
5221
|
+
subject,
|
|
5222
|
+
expiresAt: issuedAt + client.refreshTokenExpiration * 1e3
|
|
5223
|
+
});
|
|
5224
|
+
return pair;
|
|
5225
|
+
}
|
|
5226
|
+
/**
|
|
5227
|
+
* A token names its subject only while that subject's CURRENT pair holds it.
|
|
5228
|
+
* The server verifies a token against the pair saved for the user and client,
|
|
5229
|
+
* so a logged-out or rotated token stops working there too; without the same
|
|
5230
|
+
* check here, the browser host would honour a token the server had revoked.
|
|
5231
|
+
*/
|
|
5232
|
+
async readAccess(token) {
|
|
5233
|
+
return this.current(token, this.access, "accessToken");
|
|
5234
|
+
}
|
|
5235
|
+
async readRefresh(token) {
|
|
5236
|
+
return this.current(token, this.refresh, "refreshToken");
|
|
5237
|
+
}
|
|
5238
|
+
current(token, issued, kind) {
|
|
5239
|
+
const entry = issued.get(token);
|
|
5240
|
+
if (!entry) return void 0;
|
|
5241
|
+
const subject = live(entry, Date.now());
|
|
5242
|
+
if (!subject) return void 0;
|
|
5243
|
+
const pair = this.pairs.get(keyOf(subject));
|
|
5244
|
+
return pair && pair[kind] === token ? subject : void 0;
|
|
5245
|
+
}
|
|
5246
|
+
/**
|
|
5247
|
+
* The subject's saved pair, while both of its tokens are still live.
|
|
5248
|
+
*
|
|
5249
|
+
* An exchange hands a saved pair back rather than rotating a second tab's
|
|
5250
|
+
* tokens. That is only an answer if the pair can still be used: a saved pair
|
|
5251
|
+
* whose access token has aged out would sign the caller in and then refuse
|
|
5252
|
+
* every request it makes, so an aged-out pair is reported as absent and the
|
|
5253
|
+
* exchange mints a fresh one. `live()` reads the issue-time expiry, which a
|
|
5254
|
+
* seeded token does not carry - a seeded pair therefore never ages out here.
|
|
5255
|
+
*/
|
|
5256
|
+
async pairFor(subject) {
|
|
5257
|
+
const pair = this.pairs.get(keyOf(subject));
|
|
5258
|
+
if (!pair) return void 0;
|
|
5259
|
+
const now = Date.now();
|
|
5260
|
+
const access = this.access.get(pair.accessToken);
|
|
5261
|
+
const refresh = this.refresh.get(pair.refreshToken);
|
|
5262
|
+
return live(access, now) && live(refresh, now) ? pair : void 0;
|
|
5263
|
+
}
|
|
5264
|
+
async savePair(subject, pair) {
|
|
5265
|
+
this.pairs.set(keyOf(subject), pair);
|
|
5266
|
+
}
|
|
5267
|
+
async deletePair(subject) {
|
|
5268
|
+
this.pairs.delete(keyOf(subject));
|
|
5269
|
+
}
|
|
5270
|
+
async issueCode(subject) {
|
|
5271
|
+
const code = `code-${randomHex(16)}`;
|
|
5272
|
+
this.codes.set(code, {
|
|
5273
|
+
subject,
|
|
5274
|
+
expiresAt: Date.now() + CODE_LIFETIME_SECONDS * 1e3
|
|
5275
|
+
});
|
|
5276
|
+
return code;
|
|
5277
|
+
}
|
|
5278
|
+
async readCode(code) {
|
|
5279
|
+
return live(this.codes.get(code), Date.now());
|
|
5280
|
+
}
|
|
5281
|
+
async claimCode(code) {
|
|
5282
|
+
if (this.claimed.has(code) || !this.codes.has(code)) return false;
|
|
5283
|
+
this.claimed.add(code);
|
|
5284
|
+
return true;
|
|
5285
|
+
}
|
|
5286
|
+
// ---------------------------------------------------------------- records
|
|
5287
|
+
async users() {
|
|
5288
|
+
return this.userList.map((user3) => this.recordOf(user3));
|
|
5289
|
+
}
|
|
5290
|
+
/** A user as the administration routes report one: groups derived, not stored. */
|
|
5291
|
+
recordOf(user3) {
|
|
5292
|
+
return {
|
|
5293
|
+
...user3,
|
|
5294
|
+
groups: [...this.groupList.values()].filter((group) => group.users.includes(user3.uid)).map((group) => group.uid)
|
|
5295
|
+
};
|
|
5296
|
+
}
|
|
5297
|
+
async createUser(input) {
|
|
5298
|
+
const user3 = {
|
|
5299
|
+
uid: `user-${randomHex(6)}`,
|
|
5300
|
+
username: input.username,
|
|
5301
|
+
displayName: input.displayName,
|
|
5302
|
+
isAdmin: input.isAdmin,
|
|
5303
|
+
isActive: input.isActive,
|
|
5304
|
+
needsToUpdatePassword: false,
|
|
5305
|
+
autoExec: input.autoExec,
|
|
5306
|
+
authProvider: input.authProvider
|
|
5307
|
+
};
|
|
5308
|
+
this.userList.push(user3);
|
|
5309
|
+
return this.recordOf(user3);
|
|
5310
|
+
}
|
|
5311
|
+
async updateUser(uid, change) {
|
|
5312
|
+
const user3 = this.userList.find((candidate) => candidate.uid === uid);
|
|
5313
|
+
if (!user3) return void 0;
|
|
5314
|
+
if (change.username !== void 0) user3.username = change.username;
|
|
5315
|
+
if (change.displayName !== void 0) user3.displayName = change.displayName;
|
|
5316
|
+
if (change.isAdmin !== void 0) user3.isAdmin = change.isAdmin;
|
|
5317
|
+
if (change.isActive !== void 0) user3.isActive = change.isActive;
|
|
5318
|
+
if (change.needsToUpdatePassword !== void 0)
|
|
5319
|
+
user3.needsToUpdatePassword = change.needsToUpdatePassword;
|
|
5320
|
+
if (change.autoExec !== void 0) user3.autoExec = change.autoExec;
|
|
5321
|
+
return this.recordOf(user3);
|
|
5322
|
+
}
|
|
5323
|
+
async deleteUser(uid) {
|
|
5324
|
+
const index = this.userList.findIndex((user3) => user3.uid === uid);
|
|
5325
|
+
if (index === -1) return;
|
|
5326
|
+
this.userList.splice(index, 1);
|
|
5327
|
+
this.passwords.delete(uid);
|
|
5328
|
+
for (const group of this.groupList.values())
|
|
5329
|
+
group.users = group.users.filter((member) => member !== uid);
|
|
5330
|
+
for (const [key, permission] of this.permissionList)
|
|
5331
|
+
if (permission.user === uid) this.permissionList.delete(key);
|
|
5332
|
+
for (const key of this.pairs.keys())
|
|
5333
|
+
if (key.startsWith(`${uid}|`)) this.pairs.delete(key);
|
|
5334
|
+
}
|
|
5335
|
+
async setPassword(uid, password) {
|
|
5336
|
+
this.passwords.set(uid, password);
|
|
5337
|
+
}
|
|
5338
|
+
async groups() {
|
|
5339
|
+
return [...this.groupList.values()];
|
|
5340
|
+
}
|
|
5341
|
+
async groupById(uid) {
|
|
5342
|
+
return this.groupList.get(uid);
|
|
5343
|
+
}
|
|
5344
|
+
async groupByName(name) {
|
|
5345
|
+
return [...this.groupList.values()].find((group) => group.name === name);
|
|
5346
|
+
}
|
|
5347
|
+
async createGroup(input) {
|
|
5348
|
+
const group = {
|
|
5349
|
+
uid: `group-${randomHex(6)}`,
|
|
5350
|
+
name: input.name,
|
|
5351
|
+
description: input.description,
|
|
5352
|
+
isActive: input.isActive,
|
|
5353
|
+
users: [],
|
|
5354
|
+
...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
|
|
5355
|
+
};
|
|
5356
|
+
this.groupList.set(group.uid, group);
|
|
5357
|
+
return group;
|
|
5358
|
+
}
|
|
5359
|
+
async deleteGroup(uid) {
|
|
5360
|
+
this.groupList.delete(uid);
|
|
5361
|
+
for (const [key, permission] of this.permissionList)
|
|
5362
|
+
if (permission.group === uid) this.permissionList.delete(key);
|
|
5363
|
+
}
|
|
5364
|
+
async addToGroup(groupUid, userUid) {
|
|
5365
|
+
const group = this.groupList.get(groupUid);
|
|
5366
|
+
if (!group) return void 0;
|
|
5367
|
+
if (!group.users.includes(userUid)) group.users.push(userUid);
|
|
5368
|
+
return group;
|
|
5369
|
+
}
|
|
5370
|
+
async removeFromGroup(groupUid, userUid) {
|
|
5371
|
+
const group = this.groupList.get(groupUid);
|
|
5372
|
+
if (!group) return void 0;
|
|
5373
|
+
group.users = group.users.filter((member) => member !== userUid);
|
|
5374
|
+
return group;
|
|
5375
|
+
}
|
|
5376
|
+
async permissions() {
|
|
5377
|
+
return [...this.permissionList.values()];
|
|
5378
|
+
}
|
|
5379
|
+
async permissionById(uid) {
|
|
5380
|
+
return this.permissionList.get(uid);
|
|
5381
|
+
}
|
|
5382
|
+
async createPermission(input) {
|
|
5383
|
+
const permission = {
|
|
5384
|
+
uid: `rule-${randomHex(6)}`,
|
|
5385
|
+
path: input.path,
|
|
5386
|
+
type: input.type,
|
|
5387
|
+
setting: input.setting,
|
|
5388
|
+
user: input.user,
|
|
5389
|
+
group: input.group
|
|
5390
|
+
};
|
|
5391
|
+
this.permissionList.set(permission.uid, permission);
|
|
5392
|
+
return permission;
|
|
5393
|
+
}
|
|
5394
|
+
async setPermissionSetting(uid, setting) {
|
|
5395
|
+
const permission = this.permissionList.get(uid);
|
|
5396
|
+
if (!permission) return void 0;
|
|
5397
|
+
permission.setting = setting;
|
|
5398
|
+
return permission;
|
|
5399
|
+
}
|
|
5400
|
+
async deletePermission(uid) {
|
|
5401
|
+
this.permissionList.delete(uid);
|
|
5402
|
+
}
|
|
5403
|
+
async clients() {
|
|
5404
|
+
return [...this.clientRecords.values()];
|
|
5405
|
+
}
|
|
5406
|
+
async createClient(input) {
|
|
5407
|
+
this.clientRecords.set(input.clientId, input);
|
|
5408
|
+
this.clientMap.set(input.clientId, {
|
|
5409
|
+
clientId: input.clientId,
|
|
5410
|
+
accessTokenExpiration: input.accessTokenExpiration,
|
|
5411
|
+
refreshTokenExpiration: input.refreshTokenExpiration
|
|
5412
|
+
});
|
|
5413
|
+
return input;
|
|
5414
|
+
}
|
|
5415
|
+
};
|
|
5416
|
+
|
|
5417
|
+
// src/corpus/drive.ts
|
|
5418
|
+
var success2 = { status: "success" };
|
|
5419
|
+
var bytes = (...values) => Uint8Array.from(values);
|
|
5420
|
+
var manyMembers = (count) => Array.from({ length: count }, (_, at) => ({
|
|
5421
|
+
name: `f${at}.txt`,
|
|
5422
|
+
type: "file",
|
|
5423
|
+
code: ""
|
|
5424
|
+
}));
|
|
5425
|
+
var DRIVE_CORPUS = [
|
|
5426
|
+
{
|
|
5427
|
+
id: "create-file",
|
|
5428
|
+
route: "POST /SASjsApi/drive/file",
|
|
5429
|
+
description: "creates a file the drive did not have",
|
|
5430
|
+
request: {
|
|
5431
|
+
query: { _filePath: "/data/users.csv" },
|
|
5432
|
+
file: { name: "users.csv", contents: "id,name\n1,Ann\n" }
|
|
5433
|
+
},
|
|
5434
|
+
expect: { status: 200, body: success2 }
|
|
5435
|
+
},
|
|
5436
|
+
{
|
|
5437
|
+
id: "create-file-at-form-path",
|
|
5438
|
+
route: "POST /SASjsApi/drive/file",
|
|
5439
|
+
description: "takes the destination from the form field when the query has none",
|
|
5440
|
+
request: {
|
|
5441
|
+
file: { name: "x.csv", contents: "x" },
|
|
5442
|
+
body: { filePath: "/data/from-form.csv" }
|
|
5443
|
+
},
|
|
5444
|
+
expect: { status: 200, body: success2 }
|
|
5445
|
+
},
|
|
5446
|
+
{
|
|
5447
|
+
id: "create-file-over-existing",
|
|
5448
|
+
route: "POST /SASjsApi/drive/file",
|
|
5449
|
+
description: "refuses a create over a file that exists, as 409",
|
|
5450
|
+
seed: { "/data/exists.csv": "a" },
|
|
5451
|
+
request: {
|
|
5452
|
+
query: { _filePath: "/data/exists.csv" },
|
|
5453
|
+
file: { name: "x", contents: "b" }
|
|
5454
|
+
},
|
|
5455
|
+
expect: { status: 409, error: "File already exists." }
|
|
5456
|
+
},
|
|
5457
|
+
{
|
|
5458
|
+
id: "create-file-blocked-extension",
|
|
5459
|
+
route: "POST /SASjsApi/drive/file",
|
|
5460
|
+
description: "refuses a refused extension before touching the drive",
|
|
5461
|
+
request: {
|
|
5462
|
+
query: { _filePath: "/data/run.sh" },
|
|
5463
|
+
file: { name: "run.sh", contents: "x" }
|
|
5464
|
+
},
|
|
5465
|
+
expect: { status: 400, error: "Invalid file extension" }
|
|
5466
|
+
},
|
|
5467
|
+
{
|
|
5468
|
+
id: "create-file-outside-drive",
|
|
5469
|
+
route: "POST /SASjsApi/drive/file",
|
|
5470
|
+
description: "refuses a path that climbs out of the drive",
|
|
5471
|
+
request: {
|
|
5472
|
+
query: { _filePath: "/../escape.csv" },
|
|
5473
|
+
file: { name: "x", contents: "x" }
|
|
5474
|
+
},
|
|
5475
|
+
expect: { status: 400, error: "Can't put file outside drive." }
|
|
5476
|
+
},
|
|
5477
|
+
{
|
|
5478
|
+
id: "create-file-without-payload",
|
|
5479
|
+
route: "POST /SASjsApi/drive/file",
|
|
5480
|
+
description: "answers for a missing file with the server wording",
|
|
5481
|
+
request: { query: { _filePath: "/data/x.csv" } },
|
|
5482
|
+
expect: { status: 400, error: '"file" is not present.' }
|
|
5483
|
+
},
|
|
5484
|
+
{
|
|
5485
|
+
id: "create-file-without-destination",
|
|
5486
|
+
route: "POST /SASjsApi/drive/file",
|
|
5487
|
+
description: "answers for a missing destination with the validation wording",
|
|
5488
|
+
request: { file: { name: "x", contents: "x" } },
|
|
5489
|
+
expect: { status: 400, error: '"_filePath" is required' }
|
|
5490
|
+
},
|
|
5491
|
+
{
|
|
5492
|
+
id: "replace-file",
|
|
5493
|
+
route: "PATCH /SASjsApi/drive/file",
|
|
5494
|
+
description: "replaces the contents of a file that exists",
|
|
5495
|
+
seed: { "/data/keep.csv": "old" },
|
|
5496
|
+
request: {
|
|
5497
|
+
query: { _filePath: "/data/keep.csv" },
|
|
5498
|
+
file: { name: "keep.csv", contents: "new" }
|
|
5499
|
+
},
|
|
5500
|
+
expect: { status: 200, body: success2 }
|
|
5501
|
+
},
|
|
5502
|
+
{
|
|
5503
|
+
id: "replace-file-missing",
|
|
5504
|
+
route: "PATCH /SASjsApi/drive/file",
|
|
5505
|
+
description: "refuses a replace of a file that is not there, as 404",
|
|
5506
|
+
request: {
|
|
5507
|
+
query: { _filePath: "/data/missing.csv" },
|
|
5508
|
+
file: { name: "x", contents: "x" }
|
|
5509
|
+
},
|
|
5510
|
+
expect: { status: 404, error: `File doesn't exist.` }
|
|
5511
|
+
},
|
|
5512
|
+
{
|
|
5513
|
+
id: "replace-file-outside-drive",
|
|
5514
|
+
route: "PATCH /SASjsApi/drive/file",
|
|
5515
|
+
description: "refuses a replace of a path that climbs out of the drive",
|
|
5516
|
+
request: {
|
|
5517
|
+
query: { _filePath: "/../escape.csv" },
|
|
5518
|
+
file: { name: "x", contents: "x" }
|
|
5519
|
+
},
|
|
5520
|
+
expect: { status: 400, error: "Can't modify file outside drive." }
|
|
5521
|
+
},
|
|
5522
|
+
{
|
|
5523
|
+
id: "read-file",
|
|
5524
|
+
route: "GET /SASjsApi/drive/file",
|
|
5525
|
+
description: "answers with the file contents",
|
|
5526
|
+
seed: { "/data/keep.csv": "a,b\n1,2\n" },
|
|
5527
|
+
request: { query: { _filePath: "/data/keep.csv" } },
|
|
5528
|
+
expect: { status: 200, contents: "a,b\n1,2\n" }
|
|
5529
|
+
},
|
|
5530
|
+
{
|
|
5531
|
+
id: "read-file-missing",
|
|
5532
|
+
route: "GET /SASjsApi/drive/file",
|
|
5533
|
+
description: "refuses a read of a file that is not there",
|
|
5534
|
+
request: { query: { _filePath: "/data/missing.csv" } },
|
|
5535
|
+
expect: { status: 404, error: `File doesn't exist.` }
|
|
5536
|
+
},
|
|
5537
|
+
{
|
|
5538
|
+
id: "read-file-outside-drive",
|
|
5539
|
+
route: "GET /SASjsApi/drive/file",
|
|
5540
|
+
description: "refuses a read of a path that climbs out of the drive",
|
|
5541
|
+
request: { query: { _filePath: "/../escape.csv" } },
|
|
5542
|
+
expect: { status: 400, error: "Can't get file outside drive." }
|
|
5543
|
+
},
|
|
5544
|
+
{
|
|
5545
|
+
id: "delete-file",
|
|
5546
|
+
route: "DELETE /SASjsApi/drive/file",
|
|
5547
|
+
description: "deletes a file that exists",
|
|
5548
|
+
seed: { "/data/keep.csv": "a" },
|
|
5549
|
+
request: { query: { _filePath: "/data/keep.csv" } },
|
|
5550
|
+
expect: { status: 200, body: success2 }
|
|
5551
|
+
},
|
|
5552
|
+
{
|
|
5553
|
+
id: "delete-file-missing",
|
|
5554
|
+
route: "DELETE /SASjsApi/drive/file",
|
|
5555
|
+
description: "refuses a delete of a file that is not there",
|
|
5556
|
+
request: { query: { _filePath: "/data/missing.csv" } },
|
|
5557
|
+
expect: { status: 404, error: `File doesn't exist.` }
|
|
5558
|
+
},
|
|
5559
|
+
{
|
|
5560
|
+
id: "delete-file-outside-drive",
|
|
5561
|
+
route: "DELETE /SASjsApi/drive/file",
|
|
5562
|
+
description: "refuses a delete of a path that climbs out of the drive",
|
|
5563
|
+
request: { query: { _filePath: "/../escape.csv" } },
|
|
5564
|
+
expect: { status: 400, error: "Can't delete file outside drive." }
|
|
5565
|
+
},
|
|
5566
|
+
{
|
|
5567
|
+
id: "list-folder",
|
|
5568
|
+
route: "GET /SASjsApi/drive/folder",
|
|
5569
|
+
description: "lists the files and folders of a folder",
|
|
5570
|
+
seed: { "/data/a.csv": "a", "/data/reports/b.csv": "b" },
|
|
5571
|
+
request: { query: { _folderPath: "/data" } },
|
|
5572
|
+
expect: { status: 200, body: { files: ["a.csv"], folders: ["reports"] } }
|
|
5573
|
+
},
|
|
5574
|
+
{
|
|
5575
|
+
id: "list-folder-missing",
|
|
5576
|
+
route: "GET /SASjsApi/drive/folder",
|
|
5577
|
+
description: "refuses a listing of a folder that is not there",
|
|
5578
|
+
request: { query: { _folderPath: "/nope" } },
|
|
5579
|
+
expect: { status: 404, error: `Folder doesn't exist.` }
|
|
5580
|
+
},
|
|
5581
|
+
{
|
|
5582
|
+
id: "list-folder-outside-drive",
|
|
5583
|
+
route: "GET /SASjsApi/drive/folder",
|
|
5584
|
+
description: "refuses a listing of a path that climbs out of the drive",
|
|
5585
|
+
request: { query: { _folderPath: "/../escape" } },
|
|
5586
|
+
expect: { status: 400, error: "Can't get folder outside drive." }
|
|
5587
|
+
},
|
|
5588
|
+
{
|
|
5589
|
+
id: "delete-folder-without-path",
|
|
5590
|
+
route: "DELETE /SASjsApi/drive/folder",
|
|
5591
|
+
description: "answers for a missing folder path, because the table marks it required",
|
|
5592
|
+
request: {},
|
|
5593
|
+
expect: { status: 400, error: '"_folderPath" is required' }
|
|
5594
|
+
},
|
|
5595
|
+
{
|
|
5596
|
+
id: "create-folder-without-path",
|
|
5597
|
+
route: "POST /SASjsApi/drive/folder",
|
|
5598
|
+
description: "answers for a missing folder path in the body",
|
|
5599
|
+
request: { body: {} },
|
|
5600
|
+
expect: { status: 400, error: '"folderPath" is required' }
|
|
5601
|
+
},
|
|
5602
|
+
{
|
|
5603
|
+
id: "create-folder",
|
|
5604
|
+
route: "POST /SASjsApi/drive/folder",
|
|
5605
|
+
description: "creates a folder",
|
|
5606
|
+
request: { body: { folderPath: "/data/reports" } },
|
|
5607
|
+
expect: { status: 200, body: success2 }
|
|
5608
|
+
},
|
|
5609
|
+
{
|
|
5610
|
+
id: "create-folder-existing",
|
|
5611
|
+
route: "POST /SASjsApi/drive/folder",
|
|
5612
|
+
description: "refuses a folder that already exists, as 409",
|
|
5613
|
+
seed: { "/data/reports/a.csv": "a" },
|
|
5614
|
+
request: { body: { folderPath: "/data/reports" } },
|
|
5615
|
+
expect: { status: 409, error: "Folder already exists." }
|
|
5616
|
+
},
|
|
5617
|
+
{
|
|
5618
|
+
id: "delete-folder",
|
|
5619
|
+
route: "DELETE /SASjsApi/drive/folder",
|
|
5620
|
+
description: "deletes a folder with everything under it",
|
|
5621
|
+
seed: { "/data/reports/a.csv": "a", "/data/reports/nested/b.csv": "b" },
|
|
5622
|
+
request: { query: { _folderPath: "/data/reports" } },
|
|
5623
|
+
expect: { status: 200, body: success2 }
|
|
5624
|
+
},
|
|
5625
|
+
{
|
|
5626
|
+
id: "delete-folder-missing",
|
|
5627
|
+
route: "DELETE /SASjsApi/drive/folder",
|
|
5628
|
+
description: "refuses a delete of a folder that is not there",
|
|
5629
|
+
request: { query: { _folderPath: "/nope" } },
|
|
5630
|
+
expect: { status: 404, error: `Folder doesn't exist.` }
|
|
5631
|
+
},
|
|
5632
|
+
{
|
|
5633
|
+
id: "rename-file",
|
|
5634
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5635
|
+
description: "moves a file to a new path",
|
|
5636
|
+
seed: { "/data/old.csv": "r" },
|
|
5637
|
+
request: { body: { oldPath: "/data/old.csv", newPath: "/data/new.csv" } },
|
|
5638
|
+
expect: { status: 200, body: success2 }
|
|
5639
|
+
},
|
|
5640
|
+
{
|
|
5641
|
+
id: "rename-onto-existing",
|
|
5642
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5643
|
+
description: "refuses a move onto something that exists",
|
|
5644
|
+
seed: { "/data/a.csv": "a", "/data/b.csv": "b" },
|
|
5645
|
+
request: { body: { oldPath: "/data/a.csv", newPath: "/data/b.csv" } },
|
|
5646
|
+
expect: { status: 409, error: "File with new name already exists." }
|
|
5647
|
+
},
|
|
5648
|
+
{
|
|
5649
|
+
id: "rename-missing",
|
|
5650
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5651
|
+
description: "refuses a move of something that is not there",
|
|
5652
|
+
request: { body: { oldPath: "/data/nope.csv", newPath: "/data/x.csv" } },
|
|
5653
|
+
expect: { status: 404, error: "No file/folder found for provided path." }
|
|
5654
|
+
},
|
|
5655
|
+
{
|
|
5656
|
+
id: "rename-file-to-blocked-extension",
|
|
5657
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5658
|
+
description: "refuses a rename that would produce a name the file routes refuse",
|
|
5659
|
+
seed: { "/data/report.csv": "a,b" },
|
|
5660
|
+
request: {
|
|
5661
|
+
body: { oldPath: "/data/report.csv", newPath: "/data/report.sh" }
|
|
5662
|
+
},
|
|
5663
|
+
expect: { status: 400, error: "Invalid file extension" }
|
|
5664
|
+
},
|
|
5665
|
+
{
|
|
5666
|
+
id: "rename-folder-to-dotted-name",
|
|
5667
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5668
|
+
description: "renames a folder whose new name carries a blocked suffix",
|
|
5669
|
+
seed: { "/data/reports/a.csv": "a" },
|
|
5670
|
+
request: {
|
|
5671
|
+
body: { oldPath: "/data/reports", newPath: "/data/reports.sh" }
|
|
5672
|
+
},
|
|
5673
|
+
expect: { status: 200, body: { status: "success" } }
|
|
5674
|
+
},
|
|
5675
|
+
{
|
|
5676
|
+
id: "rename-folder-into-itself",
|
|
5677
|
+
route: "POST /SASjsApi/drive/rename",
|
|
5678
|
+
description: "refuses a folder moved inside itself, which the server loses at the filesystem",
|
|
5679
|
+
seed: { "/data/reports/a.csv": "a" },
|
|
5680
|
+
request: {
|
|
5681
|
+
body: { oldPath: "/data/reports", newPath: "/data/reports/nested" }
|
|
5682
|
+
},
|
|
5683
|
+
expect: {
|
|
5684
|
+
status: 400,
|
|
5685
|
+
error: "New path can't be inside the folder being moved."
|
|
5686
|
+
}
|
|
5687
|
+
},
|
|
5688
|
+
{
|
|
5689
|
+
id: "tree",
|
|
5690
|
+
route: "GET /SASjsApi/drive/filetree",
|
|
5691
|
+
description: "answers with the drive tree",
|
|
5692
|
+
seed: { "/data/a.csv": "a" },
|
|
5693
|
+
request: { query: { _folderPath: "/data" } },
|
|
5694
|
+
expect: {
|
|
5695
|
+
status: 200,
|
|
5696
|
+
// Partial, because a file's `created` and `modified` are the host's
|
|
5697
|
+
// clock rather than the contract: the shape is asserted, the timestamps
|
|
5698
|
+
// are whatever the host that ran the case says they are.
|
|
5699
|
+
partial: {
|
|
5700
|
+
status: "success",
|
|
5701
|
+
tree: {
|
|
5702
|
+
name: "data",
|
|
5703
|
+
relativePath: "/data",
|
|
5704
|
+
isFolder: true,
|
|
5705
|
+
children: [
|
|
5706
|
+
{
|
|
5707
|
+
name: "a.csv",
|
|
5708
|
+
relativePath: "/data/a.csv",
|
|
5709
|
+
isFolder: false,
|
|
5710
|
+
children: []
|
|
5711
|
+
}
|
|
5712
|
+
]
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
},
|
|
5717
|
+
{
|
|
5718
|
+
id: "deploy-tree",
|
|
5719
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5720
|
+
description: "writes a whole tree under the appLoc it names",
|
|
5721
|
+
request: {
|
|
5722
|
+
body: {
|
|
5723
|
+
appLoc: "/Public/apps/demo",
|
|
5724
|
+
fileTree: {
|
|
5725
|
+
members: [
|
|
5726
|
+
{
|
|
5727
|
+
name: "services",
|
|
5728
|
+
type: "folder",
|
|
5729
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
5730
|
+
},
|
|
5731
|
+
{ name: "index.html", type: "file", code: "PGgxPkhlbGxvPC9oMT4=" }
|
|
5732
|
+
]
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
},
|
|
5736
|
+
expect: {
|
|
5737
|
+
status: 200,
|
|
5738
|
+
body: {
|
|
5739
|
+
status: "success",
|
|
5740
|
+
message: "Files deployed successfully to @sasjs/server."
|
|
5741
|
+
}
|
|
5742
|
+
}
|
|
5743
|
+
},
|
|
5744
|
+
{
|
|
5745
|
+
id: "deploy-refused-by-entry-count",
|
|
5746
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5747
|
+
description: "refuses a tree over the entry cap, naming the figure and the cap",
|
|
5748
|
+
request: {
|
|
5749
|
+
body: {
|
|
5750
|
+
appLoc: "/Public/apps/many",
|
|
5751
|
+
fileTree: { members: manyMembers(10001) }
|
|
5752
|
+
}
|
|
5753
|
+
},
|
|
5754
|
+
expect: {
|
|
5755
|
+
status: 413,
|
|
5756
|
+
body: {
|
|
5757
|
+
status: "failure",
|
|
5758
|
+
message: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
|
|
5759
|
+
},
|
|
5760
|
+
error: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
|
|
5761
|
+
}
|
|
5762
|
+
},
|
|
5763
|
+
{
|
|
5764
|
+
id: "deploy-refused-by-name",
|
|
5765
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5766
|
+
description: "refuses a member name that would escape the deployment root",
|
|
5767
|
+
request: {
|
|
5768
|
+
body: {
|
|
5769
|
+
appLoc: "/Public/apps/hostile",
|
|
5770
|
+
fileTree: {
|
|
5771
|
+
members: [{ name: "../escape", type: "service", code: "%put hi;" }]
|
|
5772
|
+
}
|
|
5773
|
+
}
|
|
5774
|
+
},
|
|
5775
|
+
expect: {
|
|
5776
|
+
status: 400,
|
|
5777
|
+
body: {
|
|
5778
|
+
status: "failure",
|
|
5779
|
+
message: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
|
|
5780
|
+
},
|
|
5781
|
+
error: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
|
|
5782
|
+
}
|
|
5783
|
+
},
|
|
5784
|
+
{
|
|
5785
|
+
id: "deploy-refused-by-shape",
|
|
5786
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5787
|
+
description: "refuses a fileTree that is not a tree, in the routes own envelope",
|
|
5788
|
+
request: { body: { appLoc: "/Public/apps/bad", fileTree: { members: 1 } } },
|
|
5789
|
+
expect: {
|
|
5790
|
+
status: 400,
|
|
5791
|
+
body: {
|
|
5792
|
+
status: "failure",
|
|
5793
|
+
message: "Provided not supported data format."
|
|
5794
|
+
},
|
|
5795
|
+
error: "Provided not supported data format."
|
|
5796
|
+
}
|
|
5797
|
+
},
|
|
5798
|
+
{
|
|
5799
|
+
id: "deploy-refused-by-store",
|
|
5800
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5801
|
+
description: "answers the routes 500 when the drive refuses the write",
|
|
5802
|
+
unwritable: true,
|
|
5803
|
+
request: {
|
|
5804
|
+
body: {
|
|
5805
|
+
appLoc: "/Public/apps/demo",
|
|
5806
|
+
fileTree: {
|
|
5807
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
5808
|
+
}
|
|
5809
|
+
}
|
|
5810
|
+
},
|
|
5811
|
+
expect: {
|
|
5812
|
+
status: 500,
|
|
5813
|
+
body: { status: "failure", message: "Deployment failed!" },
|
|
5814
|
+
error: "Deployment failed!"
|
|
5815
|
+
}
|
|
5816
|
+
},
|
|
5817
|
+
{
|
|
5818
|
+
id: "deploy-refused-outside-drive",
|
|
5819
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
5820
|
+
description: "refuses an appLoc that resolves outside the drive",
|
|
5821
|
+
request: {
|
|
5822
|
+
body: { appLoc: "/../outside", fileTree: { members: [] } }
|
|
5823
|
+
},
|
|
5824
|
+
expect: {
|
|
5825
|
+
status: 400,
|
|
5826
|
+
body: { status: "failure", message: "appLoc cannot be outside drive." },
|
|
5827
|
+
error: "appLoc cannot be outside drive."
|
|
5828
|
+
}
|
|
5829
|
+
},
|
|
5830
|
+
{
|
|
5831
|
+
id: "bytes-round-trip",
|
|
5832
|
+
route: "GET /SASjsApi/drive/file",
|
|
5833
|
+
description: "keeps a byte file as bytes",
|
|
5834
|
+
seed: { "/data/pack.zip": bytes(80, 75, 3, 4) },
|
|
5835
|
+
request: { query: { _filePath: "/data/pack.zip" } },
|
|
5836
|
+
expect: { status: 200, contents: bytes(80, 75, 3, 4) }
|
|
5837
|
+
}
|
|
5838
|
+
];
|
|
5839
|
+
|
|
5840
|
+
// src/corpus/identity.ts
|
|
5841
|
+
var SIGNED_IN = {
|
|
5842
|
+
...DEFAULT_IDENTITY,
|
|
5843
|
+
tokens: [
|
|
5844
|
+
{
|
|
5845
|
+
username: "sasjsuser",
|
|
5846
|
+
clientId: "web_app",
|
|
5847
|
+
accessToken: "seed-access",
|
|
5848
|
+
refreshToken: "seed-refresh"
|
|
5849
|
+
},
|
|
5850
|
+
{
|
|
5851
|
+
username: "sasjsadmin",
|
|
5852
|
+
clientId: "removed_client",
|
|
5853
|
+
accessToken: "seed-access-orphan",
|
|
5854
|
+
refreshToken: "seed-refresh-orphan"
|
|
5855
|
+
}
|
|
5856
|
+
],
|
|
5857
|
+
codes: [
|
|
5858
|
+
{ code: "seed-code", username: "sasjsuser", clientId: "web_app" },
|
|
5859
|
+
{
|
|
5860
|
+
code: "seed-orphan-code",
|
|
5861
|
+
username: "sasjsuser",
|
|
5862
|
+
clientId: "removed_client"
|
|
5863
|
+
},
|
|
5864
|
+
// the same shape with a pair already issued: the exchange must still refuse,
|
|
5865
|
+
// rather than handing back tokens that belong to a client that is gone
|
|
5866
|
+
{
|
|
5867
|
+
code: "seed-orphan-pair-code",
|
|
5868
|
+
username: "sasjsadmin",
|
|
5869
|
+
clientId: "removed_client"
|
|
5870
|
+
}
|
|
5871
|
+
]
|
|
5872
|
+
};
|
|
5873
|
+
var DEACTIVATED = {
|
|
5874
|
+
...SIGNED_IN,
|
|
5875
|
+
users: SIGNED_IN.users.map(
|
|
5876
|
+
(user3) => user3.username === "sasjsuser" ? { ...user3, isActive: false } : user3
|
|
5877
|
+
)
|
|
5878
|
+
};
|
|
5879
|
+
var user2 = {
|
|
5880
|
+
username: "sasjsuser",
|
|
5881
|
+
displayName: "Demo User",
|
|
5882
|
+
isAdmin: false,
|
|
5883
|
+
needsToUpdatePassword: false
|
|
5884
|
+
};
|
|
5885
|
+
var IDENTITY_CORPUS = [
|
|
5886
|
+
{
|
|
5887
|
+
id: "login",
|
|
5888
|
+
route: "POST /SASLogon/login",
|
|
5889
|
+
description: "signs a seeded user in",
|
|
5890
|
+
request: { body: { username: "sasjsadmin", password: "Orion123" } },
|
|
5891
|
+
expect: {
|
|
5485
5892
|
status: 200,
|
|
5486
5893
|
partial: {
|
|
5487
5894
|
loggedIn: true,
|
|
5488
5895
|
user: {
|
|
5489
|
-
username: "
|
|
5896
|
+
username: "sasjsadmin",
|
|
5490
5897
|
displayName: "Demo Admin",
|
|
5491
5898
|
isAdmin: true,
|
|
5492
5899
|
needsToUpdatePassword: false
|
|
@@ -5498,7 +5905,7 @@ var SASjsApi = (() => {
|
|
|
5498
5905
|
id: "login-missing-username",
|
|
5499
5906
|
route: "POST /SASLogon/login",
|
|
5500
5907
|
description: "refuses a sign-in with no username as 400, naming the field",
|
|
5501
|
-
request: { body: { password: "
|
|
5908
|
+
request: { body: { password: "Orion123" } },
|
|
5502
5909
|
expect: { status: 400, error: '"username" is required' }
|
|
5503
5910
|
},
|
|
5504
5911
|
{
|
|
@@ -5506,21 +5913,21 @@ var SASjsApi = (() => {
|
|
|
5506
5913
|
route: "POST /SASLogon/login",
|
|
5507
5914
|
description: "refuses a deactivated account, naming it",
|
|
5508
5915
|
identity: DEACTIVATED,
|
|
5509
|
-
request: { body: { username: "
|
|
5916
|
+
request: { body: { username: "sasjsuser", password: "Orion123" } },
|
|
5510
5917
|
expect: { status: 401, error: "This account is not active." }
|
|
5511
5918
|
},
|
|
5512
5919
|
{
|
|
5513
5920
|
id: "login-wrong-password",
|
|
5514
5921
|
route: "POST /SASLogon/login",
|
|
5515
5922
|
description: "refuses a wrong password as 401, naming it",
|
|
5516
|
-
request: { body: { username: "
|
|
5923
|
+
request: { body: { username: "sasjsadmin", password: "wrong123" } },
|
|
5517
5924
|
expect: { status: 401, error: "Invalid Password." }
|
|
5518
5925
|
},
|
|
5519
5926
|
{
|
|
5520
5927
|
id: "login-unknown-user",
|
|
5521
5928
|
route: "POST /SASLogon/login",
|
|
5522
5929
|
description: "refuses an unknown username as 401, naming it",
|
|
5523
|
-
request: { body: { username: "nobody", password: "
|
|
5930
|
+
request: { body: { username: "nobody", password: "Orion123" } },
|
|
5524
5931
|
expect: { status: 401, error: "Username is not found." }
|
|
5525
5932
|
},
|
|
5526
5933
|
{
|
|
@@ -6528,13 +6935,13 @@ var SASjsApi = (() => {
|
|
|
6528
6935
|
// src/corpus/records.ts
|
|
6529
6936
|
var SIGNED_IN_TOKENS = [
|
|
6530
6937
|
{
|
|
6531
|
-
username: "
|
|
6938
|
+
username: "sasjsadmin",
|
|
6532
6939
|
clientId: "web_app",
|
|
6533
6940
|
accessToken: "admin-access",
|
|
6534
6941
|
refreshToken: "admin-refresh"
|
|
6535
6942
|
},
|
|
6536
6943
|
{
|
|
6537
|
-
username: "
|
|
6944
|
+
username: "sasjsuser",
|
|
6538
6945
|
clientId: "web_app",
|
|
6539
6946
|
accessToken: "user-access",
|
|
6540
6947
|
refreshToken: "user-refresh"
|
|
@@ -6604,13 +7011,13 @@ var SASjsApi = (() => {
|
|
|
6604
7011
|
body: [
|
|
6605
7012
|
{
|
|
6606
7013
|
uid: ADMIN_UID,
|
|
6607
|
-
username: "
|
|
7014
|
+
username: "sasjsadmin",
|
|
6608
7015
|
displayName: "Demo Admin",
|
|
6609
7016
|
isAdmin: true
|
|
6610
7017
|
},
|
|
6611
7018
|
{
|
|
6612
7019
|
uid: RESTRICTED_UID,
|
|
6613
|
-
username: "
|
|
7020
|
+
username: "sasjsuser",
|
|
6614
7021
|
displayName: "Demo User",
|
|
6615
7022
|
isAdmin: false
|
|
6616
7023
|
}
|
|
@@ -6627,7 +7034,7 @@ var SASjsApi = (() => {
|
|
|
6627
7034
|
status: 200,
|
|
6628
7035
|
partial: {
|
|
6629
7036
|
uid: RESTRICTED_UID,
|
|
6630
|
-
username: "
|
|
7037
|
+
username: "sasjsuser",
|
|
6631
7038
|
isActive: true,
|
|
6632
7039
|
isAdmin: false,
|
|
6633
7040
|
autoExec: ""
|
|
@@ -6655,10 +7062,10 @@ var SASjsApi = (() => {
|
|
|
6655
7062
|
route: "GET /SASjsApi/user/by/username/{username}",
|
|
6656
7063
|
description: "finds an account by username",
|
|
6657
7064
|
identity: ADMIN_SIGNED_IN,
|
|
6658
|
-
request: { token: ADMIN3, params: { username: "
|
|
7065
|
+
request: { token: ADMIN3, params: { username: "sasjsuser" } },
|
|
6659
7066
|
expect: {
|
|
6660
7067
|
status: 200,
|
|
6661
|
-
partial: { uid: RESTRICTED_UID, username: "
|
|
7068
|
+
partial: { uid: RESTRICTED_UID, username: "sasjsuser", isAdmin: false }
|
|
6662
7069
|
}
|
|
6663
7070
|
},
|
|
6664
7071
|
{
|
|
@@ -6666,7 +7073,7 @@ var SASjsApi = (() => {
|
|
|
6666
7073
|
route: "GET /SASjsApi/user/by/username/{username}",
|
|
6667
7074
|
description: "refuses the by-username read with no caller",
|
|
6668
7075
|
identity: ADMIN_SIGNED_IN,
|
|
6669
|
-
request: { params: { username: "
|
|
7076
|
+
request: { params: { username: "sasjsuser" } },
|
|
6670
7077
|
expect: { status: 401, error: "Unauthorized" }
|
|
6671
7078
|
},
|
|
6672
7079
|
{
|
|
@@ -6732,7 +7139,11 @@ var SASjsApi = (() => {
|
|
|
6732
7139
|
identity: ADMIN_SIGNED_IN,
|
|
6733
7140
|
request: {
|
|
6734
7141
|
token: ADMIN3,
|
|
6735
|
-
body: {
|
|
7142
|
+
body: {
|
|
7143
|
+
username: "sasjsuser",
|
|
7144
|
+
displayName: "Another",
|
|
7145
|
+
password: "newpass"
|
|
7146
|
+
}
|
|
6736
7147
|
},
|
|
6737
7148
|
expect: { status: 409, error: "Username already exists." }
|
|
6738
7149
|
},
|
|
@@ -6746,8 +7157,8 @@ var SASjsApi = (() => {
|
|
|
6746
7157
|
params: { uid: RESTRICTED_UID },
|
|
6747
7158
|
body: {
|
|
6748
7159
|
displayName: "Renamed User",
|
|
6749
|
-
username: "
|
|
6750
|
-
password: "
|
|
7160
|
+
username: "sasjsuser",
|
|
7161
|
+
password: "Orion123"
|
|
6751
7162
|
}
|
|
6752
7163
|
},
|
|
6753
7164
|
expect: {
|
|
@@ -6763,7 +7174,11 @@ var SASjsApi = (() => {
|
|
|
6763
7174
|
request: {
|
|
6764
7175
|
token: RESTRICTED2,
|
|
6765
7176
|
params: { uid: ADMIN_UID },
|
|
6766
|
-
body: {
|
|
7177
|
+
body: {
|
|
7178
|
+
displayName: "Hijacked",
|
|
7179
|
+
username: "sasjsadmin",
|
|
7180
|
+
password: "Orion123"
|
|
7181
|
+
}
|
|
6767
7182
|
},
|
|
6768
7183
|
expect: { status: 401, error: "Admin account required" }
|
|
6769
7184
|
},
|
|
@@ -6806,7 +7221,11 @@ var SASjsApi = (() => {
|
|
|
6806
7221
|
request: {
|
|
6807
7222
|
token: ADMIN3,
|
|
6808
7223
|
params: { uid: RESTRICTED_UID },
|
|
6809
|
-
body: {
|
|
7224
|
+
body: {
|
|
7225
|
+
username: "sasjsadmin",
|
|
7226
|
+
displayName: "Demo User",
|
|
7227
|
+
password: "Orion123"
|
|
7228
|
+
}
|
|
6810
7229
|
},
|
|
6811
7230
|
expect: { status: 409, error: "Username already exists." }
|
|
6812
7231
|
},
|
|
@@ -6817,15 +7236,15 @@ var SASjsApi = (() => {
|
|
|
6817
7236
|
identity: ADMIN_SIGNED_IN,
|
|
6818
7237
|
request: {
|
|
6819
7238
|
token: ADMIN3,
|
|
6820
|
-
params: { username: "
|
|
7239
|
+
params: { username: "sasjsuser" },
|
|
6821
7240
|
body: {
|
|
6822
7241
|
isActive: false,
|
|
6823
|
-
username: "
|
|
7242
|
+
username: "sasjsuser",
|
|
6824
7243
|
displayName: "Demo User",
|
|
6825
|
-
password: "
|
|
7244
|
+
password: "Orion123"
|
|
6826
7245
|
}
|
|
6827
7246
|
},
|
|
6828
|
-
expect: { status: 200, partial: { username: "
|
|
7247
|
+
expect: { status: 200, partial: { username: "sasjsuser", isActive: false } }
|
|
6829
7248
|
},
|
|
6830
7249
|
{
|
|
6831
7250
|
id: "update-user-by-username-not-admin",
|
|
@@ -6834,8 +7253,12 @@ var SASjsApi = (() => {
|
|
|
6834
7253
|
identity: ADMIN_SIGNED_IN,
|
|
6835
7254
|
request: {
|
|
6836
7255
|
token: RESTRICTED2,
|
|
6837
|
-
params: { username: "
|
|
6838
|
-
body: {
|
|
7256
|
+
params: { username: "sasjsadmin" },
|
|
7257
|
+
body: {
|
|
7258
|
+
displayName: "Hijacked",
|
|
7259
|
+
username: "sasjsadmin",
|
|
7260
|
+
password: "Orion123"
|
|
7261
|
+
}
|
|
6839
7262
|
},
|
|
6840
7263
|
expect: { status: 401, error: "Admin account required" }
|
|
6841
7264
|
},
|
|
@@ -6873,8 +7296,12 @@ var SASjsApi = (() => {
|
|
|
6873
7296
|
identity: ADMIN_SIGNED_IN,
|
|
6874
7297
|
request: {
|
|
6875
7298
|
token: ADMIN3,
|
|
6876
|
-
params: { username: "
|
|
6877
|
-
body: {
|
|
7299
|
+
params: { username: "sasjsuser" },
|
|
7300
|
+
body: {
|
|
7301
|
+
username: "sasjsadmin",
|
|
7302
|
+
displayName: "Demo User",
|
|
7303
|
+
password: "Orion123"
|
|
7304
|
+
}
|
|
6878
7305
|
},
|
|
6879
7306
|
expect: { status: 409, error: "Username already exists." }
|
|
6880
7307
|
},
|
|
@@ -6909,7 +7336,7 @@ var SASjsApi = (() => {
|
|
|
6909
7336
|
identity: ADMIN_SIGNED_IN,
|
|
6910
7337
|
request: {
|
|
6911
7338
|
token: ADMIN3,
|
|
6912
|
-
params: { username: "
|
|
7339
|
+
params: { username: "sasjsuser" },
|
|
6913
7340
|
body: {}
|
|
6914
7341
|
},
|
|
6915
7342
|
expect: { status: 200, body: "Account Deleted!" }
|
|
@@ -6921,7 +7348,7 @@ var SASjsApi = (() => {
|
|
|
6921
7348
|
identity: ADMIN_SIGNED_IN,
|
|
6922
7349
|
request: {
|
|
6923
7350
|
token: RESTRICTED2,
|
|
6924
|
-
params: { username: "
|
|
7351
|
+
params: { username: "sasjsuser" },
|
|
6925
7352
|
body: { password: "wrong123" }
|
|
6926
7353
|
},
|
|
6927
7354
|
expect: { status: 401, error: "Invalid password." }
|
|
@@ -6972,7 +7399,7 @@ var SASjsApi = (() => {
|
|
|
6972
7399
|
users: [
|
|
6973
7400
|
{
|
|
6974
7401
|
uid: ADMIN_UID,
|
|
6975
|
-
username: "
|
|
7402
|
+
username: "sasjsadmin",
|
|
6976
7403
|
displayName: "Demo Admin",
|
|
6977
7404
|
isAdmin: true
|
|
6978
7405
|
}
|
|
@@ -7359,765 +7786,395 @@ var SASjsApi = (() => {
|
|
|
7359
7786
|
}
|
|
7360
7787
|
},
|
|
7361
7788
|
{
|
|
7362
|
-
id: "list-permissions-unauthenticated",
|
|
7363
|
-
route: "GET /SASjsApi/permission",
|
|
7364
|
-
description: "refuses the list with no caller",
|
|
7365
|
-
identity: ADMIN_SIGNED_IN,
|
|
7366
|
-
request: {},
|
|
7367
|
-
expect: { status: 401, error: "Unauthorized" }
|
|
7368
|
-
},
|
|
7369
|
-
{
|
|
7370
|
-
id: "create-permission-user",
|
|
7371
|
-
route: "POST /SASjsApi/permission",
|
|
7372
|
-
description: "creates a rule for a user",
|
|
7373
|
-
identity: ADMIN_SIGNED_IN,
|
|
7374
|
-
request: {
|
|
7375
|
-
token: ADMIN3,
|
|
7376
|
-
body: {
|
|
7377
|
-
path: "/SASjsApi/drive/folder",
|
|
7378
|
-
type: "Route",
|
|
7379
|
-
setting: "Grant",
|
|
7380
|
-
principalType: "user",
|
|
7381
|
-
principalId: RESTRICTED_UID
|
|
7382
|
-
}
|
|
7383
|
-
},
|
|
7384
|
-
expect: {
|
|
7385
|
-
status: 200,
|
|
7386
|
-
partial: { path: "/SASjsApi/drive/folder", setting: "Grant" }
|
|
7387
|
-
}
|
|
7388
|
-
},
|
|
7389
|
-
{
|
|
7390
|
-
id: "create-permission-group",
|
|
7391
|
-
route: "POST /SASjsApi/permission",
|
|
7392
|
-
description: "creates a rule for a group",
|
|
7393
|
-
identity: ADMIN_SIGNED_IN,
|
|
7394
|
-
request: {
|
|
7395
|
-
token: ADMIN3,
|
|
7396
|
-
body: {
|
|
7397
|
-
path: "/SASjsApi/drive/rename",
|
|
7398
|
-
type: "Route",
|
|
7399
|
-
setting: "Grant",
|
|
7400
|
-
principalType: "group",
|
|
7401
|
-
principalId: "group-data-controller"
|
|
7402
|
-
}
|
|
7403
|
-
},
|
|
7404
|
-
expect: {
|
|
7405
|
-
status: 200,
|
|
7406
|
-
partial: {
|
|
7407
|
-
path: "/SASjsApi/drive/rename",
|
|
7408
|
-
setting: "Grant",
|
|
7409
|
-
group: "group-data-controller"
|
|
7410
|
-
}
|
|
7411
|
-
}
|
|
7412
|
-
},
|
|
7413
|
-
{
|
|
7414
|
-
id: "create-permission-invalid-principal-type",
|
|
7415
|
-
route: "POST /SASjsApi/permission",
|
|
7416
|
-
description: "refuses a principal type that is neither a user nor a group",
|
|
7417
|
-
identity: ADMIN_SIGNED_IN,
|
|
7418
|
-
request: {
|
|
7419
|
-
token: ADMIN3,
|
|
7420
|
-
body: {
|
|
7421
|
-
path: "/SASjsApi/drive/deploy",
|
|
7422
|
-
type: "Route",
|
|
7423
|
-
setting: "Grant",
|
|
7424
|
-
principalType: "role",
|
|
7425
|
-
principalId: "anything"
|
|
7426
|
-
}
|
|
7427
|
-
},
|
|
7428
|
-
expect: {
|
|
7429
|
-
status: 400,
|
|
7430
|
-
error: "Invalid principal type. Valid types are user or group."
|
|
7431
|
-
}
|
|
7432
|
-
},
|
|
7433
|
-
{
|
|
7434
|
-
id: "create-permission-admin-principal",
|
|
7435
|
-
route: "POST /SASjsApi/permission",
|
|
7436
|
-
description: "refuses a rule assigned to an administrator",
|
|
7437
|
-
identity: ADMIN_SIGNED_IN,
|
|
7438
|
-
request: {
|
|
7439
|
-
token: ADMIN3,
|
|
7440
|
-
body: {
|
|
7441
|
-
path: "/SASjsApi/drive/folder",
|
|
7442
|
-
type: "Route",
|
|
7443
|
-
setting: "Grant",
|
|
7444
|
-
principalType: "user",
|
|
7445
|
-
principalId: ADMIN_UID
|
|
7446
|
-
}
|
|
7447
|
-
},
|
|
7448
|
-
expect: {
|
|
7449
|
-
status: 400,
|
|
7450
|
-
error: "Can not add permission for admin user."
|
|
7451
|
-
}
|
|
7452
|
-
},
|
|
7453
|
-
{
|
|
7454
|
-
id: "create-permission-not-admin",
|
|
7455
|
-
route: "POST /SASjsApi/permission",
|
|
7456
|
-
description: "refuses a creation by a non-administrator",
|
|
7457
|
-
identity: ADMIN_SIGNED_IN,
|
|
7458
|
-
request: {
|
|
7459
|
-
token: RESTRICTED2,
|
|
7460
|
-
body: {
|
|
7461
|
-
path: "/SASjsApi/drive/folder",
|
|
7462
|
-
type: "Route",
|
|
7463
|
-
setting: "Grant",
|
|
7464
|
-
principalType: "user",
|
|
7465
|
-
principalId: RESTRICTED_UID
|
|
7466
|
-
}
|
|
7467
|
-
},
|
|
7468
|
-
expect: { status: 401, error: "Admin account required" }
|
|
7469
|
-
},
|
|
7470
|
-
{
|
|
7471
|
-
id: "create-permission-missing-principal",
|
|
7472
|
-
route: "POST /SASjsApi/permission",
|
|
7473
|
-
description: "answers 404 for a principal that does not exist",
|
|
7474
|
-
identity: ADMIN_SIGNED_IN,
|
|
7475
|
-
request: {
|
|
7476
|
-
token: ADMIN3,
|
|
7477
|
-
body: {
|
|
7478
|
-
path: "/SASjsApi/drive/rename",
|
|
7479
|
-
type: "Route",
|
|
7480
|
-
setting: "Grant",
|
|
7481
|
-
principalType: "group",
|
|
7482
|
-
principalId: "group-none"
|
|
7483
|
-
}
|
|
7484
|
-
},
|
|
7485
|
-
expect: { status: 404, error: "Group not found." }
|
|
7486
|
-
},
|
|
7487
|
-
{
|
|
7488
|
-
id: "create-permission-duplicate-group",
|
|
7489
|
-
route: "POST /SASjsApi/permission",
|
|
7490
|
-
description: "refuses a group rule that already exists",
|
|
7491
|
-
identity: ADMIN_SIGNED_IN,
|
|
7492
|
-
request: {
|
|
7493
|
-
token: ADMIN3,
|
|
7494
|
-
body: {
|
|
7495
|
-
path: "/SASjsApi/drive/file",
|
|
7496
|
-
type: "Route",
|
|
7497
|
-
setting: "Grant",
|
|
7498
|
-
principalType: "group",
|
|
7499
|
-
principalId: "group-data-controller"
|
|
7500
|
-
}
|
|
7501
|
-
},
|
|
7502
|
-
expect: {
|
|
7503
|
-
status: 409,
|
|
7504
|
-
error: "Permission already exists with provided Path, Type and Group."
|
|
7505
|
-
}
|
|
7506
|
-
},
|
|
7507
|
-
{
|
|
7508
|
-
id: "create-permission-duplicate",
|
|
7509
|
-
route: "POST /SASjsApi/permission",
|
|
7510
|
-
description: "refuses a rule that already exists",
|
|
7511
|
-
identity: ADMIN_SIGNED_IN,
|
|
7512
|
-
request: {
|
|
7513
|
-
token: ADMIN3,
|
|
7514
|
-
body: {
|
|
7515
|
-
path: "/SASjsApi/code/execute",
|
|
7516
|
-
type: "Route",
|
|
7517
|
-
setting: "Deny",
|
|
7518
|
-
principalType: "user",
|
|
7519
|
-
principalId: RESTRICTED_UID
|
|
7520
|
-
}
|
|
7521
|
-
},
|
|
7522
|
-
expect: {
|
|
7523
|
-
status: 409,
|
|
7524
|
-
error: "Permission already exists with provided Path, Type and User."
|
|
7525
|
-
}
|
|
7526
|
-
},
|
|
7527
|
-
{
|
|
7528
|
-
id: "update-permission",
|
|
7529
|
-
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7530
|
-
description: "flips a rule from Deny to Grant",
|
|
7531
|
-
identity: ADMIN_SIGNED_IN,
|
|
7532
|
-
request: {
|
|
7533
|
-
token: ADMIN3,
|
|
7534
|
-
params: { uid: "rule-code" },
|
|
7535
|
-
body: { setting: "Grant" }
|
|
7536
|
-
},
|
|
7537
|
-
expect: { status: 200, partial: { uid: "rule-code", setting: "Grant" } }
|
|
7538
|
-
},
|
|
7539
|
-
{
|
|
7540
|
-
id: "update-permission-not-admin",
|
|
7541
|
-
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7542
|
-
description: "refuses a change by a non-administrator",
|
|
7543
|
-
identity: ADMIN_SIGNED_IN,
|
|
7544
|
-
request: {
|
|
7545
|
-
token: RESTRICTED2,
|
|
7546
|
-
params: { uid: "rule-code" },
|
|
7547
|
-
body: { setting: "Grant" }
|
|
7548
|
-
},
|
|
7549
|
-
expect: { status: 401, error: "Admin account required" }
|
|
7550
|
-
},
|
|
7551
|
-
{
|
|
7552
|
-
id: "update-permission-missing",
|
|
7553
|
-
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7554
|
-
description: "answers 404 for a rule that does not exist",
|
|
7555
|
-
identity: ADMIN_SIGNED_IN,
|
|
7556
|
-
request: {
|
|
7557
|
-
token: ADMIN3,
|
|
7558
|
-
params: { uid: "rule-none" },
|
|
7559
|
-
body: { setting: "Grant" }
|
|
7560
|
-
},
|
|
7561
|
-
expect: { status: 404, error: "Permission not found." }
|
|
7562
|
-
},
|
|
7563
|
-
{
|
|
7564
|
-
id: "delete-permission",
|
|
7565
|
-
route: "DELETE /SASjsApi/permission/{uid}",
|
|
7566
|
-
description: "deletes a rule",
|
|
7567
|
-
identity: ADMIN_SIGNED_IN,
|
|
7568
|
-
request: { token: ADMIN3, params: { uid: "rule-code" } },
|
|
7569
|
-
expect: { status: 200, body: "Permission Deleted!" }
|
|
7570
|
-
},
|
|
7571
|
-
{
|
|
7572
|
-
id: "delete-permission-not-admin",
|
|
7573
|
-
route: "DELETE /SASjsApi/permission/{uid}",
|
|
7574
|
-
description: "refuses a deletion by a non-administrator",
|
|
7575
|
-
identity: ADMIN_SIGNED_IN,
|
|
7576
|
-
request: { token: RESTRICTED2, params: { uid: "rule-code" } },
|
|
7577
|
-
expect: { status: 401, error: "Admin account required" }
|
|
7578
|
-
},
|
|
7579
|
-
{
|
|
7580
|
-
id: "delete-permission-missing",
|
|
7581
|
-
route: "DELETE /SASjsApi/permission/{uid}",
|
|
7582
|
-
description: "answers 404 for a rule that does not exist",
|
|
7583
|
-
identity: ADMIN_SIGNED_IN,
|
|
7584
|
-
request: { token: ADMIN3, params: { uid: "rule-none" } },
|
|
7585
|
-
expect: { status: 404, error: "Permission not found." }
|
|
7586
|
-
},
|
|
7587
|
-
// --------------------------------------------------------------- clients
|
|
7588
|
-
{
|
|
7589
|
-
id: "list-clients",
|
|
7590
|
-
route: "GET /SASjsApi/client",
|
|
7591
|
-
description: "lists the registered clients",
|
|
7592
|
-
identity: ADMIN_SIGNED_IN,
|
|
7593
|
-
request: { token: ADMIN3 },
|
|
7594
|
-
expect: {
|
|
7595
|
-
status: 200,
|
|
7596
|
-
body: [
|
|
7597
|
-
{
|
|
7598
|
-
clientId: "web_app",
|
|
7599
|
-
clientSecret: "web_app",
|
|
7600
|
-
accessTokenExpiration: 86400,
|
|
7601
|
-
refreshTokenExpiration: 2592e3
|
|
7602
|
-
},
|
|
7603
|
-
{
|
|
7604
|
-
clientId: "sasjs",
|
|
7605
|
-
clientSecret: "sasjs",
|
|
7606
|
-
accessTokenExpiration: 3600,
|
|
7607
|
-
refreshTokenExpiration: 86400
|
|
7608
|
-
}
|
|
7609
|
-
]
|
|
7610
|
-
}
|
|
7611
|
-
},
|
|
7612
|
-
{
|
|
7613
|
-
id: "list-clients-not-admin",
|
|
7614
|
-
route: "GET /SASjsApi/client",
|
|
7615
|
-
description: "refuses the list to a caller who is not an administrator",
|
|
7789
|
+
id: "list-permissions-unauthenticated",
|
|
7790
|
+
route: "GET /SASjsApi/permission",
|
|
7791
|
+
description: "refuses the list with no caller",
|
|
7616
7792
|
identity: ADMIN_SIGNED_IN,
|
|
7617
|
-
request: {
|
|
7618
|
-
expect: { status: 401, error: "
|
|
7793
|
+
request: {},
|
|
7794
|
+
expect: { status: 401, error: "Unauthorized" }
|
|
7619
7795
|
},
|
|
7620
7796
|
{
|
|
7621
|
-
id: "create-
|
|
7622
|
-
route: "POST /SASjsApi/
|
|
7623
|
-
description: "
|
|
7797
|
+
id: "create-permission-user",
|
|
7798
|
+
route: "POST /SASjsApi/permission",
|
|
7799
|
+
description: "creates a rule for a user",
|
|
7624
7800
|
identity: ADMIN_SIGNED_IN,
|
|
7625
7801
|
request: {
|
|
7626
7802
|
token: ADMIN3,
|
|
7627
7803
|
body: {
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7804
|
+
path: "/SASjsApi/drive/folder",
|
|
7805
|
+
type: "Route",
|
|
7806
|
+
setting: "Grant",
|
|
7807
|
+
principalType: "user",
|
|
7808
|
+
principalId: RESTRICTED_UID
|
|
7632
7809
|
}
|
|
7633
7810
|
},
|
|
7634
7811
|
expect: {
|
|
7635
7812
|
status: 200,
|
|
7636
|
-
|
|
7637
|
-
clientId: "new_app",
|
|
7638
|
-
clientSecret: "new_secret",
|
|
7639
|
-
accessTokenExpiration: 3600,
|
|
7640
|
-
refreshTokenExpiration: 86400
|
|
7641
|
-
}
|
|
7813
|
+
partial: { path: "/SASjsApi/drive/folder", setting: "Grant" }
|
|
7642
7814
|
}
|
|
7643
7815
|
},
|
|
7644
7816
|
{
|
|
7645
|
-
id: "create-
|
|
7646
|
-
route: "POST /SASjsApi/
|
|
7647
|
-
description: "
|
|
7817
|
+
id: "create-permission-group",
|
|
7818
|
+
route: "POST /SASjsApi/permission",
|
|
7819
|
+
description: "creates a rule for a group",
|
|
7648
7820
|
identity: ADMIN_SIGNED_IN,
|
|
7649
7821
|
request: {
|
|
7650
7822
|
token: ADMIN3,
|
|
7651
|
-
body: {
|
|
7823
|
+
body: {
|
|
7824
|
+
path: "/SASjsApi/drive/rename",
|
|
7825
|
+
type: "Route",
|
|
7826
|
+
setting: "Grant",
|
|
7827
|
+
principalType: "group",
|
|
7828
|
+
principalId: "group-data-controller"
|
|
7829
|
+
}
|
|
7652
7830
|
},
|
|
7653
7831
|
expect: {
|
|
7654
7832
|
status: 200,
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
refreshTokenExpiration: 2592e3
|
|
7833
|
+
partial: {
|
|
7834
|
+
path: "/SASjsApi/drive/rename",
|
|
7835
|
+
setting: "Grant",
|
|
7836
|
+
group: "group-data-controller"
|
|
7660
7837
|
}
|
|
7661
7838
|
}
|
|
7662
7839
|
},
|
|
7663
7840
|
{
|
|
7664
|
-
id: "create-
|
|
7665
|
-
route: "POST /SASjsApi/
|
|
7666
|
-
description: "refuses a
|
|
7841
|
+
id: "create-permission-invalid-principal-type",
|
|
7842
|
+
route: "POST /SASjsApi/permission",
|
|
7843
|
+
description: "refuses a principal type that is neither a user nor a group",
|
|
7667
7844
|
identity: ADMIN_SIGNED_IN,
|
|
7668
7845
|
request: {
|
|
7669
|
-
token:
|
|
7846
|
+
token: ADMIN3,
|
|
7670
7847
|
body: {
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7848
|
+
path: "/SASjsApi/drive/deploy",
|
|
7849
|
+
type: "Route",
|
|
7850
|
+
setting: "Grant",
|
|
7851
|
+
principalType: "role",
|
|
7852
|
+
principalId: "anything"
|
|
7675
7853
|
}
|
|
7676
7854
|
},
|
|
7677
|
-
expect: {
|
|
7855
|
+
expect: {
|
|
7856
|
+
status: 400,
|
|
7857
|
+
error: "Invalid principal type. Valid types are user or group."
|
|
7858
|
+
}
|
|
7678
7859
|
},
|
|
7679
7860
|
{
|
|
7680
|
-
id: "create-
|
|
7681
|
-
route: "POST /SASjsApi/
|
|
7682
|
-
description: "refuses a
|
|
7861
|
+
id: "create-permission-admin-principal",
|
|
7862
|
+
route: "POST /SASjsApi/permission",
|
|
7863
|
+
description: "refuses a rule assigned to an administrator",
|
|
7683
7864
|
identity: ADMIN_SIGNED_IN,
|
|
7684
7865
|
request: {
|
|
7685
7866
|
token: ADMIN3,
|
|
7686
7867
|
body: {
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7868
|
+
path: "/SASjsApi/drive/folder",
|
|
7869
|
+
type: "Route",
|
|
7870
|
+
setting: "Grant",
|
|
7871
|
+
principalType: "user",
|
|
7872
|
+
principalId: ADMIN_UID
|
|
7691
7873
|
}
|
|
7692
7874
|
},
|
|
7693
|
-
expect: {
|
|
7875
|
+
expect: {
|
|
7876
|
+
status: 400,
|
|
7877
|
+
error: "Can not add permission for admin user."
|
|
7878
|
+
}
|
|
7694
7879
|
},
|
|
7695
|
-
// -------------------------------------------------------------- passwords
|
|
7696
7880
|
{
|
|
7697
|
-
id: "
|
|
7698
|
-
route: "
|
|
7699
|
-
description: "
|
|
7881
|
+
id: "create-permission-not-admin",
|
|
7882
|
+
route: "POST /SASjsApi/permission",
|
|
7883
|
+
description: "refuses a creation by a non-administrator",
|
|
7700
7884
|
identity: ADMIN_SIGNED_IN,
|
|
7701
7885
|
request: {
|
|
7702
7886
|
token: RESTRICTED2,
|
|
7703
|
-
body: {
|
|
7887
|
+
body: {
|
|
7888
|
+
path: "/SASjsApi/drive/folder",
|
|
7889
|
+
type: "Route",
|
|
7890
|
+
setting: "Grant",
|
|
7891
|
+
principalType: "user",
|
|
7892
|
+
principalId: RESTRICTED_UID
|
|
7893
|
+
}
|
|
7704
7894
|
},
|
|
7705
|
-
expect: { status:
|
|
7706
|
-
},
|
|
7707
|
-
{
|
|
7708
|
-
id: "update-password-missing-field",
|
|
7709
|
-
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
7710
|
-
description: "refuses a body without the current password",
|
|
7711
|
-
identity: ADMIN_SIGNED_IN,
|
|
7712
|
-
request: { token: RESTRICTED2, body: { newPassword: "changed123" } },
|
|
7713
|
-
expect: { status: 400, error: '"currentPassword" is required' }
|
|
7895
|
+
expect: { status: 401, error: "Admin account required" }
|
|
7714
7896
|
},
|
|
7715
7897
|
{
|
|
7716
|
-
id: "
|
|
7717
|
-
route: "
|
|
7718
|
-
description: "
|
|
7898
|
+
id: "create-permission-missing-principal",
|
|
7899
|
+
route: "POST /SASjsApi/permission",
|
|
7900
|
+
description: "answers 404 for a principal that does not exist",
|
|
7719
7901
|
identity: ADMIN_SIGNED_IN,
|
|
7720
7902
|
request: {
|
|
7721
|
-
|
|
7903
|
+
token: ADMIN3,
|
|
7904
|
+
body: {
|
|
7905
|
+
path: "/SASjsApi/drive/rename",
|
|
7906
|
+
type: "Route",
|
|
7907
|
+
setting: "Grant",
|
|
7908
|
+
principalType: "group",
|
|
7909
|
+
principalId: "group-none"
|
|
7910
|
+
}
|
|
7722
7911
|
},
|
|
7723
|
-
expect: { status:
|
|
7912
|
+
expect: { status: 404, error: "Group not found." }
|
|
7724
7913
|
},
|
|
7725
7914
|
{
|
|
7726
|
-
id: "
|
|
7727
|
-
route: "
|
|
7728
|
-
description: "refuses a
|
|
7915
|
+
id: "create-permission-duplicate-group",
|
|
7916
|
+
route: "POST /SASjsApi/permission",
|
|
7917
|
+
description: "refuses a group rule that already exists",
|
|
7729
7918
|
identity: ADMIN_SIGNED_IN,
|
|
7730
7919
|
request: {
|
|
7731
|
-
token:
|
|
7732
|
-
body: {
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
description: "refuses a password change on a provider-managed account",
|
|
7740
|
-
identity: PROVIDER_MANAGED,
|
|
7741
|
-
request: {
|
|
7742
|
-
token: "dir-access",
|
|
7743
|
-
body: { currentPassword: "dir123", newPassword: "changed123" }
|
|
7920
|
+
token: ADMIN3,
|
|
7921
|
+
body: {
|
|
7922
|
+
path: "/SASjsApi/drive/file",
|
|
7923
|
+
type: "Route",
|
|
7924
|
+
setting: "Grant",
|
|
7925
|
+
principalType: "group",
|
|
7926
|
+
principalId: "group-data-controller"
|
|
7927
|
+
}
|
|
7744
7928
|
},
|
|
7745
7929
|
expect: {
|
|
7746
|
-
status:
|
|
7747
|
-
error: "
|
|
7930
|
+
status: 409,
|
|
7931
|
+
error: "Permission already exists with provided Path, Type and Group."
|
|
7748
7932
|
}
|
|
7749
|
-
}
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7933
|
+
},
|
|
7934
|
+
{
|
|
7935
|
+
id: "create-permission-duplicate",
|
|
7936
|
+
route: "POST /SASjsApi/permission",
|
|
7937
|
+
description: "refuses a rule that already exists",
|
|
7938
|
+
identity: ADMIN_SIGNED_IN,
|
|
7939
|
+
request: {
|
|
7940
|
+
token: ADMIN3,
|
|
7941
|
+
body: {
|
|
7942
|
+
path: "/SASjsApi/code/execute",
|
|
7943
|
+
type: "Route",
|
|
7944
|
+
setting: "Deny",
|
|
7945
|
+
principalType: "user",
|
|
7946
|
+
principalId: RESTRICTED_UID
|
|
7947
|
+
}
|
|
7948
|
+
},
|
|
7949
|
+
expect: {
|
|
7950
|
+
status: 409,
|
|
7951
|
+
error: "Permission already exists with provided Path, Type and User."
|
|
7952
|
+
}
|
|
7953
|
+
},
|
|
7954
|
+
{
|
|
7955
|
+
id: "update-permission",
|
|
7956
|
+
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7957
|
+
description: "flips a rule from Deny to Grant",
|
|
7958
|
+
identity: ADMIN_SIGNED_IN,
|
|
7959
|
+
request: {
|
|
7960
|
+
token: ADMIN3,
|
|
7961
|
+
params: { uid: "rule-code" },
|
|
7962
|
+
body: { setting: "Grant" }
|
|
7963
|
+
},
|
|
7964
|
+
expect: { status: 200, partial: { uid: "rule-code", setting: "Grant" } }
|
|
7965
|
+
},
|
|
7966
|
+
{
|
|
7967
|
+
id: "update-permission-not-admin",
|
|
7968
|
+
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7969
|
+
description: "refuses a change by a non-administrator",
|
|
7970
|
+
identity: ADMIN_SIGNED_IN,
|
|
7971
|
+
request: {
|
|
7972
|
+
token: RESTRICTED2,
|
|
7973
|
+
params: { uid: "rule-code" },
|
|
7974
|
+
body: { setting: "Grant" }
|
|
7975
|
+
},
|
|
7976
|
+
expect: { status: 401, error: "Admin account required" }
|
|
7977
|
+
},
|
|
7978
|
+
{
|
|
7979
|
+
id: "update-permission-missing",
|
|
7980
|
+
route: "PATCH /SASjsApi/permission/{uid}",
|
|
7981
|
+
description: "answers 404 for a rule that does not exist",
|
|
7982
|
+
identity: ADMIN_SIGNED_IN,
|
|
7983
|
+
request: {
|
|
7984
|
+
token: ADMIN3,
|
|
7985
|
+
params: { uid: "rule-none" },
|
|
7986
|
+
body: { setting: "Grant" }
|
|
7987
|
+
},
|
|
7988
|
+
expect: { status: 404, error: "Permission not found." }
|
|
7989
|
+
},
|
|
7990
|
+
{
|
|
7991
|
+
id: "delete-permission",
|
|
7992
|
+
route: "DELETE /SASjsApi/permission/{uid}",
|
|
7993
|
+
description: "deletes a rule",
|
|
7994
|
+
identity: ADMIN_SIGNED_IN,
|
|
7995
|
+
request: { token: ADMIN3, params: { uid: "rule-code" } },
|
|
7996
|
+
expect: { status: 200, body: "Permission Deleted!" }
|
|
7997
|
+
},
|
|
7998
|
+
{
|
|
7999
|
+
id: "delete-permission-not-admin",
|
|
8000
|
+
route: "DELETE /SASjsApi/permission/{uid}",
|
|
8001
|
+
description: "refuses a deletion by a non-administrator",
|
|
8002
|
+
identity: ADMIN_SIGNED_IN,
|
|
8003
|
+
request: { token: RESTRICTED2, params: { uid: "rule-code" } },
|
|
8004
|
+
expect: { status: 401, error: "Admin account required" }
|
|
8005
|
+
},
|
|
8006
|
+
{
|
|
8007
|
+
id: "delete-permission-missing",
|
|
8008
|
+
route: "DELETE /SASjsApi/permission/{uid}",
|
|
8009
|
+
description: "answers 404 for a rule that does not exist",
|
|
8010
|
+
identity: ADMIN_SIGNED_IN,
|
|
8011
|
+
request: { token: ADMIN3, params: { uid: "rule-none" } },
|
|
8012
|
+
expect: { status: 404, error: "Permission not found." }
|
|
8013
|
+
},
|
|
8014
|
+
// --------------------------------------------------------------- clients
|
|
8015
|
+
{
|
|
8016
|
+
id: "list-clients",
|
|
8017
|
+
route: "GET /SASjsApi/client",
|
|
8018
|
+
description: "lists the registered clients",
|
|
8019
|
+
identity: ADMIN_SIGNED_IN,
|
|
8020
|
+
request: { token: ADMIN3 },
|
|
8021
|
+
expect: {
|
|
8022
|
+
status: 200,
|
|
8023
|
+
body: [
|
|
8024
|
+
{
|
|
8025
|
+
clientId: "web_app",
|
|
8026
|
+
clientSecret: "web_app",
|
|
8027
|
+
accessTokenExpiration: 86400,
|
|
8028
|
+
refreshTokenExpiration: 2592e3
|
|
8029
|
+
},
|
|
8030
|
+
{
|
|
8031
|
+
clientId: "sasjs",
|
|
8032
|
+
clientSecret: "sasjs",
|
|
8033
|
+
accessTokenExpiration: 3600,
|
|
8034
|
+
refreshTokenExpiration: 86400
|
|
8035
|
+
}
|
|
8036
|
+
]
|
|
7840
8037
|
}
|
|
7841
|
-
};
|
|
7842
|
-
};
|
|
7843
|
-
|
|
7844
|
-
// src/admin/service.ts
|
|
7845
|
-
var DEFAULT_LOG_LINES = 200;
|
|
7846
|
-
var MAX_LOG_LINES = 5e3;
|
|
7847
|
-
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7848
|
-
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
7849
|
-
var isString = (value) => typeof value === "string";
|
|
7850
|
-
var requireString = (holder, key, where) => {
|
|
7851
|
-
if (!isString(holder[key]))
|
|
7852
|
-
throw new Error(
|
|
7853
|
-
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`
|
|
7854
|
-
);
|
|
7855
|
-
};
|
|
7856
|
-
var requireNumber = (holder, key, where) => {
|
|
7857
|
-
if (!isNumber(holder[key]))
|
|
7858
|
-
throw new Error(
|
|
7859
|
-
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
|
|
7860
|
-
);
|
|
7861
|
-
};
|
|
7862
|
-
var requireObject = (holder, key, where) => {
|
|
7863
|
-
const value = holder[key];
|
|
7864
|
-
if (!isObject(value))
|
|
7865
|
-
throw new Error(
|
|
7866
|
-
`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
|
|
7867
|
-
);
|
|
7868
|
-
return value;
|
|
7869
|
-
};
|
|
7870
|
-
var normaliseDiagnostics = (report) => {
|
|
7871
|
-
if (!isObject(report))
|
|
7872
|
-
throw new Error("The diagnostics report is not an object.");
|
|
7873
|
-
const build = requireObject(
|
|
7874
|
-
report,
|
|
7875
|
-
"build",
|
|
7876
|
-
"diagnostics"
|
|
7877
|
-
);
|
|
7878
|
-
requireString(build, "version", "diagnostics build");
|
|
7879
|
-
requireString(build, "gitHash", "diagnostics build");
|
|
7880
|
-
if (!(build.buildDate === null || isString(build.buildDate)))
|
|
7881
|
-
throw new Error(
|
|
7882
|
-
`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
|
|
7883
|
-
);
|
|
7884
|
-
const server = requireObject(
|
|
7885
|
-
report,
|
|
7886
|
-
"server",
|
|
7887
|
-
"diagnostics"
|
|
7888
|
-
);
|
|
7889
|
-
requireString(server, "mode", "diagnostics server");
|
|
7890
|
-
requireString(server, "startedAt", "diagnostics server");
|
|
7891
|
-
requireString(server, "nodeVersion", "diagnostics server");
|
|
7892
|
-
requireString(server, "platform", "diagnostics server");
|
|
7893
|
-
requireString(server, "arch", "diagnostics server");
|
|
7894
|
-
requireString(server, "cpuModel", "diagnostics server");
|
|
7895
|
-
requireString(server, "sasjsRoot", "diagnostics server");
|
|
7896
|
-
requireNumber(server, "uptimeSeconds", "diagnostics server");
|
|
7897
|
-
requireNumber(server, "pid", "diagnostics server");
|
|
7898
|
-
requireNumber(server, "cpuCount", "diagnostics server");
|
|
7899
|
-
if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
|
|
7900
|
-
throw new Error(
|
|
7901
|
-
"The diagnostics server report states `loadAverage` as something other than an array of numbers."
|
|
7902
|
-
);
|
|
7903
|
-
if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
|
|
7904
|
-
throw new Error(
|
|
7905
|
-
"The diagnostics server report states `runTimes` as something other than an array of strings."
|
|
7906
|
-
);
|
|
7907
|
-
const memory = requireObject(
|
|
7908
|
-
report,
|
|
7909
|
-
"memory",
|
|
7910
|
-
"diagnostics"
|
|
7911
|
-
);
|
|
7912
|
-
for (const key of [
|
|
7913
|
-
"rssBytes",
|
|
7914
|
-
"heapTotalBytes",
|
|
7915
|
-
"heapUsedBytes",
|
|
7916
|
-
"externalBytes",
|
|
7917
|
-
"systemTotalBytes",
|
|
7918
|
-
"systemFreeBytes"
|
|
7919
|
-
])
|
|
7920
|
-
requireNumber(memory, key, "diagnostics memory");
|
|
7921
|
-
const filesystem = report.filesystem;
|
|
7922
|
-
if (filesystem !== null) {
|
|
7923
|
-
if (!isObject(filesystem))
|
|
7924
|
-
throw new Error(
|
|
7925
|
-
`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
|
|
7926
|
-
);
|
|
7927
|
-
requireString(
|
|
7928
|
-
filesystem,
|
|
7929
|
-
"path",
|
|
7930
|
-
"diagnostics filesystem"
|
|
7931
|
-
);
|
|
7932
|
-
for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
|
|
7933
|
-
requireNumber(
|
|
7934
|
-
filesystem,
|
|
7935
|
-
key,
|
|
7936
|
-
"diagnostics filesystem"
|
|
7937
|
-
);
|
|
7938
|
-
}
|
|
7939
|
-
if (!Array.isArray(report.folders))
|
|
7940
|
-
throw new Error(
|
|
7941
|
-
"The diagnostics report states `folders` as something other than an array."
|
|
7942
|
-
);
|
|
7943
|
-
for (const folder of report.folders) {
|
|
7944
|
-
if (!isObject(folder))
|
|
7945
|
-
throw new Error(
|
|
7946
|
-
"The diagnostics report carries a folder that is not an object."
|
|
7947
|
-
);
|
|
7948
|
-
const entry = folder;
|
|
7949
|
-
requireString(entry, "label", "diagnostics folder");
|
|
7950
|
-
requireString(entry, "path", "diagnostics folder");
|
|
7951
|
-
requireNumber(entry, "bytes", "diagnostics folder");
|
|
7952
|
-
requireNumber(entry, "files", "diagnostics folder");
|
|
7953
|
-
if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
|
|
7954
|
-
throw new Error(
|
|
7955
|
-
"The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
|
|
7956
|
-
);
|
|
7957
|
-
}
|
|
7958
|
-
const logs = requireObject(
|
|
7959
|
-
report,
|
|
7960
|
-
"logs",
|
|
7961
|
-
"diagnostics"
|
|
7962
|
-
);
|
|
7963
|
-
requireString(logs, "folder", "diagnostics logs");
|
|
7964
|
-
requireNumber(logs, "fileCount", "diagnostics logs");
|
|
7965
|
-
requireNumber(logs, "totalBytes", "diagnostics logs");
|
|
7966
|
-
for (const key of ["newestFile", "newestModified"])
|
|
7967
|
-
if (!(logs[key] === null || isString(logs[key])))
|
|
7968
|
-
throw new Error(
|
|
7969
|
-
`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
|
|
7970
|
-
);
|
|
7971
|
-
return report;
|
|
7972
|
-
};
|
|
7973
|
-
var normaliseLogFiles = (files) => {
|
|
7974
|
-
if (!Array.isArray(files))
|
|
7975
|
-
throw new Error("The log report is not an array of files.");
|
|
7976
|
-
return files.map((file) => {
|
|
7977
|
-
if (!isObject(file))
|
|
7978
|
-
throw new Error("The log report carries an entry that is not an object.");
|
|
7979
|
-
const entry = file;
|
|
7980
|
-
requireString(entry, "name", "logs");
|
|
7981
|
-
requireString(entry, "modified", "logs");
|
|
7982
|
-
requireNumber(entry, "sizeBytes", "logs");
|
|
7983
|
-
return file;
|
|
7984
|
-
});
|
|
7985
|
-
};
|
|
7986
|
-
var checkLogFileName = (fileName) => {
|
|
7987
|
-
if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
|
|
7988
|
-
throw new ApiError(400, "Invalid log file name.");
|
|
7989
|
-
return fileName;
|
|
7990
|
-
};
|
|
7991
|
-
var logLines = (lines) => {
|
|
7992
|
-
if (lines === void 0 || lines === null || lines === "")
|
|
7993
|
-
return DEFAULT_LOG_LINES;
|
|
7994
|
-
const wanted = Number(lines);
|
|
7995
|
-
if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
|
|
7996
|
-
return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
|
|
7997
|
-
};
|
|
7998
|
-
var normaliseLogTail = (tail) => {
|
|
7999
|
-
if (!isObject(tail)) throw new Error("The log tail report is not an object.");
|
|
8000
|
-
const entry = tail;
|
|
8001
|
-
requireString(entry, "fileName", "log tail");
|
|
8002
|
-
requireString(entry, "content", "log tail");
|
|
8003
|
-
requireNumber(entry, "lines", "log tail");
|
|
8004
|
-
requireNumber(entry, "bytesRead", "log tail");
|
|
8005
|
-
if (typeof entry.truncated !== "boolean")
|
|
8006
|
-
throw new Error(
|
|
8007
|
-
"The log tail report states `truncated` as something other than a boolean."
|
|
8008
|
-
);
|
|
8009
|
-
return tail;
|
|
8010
|
-
};
|
|
8011
|
-
var createAdminService = (reports) => ({
|
|
8012
|
-
async diagnostics() {
|
|
8013
|
-
return normaliseDiagnostics(await reports.diagnostics());
|
|
8014
8038
|
},
|
|
8015
|
-
|
|
8016
|
-
|
|
8039
|
+
{
|
|
8040
|
+
id: "list-clients-not-admin",
|
|
8041
|
+
route: "GET /SASjsApi/client",
|
|
8042
|
+
description: "refuses the list to a caller who is not an administrator",
|
|
8043
|
+
identity: ADMIN_SIGNED_IN,
|
|
8044
|
+
request: { token: RESTRICTED2 },
|
|
8045
|
+
expect: { status: 401, error: "Admin account required" }
|
|
8017
8046
|
},
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
throw new Error("The directory answer has no users array.");
|
|
8031
|
-
const seen = /* @__PURE__ */ new Set();
|
|
8032
|
-
for (const user3 of users) {
|
|
8033
|
-
if (!isNonEmptyString3(user3?.username) || !isNonEmptyString3(user3?.displayName))
|
|
8034
|
-
throw new Error(
|
|
8035
|
-
`The directory answer carries a user without a username or displayName: ${JSON.stringify(user3)}. Both are what the API keys an account on, so the import cannot guess them.`
|
|
8036
|
-
);
|
|
8037
|
-
if (seen.has(user3.username))
|
|
8038
|
-
throw new Error(
|
|
8039
|
-
`The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
|
|
8040
|
-
);
|
|
8041
|
-
seen.add(user3.username);
|
|
8042
|
-
}
|
|
8043
|
-
return users;
|
|
8044
|
-
};
|
|
8045
|
-
var groupsOf = (groups) => {
|
|
8046
|
-
if (!Array.isArray(groups))
|
|
8047
|
-
throw new Error("The directory answer has no groups array.");
|
|
8048
|
-
const seen = /* @__PURE__ */ new Set();
|
|
8049
|
-
for (const group of groups) {
|
|
8050
|
-
if (!isNonEmptyString3(group?.name))
|
|
8051
|
-
throw new Error(
|
|
8052
|
-
`The directory answer carries a group without a name: ${JSON.stringify(group)}.`
|
|
8053
|
-
);
|
|
8054
|
-
if (seen.has(group.name))
|
|
8055
|
-
throw new Error(
|
|
8056
|
-
`The directory answer names the group ${group.name} twice, which would apply its members twice.`
|
|
8057
|
-
);
|
|
8058
|
-
seen.add(group.name);
|
|
8059
|
-
}
|
|
8060
|
-
return groups;
|
|
8061
|
-
};
|
|
8062
|
-
var createDirectoryService = (store, source, options = {}) => {
|
|
8063
|
-
const provider = options.provider || "ldap";
|
|
8064
|
-
return {
|
|
8065
|
-
async synchronise() {
|
|
8066
|
-
const directoryUsers = usersOf(await source.users());
|
|
8067
|
-
const directoryGroups = groupsOf(await source.groups());
|
|
8068
|
-
const existingUsers = await store.users();
|
|
8069
|
-
const existingGroups = await store.groups();
|
|
8070
|
-
const userByName = new Map(
|
|
8071
|
-
existingUsers.map((user3) => [user3.username, user3])
|
|
8072
|
-
);
|
|
8073
|
-
const groupByName = new Map(
|
|
8074
|
-
existingGroups.map((group) => [group.name, group])
|
|
8075
|
-
);
|
|
8076
|
-
const imported = [];
|
|
8077
|
-
for (const user3 of directoryUsers) {
|
|
8078
|
-
if (userByName.has(user3.username)) continue;
|
|
8079
|
-
const created = await store.createUser({
|
|
8080
|
-
username: user3.username,
|
|
8081
|
-
displayName: user3.displayName,
|
|
8082
|
-
isAdmin: false,
|
|
8083
|
-
isActive: true,
|
|
8084
|
-
authProvider: provider
|
|
8085
|
-
});
|
|
8086
|
-
userByName.set(created.username, created);
|
|
8087
|
-
imported.push(created);
|
|
8047
|
+
{
|
|
8048
|
+
id: "create-client",
|
|
8049
|
+
route: "POST /SASjsApi/client",
|
|
8050
|
+
description: "registers a client",
|
|
8051
|
+
identity: ADMIN_SIGNED_IN,
|
|
8052
|
+
request: {
|
|
8053
|
+
token: ADMIN3,
|
|
8054
|
+
body: {
|
|
8055
|
+
clientId: "new_app",
|
|
8056
|
+
clientSecret: "new_secret",
|
|
8057
|
+
accessTokenExpiration: 3600,
|
|
8058
|
+
refreshTokenExpiration: 86400
|
|
8088
8059
|
}
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
});
|
|
8098
|
-
groupByName.set(created.name, created);
|
|
8099
|
-
importedGroups.push(created);
|
|
8060
|
+
},
|
|
8061
|
+
expect: {
|
|
8062
|
+
status: 200,
|
|
8063
|
+
body: {
|
|
8064
|
+
clientId: "new_app",
|
|
8065
|
+
clientSecret: "new_secret",
|
|
8066
|
+
accessTokenExpiration: 3600,
|
|
8067
|
+
refreshTokenExpiration: 86400
|
|
8100
8068
|
}
|
|
8101
|
-
const membersOf = /* @__PURE__ */ new Map();
|
|
8102
|
-
const note = (groupName, username) => {
|
|
8103
|
-
const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
|
|
8104
|
-
members.add(username);
|
|
8105
|
-
membersOf.set(groupName, members);
|
|
8106
|
-
};
|
|
8107
|
-
for (const group of directoryGroups)
|
|
8108
|
-
for (const member of group.members || []) note(group.name, member);
|
|
8109
|
-
for (const user3 of directoryUsers)
|
|
8110
|
-
for (const groupName of user3.groups || [])
|
|
8111
|
-
note(groupName, user3.username);
|
|
8112
|
-
for (const group of importedGroups)
|
|
8113
|
-
for (const username of membersOf.get(group.name) || []) {
|
|
8114
|
-
const user3 = userByName.get(username);
|
|
8115
|
-
if (user3) await store.addToGroup(group.uid, user3.uid);
|
|
8116
|
-
}
|
|
8117
|
-
return { userCount: imported.length, groupCount: importedGroups.length };
|
|
8118
8069
|
}
|
|
8119
|
-
}
|
|
8120
|
-
|
|
8070
|
+
},
|
|
8071
|
+
{
|
|
8072
|
+
id: "create-client-defaults",
|
|
8073
|
+
route: "POST /SASjsApi/client",
|
|
8074
|
+
description: "applies the schema defaults when the lifetimes are omitted",
|
|
8075
|
+
identity: ADMIN_SIGNED_IN,
|
|
8076
|
+
request: {
|
|
8077
|
+
token: ADMIN3,
|
|
8078
|
+
body: { clientId: "default_app", clientSecret: "default_secret" }
|
|
8079
|
+
},
|
|
8080
|
+
expect: {
|
|
8081
|
+
status: 200,
|
|
8082
|
+
body: {
|
|
8083
|
+
clientId: "default_app",
|
|
8084
|
+
clientSecret: "default_secret",
|
|
8085
|
+
accessTokenExpiration: 86400,
|
|
8086
|
+
refreshTokenExpiration: 2592e3
|
|
8087
|
+
}
|
|
8088
|
+
}
|
|
8089
|
+
},
|
|
8090
|
+
{
|
|
8091
|
+
id: "create-client-not-admin",
|
|
8092
|
+
route: "POST /SASjsApi/client",
|
|
8093
|
+
description: "refuses a registration by a non-administrator",
|
|
8094
|
+
identity: ADMIN_SIGNED_IN,
|
|
8095
|
+
request: {
|
|
8096
|
+
token: RESTRICTED2,
|
|
8097
|
+
body: {
|
|
8098
|
+
clientId: "new_app",
|
|
8099
|
+
clientSecret: "new_secret",
|
|
8100
|
+
accessTokenExpiration: 3600,
|
|
8101
|
+
refreshTokenExpiration: 86400
|
|
8102
|
+
}
|
|
8103
|
+
},
|
|
8104
|
+
expect: { status: 401, error: "Admin account required" }
|
|
8105
|
+
},
|
|
8106
|
+
{
|
|
8107
|
+
id: "create-client-duplicate",
|
|
8108
|
+
route: "POST /SASjsApi/client",
|
|
8109
|
+
description: "refuses a client id that is registered, with the 403 the server sends",
|
|
8110
|
+
identity: ADMIN_SIGNED_IN,
|
|
8111
|
+
request: {
|
|
8112
|
+
token: ADMIN3,
|
|
8113
|
+
body: {
|
|
8114
|
+
clientId: "web_app",
|
|
8115
|
+
clientSecret: "other",
|
|
8116
|
+
accessTokenExpiration: 3600,
|
|
8117
|
+
refreshTokenExpiration: 86400
|
|
8118
|
+
}
|
|
8119
|
+
},
|
|
8120
|
+
expect: { status: 403, error: "Error: Client ID already exists." }
|
|
8121
|
+
},
|
|
8122
|
+
// -------------------------------------------------------------- passwords
|
|
8123
|
+
{
|
|
8124
|
+
id: "update-password",
|
|
8125
|
+
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
8126
|
+
description: "changes the caller’s own password",
|
|
8127
|
+
identity: ADMIN_SIGNED_IN,
|
|
8128
|
+
request: {
|
|
8129
|
+
token: RESTRICTED2,
|
|
8130
|
+
body: { currentPassword: "Orion123", newPassword: "changed123" }
|
|
8131
|
+
},
|
|
8132
|
+
expect: { status: 204 }
|
|
8133
|
+
},
|
|
8134
|
+
{
|
|
8135
|
+
id: "update-password-missing-field",
|
|
8136
|
+
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
8137
|
+
description: "refuses a body without the current password",
|
|
8138
|
+
identity: ADMIN_SIGNED_IN,
|
|
8139
|
+
request: { token: RESTRICTED2, body: { newPassword: "changed123" } },
|
|
8140
|
+
expect: { status: 400, error: '"currentPassword" is required' }
|
|
8141
|
+
},
|
|
8142
|
+
{
|
|
8143
|
+
id: "update-password-unauthenticated",
|
|
8144
|
+
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
8145
|
+
description: "refuses the change with no caller",
|
|
8146
|
+
identity: ADMIN_SIGNED_IN,
|
|
8147
|
+
request: {
|
|
8148
|
+
body: { currentPassword: "Orion123", newPassword: "changed123" }
|
|
8149
|
+
},
|
|
8150
|
+
expect: { status: 401, error: "Unauthorized" }
|
|
8151
|
+
},
|
|
8152
|
+
{
|
|
8153
|
+
id: "update-password-wrong-current",
|
|
8154
|
+
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
8155
|
+
description: "refuses a change whose current password is wrong",
|
|
8156
|
+
identity: ADMIN_SIGNED_IN,
|
|
8157
|
+
request: {
|
|
8158
|
+
token: RESTRICTED2,
|
|
8159
|
+
body: { currentPassword: "wrong", newPassword: "changed123" }
|
|
8160
|
+
},
|
|
8161
|
+
expect: { status: 403, error: "Invalid current password!" }
|
|
8162
|
+
},
|
|
8163
|
+
{
|
|
8164
|
+
id: "update-password-provider",
|
|
8165
|
+
route: "PATCH /SASjsApi/auth/updatePassword",
|
|
8166
|
+
description: "refuses a password change on a provider-managed account",
|
|
8167
|
+
identity: PROVIDER_MANAGED,
|
|
8168
|
+
request: {
|
|
8169
|
+
token: "dir-access",
|
|
8170
|
+
body: { currentPassword: "dir123", newPassword: "changed123" }
|
|
8171
|
+
},
|
|
8172
|
+
expect: {
|
|
8173
|
+
status: 405,
|
|
8174
|
+
error: "Can not update password of user that is created by an external auth provider."
|
|
8175
|
+
}
|
|
8176
|
+
}
|
|
8177
|
+
];
|
|
8121
8178
|
|
|
8122
8179
|
// src/corpus/runner.ts
|
|
8123
8180
|
var servicesFor = (testCase) => {
|