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/fields.js
CHANGED
|
@@ -1,292 +1,319 @@
|
|
|
1
|
-
const mongoose = require(
|
|
2
|
-
|
|
3
|
-
module.exports = ({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(result).to.deep.equal(undefined);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('isOwner', ()=>{
|
|
40
|
-
it('data.ownerId:ObjectId, user_id not empty:string, equal', ()=>{
|
|
41
|
-
const owner = mongoose.Types.ObjectId();
|
|
42
|
-
const data = {
|
|
43
|
-
ownerId:owner
|
|
44
|
-
};
|
|
45
|
-
let result = Auth.isOwner(data, owner.toString());
|
|
46
|
-
expect(result).to.deep.equal(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('data.ownerId:ObjectId, user_id:ObjectId, not equal', ()=>{
|
|
50
|
-
const data = {
|
|
51
|
-
ownerId: mongoose.Types.ObjectId()
|
|
52
|
-
};
|
|
53
|
-
let result = Auth.isOwner(data, mongoose.Types.ObjectId());
|
|
54
|
-
expect(result).to.deep.equal(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('data.ownerId not defined, user_id:ObjectId, not equal', ()=>{
|
|
58
|
-
const data = {};
|
|
59
|
-
let result = Auth.isOwner(data, mongoose.Types.ObjectId());
|
|
60
|
-
expect(result).to.deep.equal(false);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('data.ownerId:undefined, user_id:undefined, not equal', ()=>{
|
|
64
|
-
const data = {ownerId: undefined};
|
|
65
|
-
let result = Auth.isOwner(data, undefined);
|
|
66
|
-
expect(result).to.deep.equal(false);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('ruleIsWildcard', ()=>{
|
|
71
|
-
it('undefined', ()=>{
|
|
72
|
-
const rule = undefined;
|
|
73
|
-
let result = Auth.ruleIsWildcard(rule);
|
|
74
|
-
expect(result).to.deep.equal(false);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('"*"', ()=>{
|
|
78
|
-
const rule = '*';
|
|
79
|
-
let result = Auth.ruleIsWildcard(rule);
|
|
80
|
-
expect(result).to.deep.equal(true);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('""', ()=>{
|
|
84
|
-
const rule = '';
|
|
85
|
-
let result = Auth.ruleIsWildcard(rule);
|
|
86
|
-
expect(result).to.deep.equal(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('[]', ()=>{
|
|
90
|
-
const rule = [];
|
|
91
|
-
let result = Auth.ruleIsWildcard(rule);
|
|
92
|
-
expect(result).to.deep.equal(false);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('["*"]', ()=>{
|
|
96
|
-
const rule = ['*'];
|
|
97
|
-
let result = Auth.ruleIsWildcard(rule);
|
|
98
|
-
expect(result).to.deep.equal(true);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
describe('fieldIsSafe', ()=>{
|
|
104
|
-
it('field.safe.action:Array<string>, action:string, roles:Array<string>, special:undefined', ()=>{
|
|
105
|
-
const field = {
|
|
106
|
-
safe:{
|
|
107
|
-
update: ['root']
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
action = 'update',
|
|
111
|
-
roles = ['root'],
|
|
112
|
-
special = undefined;
|
|
113
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
114
|
-
expect(result).to.deep.equal(true);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('field.safe.action:not defined, action:string, roles:Array<string>, special:undefined', ()=>{
|
|
118
|
-
const field = {
|
|
119
|
-
safe:{}
|
|
120
|
-
},
|
|
121
|
-
action = 'update',
|
|
122
|
-
roles = ['root'],
|
|
123
|
-
special = undefined;
|
|
124
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
125
|
-
expect(result).to.deep.equal(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('field.safe.action:wildcard, action:string, roles:Array<string>, special:undefined', ()=>{
|
|
129
|
-
const field = {
|
|
130
|
-
safe:{
|
|
131
|
-
update: "*"
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
action = 'update',
|
|
135
|
-
roles = ['root'],
|
|
136
|
-
special = undefined;
|
|
137
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
138
|
-
expect(result).to.deep.equal(true);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('field.safe: not defined, action:string, roles:Array<string>, special:undefined', ()=>{
|
|
142
|
-
const field = {},
|
|
143
|
-
action = 'update',
|
|
144
|
-
roles = ['root'],
|
|
145
|
-
special = undefined;
|
|
146
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
147
|
-
expect(result).to.deep.equal(false);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('field.safe.action:string but not wildcard , action:string, roles:Array<string>, special:undefined', ()=>{
|
|
151
|
-
const field = {
|
|
152
|
-
safe:{
|
|
153
|
-
update: 'root'
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
action = 'update',
|
|
157
|
-
roles = ['root'],
|
|
158
|
-
special = undefined;
|
|
159
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
160
|
-
expect(result).to.deep.equal(false);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('field.safe.action:Array<string> with special, action:string, roles:Array<string>, special:Array<string>', ()=>{
|
|
164
|
-
const field = {
|
|
165
|
-
safe:{
|
|
166
|
-
update: ['root', '@owner']
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
action = 'update',
|
|
170
|
-
roles = ['guest'],
|
|
171
|
-
special = ['@owner'];
|
|
172
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
173
|
-
expect(result).to.deep.equal(true);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('field.safe.action:Array<string> with special, action:string, roles:Array<string>, special:Array<string>', ()=>{
|
|
177
|
-
const field = {
|
|
178
|
-
safe:{
|
|
179
|
-
update: ['root', '@owner']
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
action = 'update',
|
|
183
|
-
roles = ['guest'],
|
|
184
|
-
special = ['@system'];
|
|
185
|
-
let result = Auth.fieldIsSafe(field, action,roles, special);
|
|
186
|
-
expect(result).to.deep.equal(false);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('createSpecial', ()=>{
|
|
191
|
-
it('owner - true, system - true', ()=>{
|
|
192
|
-
let result = Auth.createSpecial(true, true);
|
|
193
|
-
expect(result).to.deep.equal(['@owner', '@system']);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('owner - false, system - false', ()=>{
|
|
197
|
-
let result = Auth.createSpecial(false, false);
|
|
198
|
-
expect(result).to.deep.equal([]);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const schema_1 = {
|
|
203
|
-
name:{
|
|
204
|
-
safe: {
|
|
205
|
-
'read': '*',
|
|
206
|
-
'update': ['@owner', '@system', 'root']
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
email:{
|
|
210
|
-
safe: {
|
|
211
|
-
'read': ['@owner', '@system', 'root', 'admin', 'manager'],
|
|
212
|
-
'update': ['@owner', '@system', 'root']
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
country:{
|
|
216
|
-
safe: {
|
|
217
|
-
'read': '*',
|
|
218
|
-
'update': ['@owner']
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
active:{
|
|
222
|
-
safe: {
|
|
223
|
-
'read': '*',
|
|
224
|
-
'update': ['@system', 'root', 'admin']
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
legacy:{},
|
|
228
|
-
banned:{safe:{}},
|
|
229
|
-
ID:1
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const data_1 = {
|
|
233
|
-
name: 'alex',
|
|
234
|
-
email: 'alex@mail.net',
|
|
235
|
-
country: 'dr',
|
|
236
|
-
active: true
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const data_2 = {
|
|
240
|
-
name: 'alex',
|
|
241
|
-
country: 'dr',
|
|
242
|
-
active: true
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
describe('getSafeFieldsForRoleAction', ()=>{
|
|
246
|
-
it('guest performing reading', ()=>{
|
|
247
|
-
let result = Auth.getSafeFieldsForRoleAction(schema_1, 'read', ['guest'], false, false);
|
|
248
|
-
expect(result).to.deep.equal(['name', 'country', 'active']);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('root performing update', ()=>{
|
|
252
|
-
let result = Auth.getSafeFieldsForRoleAction(schema_1, 'update', ['root'], false, false);
|
|
253
|
-
expect(result).to.deep.equal(['name', 'email', 'active']);
|
|
254
|
-
});
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
module.exports = ({ Auth, expect }) => {
|
|
4
|
+
describe("Fields", () => {
|
|
5
|
+
describe("getOwnerId", () => {
|
|
6
|
+
it("data has ownerId as String", () => {
|
|
7
|
+
const val = mongoose.Types.ObjectId().toString();
|
|
8
|
+
const data = {
|
|
9
|
+
owner: val,
|
|
10
|
+
};
|
|
11
|
+
let result = Auth.getOwnerId(data);
|
|
12
|
+
expect(result).to.deep.equal(val);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("data has ownerId as ObjectId", () => {
|
|
16
|
+
const val = mongoose.Types.ObjectId();
|
|
17
|
+
const data = {
|
|
18
|
+
owner: val,
|
|
19
|
+
};
|
|
20
|
+
let result = Auth.getOwnerId(data);
|
|
21
|
+
expect(result).to.deep.equal(val);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("data hasn't ownerId", () => {
|
|
25
|
+
const data = {};
|
|
26
|
+
let result = Auth.getOwnerId(data);
|
|
27
|
+
expect(result).to.deep.equal(undefined);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("data undefined", () => {
|
|
31
|
+
let result = Auth.getOwnerId(undefined);
|
|
32
|
+
expect(result).to.deep.equal(undefined);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
255
35
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
36
|
+
describe("isOwner", () => {
|
|
37
|
+
it("data.ownerId:ObjectId, user_id not empty:string, equal", () => {
|
|
38
|
+
const owner = mongoose.Types.ObjectId();
|
|
39
|
+
const data = {
|
|
40
|
+
owner: owner,
|
|
41
|
+
};
|
|
42
|
+
let result = Auth.isOwner(data, owner.toString());
|
|
43
|
+
expect(result).to.deep.equal(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("data.ownerId:ObjectId, user_id:ObjectId, not equal", () => {
|
|
47
|
+
const data = {
|
|
48
|
+
owner: mongoose.Types.ObjectId(),
|
|
49
|
+
};
|
|
50
|
+
let result = Auth.isOwner(data, mongoose.Types.ObjectId());
|
|
51
|
+
expect(result).to.deep.equal(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("data.ownerId not defined, user_id:ObjectId, not equal", () => {
|
|
55
|
+
const data = {};
|
|
56
|
+
let result = Auth.isOwner(data, mongoose.Types.ObjectId());
|
|
57
|
+
expect(result).to.deep.equal(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("data.ownerId:undefined, user_id:undefined, not equal", () => {
|
|
61
|
+
const data = { ownerId: undefined };
|
|
62
|
+
let result = Auth.isOwner(data, undefined);
|
|
63
|
+
expect(result).to.deep.equal(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
260
66
|
|
|
67
|
+
describe("ruleIsWildcard", () => {
|
|
68
|
+
it("undefined", () => {
|
|
69
|
+
const rule = undefined;
|
|
70
|
+
let result = Auth.ruleIsWildcard(rule);
|
|
71
|
+
expect(result).to.deep.equal(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('"*"', () => {
|
|
75
|
+
const rule = "*";
|
|
76
|
+
let result = Auth.ruleIsWildcard(rule);
|
|
77
|
+
expect(result).to.deep.equal(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('""', () => {
|
|
81
|
+
const rule = "";
|
|
82
|
+
let result = Auth.ruleIsWildcard(rule);
|
|
83
|
+
expect(result).to.deep.equal(false);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("[]", () => {
|
|
87
|
+
const rule = [];
|
|
88
|
+
let result = Auth.ruleIsWildcard(rule);
|
|
89
|
+
expect(result).to.deep.equal(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('["*"]', () => {
|
|
93
|
+
const rule = ["*"];
|
|
94
|
+
let result = Auth.ruleIsWildcard(rule);
|
|
95
|
+
expect(result).to.deep.equal(true);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
261
98
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
99
|
+
describe("fieldIsSafe", () => {
|
|
100
|
+
it("field.safe.action:Array<string>, action:string, roles:Array<string>, special:undefined", () => {
|
|
101
|
+
const field = {
|
|
102
|
+
safe: {
|
|
103
|
+
update: ["root"],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
action = "update",
|
|
107
|
+
roles = ["root"],
|
|
108
|
+
special = undefined;
|
|
109
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
110
|
+
expect(result).to.deep.equal(true);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("field.safe.action:not defined, action:string, roles:Array<string>, special:undefined", () => {
|
|
114
|
+
const field = {
|
|
115
|
+
safe: {},
|
|
116
|
+
},
|
|
117
|
+
action = "update",
|
|
118
|
+
roles = ["root"],
|
|
119
|
+
special = undefined;
|
|
120
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
121
|
+
expect(result).to.deep.equal(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("field.safe.action:wildcard, action:string, roles:Array<string>, special:undefined", () => {
|
|
125
|
+
const field = {
|
|
126
|
+
safe: {
|
|
127
|
+
update: "*",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
action = "update",
|
|
131
|
+
roles = ["root"],
|
|
132
|
+
special = undefined;
|
|
133
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
134
|
+
expect(result).to.deep.equal(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("field.safe: not defined, action:string, roles:Array<string>, special:undefined", () => {
|
|
138
|
+
const field = {},
|
|
139
|
+
action = "update",
|
|
140
|
+
roles = ["root"],
|
|
141
|
+
special = undefined;
|
|
142
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
143
|
+
expect(result).to.deep.equal(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("field.safe.action:string but not wildcard , action:string, roles:Array<string>, special:undefined", () => {
|
|
147
|
+
const field = {
|
|
148
|
+
safe: {
|
|
149
|
+
update: "root",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
action = "update",
|
|
153
|
+
roles = ["root"],
|
|
154
|
+
special = undefined;
|
|
155
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
156
|
+
expect(result).to.deep.equal(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("field.safe.action:Array<string> with special, action:string, roles:Array<string>, special:Array<string>", () => {
|
|
160
|
+
const field = {
|
|
161
|
+
safe: {
|
|
162
|
+
update: ["root", "@owner"],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
action = "update",
|
|
166
|
+
roles = ["guest"],
|
|
167
|
+
special = ["@owner"];
|
|
168
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
169
|
+
expect(result).to.deep.equal(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("field.safe.action:Array<string> with special, action:string, roles:Array<string>, special:Array<string>", () => {
|
|
173
|
+
const field = {
|
|
174
|
+
safe: {
|
|
175
|
+
update: ["root", "@owner"],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
action = "update",
|
|
179
|
+
roles = ["guest"],
|
|
180
|
+
special = ["@system"];
|
|
181
|
+
let result = Auth.fieldIsSafe(field, action, roles, special);
|
|
182
|
+
expect(result).to.deep.equal(false);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
267
185
|
|
|
186
|
+
describe("createSpecial", () => {
|
|
187
|
+
it("owner - true, system - true", () => {
|
|
188
|
+
let result = Auth.createSpecial(true, true);
|
|
189
|
+
expect(result).to.deep.equal(["@owner", "@system"]);
|
|
190
|
+
});
|
|
268
191
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
name: 'alex',
|
|
274
|
-
country: 'dr',
|
|
275
|
-
active: true
|
|
192
|
+
it("owner - false, system - false", () => {
|
|
193
|
+
let result = Auth.createSpecial(false, false);
|
|
194
|
+
expect(result).to.deep.equal([]);
|
|
195
|
+
});
|
|
276
196
|
});
|
|
277
|
-
});
|
|
278
197
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
198
|
+
const schema_1 = {
|
|
199
|
+
name: {
|
|
200
|
+
safe: {
|
|
201
|
+
read: "*",
|
|
202
|
+
update: ["@owner", "@system", "root"],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
email: {
|
|
206
|
+
safe: {
|
|
207
|
+
read: ["@owner", "@system", "root", "admin", "manager"],
|
|
208
|
+
update: ["@owner", "@system", "root"],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
country: {
|
|
212
|
+
safe: {
|
|
213
|
+
read: "*",
|
|
214
|
+
update: ["@owner"],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
active: {
|
|
218
|
+
safe: {
|
|
219
|
+
read: "*",
|
|
220
|
+
update: ["@system", "root", "admin"],
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
legacy: {},
|
|
224
|
+
banned: { safe: {} },
|
|
225
|
+
ID: 1,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const data_1 = {
|
|
229
|
+
name: "alex",
|
|
230
|
+
email: "alex@mail.net",
|
|
231
|
+
country: "dr",
|
|
232
|
+
active: true,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const data_2 = {
|
|
236
|
+
name: "alex",
|
|
237
|
+
country: "dr",
|
|
238
|
+
active: true,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
describe("getSafeFieldsForRoleAction", () => {
|
|
242
|
+
it("guest performing reading", () => {
|
|
243
|
+
let result = Auth.getSafeFieldsForRoleAction(
|
|
244
|
+
schema_1,
|
|
245
|
+
"read",
|
|
246
|
+
["guest"],
|
|
247
|
+
false,
|
|
248
|
+
false
|
|
249
|
+
);
|
|
250
|
+
expect(result).to.deep.equal(["name", "country", "active"]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("root performing update", () => {
|
|
254
|
+
let result = Auth.getSafeFieldsForRoleAction(
|
|
255
|
+
schema_1,
|
|
256
|
+
"update",
|
|
257
|
+
["root"],
|
|
258
|
+
false,
|
|
259
|
+
false
|
|
260
|
+
);
|
|
261
|
+
expect(result).to.deep.equal(["name", "email", "active"]);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("@owner performing update", () => {
|
|
265
|
+
let result = Auth.getSafeFieldsForRoleAction(
|
|
266
|
+
schema_1,
|
|
267
|
+
"update",
|
|
268
|
+
["user"],
|
|
269
|
+
true,
|
|
270
|
+
false
|
|
271
|
+
);
|
|
272
|
+
expect(result).to.deep.equal(["name", "email", "country"]);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("@system performing update", () => {
|
|
276
|
+
let result = Auth.getSafeFieldsForRoleAction(
|
|
277
|
+
schema_1,
|
|
278
|
+
"update",
|
|
279
|
+
["user"],
|
|
280
|
+
false,
|
|
281
|
+
true
|
|
282
|
+
);
|
|
283
|
+
expect(result).to.deep.equal(["name", "email", "active"]);
|
|
284
|
+
});
|
|
285
285
|
});
|
|
286
|
-
});
|
|
287
286
|
|
|
287
|
+
describe("extractSafeFields", () => {
|
|
288
|
+
it("guest performing reading", () => {
|
|
289
|
+
let result = Auth.extractSafeFields(
|
|
290
|
+
schema_1,
|
|
291
|
+
"read",
|
|
292
|
+
data_1,
|
|
293
|
+
["guest"],
|
|
294
|
+
null
|
|
295
|
+
);
|
|
296
|
+
expect(result).to.deep.equal({
|
|
297
|
+
name: "alex",
|
|
298
|
+
country: "dr",
|
|
299
|
+
active: true,
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("guest performing reading, data has some fields not defined", () => {
|
|
304
|
+
let result = Auth.extractSafeFields(
|
|
305
|
+
schema_1,
|
|
306
|
+
"read",
|
|
307
|
+
data_2,
|
|
308
|
+
["root"],
|
|
309
|
+
null
|
|
310
|
+
);
|
|
311
|
+
expect(result).to.deep.equal({
|
|
312
|
+
name: "alex",
|
|
313
|
+
country: "dr",
|
|
314
|
+
active: true,
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
288
318
|
});
|
|
289
|
-
|
|
290
|
-
});
|
|
291
|
-
|
|
292
319
|
};
|