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.
- package/.eslintrc.json +32 -38
- package/index.js +6 -0
- package/package.json +12 -11
- package/src/app.js +2 -2
- package/src/auth/index.js +0 -2
- package/src/auth/routes.js +25 -61
- package/src/auth/rules.js +8 -7
- package/src/common.js +19 -0
- package/src/identity/exceptions.js +17 -0
- package/src/identity/identity.js +61 -0
- package/src/identity/index.js +35 -0
- package/src/identity/providers/session.js +137 -0
- package/src/identity/providers/token.js +255 -0
- package/src/manifest/result.filter.js +268 -0
- package/src/manifest/route.js +6 -36
- package/static2.js +24 -0
- package/test/auth/identity.js +0 -0
- package/test/auth/routes.js +1 -1
- package/test/auth.js +427 -229
- package/test/env.js +20 -20
- package/test/fields.js +3 -2
- package/test/identity/identity.js +1 -0
- package/test/identity/index.js +12 -0
- package/test/identity/providers/session.js +227 -0
- package/test/identity/providers/token.js +244 -0
- package/test/identity.js +5 -0
- package/test/init/app.js +359 -365
- package/test/init/bodyparser.js +37 -39
- package/test/init/compression.js +29 -31
- package/test/init/cors.js +38 -39
- package/test/init/db.js +60 -64
- package/test/init/env.js +109 -114
- package/test/init/express.js +50 -47
- package/test/init/fileupload.js +30 -32
- package/test/init/http.js +258 -240
- package/test/init/informer.js +20 -24
- package/test/init/methodoverride.js +29 -31
- package/test/init/middleware.js +56 -58
- package/test/init/modules.js +19 -19
- package/test/init/monitoring.js +22 -22
- package/test/init/routes.js +185 -171
- package/test/init/security.js +77 -103
- package/test/init/sessions/mongoose.js +56 -57
- package/test/init/sessions/redis.js +59 -61
- package/test/init/sessions.js +84 -79
- package/test/init/static.js +108 -113
- package/test/init/template.js +46 -41
- package/test/notInit.js +217 -217
- package/test/notManifest.js +232 -191
- package/test/notRoute.js +1022 -799
- package/test/result.filter.js +422 -0
- package/src/auth/session.js +0 -151
- package/test/auth/session.js +0 -266
package/test/init/middleware.js
CHANGED
|
@@ -1,65 +1,63 @@
|
|
|
1
|
-
const InitMiddleware = require(
|
|
2
|
-
const mock = require(
|
|
1
|
+
const InitMiddleware = require("../../src/init/lib/middleware");
|
|
2
|
+
const mock = require("mock-require");
|
|
3
3
|
|
|
4
|
-
module.exports = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
mock("not-fake-mod", () => {});
|
|
19
|
+
mock("not-fake-mod-2-path", {
|
|
20
|
+
middleware() {},
|
|
21
|
+
});
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
};
|
package/test/init/modules.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const InitModules = require(
|
|
1
|
+
const InitModules = require("../../src/init/lib/modules");
|
|
2
2
|
|
|
3
|
-
module.exports = ({expect})=>{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
};
|
package/test/init/monitoring.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
const InitMonitoring = require(
|
|
2
|
-
const mock = require(
|
|
1
|
+
const InitMonitoring = require("../../src/init/lib/monitoring");
|
|
2
|
+
const mock = require("mock-require");
|
|
3
3
|
|
|
4
|
-
module.exports = ({expect})=>{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
22
|
+
after(() => {
|
|
23
|
+
mock.stop("not-monitor");
|
|
24
|
+
});
|
|
24
25
|
});
|
|
25
|
-
});
|
|
26
26
|
};
|
package/test/init/routes.js
CHANGED
|
@@ -1,183 +1,197 @@
|
|
|
1
|
-
const InitRoutes = require(
|
|
2
|
-
const {notError, notRequestError} = require(
|
|
3
|
-
const 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
};
|