@@ -12,17 +12,17 @@ const {
12
12
retrieveUsersWithRole,
13
13
retrieveMembers,
14
14
retreiveFilteredUsers,
15
- privilegedAccess,
16
15
levelSpecificAccess,
17
- ACCESS_LEVEL ,
18
16
} = require ( "../../../services/dataAccessLayer" ) ;
19
17
18
+ const { ROLE_ACCESS , ACCESS_LEVEL } = require ( "../../../constants/userDataLevels" ) ;
19
+
20
20
const userData = require ( "../../fixtures/user/user" ) ( ) ;
21
- const { USER_SENSITIVE_DATA } = require ( "../../../constants/users" ) ;
22
21
23
22
chai . use ( chaiHttp ) ;
24
23
const expect = chai . expect ;
25
24
let fetchUserStub ;
25
+
26
26
describe ( "Data Access Layer" , function ( ) {
27
27
describe ( "retrieveUsers" , function ( ) {
28
28
it ( "should fetch a single user by ID and remove sensitive info" , async function ( ) {
@@ -31,7 +31,7 @@ describe("Data Access Layer", function () {
31
31
const result = await retrieveUsers ( { id : userData [ 12 ] . id } ) ;
32
32
removeSensitiveInfo ( userData [ 12 ] ) ;
33
33
expect ( result . user ) . to . deep . equal ( userData [ 12 ] ) ;
34
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
34
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
35
35
expect ( result . user ) . to . not . have . property ( key ) ;
36
36
} ) ;
37
37
} ) ;
@@ -41,7 +41,7 @@ describe("Data Access Layer", function () {
41
41
const result = await retrieveUsers ( { username : userData [ 12 ] . username } ) ;
42
42
removeSensitiveInfo ( userData [ 12 ] ) ;
43
43
expect ( result . user ) . to . deep . equal ( userData [ 12 ] ) ;
44
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
44
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
45
45
expect ( result . user ) . to . not . have . property ( key ) ;
46
46
} ) ;
47
47
} ) ;
@@ -53,7 +53,7 @@ describe("Data Access Layer", function () {
53
53
removeSensitiveInfo ( userData [ 12 ] ) ;
54
54
result . forEach ( ( user ) => {
55
55
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
56
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
56
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
57
57
expect ( user ) . to . not . have . property ( key ) ;
58
58
} ) ;
59
59
} ) ;
@@ -67,7 +67,7 @@ describe("Data Access Layer", function () {
67
67
removeSensitiveInfo ( userData [ 12 ] ) ;
68
68
result . users . forEach ( ( user ) => {
69
69
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
70
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
70
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
71
71
expect ( user ) . to . not . have . property ( key ) ;
72
72
} ) ;
73
73
} ) ;
@@ -77,7 +77,7 @@ describe("Data Access Layer", function () {
77
77
const userdata = userData [ 12 ] ;
78
78
await retrieveUsers ( { userdata } ) ;
79
79
removeSensitiveInfo ( userData [ 12 ] ) ;
80
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
80
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
81
81
expect ( userdata ) . to . not . have . property ( key ) ;
82
82
} ) ;
83
83
} ) ;
@@ -90,7 +90,7 @@ describe("Data Access Layer", function () {
90
90
const result = await retrieveDiscordUsers ( ) ;
91
91
result . forEach ( ( user ) => {
92
92
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
93
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
93
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
94
94
expect ( user ) . to . not . have . property ( key ) ;
95
95
} ) ;
96
96
} ) ;
@@ -105,7 +105,7 @@ describe("Data Access Layer", function () {
105
105
const result = await retrieveUsersWithRole ( query ) ;
106
106
result . forEach ( ( user ) => {
107
107
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
108
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
108
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
109
109
expect ( user ) . to . not . have . property ( key ) ;
110
110
} ) ;
111
111
} ) ;
@@ -119,7 +119,7 @@ describe("Data Access Layer", function () {
119
119
const result = await retrieveMembers ( ) ;
120
120
result . forEach ( ( user ) => {
121
121
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
122
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
122
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
123
123
expect ( user ) . to . not . have . property ( key ) ;
124
124
} ) ;
125
125
} ) ;
@@ -134,7 +134,7 @@ describe("Data Access Layer", function () {
134
134
const result = await retreiveFilteredUsers ( query ) ;
135
135
result . forEach ( ( user ) => {
136
136
expect ( user ) . to . deep . equal ( userData [ 12 ] ) ;
137
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
137
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
138
138
expect ( user ) . to . not . have . property ( key ) ;
139
139
} ) ;
140
140
} ) ;
@@ -143,90 +143,37 @@ describe("Data Access Layer", function () {
143
143
144
144
describe ( "removeSensitiveInfo" , function ( ) {
145
145
it ( "should remove sensitive information from the users object" , function ( ) {
146
- removeSensitiveInfo ( userData ) ;
147
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
146
+ removeSensitiveInfo ( userData [ 12 ] ) ;
147
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
148
148
expect ( userData [ 12 ] ) . to . not . have . property ( key ) ;
149
149
} ) ;
150
150
} ) ;
151
151
} ) ;
152
152
153
- describe ( "privilegedAccess" , function ( ) {
154
- it ( "should return default user fields if email does not exist in userdata and INTERNAL access requested" , function ( ) {
155
- const data = { } ;
156
- const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . INTERNAL ) ;
157
- expect ( result . email ) . to . equal ( undefined ) ;
158
- } ) ;
159
-
160
- it ( "should set only email for INTERNAL access if email exists" , function ( ) {
161
- const data = {
162
-
163
- } ;
164
- const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . INTERNAL ) ;
165
- expect ( result ) . to . have . property ( "email" ) ;
166
- } ) ;
167
-
168
- it ( "should set email and phone for PRIVATE access if email and phone exists" , function ( ) {
169
- const data = {
170
-
171
- phone : "1234567890" ,
172
- } ;
173
- const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . PRIVATE ) ;
174
- expect ( result ) . to . have . property ( "email" ) ;
175
- expect ( result ) . to . have . property ( "phone" ) ;
176
- } ) ;
177
-
178
- it ( "should set email, phone, and chaincode for CONFIDENTIAL access if email,phone and chaincode exists" , function ( ) {
179
- const data = {
180
-
181
- phone : "1234567890" ,
182
- chaincode : "abc7896" ,
183
- } ;
184
- const result = privilegedAccess ( userData [ 11 ] , data , ACCESS_LEVEL . CONFIDENTIAL ) ;
185
- expect ( result ) . to . have . property ( "email" ) ;
186
- expect ( result ) . to . have . property ( "phone" ) ;
187
- expect ( result ) . to . have . property ( "chaincode" ) ;
188
- } ) ;
189
- } ) ;
190
-
191
153
describe ( "levelSpecificAccess" , function ( ) {
192
154
it ( "should return the user object for PUBLIC level after removing all sensitive info" , function ( ) {
193
- const result = levelSpecificAccess ( userData [ 12 ] , ACCESS_LEVEL . PUBLIC ) ;
194
- USER_SENSITIVE_DATA . forEach ( ( key ) => {
155
+ const result = levelSpecificAccess ( { ... userData [ 12 ] } , ACCESS_LEVEL . PUBLIC ) ;
156
+ ROLE_ACCESS [ ACCESS_LEVEL . PUBLIC ] . forEach ( ( key ) => {
195
157
expect ( result ) . to . not . have . property ( key ) ;
196
158
} ) ;
197
159
} ) ;
198
160
199
161
it ( 'should return "unauthorized" for non-superuser role' , function ( ) {
200
- const unauthorizedRole = { role : { super_user : false } } ;
201
- const result = levelSpecificAccess ( userData [ 12 ] , ACCESS_LEVEL . PRIVATE , unauthorizedRole ) ;
162
+ const unauthorizedRole = "member" ;
163
+ const result = levelSpecificAccess ( { ... userData [ 12 ] } , ACCESS_LEVEL . PRIVATE , unauthorizedRole ) ;
202
164
expect ( result ) . to . equal ( "unauthorized" ) ;
203
165
} ) ;
204
166
205
- it ( "should call privilegedAccess for INTERNAL level and super_user role" , function ( ) {
206
- userData [ 11 ] . email = "[email protected] " ;
207
- const role = { super_user : true } ;
208
- const result = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . INTERNAL , role ) ;
167
+ it ( "should keep sensitive info for valid role and level" , function ( ) {
168
+ const user = { ...
userData [ 12 ] , email :
"[email protected] " , phone :
"7890654329" , chaincode :
"78906" } ;
169
+ const role = "super_user" ;
170
+ const level = ACCESS_LEVEL . PRIVATE ;
171
+ const result = levelSpecificAccess ( user , level , role ) ;
172
+ ROLE_ACCESS [ level ] . forEach ( ( key ) => {
173
+ expect ( result ) . to . not . have . property ( key ) ;
174
+ } ) ;
175
+ expect ( result ) . to . have . property ( "phone" ) ;
209
176
expect ( result ) . to . have . property ( "email" ) ;
210
177
} ) ;
211
-
212
- it ( "should call privilegedAccess for PRIVATE level and super_user role" , function ( ) {
213
- userData [ 11 ] . email = "[email protected] " ;
214
- userData [ 11 ] . phone = "8976509889" ;
215
- const role = { super_user : true } ;
216
- const user = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . PRIVATE , role ) ;
217
- expect ( user ) . to . have . property ( "email" ) ;
218
- expect ( user ) . to . have . property ( "phone" ) ;
219
- } ) ;
220
-
221
- it ( "should call privilegedAccess for CONFIDENTIAL level and super_user role" , function ( ) {
222
- userData [ 11 ] . email = "[email protected] " ;
223
- userData [ 11 ] . phone = "8976509889" ;
224
- userData [ 11 ] . chaincode = "1234567" ;
225
- const role = { super_user : true } ;
226
- const user = levelSpecificAccess ( userData [ 11 ] , ACCESS_LEVEL . CONFIDENTIAL , role ) ;
227
- expect ( user ) . to . have . property ( "email" ) ;
228
- expect ( user ) . to . have . property ( "phone" ) ;
229
- expect ( user ) . to . have . property ( "chaincode" ) ;
230
- } ) ;
231
178
} ) ;
232
179
} ) ;
0 commit comments