not-node 5.1.45 → 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/index.js +4 -0
- package/package.json +2 -1
- 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/route.js +2 -1
- package/static2.js +24 -0
- package/test/auth/identity.js +0 -0
- package/test/auth/routes.js +1 -1
- package/test/auth.js +0 -15
- package/test/env.js +20 -20
- 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/notRoute.js +1022 -799
- package/src/auth/session.js +0 -151
- package/test/auth/session.js +0 -266
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
const Provider = require("../../../src/identity/providers/token");
|
|
2
|
+
const mongoose = require("mongoose");
|
|
3
|
+
const JWT = require("jsonwebtoken");
|
|
4
|
+
|
|
5
|
+
function stubReq({ headers }) {
|
|
6
|
+
return {
|
|
7
|
+
get(name) {
|
|
8
|
+
return headers[name];
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function stubReqWithTokenContent({ tokenContent, secret }) {
|
|
14
|
+
const headers = {
|
|
15
|
+
Authentication: "Bearer " + JWT.toString(tokenContent, secret),
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
get(name) {
|
|
19
|
+
return headers[name];
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = ({ expect }) => {
|
|
25
|
+
describe(`${Provider.constructor.name}`, () => {
|
|
26
|
+
/* describe("isUser", function () {
|
|
27
|
+
it("check if user exists - true", function () {
|
|
28
|
+
var t = {
|
|
29
|
+
session: {
|
|
30
|
+
user: true,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
var res = new Provider(t).isUser();
|
|
34
|
+
expect(res).to.eql(true);
|
|
35
|
+
});
|
|
36
|
+
it("check if user exists - false", function () {
|
|
37
|
+
var t = {
|
|
38
|
+
session: {},
|
|
39
|
+
};
|
|
40
|
+
var res = new Provider(t).isUser();
|
|
41
|
+
expect(res).to.eql(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("isRoot", function () {
|
|
46
|
+
it("check if user admin - true", function () {
|
|
47
|
+
var t = {
|
|
48
|
+
session: {
|
|
49
|
+
user: mongoose.Types.ObjectId(),
|
|
50
|
+
role: "root",
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
var res = new Provider(t).isRoot();
|
|
54
|
+
expect(res).to.eql(true);
|
|
55
|
+
});
|
|
56
|
+
it("check if user admin - false", function () {
|
|
57
|
+
var t = {
|
|
58
|
+
session: {
|
|
59
|
+
user: mongoose.Types.ObjectId(),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
var res = new Provider(t).isRoot();
|
|
63
|
+
expect(res).to.eql(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("getRole", function () {
|
|
68
|
+
it("get role - root", function () {
|
|
69
|
+
var t = {
|
|
70
|
+
session: {
|
|
71
|
+
user: mongoose.Types.ObjectId(),
|
|
72
|
+
role: "root",
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
var res = new Provider(t).getRole();
|
|
76
|
+
expect(res).to.eql("root");
|
|
77
|
+
});
|
|
78
|
+
it("get role - undefined", function () {
|
|
79
|
+
var t = {
|
|
80
|
+
session: {
|
|
81
|
+
user: mongoose.Types.ObjectId(),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
var res = new Provider(t).getRole();
|
|
85
|
+
expect(res).to.eql(undefined);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("setRole", function () {
|
|
90
|
+
it("session exist, set role - root", function () {
|
|
91
|
+
var t = {
|
|
92
|
+
session: {
|
|
93
|
+
user: mongoose.Types.ObjectId(),
|
|
94
|
+
role: "user",
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
new Provider(t).setRole("root");
|
|
98
|
+
expect(t.tokenContent.role).to.eql("root");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("session not exist, set role - admin", function () {
|
|
102
|
+
var t = {};
|
|
103
|
+
new Provider(t).setRole("admin");
|
|
104
|
+
expect(t).to.be.deep.eql({});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("setUserId", function () {
|
|
109
|
+
it("session exist, set _id", function () {
|
|
110
|
+
const t = {
|
|
111
|
+
session: {
|
|
112
|
+
role: "user",
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
const id = mongoose.Types.ObjectId();
|
|
116
|
+
Auth.setUserId(t, id);
|
|
117
|
+
expect(t.session.user).to.eql(id);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("session not exist, set _id", function () {
|
|
121
|
+
const t = {};
|
|
122
|
+
const id = mongoose.Types.ObjectId();
|
|
123
|
+
Auth.setUserId(t, id);
|
|
124
|
+
expect(t).to.be.deep.eql({});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("getUserId", function () {
|
|
129
|
+
it("session exist, user id exist", function () {
|
|
130
|
+
const t = {
|
|
131
|
+
session: {
|
|
132
|
+
user: mongoose.Types.ObjectId(),
|
|
133
|
+
role: "user",
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const id = Auth.getUserId(t);
|
|
137
|
+
expect(id.toString()).to.eql(t.session.user.toString());
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("session not exist", function () {
|
|
141
|
+
const t = {};
|
|
142
|
+
const id = Auth.getUserId(t);
|
|
143
|
+
expect(id).to.be.deep.eql(undefined);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("getSessionId", function () {
|
|
148
|
+
it("session exist, session id exist", function () {
|
|
149
|
+
const t = {
|
|
150
|
+
session: {
|
|
151
|
+
id: mongoose.Types.ObjectId(),
|
|
152
|
+
role: "user",
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
const id = Auth.getSessionId(t);
|
|
156
|
+
expect(id.toString()).to.eql(t.session.id.toString());
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("session not exist", function () {
|
|
160
|
+
const t = {};
|
|
161
|
+
const id = Auth.getSessionId(t);
|
|
162
|
+
expect(id).to.be.deep.eql(undefined);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe("setAuth", function () {
|
|
167
|
+
it("session exist", function () {
|
|
168
|
+
const t = {
|
|
169
|
+
session: {},
|
|
170
|
+
};
|
|
171
|
+
const id = mongoose.Types.ObjectId();
|
|
172
|
+
Auth.setAuth(t, id, "root");
|
|
173
|
+
expect(t.session.user.toString()).to.eql(id.toString());
|
|
174
|
+
expect(t.session.role).to.eql("root");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("session not exist", function () {
|
|
178
|
+
const t = {};
|
|
179
|
+
const id = mongoose.Types.ObjectId();
|
|
180
|
+
Auth.setAuth(t, id, "user");
|
|
181
|
+
expect(t).to.be.deep.eql({});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("setGuest", function () {
|
|
186
|
+
it("session exist", function () {
|
|
187
|
+
const id = mongoose.Types.ObjectId();
|
|
188
|
+
const t = {
|
|
189
|
+
session: { user: id, role: "admin" },
|
|
190
|
+
user: { _id: id },
|
|
191
|
+
};
|
|
192
|
+
Auth.setGuest(t);
|
|
193
|
+
expect(t.session.user).to.eql(null);
|
|
194
|
+
expect(t.user).to.eql(null);
|
|
195
|
+
expect(t.session.role).to.eql(["guest"]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("session not exist", function () {
|
|
199
|
+
const t = {};
|
|
200
|
+
Auth.setGuest(t);
|
|
201
|
+
expect(t).to.be.deep.eql({});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("cleanse", function () {
|
|
206
|
+
it("session exist, destroy method exists", function () {
|
|
207
|
+
const id = mongoose.Types.ObjectId();
|
|
208
|
+
let destroyed = false;
|
|
209
|
+
const t = {
|
|
210
|
+
session: {
|
|
211
|
+
user: id,
|
|
212
|
+
role: "admin",
|
|
213
|
+
destroy() {
|
|
214
|
+
destroyed = true;
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
Auth.cleanse(t);
|
|
219
|
+
expect(t.session.user).to.eql(null);
|
|
220
|
+
expect(t.session.role).to.eql(["guest"]);
|
|
221
|
+
expect(destroyed).to.eql(true);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("session exist, destroy method exists", function () {
|
|
225
|
+
const id = mongoose.Types.ObjectId();
|
|
226
|
+
const t = {
|
|
227
|
+
session: {
|
|
228
|
+
user: id,
|
|
229
|
+
role: "admin",
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
Auth.cleanse(t);
|
|
233
|
+
expect(t.session.user).to.eql(null);
|
|
234
|
+
expect(t.session.role).to.eql(["guest"]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("session not exist", function () {
|
|
238
|
+
const t = {};
|
|
239
|
+
Auth.cleanse(t);
|
|
240
|
+
expect(t).to.be.deep.eql({});
|
|
241
|
+
});
|
|
242
|
+
});*/
|
|
243
|
+
});
|
|
244
|
+
};
|