not-node 6.5.6 → 6.5.8
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/package.json +1 -1
- package/src/generic/field._data.js +1 -1
- package/src/generic/field.js +3 -3
- package/src/identity/index.js +12 -8
- package/src/manifest/manifest.filter.js +94 -72
- package/src/manifest/route.js +15 -7
- package/test/fakes.js +21 -0
- package/test/notManifest.js +12 -10
- package/test/notManifestFilter.js +109 -118
- package/test/notRoute.js +13 -10
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ const initGenericDataForm = ({
|
|
|
22
22
|
});
|
|
23
23
|
const App = getApp();
|
|
24
24
|
App.getModule(MODULE_NAME).setFormConstructor(formName, cls);
|
|
25
|
-
App.getModule(MODULE_NAME).setForm(formName, new cls(App));
|
|
25
|
+
App.getModule(MODULE_NAME).setForm(formName, new cls({ app: App }));
|
|
26
26
|
return true;
|
|
27
27
|
} catch (e) {
|
|
28
28
|
getApp().logger.error(e);
|
package/src/generic/field.js
CHANGED
|
@@ -2,13 +2,13 @@ const getApp = require("../getApp");
|
|
|
2
2
|
const genericDataField = require("./field._data");
|
|
3
3
|
const Form = require("../form/form");
|
|
4
4
|
|
|
5
|
-
const initGenericDataField = (
|
|
5
|
+
const initGenericDataField = ({
|
|
6
6
|
MODULE_NAME,
|
|
7
7
|
MODEL_NAME,
|
|
8
8
|
actionName = "_data",
|
|
9
9
|
validators = [],
|
|
10
|
-
afterExtract = async (input /*, req = null*/) => input
|
|
11
|
-
) => {
|
|
10
|
+
afterExtract = async (input /*, req = null*/) => input,
|
|
11
|
+
}) => {
|
|
12
12
|
//not-module//modelName._data
|
|
13
13
|
const fieldGenericPath = Form.createPath(
|
|
14
14
|
MODULE_NAME,
|
package/src/identity/index.js
CHANGED
|
@@ -12,13 +12,7 @@ module.exports = class notAppIdentity {
|
|
|
12
12
|
return this.#identity;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* Collects various authentification and authorization data from request object
|
|
17
|
-
* @param {import('../types').notNodeExpressRequest} req ExpressRequest
|
|
18
|
-
* @return {import('../types').notAppIdentityData} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
19
|
-
*/
|
|
20
|
-
static extractAuthData(req) {
|
|
21
|
-
const identity = this.#identity.of(req);
|
|
15
|
+
static identityToAuthData(identity, req) {
|
|
22
16
|
return {
|
|
23
17
|
root: identity.isRoot(),
|
|
24
18
|
admin: identity.isAdmin(),
|
|
@@ -27,11 +21,21 @@ module.exports = class notAppIdentity {
|
|
|
27
21
|
primaryRole: identity.getPrimaryRole(),
|
|
28
22
|
uid: identity.getUserId(),
|
|
29
23
|
sid: identity.getSessionId(),
|
|
30
|
-
ip: getIP(req),
|
|
24
|
+
ip: req ? getIP(req) : undefined,
|
|
31
25
|
provider: identity.constructor.name,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Collects various authentification and authorization data from request object
|
|
31
|
+
* @param {import('../types').notNodeExpressRequest} req ExpressRequest
|
|
32
|
+
* @return {import('../types').notAppIdentityData} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
33
|
+
*/
|
|
34
|
+
static extractAuthData(req) {
|
|
35
|
+
const identity = this.#identity.of(req);
|
|
36
|
+
return this.identityToAuthData(identity, req);
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
/**
|
|
36
40
|
*
|
|
37
41
|
* @param {import('../types').notNodeExpressRequest} req
|
|
@@ -45,17 +45,17 @@ module.exports = class notManifestFilter {
|
|
|
45
45
|
if (!route.actions[actionName]) {
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
actionName,
|
|
51
|
-
actionSet,
|
|
48
|
+
const resultActionData = notManifestFilter.filterRouteAction(
|
|
49
|
+
route.actions[actionName],
|
|
52
50
|
auth,
|
|
53
51
|
role,
|
|
54
52
|
root,
|
|
55
|
-
result,
|
|
56
53
|
modelName,
|
|
57
54
|
moduleName
|
|
58
55
|
);
|
|
56
|
+
if (resultActionData) {
|
|
57
|
+
result.actions[actionName] = resultActionData;
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
return result;
|
|
61
61
|
}
|
|
@@ -64,22 +64,18 @@ module.exports = class notManifestFilter {
|
|
|
64
64
|
*
|
|
65
65
|
*
|
|
66
66
|
* @static
|
|
67
|
-
* @param {string} actionName
|
|
68
67
|
* @param {import('../types').notActionData} actionSet
|
|
69
68
|
* @param {boolean} auth
|
|
70
69
|
* @param {Array<string>} role
|
|
71
70
|
* @param {boolean} root
|
|
72
|
-
* @param {any} result
|
|
73
71
|
* @param {string} [modelName=""]
|
|
74
72
|
* @param {string} [moduleName=""]
|
|
75
73
|
*/
|
|
76
74
|
static filterRouteAction(
|
|
77
|
-
actionName,
|
|
78
75
|
actionSet,
|
|
79
76
|
auth,
|
|
80
77
|
role,
|
|
81
78
|
root,
|
|
82
|
-
result,
|
|
83
79
|
modelName = "",
|
|
84
80
|
moduleName = ""
|
|
85
81
|
) {
|
|
@@ -88,31 +84,8 @@ module.exports = class notManifestFilter {
|
|
|
88
84
|
if (
|
|
89
85
|
Auth.checkCredentials(actionSet.rules[i], auth, role, root)
|
|
90
86
|
) {
|
|
91
|
-
|
|
92
|
-
notManifestFilter.clearActionFromRules(
|
|
93
|
-
actionSet,
|
|
94
|
-
actionSet.rules[i],
|
|
95
|
-
{
|
|
96
|
-
auth,
|
|
97
|
-
role,
|
|
98
|
-
root,
|
|
99
|
-
modelName,
|
|
100
|
-
moduleName,
|
|
101
|
-
actionSignature:
|
|
102
|
-
notManifestFilter.detectActionSignature(
|
|
103
|
-
actionSet
|
|
104
|
-
),
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
if (Auth.checkCredentials(actionSet, auth, role, root)) {
|
|
112
|
-
result.actions[actionName] =
|
|
113
|
-
notManifestFilter.clearActionFromRules(
|
|
87
|
+
return notManifestFilter.clearActionFromRules(
|
|
114
88
|
actionSet,
|
|
115
|
-
undefined,
|
|
116
89
|
{
|
|
117
90
|
auth,
|
|
118
91
|
role,
|
|
@@ -123,10 +96,29 @@ module.exports = class notManifestFilter {
|
|
|
123
96
|
notManifestFilter.detectActionSignature(
|
|
124
97
|
actionSet
|
|
125
98
|
),
|
|
126
|
-
}
|
|
99
|
+
},
|
|
100
|
+
actionSet.rules[i]
|
|
127
101
|
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
if (Auth.checkCredentials(actionSet, auth, role, root)) {
|
|
106
|
+
return notManifestFilter.clearActionFromRules(
|
|
107
|
+
actionSet,
|
|
108
|
+
{
|
|
109
|
+
auth,
|
|
110
|
+
role,
|
|
111
|
+
root,
|
|
112
|
+
modelName,
|
|
113
|
+
moduleName,
|
|
114
|
+
actionSignature:
|
|
115
|
+
notManifestFilter.detectActionSignature(actionSet),
|
|
116
|
+
},
|
|
117
|
+
undefined
|
|
118
|
+
);
|
|
128
119
|
}
|
|
129
120
|
}
|
|
121
|
+
return undefined;
|
|
130
122
|
}
|
|
131
123
|
|
|
132
124
|
/**
|
|
@@ -143,7 +135,7 @@ module.exports = class notManifestFilter {
|
|
|
143
135
|
**/
|
|
144
136
|
|
|
145
137
|
static filter(manifest, auth, role, root, moduleName = "") {
|
|
146
|
-
|
|
138
|
+
const result = {};
|
|
147
139
|
for (let routeName in manifest) {
|
|
148
140
|
let routeMan = notManifestFilter.filterRoute(
|
|
149
141
|
manifest[routeName],
|
|
@@ -223,14 +215,11 @@ module.exports = class notManifestFilter {
|
|
|
223
215
|
switch (action?.method?.toLocaleLowerCase()) {
|
|
224
216
|
case "get":
|
|
225
217
|
return Auth.ACTION_SIGNATURES.READ;
|
|
226
|
-
|
|
227
218
|
case "post":
|
|
228
219
|
case "patch":
|
|
229
220
|
return Auth.ACTION_SIGNATURES.UPDATE;
|
|
230
|
-
|
|
231
221
|
case "put":
|
|
232
222
|
return Auth.ACTION_SIGNATURES.CREATE;
|
|
233
|
-
|
|
234
223
|
case "delete":
|
|
235
224
|
return Auth.ACTION_SIGNATURES.DELETE;
|
|
236
225
|
|
|
@@ -274,10 +263,50 @@ module.exports = class notManifestFilter {
|
|
|
274
263
|
return returnSet;
|
|
275
264
|
}
|
|
276
265
|
|
|
266
|
+
static filterFieldsPropOfActionRule(
|
|
267
|
+
actionRule,
|
|
268
|
+
{ modelSchema, modelName, ruleSet, actionSignature, role, auth, root }
|
|
269
|
+
) {
|
|
270
|
+
const fields = notManifestFilter.ruleSetHasFieldsDirective(ruleSet)
|
|
271
|
+
? [...ruleSet.fields]
|
|
272
|
+
: DEFAULT_FIELDS_SET;
|
|
273
|
+
|
|
274
|
+
actionRule.fields = notFieldsFilter.filter(fields, modelSchema, {
|
|
275
|
+
action: actionSignature,
|
|
276
|
+
roles: role,
|
|
277
|
+
auth,
|
|
278
|
+
root,
|
|
279
|
+
modelName,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
//remove fields property if list is empty
|
|
283
|
+
if (actionRule.fields.length == 0) {
|
|
284
|
+
delete actionRule.fields;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static filterReturnPropOfActionRule(
|
|
289
|
+
actionRule,
|
|
290
|
+
{ modelSchema, modelName, ruleSet, actionSignature, role, auth, root }
|
|
291
|
+
) {
|
|
292
|
+
if (ruleSet && ruleSet.return) {
|
|
293
|
+
actionRule.return = notManifestFilter.filterReturnSet(
|
|
294
|
+
ruleSet.return,
|
|
295
|
+
modelSchema,
|
|
296
|
+
{
|
|
297
|
+
auth,
|
|
298
|
+
role,
|
|
299
|
+
root,
|
|
300
|
+
modelName,
|
|
301
|
+
actionSignature,
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
277
307
|
/**
|
|
278
308
|
* Clear action definition from rules of access
|
|
279
309
|
* @param {object} action action data
|
|
280
|
-
* @param {object} [ruleSet] specific set of rules for this action
|
|
281
310
|
* @param {object} mods specific set of rules for this action
|
|
282
311
|
* @param {boolean} mods.auth
|
|
283
312
|
* @param {boolean} mods.root
|
|
@@ -285,11 +314,11 @@ module.exports = class notManifestFilter {
|
|
|
285
314
|
* @param {string} mods.modelName
|
|
286
315
|
* @param {string} mods.moduleName
|
|
287
316
|
* @param {string|undefined} mods.actionSignature create/read/update/delete
|
|
317
|
+
* @param {object} [ruleSet] specific set of rules for this action
|
|
288
318
|
* @return {object} clean action data
|
|
289
319
|
**/
|
|
290
320
|
static clearActionFromRules(
|
|
291
321
|
action,
|
|
292
|
-
ruleSet = null,
|
|
293
322
|
{
|
|
294
323
|
auth = false,
|
|
295
324
|
role = [Auth.DEFAULT_USER_ROLE_FOR_GUEST],
|
|
@@ -304,46 +333,39 @@ module.exports = class notManifestFilter {
|
|
|
304
333
|
modelName: "",
|
|
305
334
|
moduleName: "",
|
|
306
335
|
actionSignature: undefined,
|
|
307
|
-
}
|
|
336
|
+
},
|
|
337
|
+
ruleSet = null
|
|
308
338
|
) {
|
|
309
|
-
|
|
310
|
-
|
|
339
|
+
//full copy
|
|
340
|
+
const actionRule = merge({}, action);
|
|
341
|
+
//removes server side or secret information (full list of access rules)
|
|
342
|
+
notManifestFilter.clearFromDirtyFields(actionRule);
|
|
343
|
+
//retrives model schema
|
|
344
|
+
const fullModelName = this.composeFullModelName(moduleName, modelName);
|
|
345
|
+
const modelSchema = this.loadSchema(fullModelName);
|
|
311
346
|
//copy fields list from rule to action if it exists
|
|
312
347
|
//fields list is used to restrict fields of data that could be accessed via
|
|
313
348
|
//this action
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
copy.fields = notFieldsFilter.filter(fields, modelSchema, {
|
|
321
|
-
action: actionSignature,
|
|
322
|
-
roles: role,
|
|
349
|
+
this.filterFieldsPropOfActionRule(actionRule, {
|
|
350
|
+
modelName,
|
|
351
|
+
modelSchema,
|
|
352
|
+
ruleSet,
|
|
353
|
+
actionSignature,
|
|
354
|
+
role,
|
|
323
355
|
auth,
|
|
324
356
|
root,
|
|
357
|
+
});
|
|
358
|
+
//
|
|
359
|
+
this.filterReturnPropOfActionRule(actionRule, {
|
|
325
360
|
modelName,
|
|
361
|
+
modelSchema,
|
|
362
|
+
ruleSet,
|
|
363
|
+
actionSignature,
|
|
364
|
+
role,
|
|
365
|
+
auth,
|
|
366
|
+
root,
|
|
326
367
|
});
|
|
327
|
-
|
|
328
|
-
if (copy.fields.length == 0) {
|
|
329
|
-
delete copy.fields;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (ruleSet && ruleSet.return) {
|
|
333
|
-
copy.return = notManifestFilter.filterReturnSet(
|
|
334
|
-
ruleSet.return,
|
|
335
|
-
modelSchema,
|
|
336
|
-
{
|
|
337
|
-
auth,
|
|
338
|
-
role,
|
|
339
|
-
root,
|
|
340
|
-
modelName,
|
|
341
|
-
moduleName,
|
|
342
|
-
actionSignature,
|
|
343
|
-
}
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
return copy;
|
|
368
|
+
return actionRule;
|
|
347
369
|
}
|
|
348
370
|
|
|
349
371
|
/**
|
package/src/manifest/route.js
CHANGED
|
@@ -80,10 +80,9 @@ class notRoute {
|
|
|
80
80
|
* @param {import('../types').notNodeExpressRequest} req Express Request Object
|
|
81
81
|
* @return {import('../types').notRouteRule | null} rule or null
|
|
82
82
|
*/
|
|
83
|
-
selectRule(
|
|
84
|
-
const user = notAppIdentity.extractAuthData(req);
|
|
83
|
+
selectRule(identity) {
|
|
85
84
|
if (this.actionData) {
|
|
86
|
-
return notRoute.actionAvailableByRule(this.actionData,
|
|
85
|
+
return notRoute.actionAvailableByRule(this.actionData, identity);
|
|
87
86
|
}
|
|
88
87
|
return null;
|
|
89
88
|
}
|
|
@@ -107,7 +106,15 @@ class notRoute {
|
|
|
107
106
|
* @return {import('../types').notRouteData}
|
|
108
107
|
* @memberof notRoute
|
|
109
108
|
*/
|
|
110
|
-
createRequestRouteData(actionName, rule) {
|
|
109
|
+
createRequestRouteData(actionName, rule, identity) {
|
|
110
|
+
const actionRule = notManifestFilter.filterRouteAction(
|
|
111
|
+
this.actionData,
|
|
112
|
+
identity.auth,
|
|
113
|
+
identity.role,
|
|
114
|
+
identity.root,
|
|
115
|
+
this.routeName,
|
|
116
|
+
this.moduleName
|
|
117
|
+
);
|
|
111
118
|
return {
|
|
112
119
|
actionName,
|
|
113
120
|
modelName: this.routeName,
|
|
@@ -116,7 +123,7 @@ class notRoute {
|
|
|
116
123
|
this.routeName
|
|
117
124
|
)}`,
|
|
118
125
|
rule: copyObj(rule),
|
|
119
|
-
actionData:
|
|
126
|
+
actionData: actionRule,
|
|
120
127
|
actionSignature: notManifestFilter.detectActionSignature(
|
|
121
128
|
this.actionData
|
|
122
129
|
),
|
|
@@ -132,7 +139,8 @@ class notRoute {
|
|
|
132
139
|
**/
|
|
133
140
|
exec(req, res, next) {
|
|
134
141
|
try {
|
|
135
|
-
|
|
142
|
+
const identity = notAppIdentity.extractAuthData(req);
|
|
143
|
+
const rule = this.selectRule(identity);
|
|
136
144
|
if (!rule) {
|
|
137
145
|
return next(
|
|
138
146
|
new HttpError(
|
|
@@ -166,7 +174,7 @@ class notRoute {
|
|
|
166
174
|
const modRoute = mod.getRoute(this.routeName);
|
|
167
175
|
this.setRequestRouteData(
|
|
168
176
|
req,
|
|
169
|
-
this.createRequestRouteData(actionName, rule)
|
|
177
|
+
this.createRequestRouteData(actionName, rule, identity)
|
|
170
178
|
);
|
|
171
179
|
if (this.routeIsRunnable(modRoute, actionName)) {
|
|
172
180
|
return this.executeRoute(modRoute, actionName, {
|
package/test/fakes.js
CHANGED
|
@@ -10,6 +10,27 @@ module.exports = {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
},
|
|
13
|
+
fakeAuthData: ({
|
|
14
|
+
root = false,
|
|
15
|
+
admin = 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
|
+
return {
|
|
24
|
+
root,
|
|
25
|
+
admin,
|
|
26
|
+
auth,
|
|
27
|
+
role,
|
|
28
|
+
primaryRole,
|
|
29
|
+
uid,
|
|
30
|
+
sid,
|
|
31
|
+
ip,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
13
34
|
fakeIdentity: (
|
|
14
35
|
id = {
|
|
15
36
|
root: false,
|
package/test/notManifest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const expect = require("chai").expect,
|
|
2
2
|
notManifest = require("../src/manifest/manifest"),
|
|
3
|
+
notManifestFilter = require("../src/manifest/manifest.filter"),
|
|
3
4
|
manifest = new notManifest();
|
|
4
5
|
|
|
5
6
|
const rawRoutesManifest = {
|
|
@@ -25,31 +26,32 @@ const rawRoutesManifest = {
|
|
|
25
26
|
method: "get",
|
|
26
27
|
rules: [
|
|
27
28
|
{
|
|
28
|
-
|
|
29
|
+
root: true,
|
|
30
|
+
actionName: "listForAdmin",
|
|
29
31
|
},
|
|
30
32
|
{
|
|
31
33
|
auth: true,
|
|
32
34
|
actionPrefix: "user",
|
|
33
35
|
},
|
|
36
|
+
|
|
34
37
|
{
|
|
35
|
-
|
|
36
|
-
actionName: "listForAdmin",
|
|
38
|
+
auth: false,
|
|
37
39
|
},
|
|
38
40
|
],
|
|
39
41
|
},
|
|
40
42
|
listAll: {
|
|
41
43
|
method: "get",
|
|
42
44
|
rules: [
|
|
43
|
-
{
|
|
44
|
-
auth: true,
|
|
45
|
-
role: ["manager"],
|
|
46
|
-
actionName: "managerListAll",
|
|
47
|
-
},
|
|
48
45
|
{
|
|
49
46
|
root: true,
|
|
50
47
|
actionPrefix: "__",
|
|
51
48
|
actionName: "listForAdmin",
|
|
52
49
|
},
|
|
50
|
+
{
|
|
51
|
+
auth: true,
|
|
52
|
+
role: ["manager"],
|
|
53
|
+
actionName: "managerListAll",
|
|
54
|
+
},
|
|
53
55
|
],
|
|
54
56
|
},
|
|
55
57
|
},
|
|
@@ -70,10 +72,10 @@ const rawRoutesManifest = {
|
|
|
70
72
|
method: "get",
|
|
71
73
|
rules: [
|
|
72
74
|
{
|
|
73
|
-
|
|
75
|
+
root: true,
|
|
74
76
|
},
|
|
75
77
|
{
|
|
76
|
-
|
|
78
|
+
auth: true,
|
|
77
79
|
},
|
|
78
80
|
],
|
|
79
81
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { notFieldsFilter } = require("..");
|
|
2
|
+
|
|
2
3
|
const {
|
|
3
4
|
DEFAULT_USER_ROLE_FOR_GUEST,
|
|
4
5
|
ACTION_SIGNATURES,
|
|
@@ -31,31 +32,31 @@ const rawRoutesManifest = {
|
|
|
31
32
|
method: "get",
|
|
32
33
|
rules: [
|
|
33
34
|
{
|
|
34
|
-
|
|
35
|
+
root: true,
|
|
36
|
+
actionName: "listForAdmin",
|
|
35
37
|
},
|
|
36
38
|
{
|
|
37
39
|
auth: true,
|
|
38
40
|
actionPrefix: "user",
|
|
39
41
|
},
|
|
40
42
|
{
|
|
41
|
-
|
|
42
|
-
actionName: "listForAdmin",
|
|
43
|
+
auth: false,
|
|
43
44
|
},
|
|
44
45
|
],
|
|
45
46
|
},
|
|
46
47
|
listAll: {
|
|
47
48
|
method: "get",
|
|
48
49
|
rules: [
|
|
49
|
-
{
|
|
50
|
-
auth: true,
|
|
51
|
-
role: ["manager"],
|
|
52
|
-
actionName: "managerListAll",
|
|
53
|
-
},
|
|
54
50
|
{
|
|
55
51
|
root: true,
|
|
56
52
|
actionPrefix: "__",
|
|
57
53
|
actionName: "listForAdmin",
|
|
58
54
|
},
|
|
55
|
+
{
|
|
56
|
+
auth: true,
|
|
57
|
+
role: ["manager"],
|
|
58
|
+
actionName: "managerListAll",
|
|
59
|
+
},
|
|
59
60
|
],
|
|
60
61
|
},
|
|
61
62
|
},
|
|
@@ -76,10 +77,10 @@ const rawRoutesManifest = {
|
|
|
76
77
|
method: "get",
|
|
77
78
|
rules: [
|
|
78
79
|
{
|
|
79
|
-
|
|
80
|
+
root: true,
|
|
80
81
|
},
|
|
81
82
|
{
|
|
82
|
-
|
|
83
|
+
auth: true,
|
|
83
84
|
},
|
|
84
85
|
],
|
|
85
86
|
},
|
|
@@ -96,27 +97,73 @@ const rawRoutesManifest = {
|
|
|
96
97
|
|
|
97
98
|
describe("notManifestFilter", function () {
|
|
98
99
|
describe("clearActionFromRules", function () {
|
|
100
|
+
const spGuestC = Object.freeze({
|
|
101
|
+
[ACTION_SIGNATURES.CREATE]: ["root", "admin", "@*"],
|
|
102
|
+
[ACTION_SIGNATURES.READ]: ["root", "admin"],
|
|
103
|
+
[ACTION_SIGNATURES.UPDATE]: ["root", "admin"],
|
|
104
|
+
[ACTION_SIGNATURES.DELETE]: ["root", "admin"],
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const spSystem = Object.freeze({
|
|
108
|
+
[ACTION_SIGNATURES.CREATE]: ["@system"],
|
|
109
|
+
[ACTION_SIGNATURES.READ]: ["@system"],
|
|
110
|
+
[ACTION_SIGNATURES.UPDATE]: ["@system"],
|
|
111
|
+
[ACTION_SIGNATURES.DELETE]: ["@system"],
|
|
112
|
+
});
|
|
113
|
+
|
|
99
114
|
it("with rules", function () {
|
|
115
|
+
notManifestFilter.schemaLoader = (schemaName) => {
|
|
116
|
+
console.log("schema getter", schemaName);
|
|
117
|
+
switch (schemaName) {
|
|
118
|
+
case "Jelly":
|
|
119
|
+
return {
|
|
120
|
+
name: {
|
|
121
|
+
type: String,
|
|
122
|
+
safe: spGuestC,
|
|
123
|
+
},
|
|
124
|
+
email: {
|
|
125
|
+
type: String,
|
|
126
|
+
safe: spGuestC,
|
|
127
|
+
},
|
|
128
|
+
__version: {
|
|
129
|
+
type: String,
|
|
130
|
+
safe: spSystem,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
case "Post":
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
return undefined;
|
|
137
|
+
};
|
|
100
138
|
const input = {
|
|
101
139
|
modelName: "jelly",
|
|
102
140
|
rules: [
|
|
103
141
|
{
|
|
104
|
-
|
|
105
|
-
fields: ["name"],
|
|
142
|
+
root: true,
|
|
106
143
|
},
|
|
107
144
|
{
|
|
108
|
-
|
|
109
|
-
fields: ["name", "email"],
|
|
145
|
+
auth: true,
|
|
110
146
|
},
|
|
111
147
|
],
|
|
112
148
|
};
|
|
113
|
-
const result = notManifestFilter.clearActionFromRules(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
149
|
+
const result = notManifestFilter.clearActionFromRules(
|
|
150
|
+
//raw actionData
|
|
151
|
+
input,
|
|
152
|
+
//current user statem model name, action name and action signature - minimum if you want to filter
|
|
153
|
+
{
|
|
154
|
+
root: true,
|
|
155
|
+
role: ["root"],
|
|
156
|
+
modelName: "Jelly",
|
|
157
|
+
actionSignature: ACTION_SIGNATURES.READ,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
//what earlier were selected as best suited rule
|
|
161
|
+
root: true,
|
|
162
|
+
}
|
|
163
|
+
);
|
|
117
164
|
expect(result).to.deep.equal({
|
|
118
165
|
modelName: "jelly",
|
|
119
|
-
fields: ["name", "email"],
|
|
166
|
+
fields: ["name", "email"], //if fields ommited, it replaced by ["@safe"], __version is not safe to everyone but system invoked operations
|
|
120
167
|
});
|
|
121
168
|
});
|
|
122
169
|
|
|
@@ -491,7 +538,6 @@ describe("notManifestFilter", function () {
|
|
|
491
538
|
});
|
|
492
539
|
|
|
493
540
|
it("filterRouteAction @safe for READ", () => {
|
|
494
|
-
const actionName = "get";
|
|
495
541
|
const actionData = {
|
|
496
542
|
actionSignature: ACTION_SIGNATURES.READ,
|
|
497
543
|
method: "get",
|
|
@@ -505,32 +551,23 @@ describe("notManifestFilter", function () {
|
|
|
505
551
|
const auth = false;
|
|
506
552
|
const root = false;
|
|
507
553
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
508
|
-
|
|
509
|
-
actions: {},
|
|
510
|
-
};
|
|
554
|
+
|
|
511
555
|
const targetResult = {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
method: "get",
|
|
515
|
-
fields: ["name", "username", "country"],
|
|
516
|
-
},
|
|
517
|
-
},
|
|
556
|
+
method: "get",
|
|
557
|
+
fields: ["name", "username", "country"],
|
|
518
558
|
};
|
|
519
|
-
notManifestFilter.filterRouteAction(
|
|
520
|
-
actionName,
|
|
559
|
+
const result = notManifestFilter.filterRouteAction(
|
|
521
560
|
actionData,
|
|
522
561
|
auth,
|
|
523
562
|
roles,
|
|
524
563
|
root,
|
|
525
|
-
routeMan,
|
|
526
564
|
modelName,
|
|
527
565
|
moduleName
|
|
528
566
|
);
|
|
529
|
-
expect(
|
|
567
|
+
expect(result).to.be.deep.equal(targetResult);
|
|
530
568
|
});
|
|
531
569
|
|
|
532
570
|
it("filterRouteAction @* for READ", () => {
|
|
533
|
-
const actionName = "get";
|
|
534
571
|
const actionData = {
|
|
535
572
|
actionSignature: ACTION_SIGNATURES.READ,
|
|
536
573
|
method: "get",
|
|
@@ -544,44 +581,34 @@ describe("notManifestFilter", function () {
|
|
|
544
581
|
const auth = false;
|
|
545
582
|
const root = false;
|
|
546
583
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
547
|
-
const routeMan = {
|
|
548
|
-
actions: {},
|
|
549
|
-
};
|
|
550
584
|
const targetResult = {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
"email",
|
|
566
|
-
],
|
|
567
|
-
},
|
|
568
|
-
},
|
|
585
|
+
method: "get",
|
|
586
|
+
fields: [
|
|
587
|
+
"_id",
|
|
588
|
+
"userID",
|
|
589
|
+
"role",
|
|
590
|
+
"name",
|
|
591
|
+
"salt",
|
|
592
|
+
"telephone",
|
|
593
|
+
"username",
|
|
594
|
+
"confirm",
|
|
595
|
+
"code",
|
|
596
|
+
"country",
|
|
597
|
+
"email",
|
|
598
|
+
],
|
|
569
599
|
};
|
|
570
|
-
notManifestFilter.filterRouteAction(
|
|
571
|
-
actionName,
|
|
600
|
+
const result = notManifestFilter.filterRouteAction(
|
|
572
601
|
actionData,
|
|
573
602
|
auth,
|
|
574
603
|
roles,
|
|
575
604
|
root,
|
|
576
|
-
routeMan,
|
|
577
605
|
modelName,
|
|
578
606
|
moduleName
|
|
579
607
|
);
|
|
580
|
-
expect(
|
|
608
|
+
expect(result).to.be.deep.equal(targetResult);
|
|
581
609
|
});
|
|
582
610
|
|
|
583
611
|
it("filterRouteAction @*,-@safe for READ", () => {
|
|
584
|
-
const actionName = "get";
|
|
585
612
|
const actionData = {
|
|
586
613
|
actionSignature: ACTION_SIGNATURES.READ,
|
|
587
614
|
method: "get",
|
|
@@ -595,41 +622,32 @@ describe("notManifestFilter", function () {
|
|
|
595
622
|
const auth = false;
|
|
596
623
|
const root = false;
|
|
597
624
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
598
|
-
|
|
599
|
-
actions: {},
|
|
600
|
-
};
|
|
625
|
+
|
|
601
626
|
const targetResult = {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
"email",
|
|
614
|
-
],
|
|
615
|
-
},
|
|
616
|
-
},
|
|
627
|
+
method: "get",
|
|
628
|
+
fields: [
|
|
629
|
+
"_id",
|
|
630
|
+
"userID",
|
|
631
|
+
"role",
|
|
632
|
+
"salt",
|
|
633
|
+
"telephone",
|
|
634
|
+
"confirm",
|
|
635
|
+
"code",
|
|
636
|
+
"email",
|
|
637
|
+
],
|
|
617
638
|
};
|
|
618
|
-
notManifestFilter.filterRouteAction(
|
|
619
|
-
actionName,
|
|
639
|
+
const result = notManifestFilter.filterRouteAction(
|
|
620
640
|
actionData,
|
|
621
641
|
auth,
|
|
622
642
|
roles,
|
|
623
643
|
root,
|
|
624
|
-
routeMan,
|
|
625
644
|
modelName,
|
|
626
645
|
moduleName
|
|
627
646
|
);
|
|
628
|
-
expect(
|
|
647
|
+
expect(result).to.be.deep.equal(targetResult);
|
|
629
648
|
});
|
|
630
649
|
|
|
631
650
|
it("filterRouteAction @* for UPDATE as guest", () => {
|
|
632
|
-
const actionName = "update";
|
|
633
651
|
const actionData = {
|
|
634
652
|
actionSignature: ACTION_SIGNATURES.UPDATE,
|
|
635
653
|
method: "post",
|
|
@@ -643,27 +661,18 @@ describe("notManifestFilter", function () {
|
|
|
643
661
|
const auth = false;
|
|
644
662
|
const root = false;
|
|
645
663
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
646
|
-
const
|
|
647
|
-
actions: {},
|
|
648
|
-
};
|
|
649
|
-
const targetResult = {
|
|
650
|
-
actions: {},
|
|
651
|
-
};
|
|
652
|
-
notManifestFilter.filterRouteAction(
|
|
653
|
-
actionName,
|
|
664
|
+
const result = notManifestFilter.filterRouteAction(
|
|
654
665
|
actionData,
|
|
655
666
|
auth,
|
|
656
667
|
roles,
|
|
657
668
|
root,
|
|
658
|
-
routeMan,
|
|
659
669
|
modelName,
|
|
660
670
|
moduleName
|
|
661
671
|
);
|
|
662
|
-
expect(
|
|
672
|
+
expect(result).to.be.undefined;
|
|
663
673
|
});
|
|
664
674
|
|
|
665
675
|
it("filterRouteAction @safe for CREATE as guest", () => {
|
|
666
|
-
const actionName = "create";
|
|
667
676
|
const actionData = {
|
|
668
677
|
actionSignature: ACTION_SIGNATURES.CREATE,
|
|
669
678
|
method: "put",
|
|
@@ -677,27 +686,18 @@ describe("notManifestFilter", function () {
|
|
|
677
686
|
const auth = false;
|
|
678
687
|
const root = false;
|
|
679
688
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
680
|
-
const
|
|
681
|
-
actions: {},
|
|
682
|
-
};
|
|
683
|
-
const targetResult = {
|
|
684
|
-
actions: {},
|
|
685
|
-
};
|
|
686
|
-
notManifestFilter.filterRouteAction(
|
|
687
|
-
actionName,
|
|
689
|
+
const result = notManifestFilter.filterRouteAction(
|
|
688
690
|
actionData,
|
|
689
691
|
auth,
|
|
690
692
|
roles,
|
|
691
693
|
root,
|
|
692
|
-
routeMan,
|
|
693
694
|
modelName,
|
|
694
695
|
moduleName
|
|
695
696
|
);
|
|
696
|
-
expect(
|
|
697
|
+
expect(result).to.be.undefined;
|
|
697
698
|
});
|
|
698
699
|
|
|
699
700
|
it("filterRouteAction @listFields for READ", () => {
|
|
700
|
-
const actionName = "list";
|
|
701
701
|
notFieldsFilter.addSet("listFields", ["@ID", "@safe"]);
|
|
702
702
|
const actionData = {
|
|
703
703
|
actionSignature: ACTION_SIGNATURES.READ,
|
|
@@ -712,28 +712,19 @@ describe("notManifestFilter", function () {
|
|
|
712
712
|
const auth = false;
|
|
713
713
|
const root = false;
|
|
714
714
|
const roles = [DEFAULT_USER_ROLE_FOR_GUEST];
|
|
715
|
-
const routeMan = {
|
|
716
|
-
actions: {},
|
|
717
|
-
};
|
|
718
715
|
const targetResult = {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
method: "get",
|
|
722
|
-
fields: ["userID", "name", "username", "country"],
|
|
723
|
-
},
|
|
724
|
-
},
|
|
716
|
+
method: "get",
|
|
717
|
+
fields: ["userID", "name", "username", "country"],
|
|
725
718
|
};
|
|
726
|
-
notManifestFilter.filterRouteAction(
|
|
727
|
-
actionName,
|
|
719
|
+
const result = notManifestFilter.filterRouteAction(
|
|
728
720
|
actionData,
|
|
729
721
|
auth,
|
|
730
722
|
roles,
|
|
731
723
|
root,
|
|
732
|
-
routeMan,
|
|
733
724
|
modelName,
|
|
734
725
|
moduleName
|
|
735
726
|
);
|
|
736
|
-
expect(
|
|
727
|
+
expect(result).to.be.deep.equal(targetResult);
|
|
737
728
|
});
|
|
738
729
|
});
|
|
739
730
|
});
|
package/test/notRoute.js
CHANGED
|
@@ -27,21 +27,23 @@ describe("notRoute", function () {
|
|
|
27
27
|
|
|
28
28
|
describe("selectRule", function () {
|
|
29
29
|
it("User(auth) request, post.list action", function () {
|
|
30
|
-
|
|
30
|
+
const authData = require("./fakes").fakeAuthData({
|
|
31
31
|
auth: true,
|
|
32
|
+
role: ["user"],
|
|
33
|
+
primaryRole: "user",
|
|
32
34
|
});
|
|
33
35
|
let req = {},
|
|
34
36
|
actionData = {
|
|
35
37
|
method: "get",
|
|
36
38
|
rules: [
|
|
37
39
|
{
|
|
38
|
-
|
|
40
|
+
root: true,
|
|
39
41
|
},
|
|
40
42
|
{
|
|
41
43
|
auth: true,
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
|
-
|
|
46
|
+
auth: false,
|
|
45
47
|
},
|
|
46
48
|
],
|
|
47
49
|
},
|
|
@@ -52,12 +54,12 @@ describe("notRoute", function () {
|
|
|
52
54
|
"list",
|
|
53
55
|
actionData
|
|
54
56
|
);
|
|
55
|
-
expect(routerAction.selectRule(
|
|
57
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
56
58
|
auth: true,
|
|
57
59
|
});
|
|
58
60
|
});
|
|
59
61
|
it("User(!auth) request, post.list action", function () {
|
|
60
|
-
|
|
62
|
+
const authData = require("./fakes").fakeAuthData({
|
|
61
63
|
auth: false,
|
|
62
64
|
});
|
|
63
65
|
let req = {},
|
|
@@ -82,7 +84,7 @@ describe("notRoute", function () {
|
|
|
82
84
|
"list",
|
|
83
85
|
actionData
|
|
84
86
|
);
|
|
85
|
-
expect(routerAction.selectRule(
|
|
87
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
86
88
|
auth: false,
|
|
87
89
|
});
|
|
88
90
|
});
|
|
@@ -112,9 +114,10 @@ describe("notRoute", function () {
|
|
|
112
114
|
});
|
|
113
115
|
|
|
114
116
|
it("User(auth, manager) request, post.listAll action", function () {
|
|
115
|
-
|
|
117
|
+
const authData = require("./fakes").fakeAuthData({
|
|
116
118
|
auth: true,
|
|
117
119
|
role: ["manager"],
|
|
120
|
+
primaryRole: "admin",
|
|
118
121
|
});
|
|
119
122
|
let req = {},
|
|
120
123
|
actionData = {
|
|
@@ -136,14 +139,14 @@ describe("notRoute", function () {
|
|
|
136
139
|
"listAll",
|
|
137
140
|
actionData
|
|
138
141
|
);
|
|
139
|
-
expect(routerAction.selectRule(
|
|
142
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
140
143
|
auth: true,
|
|
141
144
|
role: ["manager"],
|
|
142
145
|
});
|
|
143
146
|
});
|
|
144
147
|
|
|
145
148
|
it("Admin request, post.listAll action", function () {
|
|
146
|
-
|
|
149
|
+
const authData = require("./fakes").fakeAuthData({
|
|
147
150
|
auth: true,
|
|
148
151
|
root: true,
|
|
149
152
|
primaryRole: DEFAULT_USER_ROLE_FOR_ROOT,
|
|
@@ -169,7 +172,7 @@ describe("notRoute", function () {
|
|
|
169
172
|
"listAll",
|
|
170
173
|
actionData
|
|
171
174
|
);
|
|
172
|
-
expect(routerAction.selectRule(
|
|
175
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
173
176
|
root: true,
|
|
174
177
|
});
|
|
175
178
|
});
|