not-node 5.1.44 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.eslintrc.json +32 -38
  2. package/index.js +6 -0
  3. package/package.json +12 -11
  4. package/src/app.js +2 -2
  5. package/src/auth/index.js +0 -2
  6. package/src/auth/routes.js +25 -61
  7. package/src/auth/rules.js +8 -7
  8. package/src/common.js +19 -0
  9. package/src/identity/exceptions.js +17 -0
  10. package/src/identity/identity.js +61 -0
  11. package/src/identity/index.js +35 -0
  12. package/src/identity/providers/session.js +137 -0
  13. package/src/identity/providers/token.js +255 -0
  14. package/src/manifest/result.filter.js +268 -0
  15. package/src/manifest/route.js +6 -36
  16. package/static2.js +24 -0
  17. package/test/auth/identity.js +0 -0
  18. package/test/auth/routes.js +1 -1
  19. package/test/auth.js +427 -229
  20. package/test/env.js +20 -20
  21. package/test/fields.js +3 -2
  22. package/test/identity/identity.js +1 -0
  23. package/test/identity/index.js +12 -0
  24. package/test/identity/providers/session.js +227 -0
  25. package/test/identity/providers/token.js +244 -0
  26. package/test/identity.js +5 -0
  27. package/test/init/app.js +359 -365
  28. package/test/init/bodyparser.js +37 -39
  29. package/test/init/compression.js +29 -31
  30. package/test/init/cors.js +38 -39
  31. package/test/init/db.js +60 -64
  32. package/test/init/env.js +109 -114
  33. package/test/init/express.js +50 -47
  34. package/test/init/fileupload.js +30 -32
  35. package/test/init/http.js +258 -240
  36. package/test/init/informer.js +20 -24
  37. package/test/init/methodoverride.js +29 -31
  38. package/test/init/middleware.js +56 -58
  39. package/test/init/modules.js +19 -19
  40. package/test/init/monitoring.js +22 -22
  41. package/test/init/routes.js +185 -171
  42. package/test/init/security.js +77 -103
  43. package/test/init/sessions/mongoose.js +56 -57
  44. package/test/init/sessions/redis.js +59 -61
  45. package/test/init/sessions.js +84 -79
  46. package/test/init/static.js +108 -113
  47. package/test/init/template.js +46 -41
  48. package/test/notInit.js +217 -217
  49. package/test/notManifest.js +232 -191
  50. package/test/notRoute.js +1022 -799
  51. package/test/result.filter.js +422 -0
  52. package/src/auth/session.js +0 -151
  53. package/test/auth/session.js +0 -266
package/test/notRoute.js CHANGED
@@ -1,832 +1,1055 @@
1
- const
2
- HttpError = require('../src/error').Http,
3
- notRoute = require('../src/manifest/route'),
4
- {
5
- copyObj
6
- } = require('../src/common'),
7
- expect = require('chai').expect;
1
+ const HttpError = require("../src/error").Http,
2
+ notRoute = require("../src/manifest/route"),
3
+ expect = require("chai").expect;
8
4
 
9
- describe('notRoute', function() {
10
- describe('init call', function() {
11
- it('Init object', function() {
12
- let routerAction = new notRoute({}, 'not-user', 'user', 'getAll', {});
13
- expect(routerAction).to.have.keys(['notApp', 'routeName', 'moduleName', 'actionName', 'actionData']);
5
+ describe("notRoute", function () {
6
+ describe("init call", function () {
7
+ it("Init object", function () {
8
+ let routerAction = new notRoute(
9
+ {},
10
+ "not-user",
11
+ "user",
12
+ "getAll",
13
+ {}
14
+ );
15
+ expect(routerAction).to.have.keys([
16
+ "notApp",
17
+ "routeName",
18
+ "moduleName",
19
+ "actionName",
20
+ "actionData",
21
+ ]);
22
+ });
14
23
  });
15
- });
16
24
 
17
- describe('selectRule', function() {
18
- it('User(auth) request, post.list action', function() {
19
- let req = {
20
- session: {
21
- user: true,
22
- role: 'root'
23
- }
24
- },
25
- actionData = {
26
- method: 'get',
27
- rules: [{
28
- auth: false
29
- }, {
30
- auth: true
31
- }, {
32
- root: true
33
- }]
34
- },
35
- routerAction = new notRoute({}, 'not-user', 'user', 'list', actionData);
36
- expect(routerAction.selectRule(req)).to.deep.equal({
37
- auth: true
38
- });
39
- });
40
- it('User(!auth) request, post.list action', function() {
41
- let req = {
42
- session: {
43
- user: false
44
- }
45
- },
46
- actionData = {
47
- method: 'get',
48
- rules: [{
49
- root: true
50
- }, {
51
- auth: false
52
- }, {
53
- auth: true
54
- }]
55
- },
56
- routerAction = new notRoute({}, 'not-user', 'user', 'list', actionData);
57
- expect(routerAction.selectRule(req)).to.deep.equal({
58
- auth: false
59
- });
60
- });
25
+ describe("selectRule", function () {
26
+ it("User(auth) request, post.list action", function () {
27
+ let req = {
28
+ session: {
29
+ user: true,
30
+ role: "root",
31
+ },
32
+ },
33
+ actionData = {
34
+ method: "get",
35
+ rules: [
36
+ {
37
+ auth: false,
38
+ },
39
+ {
40
+ auth: true,
41
+ },
42
+ {
43
+ root: true,
44
+ },
45
+ ],
46
+ },
47
+ routerAction = new notRoute(
48
+ {},
49
+ "not-user",
50
+ "user",
51
+ "list",
52
+ actionData
53
+ );
54
+ expect(routerAction.selectRule(req)).to.deep.equal({
55
+ auth: true,
56
+ });
57
+ });
58
+ it("User(!auth) request, post.list action", function () {
59
+ let req = {
60
+ session: {
61
+ user: false,
62
+ },
63
+ },
64
+ actionData = {
65
+ method: "get",
66
+ rules: [
67
+ {
68
+ root: true,
69
+ },
70
+ {
71
+ auth: false,
72
+ },
73
+ {
74
+ auth: true,
75
+ },
76
+ ],
77
+ },
78
+ routerAction = new notRoute(
79
+ {},
80
+ "not-user",
81
+ "user",
82
+ "list",
83
+ actionData
84
+ );
85
+ expect(routerAction.selectRule(req)).to.deep.equal({
86
+ auth: false,
87
+ });
88
+ });
61
89
 
62
- it('User(auth) request, post.listAll action', function() {
63
- let req = {
64
- session: {
65
- user: true
66
- }
67
- },
68
- actionData = {
69
- method: 'get',
70
- rules: [{
71
- auth: true,
72
- role: ['manager']
73
- }, {
74
- root: true
75
- }]
76
- },
77
- routerAction = new notRoute({}, 'not-user', 'user', 'listAll', actionData);
78
- expect(routerAction.selectRule(req)).to.deep.equal(null);
79
- });
90
+ it("User(auth) request, post.listAll action", function () {
91
+ let req = {
92
+ session: {
93
+ user: true,
94
+ },
95
+ },
96
+ actionData = {
97
+ method: "get",
98
+ rules: [
99
+ {
100
+ auth: true,
101
+ role: ["manager"],
102
+ },
103
+ {
104
+ root: true,
105
+ },
106
+ ],
107
+ },
108
+ routerAction = new notRoute(
109
+ {},
110
+ "not-user",
111
+ "user",
112
+ "listAll",
113
+ actionData
114
+ );
115
+ expect(routerAction.selectRule(req)).to.deep.equal(null);
116
+ });
80
117
 
81
- it('User(auth, manager) request, post.listAll action', function() {
82
- let req = {
83
- session: {
84
- user: true,
85
- role: ['manager']
86
- }
87
- },
88
- actionData = {
89
- method: 'get',
90
- rules: [{
91
- auth: true,
92
- role: ['manager']
93
- }, {
94
- root: true
95
- }]
96
- },
97
- routerAction = new notRoute({}, 'not-user', 'user', 'listAll', actionData);
98
- expect(routerAction.selectRule(req)).to.deep.equal({
99
- auth: true,
100
- role: ['manager']
101
- });
102
- });
118
+ it("User(auth, manager) request, post.listAll action", function () {
119
+ let req = {
120
+ session: {
121
+ user: true,
122
+ role: ["manager"],
123
+ },
124
+ },
125
+ actionData = {
126
+ method: "get",
127
+ rules: [
128
+ {
129
+ auth: true,
130
+ role: ["manager"],
131
+ },
132
+ {
133
+ root: true,
134
+ },
135
+ ],
136
+ },
137
+ routerAction = new notRoute(
138
+ {},
139
+ "not-user",
140
+ "user",
141
+ "listAll",
142
+ actionData
143
+ );
144
+ expect(routerAction.selectRule(req)).to.deep.equal({
145
+ auth: true,
146
+ role: ["manager"],
147
+ });
148
+ });
103
149
 
104
- it('Admin request, post.listAll action', function() {
105
- let req = {
106
- session: {
107
- user: true,
108
- role: 'root'
109
- }
110
- },
111
- actionData = {
112
- method: 'get',
113
- rules: [{
114
- root: true
115
- }, {
116
- auth: true,
117
- role: ['manager']
118
- }]
119
- },
120
- routerAction = new notRoute({}, 'not-user', 'user', 'listAll', actionData);
121
- expect(routerAction.selectRule(req)).to.deep.equal({
122
- root: true
123
- });
124
- });
150
+ it("Admin request, post.listAll action", function () {
151
+ let req = {
152
+ session: {
153
+ user: true,
154
+ role: "root",
155
+ },
156
+ },
157
+ actionData = {
158
+ method: "get",
159
+ rules: [
160
+ {
161
+ root: true,
162
+ },
163
+ {
164
+ auth: true,
165
+ role: ["manager"],
166
+ },
167
+ ],
168
+ },
169
+ routerAction = new notRoute(
170
+ {},
171
+ "not-user",
172
+ "user",
173
+ "listAll",
174
+ actionData
175
+ );
176
+ expect(routerAction.selectRule(req)).to.deep.equal({
177
+ root: true,
178
+ });
179
+ });
125
180
 
126
- it('Guest request, post.list action', function() {
127
- let req = {
128
- session: {
129
- user: false
130
- }
131
- },
132
- actionData = {
133
- method: 'get',
134
- auth: false
135
- },
136
- routerAction = new notRoute({}, 'not-user', 'user', 'list', actionData),
137
- rule = routerAction.selectRule(req);
138
- expect(rule).to.have.keys(['method', 'auth']);
139
- expect(rule.method).to.be.equal('get');
140
- expect(rule.auth).to.be.equal(false);
141
- });
181
+ it("Guest request, post.list action", function () {
182
+ let req = {
183
+ session: {
184
+ user: false,
185
+ },
186
+ },
187
+ actionData = {
188
+ method: "get",
189
+ auth: false,
190
+ },
191
+ routerAction = new notRoute(
192
+ {},
193
+ "not-user",
194
+ "user",
195
+ "list",
196
+ actionData
197
+ ),
198
+ rule = routerAction.selectRule(req);
199
+ expect(rule).to.have.keys(["method", "auth"]);
200
+ expect(rule.method).to.be.equal("get");
201
+ expect(rule.auth).to.be.equal(false);
202
+ });
142
203
 
143
- it('actionData - null', function() {
144
- let req = {
145
- session: {
146
- user: false
147
- }
148
- },
149
- actionData = false,
150
- routerAction = new notRoute({}, 'not-user', 'user', 'list', actionData),
151
- rule = routerAction.selectRule(req);
152
- expect(rule).to.be.null;
204
+ it("actionData - null", function () {
205
+ let req = {
206
+ session: {
207
+ user: false,
208
+ },
209
+ },
210
+ actionData = false,
211
+ routerAction = new notRoute(
212
+ {},
213
+ "not-user",
214
+ "user",
215
+ "list",
216
+ actionData
217
+ ),
218
+ rule = routerAction.selectRule(req);
219
+ expect(rule).to.be.null;
220
+ });
153
221
  });
154
- });
155
222
 
156
- describe('exec', function() {
157
- //manifest.registerRoutesPath('', __dirname + '/routes');
158
- //manifest.getManifest();
159
- let fakeRoute = {
160
- list: () => {
161
- return 'list';
162
- }
163
- },
164
- fakeMod = {
165
- getRoute: () => {
166
- return fakeRoute;
167
- }
168
- },
169
- fakeNotApp = {
170
- getModule: () => {
171
- return fakeMod;
172
- }
173
- };
174
- it('Guest request post.list', function(done) {
175
- let req = {
176
- session: {
177
- user: false
178
- }
179
- },
180
- actionData = {
181
- method: 'get',
182
- auth: false
183
- },
184
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
185
- routerAction.exec(req)
186
- .then((result) => {
187
- expect(result).to.deep.equal('list');
188
- done();
189
- })
190
- .catch(done);
191
- //console.log('result', routerAction, actionData, result);
223
+ describe("exec", function () {
224
+ //manifest.registerRoutesPath('', __dirname + '/routes');
225
+ //manifest.getManifest();
226
+ let fakeRoute = {
227
+ list: () => {
228
+ return "list";
229
+ },
230
+ },
231
+ fakeMod = {
232
+ getRoute: () => {
233
+ return fakeRoute;
234
+ },
235
+ },
236
+ fakeNotApp = {
237
+ getModule: () => {
238
+ return fakeMod;
239
+ },
240
+ };
241
+ it("Guest request post.list", function (done) {
242
+ let req = {
243
+ session: {
244
+ user: false,
245
+ },
246
+ },
247
+ actionData = {
248
+ method: "get",
249
+ auth: false,
250
+ },
251
+ routerAction = new notRoute(
252
+ fakeNotApp,
253
+ "not-user",
254
+ "post",
255
+ "list",
256
+ actionData
257
+ );
258
+ routerAction
259
+ .exec(req)
260
+ .then((result) => {
261
+ expect(result).to.deep.equal("list");
262
+ done();
263
+ })
264
+ .catch(done);
265
+ //console.log('result', routerAction, actionData, result);
266
+ });
192
267
 
193
- });
268
+ it("Admin request post.listAll", function (done) {
269
+ let fakeRoute = {
270
+ _listAll: () => {
271
+ return "_listAll";
272
+ },
273
+ },
274
+ fakeMod = {
275
+ getRoute: () => {
276
+ return fakeRoute;
277
+ },
278
+ },
279
+ fakeNotApp = {
280
+ getModule: () => {
281
+ return fakeMod;
282
+ },
283
+ };
284
+ let req = {
285
+ session: {
286
+ user: true,
287
+ role: "root",
288
+ },
289
+ },
290
+ actionData = {
291
+ method: "get",
292
+ rules: [
293
+ {
294
+ auth: true,
295
+ role: ["manager"],
296
+ },
297
+ {
298
+ root: true,
299
+ },
300
+ ],
301
+ },
302
+ routerAction = new notRoute(
303
+ fakeNotApp,
304
+ "not-user",
305
+ "post",
306
+ "listAll",
307
+ actionData
308
+ );
309
+ routerAction
310
+ .exec(req)
311
+ .then((result) => {
312
+ expect(result).to.deep.equal("_listAll");
313
+ done();
314
+ })
315
+ .catch(done);
316
+ });
194
317
 
195
- it('Admin request post.listAll', function(done) {
196
- let fakeRoute = {
197
- _listAll: () => {
198
- return '_listAll';
199
- }
200
- },
201
- fakeMod = {
202
- getRoute: () => {
203
- return fakeRoute;
204
- }
205
- },
206
- fakeNotApp = {
207
- getModule: () => {
208
- return fakeMod;
209
- }
210
- };
211
- let req = {
212
- session: {
213
- user: true,
214
- role: 'root'
215
- }
216
- },
217
- actionData = {
218
- method: 'get',
219
- rules: [{
220
- auth: true,
221
- role: ['manager']
222
- }, {
223
- root: true
224
- }]
225
- },
226
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'listAll', actionData);
227
- routerAction.exec(req)
228
- .then((result) => {
229
- expect(result).to.deep.equal('_listAll');
230
- done()
231
- })
232
- .catch(done);
233
- });
318
+ it("Auth with manager role request post.listAll", function (done) {
319
+ let fakeRoute = {
320
+ listAll: () => {
321
+ return "listAll";
322
+ },
323
+ },
324
+ fakeMod = {
325
+ getRoute: () => {
326
+ return fakeRoute;
327
+ },
328
+ },
329
+ fakeNotApp = {
330
+ getModule: () => {
331
+ return fakeMod;
332
+ },
333
+ };
334
+ let req = {
335
+ session: {
336
+ user: true,
337
+ role: "manager",
338
+ },
339
+ },
340
+ actionData = {
341
+ method: "get",
342
+ rules: [
343
+ {
344
+ root: true,
345
+ },
346
+ {
347
+ auth: true,
348
+ role: ["manager"],
349
+ },
350
+ ],
351
+ },
352
+ routerAction = new notRoute(
353
+ fakeNotApp,
354
+ "not-user",
355
+ "post",
356
+ "listAll",
357
+ actionData
358
+ );
359
+ routerAction
360
+ .exec(req)
361
+ .then((result) => {
362
+ expect(result).to.deep.equal("listAll");
363
+ done();
364
+ })
365
+ .catch(done);
366
+ });
234
367
 
235
- it('Auth with manager role request post.listAll', function(done) {
236
- let fakeRoute = {
237
- listAll: () => {
238
- return 'listAll';
239
- }
240
- },
241
- fakeMod = {
242
- getRoute: () => {
243
- return fakeRoute;
244
- }
245
- },
246
- fakeNotApp = {
247
- getModule: () => {
248
- return fakeMod;
249
- }
250
- };
251
- let req = {
252
- session: {
253
- user: true,
254
- role: 'manager'
255
- }
256
- },
257
- actionData = {
258
- method: 'get',
259
- rules: [{
260
- root: true
261
- }, {
262
- auth: true,
263
- role: ['manager']
264
- }]
265
- },
266
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'listAll', actionData);
267
- routerAction.exec(req)
268
- .then((result) => {
269
- expect(result).to.deep.equal('listAll');
270
- done();
271
- })
272
- .catch(done);
273
- });
368
+ it("Auth request post.list", function (done) {
369
+ let fakeRoute = {
370
+ list: () => {
371
+ return "list";
372
+ },
373
+ },
374
+ fakeMod = {
375
+ getRoute: () => {
376
+ return fakeRoute;
377
+ },
378
+ },
379
+ fakeNotApp = {
380
+ getModule: () => {
381
+ return fakeMod;
382
+ },
383
+ };
384
+ let req = {
385
+ session: {
386
+ user: true,
387
+ },
388
+ },
389
+ actionData = {
390
+ method: "get",
391
+ rules: [
392
+ {
393
+ auth: true,
394
+ },
395
+ {
396
+ auth: false,
397
+ },
398
+ {
399
+ root: true,
400
+ },
401
+ ],
402
+ },
403
+ routerAction = new notRoute(
404
+ fakeNotApp,
405
+ "not-user",
406
+ "post",
407
+ "list",
408
+ actionData
409
+ );
410
+ routerAction
411
+ .exec(req)
412
+ .then((result) => {
413
+ expect(result).to.deep.equal("list");
414
+ done();
415
+ })
416
+ .catch(done);
417
+ });
274
418
 
275
- it('Auth request post.list', function(done) {
276
- let fakeRoute = {
277
- list: () => {
278
- return 'list';
279
- }
280
- },
281
- fakeMod = {
282
- getRoute: () => {
283
- return fakeRoute;
284
- }
285
- },
286
- fakeNotApp = {
287
- getModule: () => {
288
- return fakeMod;
289
- }
290
- };
291
- let req = {
292
- session: {
293
- user: true
294
- }
295
- },
296
- actionData = {
297
- method: 'get',
298
- rules: [{
299
- auth: true
300
- }, {
301
- auth: false
302
- }, {
303
- root: true
304
- }]
305
- },
306
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
307
- routerAction.exec(req)
308
- .then((result) => {
309
- expect(result).to.deep.equal('list');
310
- done();
311
- })
312
- .catch(done);
313
- });
419
+ it("Admin request post.list", function (done) {
420
+ let fakeRoute = {
421
+ _list: () => {
422
+ return "_list";
423
+ },
424
+ },
425
+ fakeMod = {
426
+ getRoute: () => {
427
+ return fakeRoute;
428
+ },
429
+ },
430
+ fakeNotApp = {
431
+ getModule: () => {
432
+ return fakeMod;
433
+ },
434
+ };
435
+ let req = {
436
+ session: {
437
+ user: true,
438
+ role: "root",
439
+ },
440
+ },
441
+ actionData = {
442
+ method: "get",
443
+ rules: [
444
+ {
445
+ auth: false,
446
+ },
447
+ {
448
+ root: true,
449
+ },
450
+ {
451
+ auth: true,
452
+ },
453
+ ],
454
+ },
455
+ routerAction = new notRoute(
456
+ fakeNotApp,
457
+ "not-user",
458
+ "post",
459
+ "list",
460
+ actionData
461
+ );
462
+ routerAction
463
+ .exec(req)
464
+ .then((result) => {
465
+ expect(result).to.deep.equal("_list");
466
+ done();
467
+ })
468
+ .catch(done);
469
+ });
314
470
 
315
- it('Admin request post.list', function(done) {
316
- let fakeRoute = {
317
- _list: () => {
318
- return '_list';
319
- }
320
- },
321
- fakeMod = {
322
- getRoute: () => {
323
- return fakeRoute;
324
- }
325
- },
326
- fakeNotApp = {
327
- getModule: () => {
328
- return fakeMod;
329
- }
330
- };
331
- let req = {
332
- session: {
333
- user: true,
334
- role: 'root'
335
- }
336
- },
337
- actionData = {
338
- method: 'get',
339
- rules: [{
340
- auth: false,
341
- }, {
342
- root: true,
343
- }, {
344
- auth: true
345
- }]
346
- },
347
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
348
- routerAction.exec(req)
349
- .then((result) => {
350
- expect(result).to.deep.equal('_list');
351
- done();
352
- })
353
- .catch(done);
354
- });
471
+ it("Admin request post.list with actionName override", function (done) {
472
+ let fakeRoute = {
473
+ manager_listAll: () => {
474
+ return "manager_listAll";
475
+ },
476
+ },
477
+ fakeMod = {
478
+ getRoute: () => {
479
+ return fakeRoute;
480
+ },
481
+ },
482
+ fakeNotApp = {
483
+ report(e) {
484
+ done(e);
485
+ },
486
+ getModule: () => {
487
+ return fakeMod;
488
+ },
489
+ };
490
+ let req = {
491
+ session: {
492
+ user: true,
493
+ role: "root",
494
+ },
495
+ },
496
+ actionData = {
497
+ method: "get",
498
+ rules: [
499
+ {
500
+ auth: false,
501
+ },
502
+ {
503
+ root: true,
504
+ actionName: "manager_listAll",
505
+ },
506
+ {
507
+ auth: true,
508
+ },
509
+ ],
510
+ },
511
+ routerAction = new notRoute(
512
+ fakeNotApp,
513
+ "not-user",
514
+ "post",
515
+ "list",
516
+ actionData
517
+ );
518
+ routerAction
519
+ .exec(req)
520
+ .then((result) => {
521
+ expect(result).to.deep.equal("manager_listAll");
522
+ done();
523
+ })
524
+ .catch(done);
525
+ });
355
526
 
356
- it('Admin request post.list with actionName override', function(done) {
357
- let fakeRoute = {
358
- manager_listAll: () => {
359
- return 'manager_listAll';
360
- }
361
- },
362
- fakeMod = {
363
- getRoute: () => {
364
- return fakeRoute;
365
- }
366
- },
367
- fakeNotApp = {
368
- report(e) {
369
- done(e);
370
- },
371
- getModule: () => {
372
- return fakeMod;
373
- }
374
- };
375
- let req = {
376
- session: {
377
- user: true,
378
- role: 'root'
379
- }
380
- },
381
- actionData = {
382
- method: 'get',
383
- rules: [{
384
- auth: false,
385
- }, {
386
- root: true,
387
- actionName: 'manager_listAll'
388
- }, {
389
- auth: true
390
- }]
391
- },
392
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
393
- routerAction.exec(req)
394
- .then((result) => {
395
- expect(result).to.deep.equal('manager_listAll');
396
- done();
397
- })
398
- .catch(done);
399
- });
527
+ it("Admin request post.list with actionPrefix override", function (done) {
528
+ let fakeRoute = {
529
+ __listAll: () => {
530
+ return "__listAll";
531
+ },
532
+ },
533
+ fakeMod = {
534
+ getRoute: () => {
535
+ return fakeRoute;
536
+ },
537
+ },
538
+ fakeNotApp = {
539
+ report(e) {
540
+ done(e);
541
+ },
542
+ getModule: () => {
543
+ return fakeMod;
544
+ },
545
+ };
546
+ let req = {
547
+ session: {
548
+ user: true,
549
+ role: "root",
550
+ },
551
+ },
552
+ actionData = {
553
+ method: "get",
554
+ rules: [
555
+ {
556
+ auth: false,
557
+ },
558
+ {
559
+ root: true,
560
+ actionPrefix: "__",
561
+ },
562
+ {
563
+ auth: true,
564
+ },
565
+ ],
566
+ },
567
+ routerAction = new notRoute(
568
+ fakeNotApp,
569
+ "not-user",
570
+ "post",
571
+ "listAll",
572
+ actionData
573
+ );
574
+ routerAction
575
+ .exec(req)
576
+ .then((result) => {
577
+ expect(result).to.deep.equal("__listAll");
578
+ done();
579
+ })
580
+ .catch(done);
581
+ });
400
582
 
401
- it('Admin request post.list with actionPrefix override', function(done) {
402
- let fakeRoute = {
403
- __listAll: () => {
404
- return '__listAll';
405
- }
406
- },
407
- fakeMod = {
408
- getRoute: () => {
409
- return fakeRoute;
410
- }
411
- },
412
- fakeNotApp = {
413
- report(e) {
414
- done(e);
415
- },
416
- getModule: () => {
417
- return fakeMod;
418
- }
419
- };
420
- let req = {
421
- session: {
422
- user: true,
423
- role: 'root'
424
- }
425
- },
426
- actionData = {
427
- method: 'get',
428
- rules: [{
429
- auth: false,
430
- }, {
431
- root: true,
432
- actionPrefix: '__'
433
- }, {
434
- auth: true
435
- }]
436
- },
437
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'listAll', actionData);
438
- routerAction.exec(req)
439
- .then((result) => {
440
- expect(result).to.deep.equal('__listAll');
441
- done();
442
- })
443
- .catch(done);
444
- });
583
+ it("Auth request post.list with actionPrefix override", function (done) {
584
+ let fakeRoute = {
585
+ __list: () => {
586
+ return "__list";
587
+ },
588
+ },
589
+ fakeMod = {
590
+ getRoute: () => {
591
+ return fakeRoute;
592
+ },
593
+ },
594
+ fakeNotApp = {
595
+ report(e) {
596
+ done(e);
597
+ },
598
+ getModule: () => {
599
+ return fakeMod;
600
+ },
601
+ };
602
+ let req = {
603
+ session: {
604
+ user: true,
605
+ },
606
+ },
607
+ actionData = {
608
+ method: "get",
609
+ rules: [
610
+ {
611
+ auth: false,
612
+ },
613
+ {
614
+ root: true,
615
+ },
616
+ {
617
+ auth: true,
618
+ actionPrefix: "__",
619
+ },
620
+ ],
621
+ },
622
+ routerAction = new notRoute(
623
+ fakeNotApp,
624
+ "not-user",
625
+ "post",
626
+ "list",
627
+ actionData
628
+ );
629
+ routerAction
630
+ .exec(req)
631
+ .then((result) => {
632
+ expect(result).to.deep.equal("__list");
633
+ done();
634
+ })
635
+ .catch(done);
636
+ });
445
637
 
446
- it('Auth request post.list with actionPrefix override', function(done) {
447
- let fakeRoute = {
448
- __list: () => {
449
- return '__list';
450
- }
451
- },
452
- fakeMod = {
453
- getRoute: () => {
454
- return fakeRoute;
455
- }
456
- },
457
- fakeNotApp = {
458
- report(e) {
459
- done(e);
460
- },
461
- getModule: () => {
462
- return fakeMod;
463
- }
464
- };
465
- let req = {
466
- session: {
467
- user: true
468
- }
469
- },
470
- actionData = {
471
- method: 'get',
472
- rules: [{
473
- auth: false,
474
- }, {
475
- root: true
476
- }, {
477
- auth: true,
478
- actionPrefix: '__'
479
- }]
480
- },
481
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
482
- routerAction.exec(req)
483
- .then((result) => {
484
- expect(result).to.deep.equal('__list');
485
- done();
486
- })
487
- .catch(done);
488
- });
638
+ it("Auth request post.list with actionName override", function (done) {
639
+ let fakeRoute = {
640
+ manager_listAll: () => {
641
+ return "manager_listAll";
642
+ },
643
+ },
644
+ fakeMod = {
645
+ getRoute: () => {
646
+ return fakeRoute;
647
+ },
648
+ },
649
+ fakeNotApp = {
650
+ report(e) {
651
+ done(e);
652
+ },
653
+ getModule: () => {
654
+ return fakeMod;
655
+ },
656
+ };
657
+ let req = {
658
+ session: {
659
+ user: true,
660
+ },
661
+ },
662
+ actionData = {
663
+ method: "get",
664
+ rules: [
665
+ {
666
+ auth: false,
667
+ },
668
+ {
669
+ root: true,
670
+ },
671
+ {
672
+ auth: true,
673
+ actionName: "manager_listAll",
674
+ },
675
+ ],
676
+ },
677
+ routerAction = new notRoute(
678
+ fakeNotApp,
679
+ "not-user",
680
+ "post",
681
+ "list",
682
+ actionData
683
+ );
684
+ routerAction
685
+ .exec(req)
686
+ .then((result) => {
687
+ expect(result).to.deep.equal("manager_listAll");
688
+ done();
689
+ })
690
+ .catch(done);
691
+ });
489
692
 
490
- it('Auth request post.list with actionName override', function(done) {
491
- let fakeRoute = {
492
- manager_listAll: () => {
493
- return 'manager_listAll';
494
- }
495
- },
496
- fakeMod = {
497
- getRoute: () => {
498
- return fakeRoute;
499
- }
500
- },
501
- fakeNotApp = {
502
- report(e) {
503
- done(e);
504
- },
505
- getModule: () => {
506
- return fakeMod;
507
- }
508
- };
509
- let req = {
510
- session: {
511
- user: true
512
- }
513
- },
514
- actionData = {
515
- method: 'get',
516
- rules: [{
517
- auth: false,
518
- }, {
519
- root: true
520
- }, {
521
- auth: true,
522
- actionName: 'manager_listAll'
523
- }]
524
- },
525
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
526
- routerAction.exec(req)
527
- .then((result) => {
528
- expect(result).to.deep.equal('manager_listAll');
529
- done();
530
- })
531
- .catch(done);
532
- });
693
+ it("Auth with manager role request post.list with actionPrefix override", function (done) {
694
+ let fakeRoute = {
695
+ __list: () => {
696
+ return "__list";
697
+ },
698
+ },
699
+ fakeMod = {
700
+ getRoute: () => {
701
+ return fakeRoute;
702
+ },
703
+ },
704
+ fakeNotApp = {
705
+ report(e) {
706
+ done(e);
707
+ },
708
+ getModule: () => {
709
+ return fakeMod;
710
+ },
711
+ };
712
+ let req = {
713
+ session: {
714
+ user: true,
715
+ role: "manager",
716
+ },
717
+ },
718
+ actionData = {
719
+ method: "get",
720
+ rules: [
721
+ {
722
+ auth: false,
723
+ },
724
+ {
725
+ root: true,
726
+ },
727
+ {
728
+ auth: true,
729
+ role: "manager",
730
+ actionPrefix: "__",
731
+ },
732
+ ],
733
+ },
734
+ routerAction = new notRoute(
735
+ fakeNotApp,
736
+ "not-user",
737
+ "post",
738
+ "list",
739
+ actionData
740
+ );
741
+ routerAction
742
+ .exec(req)
743
+ .then((result) => {
744
+ expect(result).to.deep.equal("__list");
745
+ done();
746
+ })
747
+ .catch(done);
748
+ });
533
749
 
534
- it('Auth with manager role request post.list with actionPrefix override', function(done) {
535
- let fakeRoute = {
536
- __list: () => {
537
- return '__list';
538
- }
539
- },
540
- fakeMod = {
541
- getRoute: () => {
542
- return fakeRoute;
543
- }
544
- },
545
- fakeNotApp = {
546
- report(e) {
547
- done(e);
548
- },
549
- getModule: () => {
550
- return fakeMod;
551
- }
552
- };
553
- let req = {
554
- session: {
555
- user: true,
556
- role: 'manager'
557
- }
558
- },
559
- actionData = {
560
- method: 'get',
561
- rules: [{
562
- auth: false,
563
- }, {
564
- root: true
565
- }, {
566
- auth: true,
567
- role: 'manager',
568
- actionPrefix: '__'
569
- }]
570
- },
571
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
572
- routerAction.exec(req)
573
- .then((result) => {
574
- expect(result).to.deep.equal('__list');
575
- done();
576
- })
577
- .catch(done);
578
- });
750
+ it("Auth with manager role request post.list with actionName override", async () => {
751
+ let fakeRoute = {
752
+ manager_listAll: () => {
753
+ return "manager_listAll";
754
+ },
755
+ },
756
+ fakeMod = {
757
+ getRoute: () => {
758
+ return fakeRoute;
759
+ },
760
+ },
761
+ fakeNotApp = {
762
+ report(e) {
763
+ throw e;
764
+ },
765
+ getModule: () => {
766
+ return fakeMod;
767
+ },
768
+ };
769
+ let req = {
770
+ session: {
771
+ user: true,
772
+ role: "manager",
773
+ },
774
+ },
775
+ actionData = {
776
+ method: "get",
777
+ rules: [
778
+ {
779
+ auth: false,
780
+ },
781
+ {
782
+ root: true,
783
+ },
784
+ {
785
+ auth: true,
786
+ role: "manager",
787
+ actionName: "manager_listAll",
788
+ },
789
+ ],
790
+ },
791
+ routerAction = new notRoute(
792
+ fakeNotApp,
793
+ "not-user",
794
+ "post",
795
+ "list",
796
+ actionData
797
+ );
798
+ const result = await routerAction.exec(req, {}, (e) => {
799
+ throw e;
800
+ });
801
+ expect(result).to.deep.equal("manager_listAll");
802
+ });
579
803
 
580
- it('Auth with manager role request post.list with actionName override', async () => {
581
- let fakeRoute = {
582
- manager_listAll: () => {
583
- return 'manager_listAll';
584
- }
585
- },
586
- fakeMod = {
587
- getRoute: () => {
588
- return fakeRoute;
589
- }
590
- },
591
- fakeNotApp = {
592
- report(e) {
593
- throw e;
594
- },
595
- getModule: () => {
596
- return fakeMod;
597
- }
598
- };
599
- let req = {
600
- session: {
601
- user: true,
602
- role: 'manager'
603
- }
604
- },
605
- actionData = {
606
- method: 'get',
607
- rules: [{
608
- auth: false,
609
- }, {
610
- root: true
611
- }, {
612
- auth: true,
613
- role: 'manager',
614
- actionName: 'manager_listAll'
615
- }]
616
- },
617
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post', 'list', actionData);
618
- const result = await routerAction.exec(req, {}, (e) => {
619
- throw e;
620
- });
621
- expect(result).to.deep.equal('manager_listAll');
622
- });
804
+ it("Wrong modelName", function (done) {
805
+ let fakeRoute = {
806
+ manager_listAll: () => {
807
+ return "manager_listAll";
808
+ },
809
+ },
810
+ fakeMod = {
811
+ getRoute: () => {
812
+ return fakeRoute;
813
+ },
814
+ },
815
+ fakeNotApp = {
816
+ report(e) {
817
+ done(e);
818
+ },
819
+ getModule: () => {
820
+ return null;
821
+ },
822
+ };
823
+ let req = {
824
+ session: {
825
+ user: true,
826
+ role: "manager",
827
+ },
828
+ },
829
+ actionData = {
830
+ method: "get",
831
+ rules: [
832
+ {
833
+ auth: false,
834
+ },
835
+ {
836
+ root: true,
837
+ },
838
+ {
839
+ auth: true,
840
+ role: "manager",
841
+ actionName: "manager_listAll",
842
+ },
843
+ ],
844
+ },
845
+ routerAction = new notRoute(
846
+ fakeNotApp,
847
+ "not-user",
848
+ "post1",
849
+ "listasdf",
850
+ actionData
851
+ );
623
852
 
624
- it('Wrong modelName', function(done) {
625
- let fakeRoute = {
626
- manager_listAll: () => {
627
- return 'manager_listAll';
628
- }
629
- },
630
- fakeMod = {
631
- getRoute: () => {
632
- return fakeRoute;
633
- }
634
- },
635
- fakeNotApp = {
636
- report(e) {
637
- done(e);
638
- },
639
- getModule: () => {
640
- return null;
641
- }
642
- };
643
- let req = {
644
- session: {
645
- user: true,
646
- role: 'manager'
647
- }
648
- },
649
- actionData = {
650
- method: 'get',
651
- rules: [{
652
- auth: false,
653
- }, {
654
- root: true
655
- }, {
656
- auth: true,
657
- role: 'manager',
658
- actionName: 'manager_listAll'
659
- }]
660
- },
661
- routerAction = new notRoute(fakeNotApp, 'not-user', 'post1', 'listasdf', actionData);
853
+ routerAction.exec(req, {}, (err) => {
854
+ expect(err).to.be.instanceof(Error);
855
+ done();
856
+ });
857
+ });
662
858
 
663
- routerAction.exec(req, {}, (err) => {
664
- expect(err).to.be.instanceof(Error);
665
- done();
666
- })
667
- });
859
+ it("Wrong rule", function () {
860
+ let req = {
861
+ session: {
862
+ user: false,
863
+ role: "manager",
864
+ },
865
+ },
866
+ actionData = {
867
+ method: "get",
868
+ rules: [
869
+ {
870
+ root: true,
871
+ },
872
+ {
873
+ auth: true,
874
+ role: "manager",
875
+ actionName: "manager_listAll",
876
+ },
877
+ ],
878
+ },
879
+ routerAction = new notRoute(
880
+ {},
881
+ "not-user",
882
+ "post",
883
+ "list",
884
+ actionData
885
+ );
886
+ routerAction.exec(req, false, (err) => {
887
+ expect(err).to.be.deep.equal(
888
+ new HttpError(
889
+ 403,
890
+ "rule for router not found; not-user; post"
891
+ )
892
+ );
893
+ });
894
+ });
668
895
 
669
- it('Wrong rule', function() {
670
- let
671
- req = {
672
- session: {
673
- user: false,
674
- role: 'manager'
675
- }
676
- },
677
- actionData = {
678
- method: 'get',
679
- rules: [{
680
- root: true
681
- }, {
682
- auth: true,
683
- role: 'manager',
684
- actionName: 'manager_listAll'
685
- }]
686
- },
687
- routerAction = new notRoute({}, 'not-user', 'post', 'list', actionData);
688
- routerAction.exec(req, false, (err) => {
689
- expect(err).to.be.deep.equal(new HttpError(403, 'rule for router not found; not-user; post'));
690
- });
691
- });
896
+ it("Route is not runnable", function () {
897
+ let fakeRoute = {
898
+ list: "not runnable string",
899
+ },
900
+ fakeMod = {
901
+ getRoute: () => {
902
+ return fakeRoute;
903
+ },
904
+ },
905
+ fakeApp = {
906
+ getModule() {
907
+ return fakeMod;
908
+ },
909
+ },
910
+ req = {
911
+ session: {
912
+ user: true,
913
+ role: "user",
914
+ },
915
+ },
916
+ actionData = {
917
+ method: "get",
918
+ rules: [
919
+ {
920
+ root: true,
921
+ },
922
+ {
923
+ auth: true,
924
+ },
925
+ ],
926
+ },
927
+ routerAction = new notRoute(
928
+ fakeApp,
929
+ "not-user",
930
+ "post",
931
+ "list",
932
+ actionData
933
+ );
934
+ routerAction.exec(req, false, (err) => {
935
+ console.error(err);
936
+ expect(err).to.instanceof(HttpError);
937
+ expect(err.status).to.be.equal(404);
938
+ expect(err.message.indexOf("route not found")).to.be.equal(0);
939
+ });
940
+ });
692
941
 
693
- it('Route is not runnable', function() {
694
- let
695
- fakeRoute = {
696
- list: 'not runnable string'
697
- },
698
- fakeMod = {
699
- getRoute: () => {
700
- return fakeRoute;
701
- }
702
- },
703
- fakeApp = {
704
- getModule() {
705
- return fakeMod
706
- }
707
- },
708
- req = {
709
- session: {
710
- user: true,
711
- role: 'user'
712
- }
713
- },
714
- actionData = {
715
- method: 'get',
716
- rules: [{
717
- root: true
718
- }, {
719
- auth: true
720
- }]
721
- },
722
- routerAction = new notRoute(fakeApp, 'not-user', 'post', 'list', actionData);
723
- routerAction.exec(req, false, (err) => {
724
- console.error(err);
725
- expect(err).to.instanceof(HttpError);
726
- expect(err.status).to.be.equal(404);
727
- expect(err.message.indexOf('route not found')).to.be.equal(0);
728
- })
942
+ it("Exception throwned", function () {
943
+ let throwned = false;
944
+ let fakeApp = {
945
+ getModule: false,
946
+ report() {
947
+ throwned = true;
948
+ },
949
+ },
950
+ req = {
951
+ session: {
952
+ user: true,
953
+ role: "user",
954
+ },
955
+ },
956
+ actionData = {
957
+ method: "get",
958
+ rules: [
959
+ {
960
+ root: true,
961
+ },
962
+ {
963
+ auth: true,
964
+ },
965
+ ],
966
+ },
967
+ routerAction = new notRoute(
968
+ fakeApp,
969
+ "not-user",
970
+ "post",
971
+ "list",
972
+ actionData
973
+ );
974
+ routerAction.exec(req, false, () => {});
975
+ expect(throwned).to.be.true;
976
+ });
729
977
  });
730
978
 
731
- it('Exception throwned', function() {
732
- let throwned = false;
733
- let
734
- fakeApp = {
735
- getModule: false,
736
- report() {
737
- throwned = true;
738
- }
739
- },
740
- req = {
741
- session: {
742
- user: true,
743
- role: 'user'
744
- }
745
- },
746
- actionData = {
747
- method: 'get',
748
- rules: [{
749
- root: true
750
- }, {
751
- auth: true
752
- }]
753
- },
754
- routerAction = new notRoute(fakeApp, 'not-user', 'post', 'list', actionData);
755
- routerAction.exec(req, false, () => {});
756
- expect(throwned).to.be.true;
757
- });
758
- });
979
+ describe("actionAvailableByRule", function () {
980
+ it('rules[{auth:true,role:"client"},{auth:false}] X user(auth:true) = null', function () {
981
+ const action = {
982
+ rules: [
983
+ {
984
+ auth: true,
985
+ role: "client",
986
+ },
987
+ {
988
+ auth: false,
989
+ },
990
+ ],
991
+ },
992
+ user = {
993
+ auth: true,
994
+ };
995
+ const role = notRoute.actionAvailableByRule(action, user);
996
+ expect(role).to.be.null;
997
+ });
759
998
 
999
+ it('rules[{auth:true,role:"client"},{auth:true}] X user(auth:false) = {auth:false}', function () {
1000
+ const action = {
1001
+ rules: [
1002
+ {
1003
+ auth: true,
1004
+ role: "client",
1005
+ },
1006
+ {
1007
+ auth: false,
1008
+ },
1009
+ ],
1010
+ },
1011
+ user = {
1012
+ auth: false,
1013
+ };
1014
+ const role = notRoute.actionAvailableByRule(action, user);
1015
+ expect(role).to.be.deep.equal({
1016
+ auth: false,
1017
+ });
1018
+ });
760
1019
 
761
- describe('actionAvailableByRule', function() {
762
- it('rules[{auth:true,role:"client"},{auth:false}] X user(auth:true) = null', function() {
763
- const action = {
764
- rules: [{
765
- auth: true,
766
- role: 'client'
767
- }, {
768
- auth: false
769
- }]
770
- },
771
- user = {
772
- auth: true
773
- };
774
- const role = notRoute.actionAvailableByRule(action, user);
775
- expect(role).to.be.null;
776
- });
1020
+ it("action({root:true,fields:[]}]) X user(root:true) = {root:true, fields:[]}", function () {
1021
+ const action = {
1022
+ root: true,
1023
+ fields: ["some", "foo", "bar"],
1024
+ },
1025
+ user = {
1026
+ root: true,
1027
+ };
1028
+ const role = notRoute.actionAvailableByRule(action, user);
1029
+ expect(role).to.be.deep.equal({
1030
+ root: true,
1031
+ fields: ["some", "foo", "bar"],
1032
+ });
1033
+ });
777
1034
 
778
- it('rules[{auth:true,role:"client"},{auth:true}] X user(auth:false) = {auth:false}', function() {
779
- const action = {
780
- rules: [{
781
- auth: true,
782
- role: 'client'
783
- }, {
784
- auth: false
785
- }]
786
- },
787
- user = {
788
- auth: false
789
- };
790
- const role = notRoute.actionAvailableByRule(action, user);
791
- expect(role).to.be.deep.equal({
792
- auth: false
793
- });
794
- });
795
-
796
-
797
- it('action({root:true,fields:[]}]) X user(root:true) = {root:true, fields:[]}', function() {
798
- const action = {
799
- root: true,
800
- fields: ['some', 'foo', 'bar']
801
- },
802
- user = {
803
- root: true
804
- };
805
- const role = notRoute.actionAvailableByRule(action, user);
806
- expect(role).to.be.deep.equal({
807
- root: true,
808
- fields: ['some', 'foo', 'bar']
809
- });
810
- });
811
-
812
- it('action - false X user(root:true) = null', function() {
813
- const action = false,
814
- user = {
815
- root: true
816
- };
817
- const role = notRoute.actionAvailableByRule(action, user);
818
- expect(role).to.be.null;
819
- });
1035
+ it("action - false X user(root:true) = null", function () {
1036
+ const action = false,
1037
+ user = {
1038
+ root: true,
1039
+ };
1040
+ const role = notRoute.actionAvailableByRule(action, user);
1041
+ expect(role).to.be.null;
1042
+ });
820
1043
 
821
- it('action(auth:true) X user(auth:false) = null', function() {
822
- const action = {
823
- auth: true
824
- },
825
- user = {
826
- auth: false
827
- };
828
- const role = notRoute.actionAvailableByRule(action, user);
829
- expect(role).to.be.null;
1044
+ it("action(auth:true) X user(auth:false) = null", function () {
1045
+ const action = {
1046
+ auth: true,
1047
+ },
1048
+ user = {
1049
+ auth: false,
1050
+ };
1051
+ const role = notRoute.actionAvailableByRule(action, user);
1052
+ expect(role).to.be.null;
1053
+ });
830
1054
  });
831
- });
832
1055
  });