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
@@ -1,65 +1,63 @@
1
- const InitMiddleware = require('../../src/init/middleware');
2
- const mock = require('mock-require');
1
+ const InitMiddleware = require("../../src/init/lib/middleware");
2
+ const mock = require("mock-require");
3
3
 
4
- module.exports = ({
5
- expect
6
- }) => {
7
- describe('Middleware', () => {
8
- describe('run', () => {
9
- it('config middleware empty', async () => {
10
- const config = {
11
- get() {
12
- return false;
13
- }
14
- }
15
- await (new InitMiddleware()).run({
16
- config
17
- });
18
- });
4
+ module.exports = ({ expect }) => {
5
+ describe("Middleware", () => {
6
+ describe("run", () => {
7
+ it("config middleware empty", async () => {
8
+ const config = {
9
+ get() {
10
+ return false;
11
+ },
12
+ };
13
+ await new InitMiddleware().run({
14
+ config,
15
+ });
16
+ });
19
17
 
20
- mock('not-fake-mod', () => {});
21
- mock('not-fake-mod-2-path', {
22
- middleware() {}
23
- });
18
+ mock("not-fake-mod", () => {});
19
+ mock("not-fake-mod-2-path", {
20
+ middleware() {},
21
+ });
24
22
 
25
- mock('not-fake-mod-getMiddleware', {
26
- getMiddleware(opts) {
27
- expect(opts).to.be.deep.equal({
28
- params: true
29
- });
30
- return () => {};
31
- }
32
- });
23
+ mock("not-fake-mod-getMiddleware", {
24
+ getMiddleware(opts) {
25
+ expect(opts).to.be.deep.equal({
26
+ params: true,
27
+ });
28
+ return () => {};
29
+ },
30
+ });
33
31
 
34
- it('config middleware not empty', async () => {
35
- const config = {
36
- get() {
37
- return {
38
- 'not-fake-mod': {},
39
- 'not-fake-mod-2': {
40
- path: 'not-fake-mod-2-path'
41
- },
42
- 'not-fake-mod-getMiddleware': {
43
- params: true
44
- },
45
- };
46
- }
47
- };
48
- const fakeServer = {
49
- use(func) {
50
- expect(typeof func).to.be.equal('function');
51
- }
52
- };
53
- const master = {
54
- getServer() {
55
- return fakeServer;
56
- }
57
- };
58
- await (new InitMiddleware()).run({
59
- config,
60
- master
32
+ it("config middleware not empty", async () => {
33
+ const config = {
34
+ get() {
35
+ return {
36
+ "not-fake-mod": {},
37
+ "not-fake-mod-2": {
38
+ path: "not-fake-mod-2-path",
39
+ },
40
+ "not-fake-mod-getMiddleware": {
41
+ params: true,
42
+ },
43
+ };
44
+ },
45
+ };
46
+ const fakeServer = {
47
+ use(func) {
48
+ expect(typeof func).to.be.equal("function");
49
+ },
50
+ };
51
+ const master = {
52
+ getServer() {
53
+ return fakeServer;
54
+ },
55
+ };
56
+ await new InitMiddleware().run({
57
+ config,
58
+ master,
59
+ });
60
+ });
61
61
  });
62
- });
63
62
  });
64
- });
65
63
  };
@@ -1,22 +1,22 @@
1
- const InitModules = require('../../src/init/modules');
1
+ const InitModules = require("../../src/init/lib/modules");
2
2
 
3
- module.exports = ({expect})=>{
4
- describe('Modules', ()=>{
5
- describe('run', ()=>{
6
- it('ok', async()=>{
7
- let executed = false;
8
- const master = {
9
- getApp(){
10
- return {
11
- execInModules(str){
12
- executed = str;
13
- }
14
- };
15
- }
16
- };
17
- await (new InitModules()).run({master});
18
- expect(executed).to.be.equal('initialize');
19
- });
3
+ module.exports = ({ expect }) => {
4
+ describe("Modules", () => {
5
+ describe("run", () => {
6
+ it("ok", async () => {
7
+ let executed = false;
8
+ const master = {
9
+ getApp() {
10
+ return {
11
+ execInModules(str) {
12
+ executed = str;
13
+ },
14
+ };
15
+ },
16
+ };
17
+ await new InitModules().run({ master });
18
+ expect(executed).to.be.equal("initialize");
19
+ });
20
+ });
20
21
  });
21
- });
22
22
  };
@@ -1,26 +1,26 @@
1
- const InitMonitoring = require('../../src/init/monitoring');
2
- const mock = require('mock-require');
1
+ const InitMonitoring = require("../../src/init/lib/monitoring");
2
+ const mock = require("mock-require");
3
3
 
4
- module.exports = ({expect})=>{
5
- describe('Monitoring', ()=>{
6
- it('run', async ()=>{
7
- let event = false;
8
- mock('not-monitor', {
9
- monitor:{
10
- on(name, cb){
11
- expect(name).to.be.equal('afterReportError');
12
- expect(typeof cb).to.be.equal('function');
13
- event = true;
14
- cb(new Error('some error'));
15
- }
16
- }
17
- });
18
- await new InitMonitoring().run();
19
- expect(event).to.be.equal(true);
20
- });
4
+ module.exports = ({ expect }) => {
5
+ describe("Monitoring", () => {
6
+ it("run", async () => {
7
+ let event = false;
8
+ mock("not-monitor", {
9
+ monitor: {
10
+ on(name, cb) {
11
+ expect(name).to.be.equal("afterReportError");
12
+ expect(typeof cb).to.be.equal("function");
13
+ event = true;
14
+ cb(new Error("some error"));
15
+ },
16
+ },
17
+ });
18
+ await new InitMonitoring().run();
19
+ expect(event).to.be.equal(true);
20
+ });
21
21
 
22
- after(()=>{
23
- mock.stop('not-monitor');
22
+ after(() => {
23
+ mock.stop("not-monitor");
24
+ });
24
25
  });
25
- });
26
26
  };
@@ -1,183 +1,197 @@
1
- const InitRoutes = require('../../src/init/routes');
2
- const {notError, notRequestError} = require('not-error');
3
- const mock = require('mock-require');
1
+ const InitRoutes = require("../../src/init/lib/routes");
2
+ const { notError, notRequestError } = require("not-error");
3
+ const mock = require("mock-require");
4
4
 
5
- module.exports = ({expect})=>{
6
- describe('Routes', ()=>{
7
- mock('serve-static', ()=>{});
8
- describe('finalError', ()=>{
9
- it('Error, !statusCode', (done)=>{
10
- const req = {
11
- url: 'failure_path'
12
- };
13
- const res = {
14
- status(code){
15
- expect(code).to.be.equal(500);
16
- },
17
- json(dat){
18
- expect(dat).to.be.deep.equal({
19
- status: 'error',
20
- message: 'Serious generic error'
5
+ module.exports = ({ expect }) => {
6
+ describe("Routes", () => {
7
+ mock("serve-static", () => {});
8
+ describe("finalError", () => {
9
+ it("Error, !statusCode", (done) => {
10
+ const req = {
11
+ url: "failure_path",
12
+ };
13
+ const res = {
14
+ status(code) {
15
+ expect(code).to.be.equal(500);
16
+ },
17
+ json(dat) {
18
+ expect(dat).to.be.deep.equal({
19
+ status: "error",
20
+ message: "Serious generic error",
21
+ });
22
+ done();
23
+ },
24
+ };
25
+ const master = {
26
+ getApp() {
27
+ return {
28
+ report(err) {
29
+ expect(err).to.be.instanceof(notError);
30
+ },
31
+ };
32
+ },
33
+ };
34
+ const final = InitRoutes.finalError({ master });
35
+ final(new Error("Serious generic error"), req, res);
21
36
  });
22
- done();
23
- }
24
- };
25
- const master = {
26
- getApp(){
27
- return {
28
- report(err){
29
- expect(err).to.be.instanceof(notError);
30
- }
31
- };
32
- }
33
- };
34
- const final = InitRoutes.finalError({master});
35
- final(new Error('Serious generic error'), req, res);
36
- });
37
37
 
38
- it('!Error, !statusCode', (done)=>{
39
- const req = {
40
- url: 'failure_path'
41
- };
42
- const res = {
43
- status(code){
44
- expect(code).to.be.equal(500);
45
- return this;
46
- },
47
- json(dat){
48
- expect(dat).to.be.deep.equal({
49
- status: 'error'
38
+ it("!Error, !statusCode", (done) => {
39
+ const req = {
40
+ url: "failure_path",
41
+ };
42
+ const res = {
43
+ status(code) {
44
+ expect(code).to.be.equal(500);
45
+ return this;
46
+ },
47
+ json(dat) {
48
+ expect(dat).to.be.deep.equal({
49
+ status: "error",
50
+ });
51
+ done();
52
+ },
53
+ };
54
+ const master = {
55
+ getApp() {
56
+ return {
57
+ report(err) {
58
+ expect(err).to.be.instanceof(notError);
59
+ },
60
+ };
61
+ },
62
+ };
63
+ const final = InitRoutes.finalError({ master });
64
+ final("Serious generic error", req, res);
50
65
  });
51
- done();
52
- }
53
- };
54
- const master = {
55
- getApp(){
56
- return {
57
- report(err){
58
- expect(err).to.be.instanceof(notError);
59
- }
60
- };
61
- }
62
- };
63
- const final = InitRoutes.finalError({master});
64
- final('Serious generic error', req, res);
65
- });
66
66
 
67
+ it("notError, !statusCode", (done) => {
68
+ const req = {
69
+ url: "failure_path",
70
+ };
71
+ const res = {};
72
+ const master = {
73
+ getApp() {
74
+ return {
75
+ report(err) {
76
+ expect(err).to.be.instanceof(notError);
77
+ done();
78
+ },
79
+ };
80
+ },
81
+ };
82
+ const final = InitRoutes.finalError({ master });
83
+ final(new notError("Serious not error", {}), req, res);
84
+ });
67
85
 
68
- it('notError, !statusCode', (done)=>{
69
- const req = {
70
- url: 'failure_path'
71
- };
72
- const res = {};
73
- const master = {
74
- getApp(){
75
- return {
76
- report(err){
77
- expect(err).to.be.instanceof(notError);
78
- done();
79
- }
80
- };
81
- }
82
- };
83
- const final = InitRoutes.finalError({master});
84
- final(new notError('Serious not error', {}), req, res);
85
- });
86
-
87
-
88
- it('notRequestError, redirect, code = 404', (done)=>{
89
- const req = {
90
- url: 'failure_path'
91
- };
92
- const res = {
93
- redirect(url){
94
- expect(url).to.be.equal('redirect_url_fake');
95
- done();
96
- }
97
- };
98
- const master = {
99
- getApp(){
100
- return {
101
- report(err){
102
- expect(err).to.be.instanceof(notRequestError);
103
- }
104
- };
105
- }
106
- };
107
- const final = InitRoutes.finalError({master});
108
- final(new notRequestError('Serious not error', {code: 404, redirect: 'redirect_url_fake'}), req, res);
109
- });
110
-
111
- it('notRequestError, no redirect, code = 404', (done)=>{
112
- const req = {
113
- url: 'failure_path'
114
- };
115
- const res = {
116
- status(code){
117
- expect(code).to.be.equal(404);
118
- return this;
119
- },
120
- json(dat){
121
- expect(dat).to.be.deep.equal({
122
- status: 'error',
123
- message: 'Serious not error request',
124
- errors: {field: ['name']},
86
+ it("notRequestError, redirect, code = 404", (done) => {
87
+ const req = {
88
+ url: "failure_path",
89
+ };
90
+ const res = {
91
+ redirect(url) {
92
+ expect(url).to.be.equal("redirect_url_fake");
93
+ done();
94
+ },
95
+ };
96
+ const master = {
97
+ getApp() {
98
+ return {
99
+ report(err) {
100
+ expect(err).to.be.instanceof(notRequestError);
101
+ },
102
+ };
103
+ },
104
+ };
105
+ const final = InitRoutes.finalError({ master });
106
+ final(
107
+ new notRequestError("Serious not error", {
108
+ code: 404,
109
+ redirect: "redirect_url_fake",
110
+ }),
111
+ req,
112
+ res
113
+ );
125
114
  });
126
- done();
127
- }
128
- };
129
- const master = {
130
- getApp(){
131
- return {
132
- report(err){
133
- expect(err).to.be.instanceof(notRequestError);
134
- }
135
- };
136
- }
137
- };
138
- const final = InitRoutes.finalError({master});
139
- final(new notRequestError('Serious not error request', {code: 404, errors: {field: ['name']} }), req, res);
140
- });
141
- });
142
115
 
116
+ it("notRequestError, no redirect, code = 404", (done) => {
117
+ const req = {
118
+ url: "failure_path",
119
+ };
120
+ const res = {
121
+ status(code) {
122
+ expect(code).to.be.equal(404);
123
+ return this;
124
+ },
125
+ json(dat) {
126
+ expect(dat).to.be.deep.equal({
127
+ status: "error",
128
+ message: "Serious not error request",
129
+ errors: { field: ["name"] },
130
+ });
131
+ done();
132
+ },
133
+ };
134
+ const master = {
135
+ getApp() {
136
+ return {
137
+ report(err) {
138
+ expect(err).to.be.instanceof(notRequestError);
139
+ },
140
+ };
141
+ },
142
+ };
143
+ const final = InitRoutes.finalError({ master });
144
+ final(
145
+ new notRequestError("Serious not error request", {
146
+ code: 404,
147
+ errors: { field: ["name"] },
148
+ }),
149
+ req,
150
+ res
151
+ );
152
+ });
153
+ });
143
154
 
144
- describe('run', ()=>{
145
- it('run', async ()=>{
146
- const fakeServer = { sarver: true, use(fn){
147
- expect(typeof fn).to.be.equal('function');
148
- }};
149
- const fakeApp = {
150
- report(){},
151
- use(fn){
152
- expect(typeof fn).to.be.equal('function');
153
- },
154
- expose(ser){
155
- expect(ser).to.be.deep.equal(fakeServer);
156
- },
157
- };
158
- mock('main-not-app-routes', (ser, app)=>{
159
- expect(ser).to.be.deep.equal(fakeServer);
160
- expect(app).to.be.deep.equal(fakeApp);
155
+ describe("run", () => {
156
+ it("run", async () => {
157
+ const fakeServer = {
158
+ sarver: true,
159
+ use(fn) {
160
+ expect(typeof fn).to.be.equal("function");
161
+ },
162
+ };
163
+ const fakeApp = {
164
+ report() {},
165
+ use(fn) {
166
+ expect(typeof fn).to.be.equal("function");
167
+ },
168
+ expose(ser) {
169
+ expect(ser).to.be.deep.equal(fakeServer);
170
+ },
171
+ };
172
+ mock("main-not-app-routes", (ser, app) => {
173
+ expect(ser).to.be.deep.equal(fakeServer);
174
+ expect(app).to.be.deep.equal(fakeApp);
175
+ });
176
+ const options = {
177
+ indexRoute: () => {},
178
+ routesPath: "main-not-app-routes",
179
+ };
180
+ const master = {
181
+ getServer() {
182
+ return fakeServer;
183
+ },
184
+ getApp() {
185
+ return fakeApp;
186
+ },
187
+ };
188
+ const config = {
189
+ get(str) {
190
+ return str + "__fake";
191
+ },
192
+ };
193
+ await new InitRoutes().run({ master, config, options });
194
+ });
161
195
  });
162
- const options = {
163
- indexRoute: ()=>{},
164
- routesPath: 'main-not-app-routes'
165
- };
166
- const master = {
167
- getServer(){
168
- return fakeServer;
169
- },
170
- getApp(){
171
- return fakeApp;
172
- }
173
- };
174
- const config = {
175
- get(str){
176
- return str + '__fake';
177
- }
178
- };
179
- await new InitRoutes().run({master, config, options});
180
- });
181
196
  });
182
- });
183
197
  };