not-node 6.2.18 → 6.2.20
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/.husky/pre-commit +4 -0
- package/package.json +7 -4
- package/src/auth/roles.js +9 -1
- package/src/auth/rules.js +5 -5
- package/src/cli/actions/env.mjs +1 -1
- package/src/cli/actions/nginx.mjs +1 -1
- package/src/cli/actions/pm2.mjs +1 -1
- package/src/common.js +1 -1
- package/src/domain.js +36 -24
- package/src/form/env_extractors/index.js +2 -2
- package/src/form/extractors/index.js +1 -1
- package/src/identity/providers/session.js +3 -0
- package/src/manifest/batchRunner.js +5 -1
- package/src/manifest/registrator/fields.js +4 -4
- package/src/manifest/route.js +9 -0
- package/src/model/exceptions.js +3 -3
- package/src/model/versioning.js +2 -2
- package/test/auth/routes.js +34 -10
- package/test/fakes.js +52 -0
- package/test/identity/providers/session.js +14 -5
- package/test/identity/providers/token.js +1 -1
- package/test/init/additional.js +31 -33
- package/test/init/app.js +66 -10
- package/test/init/bodyparser.js +4 -1
- package/test/init/compression.js +4 -1
- package/test/init/cors.js +5 -1
- package/test/init/csp.js +2 -2
- package/test/init/db.js +5 -1
- package/test/init/env.js +12 -2
- package/test/init/express.js +4 -1
- package/test/init/fileupload.js +4 -1
- package/test/init/http.js +21 -4
- package/test/init/middleware.js +13 -1
- package/test/init/routes.js +1 -0
- package/test/init/sessions/mongoose.js +5 -1
- package/test/init/sessions/redis.js +5 -1
- package/test/init/sessions.js +21 -15
- package/test/init/static.js +4 -1
- package/test/init/template.js +5 -1
- package/test/model/versioning.js +3 -3
- package/test/module/fields.js +45 -20
- package/test/module/index.js +26 -15
- package/test/notApp.js +221 -187
- package/test/notDomain.js +799 -707
- package/test/notManifestFilter.js +385 -322
- package/test/notModule.js +689 -644
- package/test/notRoute.js +112 -99
- package/test/testies/module/fields/collection.js +16 -14
- package/test/testies/module/fields/single.js +11 -11
- package/tmpl/files/module.server/layers/forms/_data.ejs +29 -29
- package/tmpl/files/module.server/layers/forms/create.ejs +38 -38
- package/tmpl/files/module.server/layers/forms/listAll.ejs +3 -3
- package/tmpl/files/module.server/layers/forms/listAndCount.ejs +3 -3
- package/tmpl/files/module.server/layers/forms/update.ejs +31 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "not-node",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.20",
|
|
4
4
|
"description": "node complimentary part for client side notFramework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"js-watch": "watch 'npm run cover' ./src ./test --interval=5",
|
|
12
12
|
"watch:build:cover:dev": "npm-run-all --parallel js-watch",
|
|
13
13
|
"cover": "nyc npm test",
|
|
14
|
-
"clear:playground": "rm -rf ./playground"
|
|
14
|
+
"clear:playground": "rm -rf ./playground",
|
|
15
|
+
"prepare": "husky install"
|
|
15
16
|
},
|
|
16
17
|
"bin": {
|
|
17
18
|
"not-node": "./bin/not-node.js",
|
|
@@ -35,7 +36,6 @@
|
|
|
35
36
|
"url": "https://github.com/interrupter/not-node/issues"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"xss": "*",
|
|
39
39
|
"body-parser": "^1.20.1",
|
|
40
40
|
"commander": "^9.5.0",
|
|
41
41
|
"compression": "^1.7.4",
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
"not-config": "*",
|
|
64
64
|
"not-error": "*",
|
|
65
65
|
"not-filter": "*",
|
|
66
|
-
"not-
|
|
66
|
+
"not-inform": "*",
|
|
67
|
+
"not-locale": "^0.0.22",
|
|
67
68
|
"not-log": "*",
|
|
68
69
|
"not-monitor": "*",
|
|
69
70
|
"not-path": "*",
|
|
@@ -76,6 +77,7 @@
|
|
|
76
77
|
"serve-static": "*",
|
|
77
78
|
"simple-git": "*",
|
|
78
79
|
"validator": "*",
|
|
80
|
+
"xss": "*",
|
|
79
81
|
"yargs": "*"
|
|
80
82
|
},
|
|
81
83
|
"devDependencies": {
|
|
@@ -85,6 +87,7 @@
|
|
|
85
87
|
"eslint": "^8.31.0",
|
|
86
88
|
"eslint-plugin-node": "^11.1.0",
|
|
87
89
|
"eslint-plugin-sonarjs": "^0.17.0",
|
|
90
|
+
"husky": "^8.0.3",
|
|
88
91
|
"ink-docstrap": "^1.3.2",
|
|
89
92
|
"ioredis": "^5.2.4",
|
|
90
93
|
"jsdoc": "^4.0.0",
|
package/src/auth/roles.js
CHANGED
|
@@ -16,6 +16,14 @@ function compareRolesArrayAgainstArray(userRoles, actionRoles, strict) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function compareRolesStrict(userRoles, actionRoles) {
|
|
20
|
+
if (actionRoles.length === 1) {
|
|
21
|
+
return actionRoles.includes(userRoles);
|
|
22
|
+
} else {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
/**
|
|
20
28
|
* Compares two list of roles
|
|
21
29
|
* @param {array|string} userRoles roles of user
|
|
@@ -41,7 +49,7 @@ function compareRoles(userRoles, actionRoles, strict = true) {
|
|
|
41
49
|
} else {
|
|
42
50
|
if (Array.isArray(actionRoles)) {
|
|
43
51
|
if (strict) {
|
|
44
|
-
return
|
|
52
|
+
return compareRolesStrict(userRoles, actionRoles);
|
|
45
53
|
} else {
|
|
46
54
|
return actionRoles.indexOf(userRoles) > -1;
|
|
47
55
|
}
|
package/src/auth/rules.js
CHANGED
|
@@ -17,13 +17,13 @@ function compareWithRoot(rule, root) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function compareRuleRoles(
|
|
21
|
-
if (ROLES.compareRoles(
|
|
22
|
-
if (objHas(
|
|
23
|
-
if (
|
|
20
|
+
function compareRuleRoles(actionRule, userRole, auth) {
|
|
21
|
+
if (ROLES.compareRoles(userRole, actionRule.role)) {
|
|
22
|
+
if (objHas(actionRule, "auth")) {
|
|
23
|
+
if (actionRule.auth && auth) {
|
|
24
24
|
return true;
|
|
25
25
|
} else {
|
|
26
|
-
return !
|
|
26
|
+
return !actionRule.auth && !auth;
|
|
27
27
|
}
|
|
28
28
|
} else {
|
|
29
29
|
return true;
|
package/src/cli/actions/env.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default (program, { CWD }) => {};
|
|
1
|
+
export default (/*program, { /*CWD }*/) => {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default (program, { CWD }) => {};
|
|
1
|
+
export default (/*program, { CWD }*/) => {};
|
package/src/cli/actions/pm2.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default (program, { CWD }) => {};
|
|
1
|
+
export default (/*program, { CWD }*/) => {};
|
package/src/common.js
CHANGED
|
@@ -155,7 +155,7 @@ module.exports.executeFunctionAsAsync = executeFunctionAsAsync;
|
|
|
155
155
|
* @return {Promise} results of method execution
|
|
156
156
|
**/
|
|
157
157
|
module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
158
|
-
if (obj) {
|
|
158
|
+
if (!obj) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
if (name.indexOf(".") > -1) {
|
package/src/domain.js
CHANGED
|
@@ -63,19 +63,27 @@ class notDomain extends EventEmitter {
|
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
get modules() {
|
|
67
|
+
return this.#modules;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get options() {
|
|
67
71
|
return this.#options;
|
|
68
72
|
}
|
|
69
73
|
|
|
74
|
+
getOptions() {
|
|
75
|
+
return this.options;
|
|
76
|
+
}
|
|
77
|
+
|
|
70
78
|
/**
|
|
71
79
|
* Cycles throu all imported modules, passes name, module, and itself
|
|
72
80
|
* to argument function
|
|
73
81
|
* @param {function} func function to perfom some action with module
|
|
74
82
|
**/
|
|
75
83
|
forEachMod(func) {
|
|
76
|
-
if (this
|
|
77
|
-
for (let t of Object.keys(this
|
|
78
|
-
let mod = this
|
|
84
|
+
if (this.modules) {
|
|
85
|
+
for (let t of Object.keys(this.modules)) {
|
|
86
|
+
let mod = this.modules[t];
|
|
79
87
|
if (mod) {
|
|
80
88
|
func(t, mod, this);
|
|
81
89
|
}
|
|
@@ -105,14 +113,18 @@ class notDomain extends EventEmitter {
|
|
|
105
113
|
let mod = new notModule({
|
|
106
114
|
modPath: modulePath,
|
|
107
115
|
modObject: null,
|
|
108
|
-
mongoose: this
|
|
116
|
+
mongoose: this.options.mongoose,
|
|
109
117
|
notApp: this,
|
|
110
|
-
fields: this
|
|
118
|
+
fields: this.options.fields,
|
|
111
119
|
});
|
|
112
120
|
this.importModule(mod, mod.getName() || moduleName);
|
|
113
121
|
return this;
|
|
114
122
|
}
|
|
115
123
|
|
|
124
|
+
setModule(name, val) {
|
|
125
|
+
this.#modules[name] = val;
|
|
126
|
+
}
|
|
127
|
+
|
|
116
128
|
/**
|
|
117
129
|
* Import module object. Chainable.
|
|
118
130
|
* @param {object} mod notModule instance
|
|
@@ -120,7 +132,7 @@ class notDomain extends EventEmitter {
|
|
|
120
132
|
* @return {object} notDomain
|
|
121
133
|
**/
|
|
122
134
|
importModule(mod, moduleName) {
|
|
123
|
-
this
|
|
135
|
+
this.setModule(moduleName, mod);
|
|
124
136
|
return this;
|
|
125
137
|
}
|
|
126
138
|
|
|
@@ -132,8 +144,8 @@ class notDomain extends EventEmitter {
|
|
|
132
144
|
getRoute(name) {
|
|
133
145
|
if (name.indexOf("//") > 0) {
|
|
134
146
|
let [moduleName, routeName, routeFunctionName] = name.split("//");
|
|
135
|
-
if (this
|
|
136
|
-
let route = this
|
|
147
|
+
if (this.modules && objHas(this.modules, moduleName)) {
|
|
148
|
+
let route = this.getModule(moduleName).getRoute(routeName);
|
|
137
149
|
if (objHas(route, routeFunctionName)) {
|
|
138
150
|
return route[routeFunctionName];
|
|
139
151
|
}
|
|
@@ -177,8 +189,8 @@ class notDomain extends EventEmitter {
|
|
|
177
189
|
|
|
178
190
|
getByFullPath(name, type) {
|
|
179
191
|
let [moduleName, resourceName] = name.split("//");
|
|
180
|
-
if (this
|
|
181
|
-
return this
|
|
192
|
+
if (this.modules && objHas(this.modules, moduleName)) {
|
|
193
|
+
return this.getModule(moduleName)[`get${firstLetterToUpper(type)}`](
|
|
182
194
|
resourceName
|
|
183
195
|
);
|
|
184
196
|
} else {
|
|
@@ -188,9 +200,9 @@ class notDomain extends EventEmitter {
|
|
|
188
200
|
}
|
|
189
201
|
|
|
190
202
|
getByShortPath(resourceName, type) {
|
|
191
|
-
for (let moduleName of Object.keys(this
|
|
203
|
+
for (let moduleName of Object.keys(this.modules)) {
|
|
192
204
|
const res =
|
|
193
|
-
this
|
|
205
|
+
this.getModule(moduleName)[`get${firstLetterToUpper(type)}`](
|
|
194
206
|
resourceName
|
|
195
207
|
);
|
|
196
208
|
if (res) {
|
|
@@ -257,12 +269,12 @@ class notDomain extends EventEmitter {
|
|
|
257
269
|
* @return {object} module
|
|
258
270
|
**/
|
|
259
271
|
getModule(moduleName) {
|
|
260
|
-
if (this
|
|
261
|
-
return this
|
|
272
|
+
if (this.modules && objHas(this.modules, moduleName)) {
|
|
273
|
+
return this.modules[moduleName];
|
|
262
274
|
} else {
|
|
263
|
-
for (let t in this
|
|
264
|
-
if (this
|
|
265
|
-
return this
|
|
275
|
+
for (let t in this.modules) {
|
|
276
|
+
if (this.modules[t].getName() === moduleName) {
|
|
277
|
+
return this.modules[t];
|
|
266
278
|
}
|
|
267
279
|
}
|
|
268
280
|
return null;
|
|
@@ -275,7 +287,7 @@ class notDomain extends EventEmitter {
|
|
|
275
287
|
* @param {Object} params params to pass to method
|
|
276
288
|
**/
|
|
277
289
|
async execInModules(methodName, params) {
|
|
278
|
-
for (let mod of Object.values(this
|
|
290
|
+
for (let mod of Object.values(this.modules)) {
|
|
279
291
|
try {
|
|
280
292
|
await executeObjectFunction(mod, "exec", [methodName, params]);
|
|
281
293
|
} catch (e) {
|
|
@@ -289,7 +301,7 @@ class notDomain extends EventEmitter {
|
|
|
289
301
|
* Create mongoose models.
|
|
290
302
|
**/
|
|
291
303
|
fabricate() {
|
|
292
|
-
for (let mod of Object.values(this
|
|
304
|
+
for (let mod of Object.values(this.modules)) {
|
|
293
305
|
mod.fabricateModels && mod.fabricateModels();
|
|
294
306
|
}
|
|
295
307
|
}
|
|
@@ -406,7 +418,7 @@ class notDomain extends EventEmitter {
|
|
|
406
418
|
* @return {Object} complex object with results
|
|
407
419
|
**/
|
|
408
420
|
getStatus() {
|
|
409
|
-
const mods = Object.keys(this
|
|
421
|
+
const mods = Object.keys(this.modules);
|
|
410
422
|
let stats = {
|
|
411
423
|
modules: {
|
|
412
424
|
count: mods.length,
|
|
@@ -434,8 +446,8 @@ class notDomain extends EventEmitter {
|
|
|
434
446
|
list: [],
|
|
435
447
|
},
|
|
436
448
|
};
|
|
437
|
-
for (let modName in this
|
|
438
|
-
const mod = this
|
|
449
|
+
for (let modName in this.modules) {
|
|
450
|
+
const mod = this.modules[modName];
|
|
439
451
|
let modStatus = mod.getStatus();
|
|
440
452
|
stats.modules.content[modName] = modStatus;
|
|
441
453
|
stats.routes.count += modStatus.routes.count;
|
|
@@ -469,7 +481,7 @@ class notDomain extends EventEmitter {
|
|
|
469
481
|
}
|
|
470
482
|
|
|
471
483
|
getModulesNames() {
|
|
472
|
-
return Object.keys(this
|
|
484
|
+
return Object.keys(this.modules);
|
|
473
485
|
}
|
|
474
486
|
}
|
|
475
487
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
|
-
_id: require("./_id.js"),
|
|
7
6
|
ID: require("./ID.js"),
|
|
7
|
+
_id: require("./_id.js"),
|
|
8
8
|
activeUser: require("./activeUser.js"),
|
|
9
9
|
ip: require("./ip.js"),
|
|
10
|
-
query: require("./query.js"),
|
|
11
10
|
modelNameID: require("./modelNameID.js"),
|
|
11
|
+
query: require("./query.js"),
|
|
12
12
|
};
|
|
@@ -5,6 +5,6 @@ module.exports = {
|
|
|
5
5
|
activeUserId: require("./activeUserId.js"),
|
|
6
6
|
activeUserModelName: require("./activeUserModelName.js"),
|
|
7
7
|
fromBody: require("./fromBody.js"),
|
|
8
|
-
fromQuery: require("./fromQuery.js"),
|
|
9
8
|
fromParams: require("./fromParams.js"),
|
|
9
|
+
fromQuery: require("./fromQuery.js"),
|
|
10
10
|
};
|
|
@@ -43,6 +43,9 @@ module.exports = class IdentityProviderSession {
|
|
|
43
43
|
const roles = this.getRole();
|
|
44
44
|
for (let role of roles) {
|
|
45
45
|
if (
|
|
46
|
+
Array.isArray(
|
|
47
|
+
IdentityProviderSession.#getOptions().primaryRoles
|
|
48
|
+
) &&
|
|
46
49
|
IdentityProviderSession.#getOptions().primaryRoles.includes(
|
|
47
50
|
role
|
|
48
51
|
)
|
|
@@ -8,6 +8,10 @@ module.exports = class BatchRunner {
|
|
|
8
8
|
this.setProcessors(processors);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
get processors() {
|
|
12
|
+
return this.#processors;
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
setProcessors(list = []) {
|
|
12
16
|
this.#processors = [...list];
|
|
13
17
|
}
|
|
@@ -24,7 +28,7 @@ module.exports = class BatchRunner {
|
|
|
24
28
|
* @return {boolean} true - executed, false - no paths
|
|
25
29
|
**/
|
|
26
30
|
exec({ nModule }) {
|
|
27
|
-
if (!nModule
|
|
31
|
+
if (!nModule?.module?.paths) {
|
|
28
32
|
return false;
|
|
29
33
|
}
|
|
30
34
|
//starting from simpliest forms and moving upwards
|
|
@@ -87,12 +87,12 @@ module.exports = class notModuleRegistratorFields {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
register({ nModule, fromPath }) {
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
90
|
+
let file = notModuleRegistratorFields.openFile(fromPath);
|
|
91
|
+
if (file && objHas(file, "FIELDS")) {
|
|
92
92
|
//collection
|
|
93
93
|
this.registerFields({
|
|
94
94
|
nModule,
|
|
95
|
-
lib:
|
|
95
|
+
lib: file.FIELDS, //fields dictionary
|
|
96
96
|
fromPath,
|
|
97
97
|
});
|
|
98
98
|
} else {
|
|
@@ -101,7 +101,7 @@ module.exports = class notModuleRegistratorFields {
|
|
|
101
101
|
this.registerField({
|
|
102
102
|
nModule,
|
|
103
103
|
name: parts.name, //fields name
|
|
104
|
-
field:
|
|
104
|
+
field: file, //field description
|
|
105
105
|
fromPath,
|
|
106
106
|
});
|
|
107
107
|
}
|
package/src/manifest/route.js
CHANGED
|
@@ -108,6 +108,7 @@ class notRoute {
|
|
|
108
108
|
)
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
|
+
console.log(rule);
|
|
111
112
|
obsoleteWarning(rule, req.originalUrl);
|
|
112
113
|
let actionName = this.selectActionName(rule);
|
|
113
114
|
let mod = this.notApp.getModule(this.moduleName);
|
|
@@ -190,6 +191,14 @@ class notRoute {
|
|
|
190
191
|
prepared,
|
|
191
192
|
]);
|
|
192
193
|
//filter result IF actionData.return specified
|
|
194
|
+
if (typeof result.toObject === "function") {
|
|
195
|
+
result = result.toObject();
|
|
196
|
+
}
|
|
197
|
+
if (Array.isArray(result)) {
|
|
198
|
+
result = result.map((itm) =>
|
|
199
|
+
itm.toObject ? itm.toObject() : itm
|
|
200
|
+
);
|
|
201
|
+
}
|
|
193
202
|
notManifestRouteResultFilter.filter(req.notRouteData, result);
|
|
194
203
|
//run after with results, continue without waiting when it finished
|
|
195
204
|
return this.executeFunction(modRoute, CONST_AFTER_ACTION, [
|
package/src/model/exceptions.js
CHANGED
|
@@ -7,13 +7,13 @@ class VersioningExceptionSameOldData extends notError {
|
|
|
7
7
|
}
|
|
8
8
|
module.exports.VersioningExceptionSameOldData = VersioningExceptionSameOldData;
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class VersioningExceptionNoPreviousVersions extends notError {
|
|
11
11
|
constructor() {
|
|
12
12
|
super("not-node:versioning_error_no_previous_versions");
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
module.exports.
|
|
16
|
-
|
|
15
|
+
module.exports.VersioningExceptionNoPreviousVersions =
|
|
16
|
+
VersioningExceptionNoPreviousVersions;
|
|
17
17
|
|
|
18
18
|
class IncrementExceptionIDGeneratorRebaseFailed extends notError {
|
|
19
19
|
constructor() {
|
package/src/model/versioning.js
CHANGED
|
@@ -16,7 +16,7 @@ function toObject(obj) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
|
-
|
|
19
|
+
VersioningExceptionNoPreviousVersions,
|
|
20
20
|
VersioningExceptionSameOldData,
|
|
21
21
|
} = require("./exceptions.js");
|
|
22
22
|
|
|
@@ -78,7 +78,7 @@ class ModelVersioning {
|
|
|
78
78
|
toObject(previous)
|
|
79
79
|
);
|
|
80
80
|
} else {
|
|
81
|
-
throw new
|
|
81
|
+
throw new VersioningExceptionNoPreviousVersions();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
package/test/auth/routes.js
CHANGED
|
@@ -3,6 +3,8 @@ const {
|
|
|
3
3
|
HttpExceptionForbidden,
|
|
4
4
|
} = require("../../src/exceptions/http");
|
|
5
5
|
|
|
6
|
+
const notAppIdentity = require("../../src/identity/index");
|
|
7
|
+
|
|
6
8
|
module.exports = ({ Auth, expect }) => {
|
|
7
9
|
describe("Routes", () => {
|
|
8
10
|
describe("getIP", () => {
|
|
@@ -31,6 +33,7 @@ module.exports = ({ Auth, expect }) => {
|
|
|
31
33
|
socket: {
|
|
32
34
|
remoteAddress: "127.0.0.1",
|
|
33
35
|
},
|
|
36
|
+
get() {},
|
|
34
37
|
};
|
|
35
38
|
let result = Auth.getIP(req);
|
|
36
39
|
expect(result).to.deep.equal("127.0.0.1");
|
|
@@ -55,15 +58,19 @@ module.exports = ({ Auth, expect }) => {
|
|
|
55
58
|
headers: {
|
|
56
59
|
"x-forwarded-for": "127.0.0.1",
|
|
57
60
|
},
|
|
61
|
+
get() {},
|
|
58
62
|
user: {},
|
|
59
|
-
session: {
|
|
63
|
+
session: {
|
|
64
|
+
save() {},
|
|
65
|
+
},
|
|
60
66
|
};
|
|
61
67
|
let result = Auth.extractAuthData(req);
|
|
62
68
|
expect(result).to.deep.equal({
|
|
63
69
|
root: false,
|
|
64
70
|
auth: false,
|
|
65
|
-
role:
|
|
66
|
-
|
|
71
|
+
role: [Auth.DEFAULT_USER_ROLE_FOR_GUEST],
|
|
72
|
+
primaryRole: Auth.DEFAULT_USER_ROLE_FOR_GUEST,
|
|
73
|
+
uid: null,
|
|
67
74
|
sid: undefined,
|
|
68
75
|
ip: "127.0.0.1",
|
|
69
76
|
});
|
|
@@ -76,6 +83,7 @@ module.exports = ({ Auth, expect }) => {
|
|
|
76
83
|
session: {
|
|
77
84
|
user: true,
|
|
78
85
|
},
|
|
86
|
+
get() {},
|
|
79
87
|
},
|
|
80
88
|
next = function (val) {
|
|
81
89
|
return val;
|
|
@@ -89,6 +97,7 @@ module.exports = ({ Auth, expect }) => {
|
|
|
89
97
|
session: {
|
|
90
98
|
user: false,
|
|
91
99
|
},
|
|
100
|
+
get() {},
|
|
92
101
|
},
|
|
93
102
|
next = function (val) {
|
|
94
103
|
return val;
|
|
@@ -101,6 +110,7 @@ module.exports = ({ Auth, expect }) => {
|
|
|
101
110
|
describe("checkRoot", function () {
|
|
102
111
|
it("check if admin exists and continues", function () {
|
|
103
112
|
const req = {
|
|
113
|
+
get() {},
|
|
104
114
|
session: {
|
|
105
115
|
user: true,
|
|
106
116
|
role: [Auth.DEFAULT_USER_ROLE_FOR_ADMIN],
|
|
@@ -119,6 +129,7 @@ module.exports = ({ Auth, expect }) => {
|
|
|
119
129
|
user: true,
|
|
120
130
|
role: "manager",
|
|
121
131
|
},
|
|
132
|
+
get() {},
|
|
122
133
|
},
|
|
123
134
|
next = function (val) {
|
|
124
135
|
return val;
|
|
@@ -135,24 +146,33 @@ module.exports = ({ Auth, expect }) => {
|
|
|
135
146
|
user: true,
|
|
136
147
|
role: [Auth.DEFAULT_USER_ROLE_FOR_ADMIN],
|
|
137
148
|
},
|
|
149
|
+
get() {},
|
|
138
150
|
},
|
|
139
151
|
next = function (val) {
|
|
140
152
|
return val;
|
|
141
153
|
};
|
|
142
|
-
let result = Auth.
|
|
154
|
+
let result = Auth.checkRoot(req, false, next);
|
|
143
155
|
expect(result).to.deep.equal();
|
|
144
156
|
});
|
|
145
157
|
});
|
|
146
158
|
|
|
147
159
|
describe("checkRoleBuilder", function () {
|
|
148
160
|
it("Role", function () {
|
|
161
|
+
notAppIdentity.identity = class {
|
|
162
|
+
static of() {
|
|
163
|
+
return class {
|
|
164
|
+
static getRole() {
|
|
165
|
+
return "user";
|
|
166
|
+
}
|
|
167
|
+
static getUserId() {}
|
|
168
|
+
static isUser() {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
149
174
|
const role = "user",
|
|
150
|
-
req = {
|
|
151
|
-
session: {
|
|
152
|
-
user: true,
|
|
153
|
-
role: "user",
|
|
154
|
-
},
|
|
155
|
-
},
|
|
175
|
+
req = {},
|
|
156
176
|
next = function (val) {
|
|
157
177
|
return val;
|
|
158
178
|
};
|
|
@@ -162,9 +182,13 @@ module.exports = ({ Auth, expect }) => {
|
|
|
162
182
|
});
|
|
163
183
|
|
|
164
184
|
it("Role with error", function () {
|
|
185
|
+
let saved = false;
|
|
165
186
|
const role = "manager",
|
|
166
187
|
req = {
|
|
167
188
|
session: {
|
|
189
|
+
save() {
|
|
190
|
+
saved = true;
|
|
191
|
+
},
|
|
168
192
|
user: true,
|
|
169
193
|
role: "user",
|
|
170
194
|
},
|
package/test/fakes.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { DEFAULT_USER_ROLE_FOR_GUEST } = require("../src/auth");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
createFakeEmit: (val, err) => {
|
|
5
|
+
return async () => {
|
|
6
|
+
if (err) {
|
|
7
|
+
throw err;
|
|
8
|
+
} else {
|
|
9
|
+
return val;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
fakeIdentity: (
|
|
14
|
+
id = {
|
|
15
|
+
root: false,
|
|
16
|
+
auth: false,
|
|
17
|
+
role: [DEFAULT_USER_ROLE_FOR_GUEST],
|
|
18
|
+
primaryRole: DEFAULT_USER_ROLE_FOR_GUEST,
|
|
19
|
+
uid: undefined,
|
|
20
|
+
sid: undefined,
|
|
21
|
+
ip: undefined,
|
|
22
|
+
}
|
|
23
|
+
) => {
|
|
24
|
+
return class {
|
|
25
|
+
static of() {
|
|
26
|
+
return class {
|
|
27
|
+
static isRoot() {
|
|
28
|
+
return id.root;
|
|
29
|
+
}
|
|
30
|
+
static isUser() {
|
|
31
|
+
return id.auth;
|
|
32
|
+
}
|
|
33
|
+
static getRole() {
|
|
34
|
+
return id.role;
|
|
35
|
+
}
|
|
36
|
+
static getPrimaryRole() {
|
|
37
|
+
return id.primaryRole;
|
|
38
|
+
}
|
|
39
|
+
static getUserId() {
|
|
40
|
+
return id.uid;
|
|
41
|
+
}
|
|
42
|
+
static getSessionId() {
|
|
43
|
+
return id.sid;
|
|
44
|
+
}
|
|
45
|
+
static getIP() {
|
|
46
|
+
return id.ip;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
};
|