not-node 5.1.36 → 5.1.39
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/bootstrap/route.js +29 -2
- package/src/core/fields/ID.js +4 -0
- package/src/fields/index.js +2 -2
- package/src/manifest/module.js +18 -0
- package/src/model/exceptions.js +3 -3
- package/src/model/routine.js +11 -6
- package/src/model/versioning.js +2 -2
- package/test/auth/fields.js +308 -281
- package/test/auth/routes.js +166 -168
- package/test/fields.js +271 -266
- package/test/model/increment.js +235 -220
- package/test/model/proto.js +380 -369
- package/test/model/versioning.js +366 -310
- package/test/notModel.js +44 -48
package/test/auth/routes.js
CHANGED
|
@@ -1,183 +1,181 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) => {
|
|
6
|
-
describe('Routes', () => {
|
|
7
|
-
describe('getIP', ()=>{
|
|
8
|
-
it('req.header[x-forwarded-for]', ()=>{
|
|
9
|
-
const req = {
|
|
10
|
-
headers:{
|
|
11
|
-
'x-forwarded-for': '127.0.0.1'
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
let result = Auth.getIP(req);
|
|
15
|
-
expect(result).to.deep.equal('127.0.0.1');
|
|
16
|
-
});
|
|
1
|
+
const {
|
|
2
|
+
HttpExceptionUnauthorized,
|
|
3
|
+
HttpExceptionForbidden,
|
|
4
|
+
} = require("../../src/exceptions/http");
|
|
17
5
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
module.exports = ({ Auth, HttpError, expect }) => {
|
|
7
|
+
describe("Routes", () => {
|
|
8
|
+
describe("getIP", () => {
|
|
9
|
+
it("req.header[x-forwarded-for]", () => {
|
|
10
|
+
const req = {
|
|
11
|
+
headers: {
|
|
12
|
+
"x-forwarded-for": "127.0.0.1",
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
let result = Auth.getIP(req);
|
|
16
|
+
expect(result).to.deep.equal("127.0.0.1");
|
|
17
|
+
});
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
it("req.connection.remoteAddress", () => {
|
|
20
|
+
const req = {
|
|
21
|
+
connection: {
|
|
22
|
+
remoteAddress: "127.0.0.1",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
let result = Auth.getIP(req);
|
|
26
|
+
expect(result).to.deep.equal("127.0.0.1");
|
|
27
|
+
});
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(result).to.deep.equal('127.0.0.1');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
29
|
+
it("req.socket.remoteAddress", () => {
|
|
30
|
+
const req = {
|
|
31
|
+
socket: {
|
|
32
|
+
remoteAddress: "127.0.0.1",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
let result = Auth.getIP(req);
|
|
36
|
+
expect(result).to.deep.equal("127.0.0.1");
|
|
37
|
+
});
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
root: false,
|
|
63
|
-
auth: false,
|
|
64
|
-
role: undefined,
|
|
65
|
-
uid: undefined,
|
|
66
|
-
sid: undefined,
|
|
67
|
-
ip: '127.0.0.1'
|
|
39
|
+
it("req.connection.socket.remoteAddress", () => {
|
|
40
|
+
const req = {
|
|
41
|
+
connection: {
|
|
42
|
+
socket: {
|
|
43
|
+
remoteAddress: "127.0.0.1",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
let result = Auth.getIP(req);
|
|
48
|
+
expect(result).to.deep.equal("127.0.0.1");
|
|
49
|
+
});
|
|
68
50
|
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('checkUser', function() {
|
|
73
|
-
it('check if user exists and continues', function() {
|
|
74
|
-
const req = {
|
|
75
|
-
session: {
|
|
76
|
-
user: true
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
next = function(val) {
|
|
80
|
-
return val;
|
|
81
|
-
};
|
|
82
|
-
let result = Auth.checkUser(req, false, next);
|
|
83
|
-
expect(result).to.deep.equal();
|
|
84
|
-
});
|
|
85
51
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
52
|
+
describe("extractAuthData", () => {
|
|
53
|
+
it("not authorized", () => {
|
|
54
|
+
const req = {
|
|
55
|
+
headers: {
|
|
56
|
+
"x-forwarded-for": "127.0.0.1",
|
|
57
|
+
},
|
|
58
|
+
user: {},
|
|
59
|
+
session: {},
|
|
60
|
+
};
|
|
61
|
+
let result = Auth.extractAuthData(req);
|
|
62
|
+
expect(result).to.deep.equal({
|
|
63
|
+
root: false,
|
|
64
|
+
auth: false,
|
|
65
|
+
role: undefined,
|
|
66
|
+
uid: undefined,
|
|
67
|
+
sid: undefined,
|
|
68
|
+
ip: "127.0.0.1",
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
99
72
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
73
|
+
describe("checkUser", function () {
|
|
74
|
+
it("check if user exists and continues", function () {
|
|
75
|
+
const req = {
|
|
76
|
+
session: {
|
|
77
|
+
user: true,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
next = function (val) {
|
|
81
|
+
return val;
|
|
82
|
+
};
|
|
83
|
+
let result = Auth.checkUser(req, false, next);
|
|
84
|
+
expect(result).to.deep.equal();
|
|
85
|
+
});
|
|
114
86
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
87
|
+
it("check if user exists and throw exception", function () {
|
|
88
|
+
const req = {
|
|
89
|
+
session: {
|
|
90
|
+
user: false,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
next = function (val) {
|
|
94
|
+
return val;
|
|
95
|
+
};
|
|
96
|
+
let result = Auth.checkUser(req, false, next);
|
|
97
|
+
expect(result).to.be.instanceOf(HttpExceptionUnauthorized);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
129
100
|
|
|
101
|
+
describe("checkRoot", function () {
|
|
102
|
+
it("check if admin exists and continues", function () {
|
|
103
|
+
const req = {
|
|
104
|
+
session: {
|
|
105
|
+
user: true,
|
|
106
|
+
role: [Auth.DEFAULT_USER_ROLE_FOR_ADMIN],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
next = function (val) {
|
|
110
|
+
return val;
|
|
111
|
+
};
|
|
112
|
+
let result = Auth.checkRoot(req, false, next);
|
|
113
|
+
expect(result).to.deep.equal();
|
|
114
|
+
});
|
|
130
115
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
});
|
|
116
|
+
it("check if admin exists and throw exception", function () {
|
|
117
|
+
const req = {
|
|
118
|
+
session: {
|
|
119
|
+
user: true,
|
|
120
|
+
role: "manager",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
next = function (val) {
|
|
124
|
+
return val;
|
|
125
|
+
};
|
|
126
|
+
let result = Auth.checkRoot(req, false, next);
|
|
127
|
+
expect(result).to.be.instanceOf(HttpExceptionForbidden);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
146
130
|
|
|
131
|
+
describe("checkAdmin", function () {
|
|
132
|
+
it("check if admin exists and continues", function () {
|
|
133
|
+
const req = {
|
|
134
|
+
session: {
|
|
135
|
+
user: true,
|
|
136
|
+
role: [Auth.DEFAULT_USER_ROLE_FOR_ADMIN],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
next = function (val) {
|
|
140
|
+
return val;
|
|
141
|
+
};
|
|
142
|
+
let result = Auth.checkAdmin(req, false, next);
|
|
143
|
+
expect(result).to.deep.equal();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
describe("checkRoleBuilder", function () {
|
|
148
|
+
it("Role", function () {
|
|
149
|
+
const role = "user",
|
|
150
|
+
req = {
|
|
151
|
+
session: {
|
|
152
|
+
user: true,
|
|
153
|
+
role: "user",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
next = function (val) {
|
|
157
|
+
return val;
|
|
158
|
+
};
|
|
159
|
+
let resultFunction = Auth.checkRoleBuilder(role),
|
|
160
|
+
result = resultFunction(req, false, next);
|
|
161
|
+
expect(result).to.deep.equal();
|
|
162
|
+
});
|
|
164
163
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
164
|
+
it("Role with error", function () {
|
|
165
|
+
const role = "manager",
|
|
166
|
+
req = {
|
|
167
|
+
session: {
|
|
168
|
+
user: true,
|
|
169
|
+
role: "user",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
next = function (val) {
|
|
173
|
+
return val;
|
|
174
|
+
};
|
|
175
|
+
let resultFunction = Auth.checkRoleBuilder(role),
|
|
176
|
+
result = resultFunction(req, false, next);
|
|
177
|
+
expect(result).to.be.instanceOf(HttpExceptionForbidden);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
180
|
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
181
|
};
|