maskdata 1.2.2 → 1.2.4
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/.prettierrc.js +7 -0
- package/README.md +213 -144
- package/index.d.ts +86 -72
- package/index.js +11 -3
- package/lib/ExceptionsHandler/BadOption.js +2 -2
- package/lib/helpers/Constants.js +57 -48
- package/lib/helpers/MaskHelper.js +156 -95
- package/lib/helpers/jsonGetSet.js +8 -9
- package/lib/maskService/CardMask.js +51 -51
- package/lib/maskService/EmailMask.js +26 -20
- package/lib/maskService/JsonMask.js +166 -87
- package/lib/maskService/JwtMask.js +92 -0
- package/lib/maskService/PasswordMask.js +34 -33
- package/lib/maskService/PhoneMask.js +19 -15
- package/lib/maskService/StringMask.js +33 -34
- package/lib/maskService/UuidMask.js +28 -21
- package/package.json +18 -7
- package/tests/scribble.js +379 -122
- package/tests/testCard.js +35 -40
- package/tests/testEmail.js +46 -53
- package/tests/testJsonFields.js +486 -240
- package/tests/testJsonGetSet.js +54 -21
- package/tests/testJwt.js +262 -0
- package/tests/testMaskHelper.js +109 -103
- package/tests/testPassword.js +51 -51
- package/tests/testPhone.js +35 -41
- package/tests/testString.js +46 -57
- package/tests/testUuid.js +55 -43
package/tests/testJsonFields.js
CHANGED
|
@@ -6,197 +6,253 @@ const maskData = require('../index');
|
|
|
6
6
|
const Constants = require('../lib/helpers/Constants');
|
|
7
7
|
|
|
8
8
|
const jsonInput = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
credit: '1234-5678-8765-1234',
|
|
10
|
+
debit: '0000-1111-2222-3333',
|
|
11
|
+
primaryEmail: 'primary@Email.com',
|
|
12
|
+
secondaryEmail: 'secondary@Email.com',
|
|
13
|
+
password: 'dummyPassword',
|
|
14
|
+
homePhone: '+1 1234567890',
|
|
15
|
+
workPhone: '+1 9876543210',
|
|
16
|
+
addressLine1: 'This is my addressline 1. This is my home',
|
|
17
|
+
addressLine2: 'AddressLine 2',
|
|
18
|
+
uuid1: '123e4567-e89b-12d3-a456-426614174000'
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
describe('JSON mask1', function() {
|
|
22
|
-
describe('Mask json with default options', function() {
|
|
21
|
+
describe('JSON mask1', function () {
|
|
22
|
+
describe('Mask json with default options', function () {
|
|
23
23
|
let testData = {
|
|
24
|
-
title:
|
|
24
|
+
title: 'Mask json with default options',
|
|
25
25
|
input: {
|
|
26
26
|
level1: {
|
|
27
|
-
field1:
|
|
27
|
+
field1: 'field1Value',
|
|
28
28
|
level2: {
|
|
29
|
-
field2:
|
|
30
|
-
field3: [
|
|
29
|
+
field2: 'field2Value',
|
|
30
|
+
field3: [{ Hello: 'Hello', Hi: 'one' }, { Hello: 'Hello again' }],
|
|
31
31
|
level3: {
|
|
32
|
-
field4:
|
|
33
|
-
field5:
|
|
32
|
+
field4: 'field4Value',
|
|
33
|
+
field5: 'field5Value'
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
value1:
|
|
37
|
+
value1: 'value'
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
|
|
41
|
-
it(`${testData.title}`, function() {
|
|
41
|
+
it(`${testData.title}`, function () {
|
|
42
42
|
const jsonMaskConfig = {
|
|
43
|
-
fields
|
|
43
|
+
fields: ['level1.level2.field3[*].Hello', 'level1.level2.level3.*', 'value1']
|
|
44
44
|
};
|
|
45
45
|
const masked = maskData.maskJSONFields(testData.input, jsonMaskConfig);
|
|
46
|
-
expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal(
|
|
47
|
-
expect(masked['level1']['level2']['field3'][1]['Hello']).to.equal(
|
|
48
|
-
expect(masked['level1']['level2']['level3']['field4']).to.equal(
|
|
49
|
-
expect(masked['level1']['level2']['level3']['field5']).to.equal(
|
|
50
|
-
expect(masked['value1']).to.equal(
|
|
46
|
+
expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal('*****');
|
|
47
|
+
expect(masked['level1']['level2']['field3'][1]['Hello']).to.equal('***********');
|
|
48
|
+
expect(masked['level1']['level2']['level3']['field4']).to.equal('***********');
|
|
49
|
+
expect(masked['level1']['level2']['level3']['field5']).to.equal('***********');
|
|
50
|
+
expect(masked['value1']).to.equal('*****');
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
it('Mask json with maxMaskedCharactersStr', function() {
|
|
53
|
+
it('Mask json with maxMaskedCharactersStr', function () {
|
|
54
54
|
const jsonMaskConfig = {
|
|
55
|
-
fields
|
|
55
|
+
fields: ['key1'],
|
|
56
56
|
maxMaskedCharactersStr: 10
|
|
57
57
|
};
|
|
58
|
-
const masked = maskData.maskJSONFields(
|
|
59
|
-
|
|
58
|
+
const masked = maskData.maskJSONFields(
|
|
59
|
+
{ key1: 'value1WithTooManyCharacters' },
|
|
60
|
+
jsonMaskConfig
|
|
61
|
+
);
|
|
62
|
+
expect(masked['key1']).to.equal('**********');
|
|
60
63
|
});
|
|
61
64
|
});
|
|
62
65
|
|
|
63
|
-
describe('Mask json without passing configs', function() {
|
|
66
|
+
describe('Mask json without passing configs', function () {
|
|
64
67
|
let testData = {
|
|
65
|
-
title:
|
|
68
|
+
title: 'Mask json with default options',
|
|
66
69
|
input: {
|
|
67
70
|
level1: {
|
|
68
|
-
field1:
|
|
71
|
+
field1: 'field1Value',
|
|
69
72
|
level2: {
|
|
70
|
-
field2:
|
|
71
|
-
field3: [
|
|
73
|
+
field2: 'field2Value',
|
|
74
|
+
field3: [
|
|
75
|
+
{ Hello: 'Hello', Hi: 'one' },
|
|
76
|
+
{ Hello: 'Hello again' },
|
|
77
|
+
{ NoHello: 'No Hello' }
|
|
78
|
+
],
|
|
72
79
|
level3: {
|
|
73
|
-
field4:
|
|
74
|
-
field5:
|
|
80
|
+
field4: 'field4Value',
|
|
81
|
+
field5: 'field5Value'
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
},
|
|
78
|
-
value1:
|
|
85
|
+
value1: 'value'
|
|
79
86
|
}
|
|
80
|
-
}
|
|
87
|
+
};
|
|
81
88
|
|
|
82
|
-
it(`${testData.title}`, function() {
|
|
89
|
+
it(`${testData.title}`, function () {
|
|
83
90
|
const jsonMaskConfig = {
|
|
84
|
-
fields
|
|
91
|
+
fields: [
|
|
92
|
+
'level1.level2.field3[*].Hello',
|
|
93
|
+
'level1.level2.level3.*',
|
|
94
|
+
'value1',
|
|
95
|
+
'unknownField'
|
|
96
|
+
]
|
|
85
97
|
};
|
|
86
98
|
const masked = maskData.maskJSONFields(testData.input);
|
|
87
|
-
expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
expect(masked['level1']['level2']['
|
|
99
|
+
expect(masked['level1']['level2']['field3'][0]['Hello']).to.equal(
|
|
100
|
+
testData.input['level1']['level2']['field3'][0]['Hello']
|
|
101
|
+
);
|
|
102
|
+
expect(masked['level1']['level2']['field3'][1]['Hello']).to.equal(
|
|
103
|
+
testData.input['level1']['level2']['field3'][1]['Hello']
|
|
104
|
+
);
|
|
105
|
+
expect(masked['level1']['level2']['level3']['field4']).to.equal(
|
|
106
|
+
testData.input['level1']['level2']['level3']['field4']
|
|
107
|
+
);
|
|
108
|
+
expect(masked['level1']['level2']['level3']['field5']).to.equal(
|
|
109
|
+
testData.input['level1']['level2']['level3']['field5']
|
|
110
|
+
);
|
|
91
111
|
expect(masked['value1']).to.equal(testData.input['value1']);
|
|
92
112
|
});
|
|
93
113
|
});
|
|
94
|
-
|
|
95
114
|
});
|
|
96
115
|
|
|
97
|
-
describe('JSON mask2', function() {
|
|
98
|
-
|
|
99
|
-
describe('Mask with default options and no fields', function() {
|
|
116
|
+
describe('JSON mask2', function () {
|
|
117
|
+
describe('Mask with default options and no fields', function () {
|
|
100
118
|
let testData = [
|
|
101
119
|
{
|
|
102
120
|
title: 'test json masking with default options and no fields',
|
|
103
121
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
104
|
-
outputCredit: '1234-5678-8765-1234',
|
|
105
|
-
outputDebit: '0000-1111-2222-3333',
|
|
106
|
-
outputPrimaryEmail: 'primary@Email.com',
|
|
122
|
+
outputCredit: '1234-5678-8765-1234',
|
|
123
|
+
outputDebit: '0000-1111-2222-3333',
|
|
124
|
+
outputPrimaryEmail: 'primary@Email.com',
|
|
107
125
|
outputSecondaryEmail: 'secondary@Email.com',
|
|
108
126
|
outputPassword: 'dummyPassword',
|
|
109
|
-
outputHomePhone:
|
|
110
|
-
outputWorkPhone:
|
|
111
|
-
outputAddressLine1:
|
|
112
|
-
outputAddressLine2:
|
|
113
|
-
outputUuid:
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
|
|
117
|
-
testData.forEach(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})
|
|
132
|
-
|
|
127
|
+
outputHomePhone: '+1 1234567890',
|
|
128
|
+
outputWorkPhone: '+1 9876543210',
|
|
129
|
+
outputAddressLine1: 'This is my addressline 1. This is my home',
|
|
130
|
+
outputAddressLine2: 'AddressLine 2',
|
|
131
|
+
outputUuid: '123e4567-e89b-12d3-a456-426614174000'
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
testData.forEach(
|
|
136
|
+
({
|
|
137
|
+
title,
|
|
138
|
+
input,
|
|
139
|
+
outputCredit,
|
|
140
|
+
outputDebit,
|
|
141
|
+
outputPrimaryEmail,
|
|
142
|
+
outputSecondaryEmail,
|
|
143
|
+
outputPassword,
|
|
144
|
+
outputHomePhone,
|
|
145
|
+
outputWorkPhone,
|
|
146
|
+
outputAddressLine1,
|
|
147
|
+
outputAddressLine2,
|
|
148
|
+
outputUuid
|
|
149
|
+
}) => {
|
|
150
|
+
it(`${title}`, function () {
|
|
151
|
+
const masked = maskData.maskJSON2(input, Constants.defaultjsonMask2Configs);
|
|
152
|
+
expect(masked['credit']).to.equal(outputCredit);
|
|
153
|
+
expect(masked['debit']).to.equal(outputDebit);
|
|
154
|
+
expect(masked['primaryEmail']).to.equal(outputPrimaryEmail);
|
|
155
|
+
expect(masked['secondaryEmail']).to.equal(outputSecondaryEmail);
|
|
156
|
+
expect(masked['password']).to.equal(outputPassword);
|
|
157
|
+
expect(masked['homePhone']).to.equal(outputHomePhone);
|
|
158
|
+
expect(masked['workPhone']).to.equal(outputWorkPhone);
|
|
159
|
+
expect(masked['addressLine1']).to.equal(outputAddressLine1);
|
|
160
|
+
expect(masked['addressLine2']).to.equal(outputAddressLine2);
|
|
161
|
+
expect(masked['uuid1']).to.equal(outputUuid);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
);
|
|
133
165
|
});
|
|
134
166
|
|
|
135
|
-
describe('Mask all fields with default options', function() {
|
|
167
|
+
describe('Mask all fields with default options', function () {
|
|
136
168
|
let testData = [
|
|
137
169
|
{
|
|
138
170
|
title: 'test json masking with default options and all types of fields',
|
|
139
171
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
140
|
-
outputCredit: '1234-****-****-***4',
|
|
141
|
-
outputDebit: '0000-****-****-***3',
|
|
142
|
-
outputPrimaryEmail: 'pri****@*******om',
|
|
172
|
+
outputCredit: '1234-****-****-***4',
|
|
173
|
+
outputDebit: '0000-****-****-***3',
|
|
174
|
+
outputPrimaryEmail: 'pri****@*******om',
|
|
143
175
|
outputSecondaryEmail: 'sec******@*******om',
|
|
144
176
|
outputPassword: '*************',
|
|
145
|
-
outputHomePhone:
|
|
146
|
-
outputWorkPhone:
|
|
147
|
-
outputAddressLine1:
|
|
148
|
-
outputAddressLine2:
|
|
149
|
-
outputUuid:
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
|
|
153
|
-
testData.forEach(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
outputHomePhone: '+1 1********0',
|
|
178
|
+
outputWorkPhone: '+1 9********0',
|
|
179
|
+
outputAddressLine1: 'This is my addressline 1. This is my home',
|
|
180
|
+
outputAddressLine2: 'AddressLine 2',
|
|
181
|
+
outputUuid: '********-****-****-****-************'
|
|
182
|
+
}
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
testData.forEach(
|
|
186
|
+
({
|
|
187
|
+
title,
|
|
188
|
+
input,
|
|
189
|
+
outputCredit,
|
|
190
|
+
outputDebit,
|
|
191
|
+
outputPrimaryEmail,
|
|
192
|
+
outputSecondaryEmail,
|
|
193
|
+
outputPassword,
|
|
194
|
+
outputHomePhone,
|
|
195
|
+
outputWorkPhone,
|
|
196
|
+
outputAddressLine1,
|
|
197
|
+
outputAddressLine2,
|
|
198
|
+
outputUuid
|
|
199
|
+
}) => {
|
|
200
|
+
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
201
|
+
jsonMaskConfig['cardFields'] = ['credit', 'debit'];
|
|
202
|
+
jsonMaskConfig['emailFields'] = ['primaryEmail', 'secondaryEmail'];
|
|
203
|
+
jsonMaskConfig['passwordFields'] = ['password'];
|
|
204
|
+
jsonMaskConfig['phoneFields'] = ['homePhone', 'workPhone'];
|
|
205
|
+
jsonMaskConfig['stringFields'] = ['addressLine1', 'addressLine2'];
|
|
206
|
+
jsonMaskConfig['uuidFields'] = ['uuid1'];
|
|
207
|
+
it(`${title}`, function () {
|
|
208
|
+
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
209
|
+
expect(masked['credit']).to.equal(outputCredit);
|
|
210
|
+
expect(masked['debit']).to.equal(outputDebit);
|
|
211
|
+
expect(masked['primaryEmail']).to.equal(outputPrimaryEmail);
|
|
212
|
+
expect(masked['secondaryEmail']).to.equal(outputSecondaryEmail);
|
|
213
|
+
expect(masked['password']).to.equal(outputPassword);
|
|
214
|
+
expect(masked['homePhone']).to.equal(outputHomePhone);
|
|
215
|
+
expect(masked['workPhone']).to.equal(outputWorkPhone);
|
|
216
|
+
expect(masked['addressLine1']).to.equal(outputAddressLine1);
|
|
217
|
+
expect(masked['addressLine2']).to.equal(outputAddressLine2);
|
|
218
|
+
expect(masked['uuid1']).to.equal(outputUuid);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
);
|
|
177
222
|
});
|
|
178
223
|
|
|
179
|
-
describe('Mask all nested fields with default options', function() {
|
|
224
|
+
describe('Mask all nested fields with default options', function () {
|
|
180
225
|
const jsonInput2 = {
|
|
181
226
|
cards: {
|
|
182
227
|
creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'],
|
|
183
228
|
debitCards: ['0000-1111-2222-3333', '2222-1111-3333-4444']
|
|
184
229
|
},
|
|
185
230
|
emails: {
|
|
186
|
-
primaryEmail: 'primary@Email.com',
|
|
231
|
+
primaryEmail: 'primary@Email.com',
|
|
187
232
|
secondaryEmail: 'secondary@Email.com'
|
|
188
233
|
},
|
|
189
234
|
password: 'dummyPasswordANDdummyPassword',
|
|
190
235
|
phones: {
|
|
191
|
-
homePhone:
|
|
192
|
-
workPhone:
|
|
236
|
+
homePhone: '+1 1234567890',
|
|
237
|
+
workPhone: '+1 9876543210'
|
|
193
238
|
},
|
|
194
239
|
address: {
|
|
195
|
-
addressLine1:
|
|
196
|
-
addressLine2:
|
|
240
|
+
addressLine1: 'This is my addressline 1. This is my home',
|
|
241
|
+
addressLine2: 'AddressLine 2'
|
|
197
242
|
},
|
|
198
243
|
uuids: {
|
|
199
244
|
uuid1: '123e4567-e89b-12d3-a456-426614174000'
|
|
245
|
+
},
|
|
246
|
+
jwts: {
|
|
247
|
+
token1:
|
|
248
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
|
|
249
|
+
token2:
|
|
250
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJsb2wiLCJuYW1lIjoiVGVzdCIsImlhdCI6ImxvbCJ9.XNDxZcBWWEKYkCiu6XFGmAeuPF7iFnI7Sdv91gVZJMU',
|
|
251
|
+
token3List: [
|
|
252
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVGVzdDEifQ.TvKsZHhAgnZeplD4YdkKAgjdhdtFSQn-xZJ7HiiS1ok',
|
|
253
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVGVzdDIifQ.ekZkXoeOb4SE_YLlc0Iv8V3wm17xS1B7TzhtYHvIYl0',
|
|
254
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVGVzdDMifQ.CNiJIr7TZgsVGS0dbFFwdPtG6v1wwSor9jFoVeUkrJ0'
|
|
255
|
+
]
|
|
200
256
|
}
|
|
201
257
|
};
|
|
202
258
|
|
|
@@ -204,82 +260,109 @@ describe('JSON mask2', function() {
|
|
|
204
260
|
{
|
|
205
261
|
title: 'test json masking with default options and all types of fields',
|
|
206
262
|
input: jsonInput2,
|
|
207
|
-
outputCredit: '1234-****-****-***4',
|
|
208
|
-
outputDebit: '0000-****-****-***3',
|
|
209
|
-
outputPrimaryEmail: 'pri****@*******om',
|
|
263
|
+
outputCredit: '1234-****-****-***4',
|
|
264
|
+
outputDebit: '0000-****-****-***3',
|
|
265
|
+
outputPrimaryEmail: 'pri****@*******om',
|
|
210
266
|
outputSecondaryEmail: 'sec******@*******om',
|
|
211
267
|
outputPassword: '****************',
|
|
212
|
-
outputHomePhone:
|
|
213
|
-
outputWorkPhone:
|
|
214
|
-
outputAddressLine1:
|
|
215
|
-
outputAddressLine2:
|
|
216
|
-
outputUuid:
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
268
|
+
outputHomePhone: '+1 1********0',
|
|
269
|
+
outputWorkPhone: '+1 9********0',
|
|
270
|
+
outputAddressLine1: 'This is my addressline 1. This is my home',
|
|
271
|
+
outputAddressLine2: 'AddressLine 2',
|
|
272
|
+
outputUuid: '********-****-****-****-************',
|
|
273
|
+
outputJwt1:
|
|
274
|
+
'***********************************************************************************************************************************************************',
|
|
275
|
+
outputJwt2:
|
|
276
|
+
'*************************************************************************************************************************************'
|
|
277
|
+
}
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
testData.forEach(
|
|
281
|
+
({
|
|
282
|
+
title,
|
|
283
|
+
input,
|
|
284
|
+
outputCredit,
|
|
285
|
+
outputDebit,
|
|
286
|
+
outputPrimaryEmail,
|
|
287
|
+
outputSecondaryEmail,
|
|
288
|
+
outputPassword,
|
|
289
|
+
outputHomePhone,
|
|
290
|
+
outputWorkPhone,
|
|
291
|
+
outputAddressLine1,
|
|
292
|
+
outputAddressLine2,
|
|
293
|
+
outputUuid,
|
|
294
|
+
outputJwt1,
|
|
295
|
+
outputJwt2
|
|
296
|
+
}) => {
|
|
297
|
+
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
298
|
+
jsonMaskConfig['cardFields'] = [
|
|
299
|
+
'cards.creditCards[0]',
|
|
300
|
+
'cards.creditCards[1]',
|
|
301
|
+
'cards.debitCards[0]',
|
|
302
|
+
'cards.debitCards[1]'
|
|
303
|
+
];
|
|
304
|
+
jsonMaskConfig['emailFields'] = ['emails.primaryEmail', 'emails.secondaryEmail'];
|
|
305
|
+
jsonMaskConfig['passwordFields'] = ['password'];
|
|
306
|
+
jsonMaskConfig['phoneFields'] = ['phones.homePhone', 'phones.workPhone'];
|
|
307
|
+
jsonMaskConfig['stringFields'] = ['address.addressLine1', 'address.addressLine2'];
|
|
308
|
+
jsonMaskConfig['uuidFields'] = ['uuids.uuid1'];
|
|
309
|
+
jsonMaskConfig['jwtFields'] = ['jwts.token1', 'jwts.token2'];
|
|
310
|
+
it(`${title}`, function () {
|
|
311
|
+
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
312
|
+
expect(masked['cards']['creditCards'][0]).to.equal(outputCredit);
|
|
313
|
+
expect(masked['cards']['creditCards'][1]).to.equal('1111-****-****-***2');
|
|
314
|
+
expect(masked['cards']['debitCards'][0]).to.equal(outputDebit);
|
|
315
|
+
expect(masked['cards']['debitCards'][1]).to.equal('2222-****-****-***4');
|
|
316
|
+
|
|
317
|
+
expect(masked['emails']['primaryEmail']).to.equal(outputPrimaryEmail);
|
|
318
|
+
expect(masked['emails']['secondaryEmail']).to.equal(outputSecondaryEmail);
|
|
319
|
+
|
|
320
|
+
expect(masked['password']).to.equal(outputPassword);
|
|
321
|
+
|
|
322
|
+
expect(masked['phones']['homePhone']).to.equal(outputHomePhone);
|
|
323
|
+
expect(masked['phones']['workPhone']).to.equal(outputWorkPhone);
|
|
324
|
+
|
|
325
|
+
expect(masked['address']['addressLine1']).to.equal(outputAddressLine1);
|
|
326
|
+
expect(masked['address']['addressLine2']).to.equal(outputAddressLine2);
|
|
327
|
+
|
|
328
|
+
expect(masked['uuids']['uuid1']).to.equal(outputUuid);
|
|
329
|
+
|
|
330
|
+
expect(masked['jwts']['token1']).to.equal(outputJwt1);
|
|
331
|
+
expect(masked['jwts']['token2']).to.equal(outputJwt2);
|
|
332
|
+
});
|
|
333
|
+
it('Test masking improper JSON', function () {
|
|
334
|
+
const notAJson = 'Not a JSON. Just a String';
|
|
335
|
+
const masked = maskData.maskJSON2(notAJson, jsonMaskConfig);
|
|
336
|
+
expect(masked).to.equal(notAJson);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
);
|
|
256
340
|
});
|
|
257
341
|
|
|
258
|
-
describe('Mask card fields with custom options', function() {
|
|
342
|
+
describe('Mask card fields with custom options', function () {
|
|
259
343
|
let testData = [
|
|
260
344
|
{
|
|
261
345
|
title: 'Mask card fields with custom options',
|
|
262
346
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
263
|
-
outputCredit: 'XXXX-XXXX-XXXX-1234',
|
|
347
|
+
outputCredit: 'XXXX-XXXX-XXXX-1234',
|
|
264
348
|
outputDebit: 'XXXX-XXXX-XXXX-3333'
|
|
265
349
|
}
|
|
266
|
-
]
|
|
350
|
+
];
|
|
267
351
|
|
|
268
|
-
testData.forEach(({title, input, outputCredit, outputDebit}) => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
it(`${title}`, function() {
|
|
352
|
+
testData.forEach(({ title, input, outputCredit, outputDebit }) => {
|
|
353
|
+
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
354
|
+
const cardMaskOptions = JSON.parse(JSON.stringify(Constants.defaultCardMaskOptions));
|
|
355
|
+
// const defaultCardMaskOptions = {
|
|
356
|
+
// maskWith: "*",
|
|
357
|
+
// unmaskedStartDigits: 4,
|
|
358
|
+
// unmaskedEndDigits: 1
|
|
359
|
+
// };
|
|
360
|
+
cardMaskOptions['maskWith'] = 'X';
|
|
361
|
+
cardMaskOptions['unmaskedStartDigits'] = 0;
|
|
362
|
+
cardMaskOptions['unmaskedEndDigits'] = 4;
|
|
363
|
+
jsonMaskConfig['cardFields'] = ['credit', 'debit'];
|
|
364
|
+
jsonMaskConfig['cardMaskOptions'] = cardMaskOptions;
|
|
365
|
+
it(`${title}`, function () {
|
|
283
366
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
284
367
|
expect(masked['credit']).to.equal(outputCredit);
|
|
285
368
|
expect(masked['debit']).to.equal(outputDebit);
|
|
@@ -291,21 +374,20 @@ describe('JSON mask2', function() {
|
|
|
291
374
|
expect(masked['addressLine1']).to.equal(input['addressLine1']);
|
|
292
375
|
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
293
376
|
});
|
|
294
|
-
})
|
|
377
|
+
});
|
|
295
378
|
});
|
|
296
379
|
|
|
297
|
-
describe('Mask email fields with custom options', function() {
|
|
380
|
+
describe('Mask email fields with custom options', function () {
|
|
298
381
|
let testData = [
|
|
299
382
|
{
|
|
300
383
|
title: 'Mask email fields with custom options',
|
|
301
384
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
302
|
-
outputPrimaryEmail: 'prim...@........m',
|
|
385
|
+
outputPrimaryEmail: 'prim...@........m',
|
|
303
386
|
outputSecondaryEmail: 'seco.....@........m'
|
|
304
|
-
}
|
|
305
|
-
]
|
|
306
|
-
|
|
307
|
-
testData.forEach(({title, input, outputPrimaryEmail, outputSecondaryEmail}) => {
|
|
387
|
+
}
|
|
388
|
+
];
|
|
308
389
|
|
|
390
|
+
testData.forEach(({ title, input, outputPrimaryEmail, outputSecondaryEmail }) => {
|
|
309
391
|
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
310
392
|
const emailMaskOptions = JSON.parse(JSON.stringify(Constants.defaultEmailMask2Options));
|
|
311
393
|
// const defaultEmailMask2Options = {
|
|
@@ -314,13 +396,13 @@ describe('JSON mask2', function() {
|
|
|
314
396
|
// unmaskedEndCharactersAfterAt: 2,
|
|
315
397
|
// maskAtTheRate: false
|
|
316
398
|
// };
|
|
317
|
-
emailMaskOptions['maskWith'] =
|
|
318
|
-
emailMaskOptions['unmaskedStartCharactersBeforeAt'] = 4
|
|
319
|
-
emailMaskOptions['unmaskedEndCharactersAfterAt'] = 1
|
|
399
|
+
emailMaskOptions['maskWith'] = '.';
|
|
400
|
+
emailMaskOptions['unmaskedStartCharactersBeforeAt'] = 4;
|
|
401
|
+
emailMaskOptions['unmaskedEndCharactersAfterAt'] = 1;
|
|
320
402
|
jsonMaskConfig['emailFields'] = ['primaryEmail', 'secondaryEmail'];
|
|
321
403
|
jsonMaskConfig['emailMaskOptions'] = emailMaskOptions;
|
|
322
404
|
|
|
323
|
-
it(`${title}`, function() {
|
|
405
|
+
it(`${title}`, function () {
|
|
324
406
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
325
407
|
expect(masked['credit']).to.equal(input['credit']);
|
|
326
408
|
expect(masked['debit']).to.equal(input['debit']);
|
|
@@ -332,20 +414,19 @@ describe('JSON mask2', function() {
|
|
|
332
414
|
expect(masked['addressLine1']).to.equal(input['addressLine1']);
|
|
333
415
|
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
334
416
|
});
|
|
335
|
-
})
|
|
417
|
+
});
|
|
336
418
|
});
|
|
337
419
|
|
|
338
|
-
describe('Mask password fields with custom options', function() {
|
|
420
|
+
describe('Mask password fields with custom options', function () {
|
|
339
421
|
let testData = [
|
|
340
422
|
{
|
|
341
423
|
title: 'Mask password fields with custom options',
|
|
342
424
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
343
425
|
outputPassword: 'd????d'
|
|
344
|
-
}
|
|
345
|
-
]
|
|
426
|
+
}
|
|
427
|
+
];
|
|
346
428
|
|
|
347
|
-
testData.forEach(({title, input, outputPassword}) => {
|
|
348
|
-
|
|
429
|
+
testData.forEach(({ title, input, outputPassword }) => {
|
|
349
430
|
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
350
431
|
const passwordMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPasswordMaskOptions));
|
|
351
432
|
// const defaultPasswordMaskOptions = {
|
|
@@ -354,13 +435,13 @@ describe('JSON mask2', function() {
|
|
|
354
435
|
// unmaskedStartCharacters: 0,
|
|
355
436
|
// unmaskedEndCharacters: 0
|
|
356
437
|
// };
|
|
357
|
-
passwordMaskOptions['maskWith'] =
|
|
358
|
-
passwordMaskOptions['maxMaskedCharacters'] = 6
|
|
359
|
-
passwordMaskOptions['unmaskedStartCharacters'] = 1
|
|
360
|
-
passwordMaskOptions['unmaskedEndCharacters'] = 1
|
|
438
|
+
passwordMaskOptions['maskWith'] = '?';
|
|
439
|
+
passwordMaskOptions['maxMaskedCharacters'] = 6;
|
|
440
|
+
passwordMaskOptions['unmaskedStartCharacters'] = 1;
|
|
441
|
+
passwordMaskOptions['unmaskedEndCharacters'] = 1;
|
|
361
442
|
jsonMaskConfig['passwordFields'] = ['password'];
|
|
362
443
|
jsonMaskConfig['passwordMaskOptions'] = passwordMaskOptions;
|
|
363
|
-
it(`${title}`, function() {
|
|
444
|
+
it(`${title}`, function () {
|
|
364
445
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
365
446
|
expect(masked['credit']).to.equal(input['credit']);
|
|
366
447
|
expect(masked['debit']).to.equal(input['debit']);
|
|
@@ -372,21 +453,20 @@ describe('JSON mask2', function() {
|
|
|
372
453
|
expect(masked['addressLine1']).to.equal(input['addressLine1']);
|
|
373
454
|
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
374
455
|
});
|
|
375
|
-
})
|
|
456
|
+
});
|
|
376
457
|
});
|
|
377
458
|
|
|
378
|
-
describe('Mask phone fields with custom options', function() {
|
|
459
|
+
describe('Mask phone fields with custom options', function () {
|
|
379
460
|
let testData = [
|
|
380
461
|
{
|
|
381
462
|
title: 'Mask phone fields with custom options',
|
|
382
463
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
383
464
|
outputHomePhone: '+1 #######890',
|
|
384
465
|
outputWorkPhone: '+1 #######210'
|
|
385
|
-
}
|
|
386
|
-
]
|
|
466
|
+
}
|
|
467
|
+
];
|
|
387
468
|
|
|
388
|
-
testData.forEach(({title, input, outputHomePhone, outputWorkPhone}) => {
|
|
389
|
-
|
|
469
|
+
testData.forEach(({ title, input, outputHomePhone, outputWorkPhone }) => {
|
|
390
470
|
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
391
471
|
const phoneMaskOptions = JSON.parse(JSON.stringify(Constants.defaultPhoneMaskOptions));
|
|
392
472
|
// const defaultPhoneMaskOptions = {
|
|
@@ -394,12 +474,12 @@ describe('JSON mask2', function() {
|
|
|
394
474
|
// unmaskedStartDigits: 4,
|
|
395
475
|
// unmaskedEndDigits: 1
|
|
396
476
|
// };
|
|
397
|
-
phoneMaskOptions['maskWith'] =
|
|
398
|
-
phoneMaskOptions['unmaskedStartDigits'] = 3
|
|
399
|
-
phoneMaskOptions['unmaskedEndDigits'] = 3
|
|
477
|
+
phoneMaskOptions['maskWith'] = '#';
|
|
478
|
+
phoneMaskOptions['unmaskedStartDigits'] = 3;
|
|
479
|
+
phoneMaskOptions['unmaskedEndDigits'] = 3;
|
|
400
480
|
jsonMaskConfig['phoneFields'] = ['homePhone', 'workPhone'];
|
|
401
481
|
jsonMaskConfig['phoneMaskOptions'] = phoneMaskOptions;
|
|
402
|
-
it(`${title}`, function() {
|
|
482
|
+
it(`${title}`, function () {
|
|
403
483
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
404
484
|
expect(masked['credit']).to.equal(input['credit']);
|
|
405
485
|
expect(masked['debit']).to.equal(input['debit']);
|
|
@@ -411,21 +491,20 @@ describe('JSON mask2', function() {
|
|
|
411
491
|
expect(masked['addressLine1']).to.equal(input['addressLine1']);
|
|
412
492
|
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
413
493
|
});
|
|
414
|
-
})
|
|
494
|
+
});
|
|
415
495
|
});
|
|
416
496
|
|
|
417
|
-
describe('Mask String fields with custom options', function() {
|
|
497
|
+
describe('Mask String fields with custom options', function () {
|
|
418
498
|
let testData = [
|
|
419
499
|
{
|
|
420
500
|
title: 'Mask String fields with custom options',
|
|
421
501
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
422
502
|
outputAddressLine1: 'XXXX is my addressline 1. This is my home',
|
|
423
503
|
outputAddressLine2: 'AddressLine 2'
|
|
424
|
-
}
|
|
425
|
-
]
|
|
504
|
+
}
|
|
505
|
+
];
|
|
426
506
|
|
|
427
|
-
testData.forEach(({title, input, outputAddressLine1, outputAddressLine2}) => {
|
|
428
|
-
|
|
507
|
+
testData.forEach(({ title, input, outputAddressLine1, outputAddressLine2 }) => {
|
|
429
508
|
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
430
509
|
const stringMaskOptions = JSON.parse(JSON.stringify(Constants.defaultStringMaskOptions));
|
|
431
510
|
// const defaultStringMaskOptions = {
|
|
@@ -435,12 +514,12 @@ describe('JSON mask2', function() {
|
|
|
435
514
|
// maskAll: false,
|
|
436
515
|
// maskSpace: true
|
|
437
516
|
// };
|
|
438
|
-
stringMaskOptions['maskWith'] =
|
|
439
|
-
stringMaskOptions['maskOnlyFirstOccurance'] = true
|
|
440
|
-
stringMaskOptions['values'] = ['This']
|
|
517
|
+
stringMaskOptions['maskWith'] = 'X';
|
|
518
|
+
stringMaskOptions['maskOnlyFirstOccurance'] = true;
|
|
519
|
+
stringMaskOptions['values'] = ['This'];
|
|
441
520
|
jsonMaskConfig['stringFields'] = ['addressLine1', 'addressLine2'];
|
|
442
521
|
jsonMaskConfig['stringMaskOptions'] = stringMaskOptions;
|
|
443
|
-
it(`${title}`, function() {
|
|
522
|
+
it(`${title}`, function () {
|
|
444
523
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
445
524
|
expect(masked['credit']).to.equal(input['credit']);
|
|
446
525
|
expect(masked['debit']).to.equal(input['debit']);
|
|
@@ -452,20 +531,19 @@ describe('JSON mask2', function() {
|
|
|
452
531
|
expect(masked['addressLine1']).to.equal(outputAddressLine1);
|
|
453
532
|
expect(masked['addressLine2']).to.equal(outputAddressLine2);
|
|
454
533
|
});
|
|
455
|
-
})
|
|
534
|
+
});
|
|
456
535
|
});
|
|
457
536
|
|
|
458
|
-
describe('Mask UUID fields with custom options', function() {
|
|
537
|
+
describe('Mask UUID fields with custom options', function () {
|
|
459
538
|
let testData = [
|
|
460
539
|
{
|
|
461
540
|
title: 'Mask UUID fields with custom options',
|
|
462
541
|
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
463
|
-
outputUuid:
|
|
464
|
-
}
|
|
465
|
-
]
|
|
542
|
+
outputUuid: '123e4567-XXXX-XXXX-XXXX-426614174000'
|
|
543
|
+
}
|
|
544
|
+
];
|
|
466
545
|
|
|
467
|
-
testData.forEach(({title, input, outputUuid}) => {
|
|
468
|
-
|
|
546
|
+
testData.forEach(({ title, input, outputUuid }) => {
|
|
469
547
|
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
470
548
|
const uuidMaskOptions = JSON.parse(JSON.stringify(Constants.defaultUuidMaskOptions));
|
|
471
549
|
// const defaultUuidMaskOptions = {
|
|
@@ -473,12 +551,12 @@ describe('JSON mask2', function() {
|
|
|
473
551
|
// unmaskedStartCharacters: 0,
|
|
474
552
|
// unmaskedEndCharacters: 0
|
|
475
553
|
// };
|
|
476
|
-
uuidMaskOptions['maskWith'] =
|
|
477
|
-
uuidMaskOptions['unmaskedStartCharacters'] = 8
|
|
478
|
-
uuidMaskOptions['unmaskedEndCharacters'] = 12
|
|
554
|
+
uuidMaskOptions['maskWith'] = 'X';
|
|
555
|
+
uuidMaskOptions['unmaskedStartCharacters'] = 8;
|
|
556
|
+
uuidMaskOptions['unmaskedEndCharacters'] = 12;
|
|
479
557
|
jsonMaskConfig['uuidFields'] = ['uuid1'];
|
|
480
558
|
jsonMaskConfig['uuidMaskOptions'] = uuidMaskOptions;
|
|
481
|
-
it(`${title}`, function() {
|
|
559
|
+
it(`${title}`, function () {
|
|
482
560
|
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
483
561
|
expect(masked['credit']).to.equal(input['credit']);
|
|
484
562
|
expect(masked['debit']).to.equal(input['debit']);
|
|
@@ -491,7 +569,175 @@ describe('JSON mask2', function() {
|
|
|
491
569
|
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
492
570
|
expect(masked['uuid1']).to.equal(outputUuid);
|
|
493
571
|
});
|
|
494
|
-
})
|
|
572
|
+
});
|
|
495
573
|
});
|
|
496
|
-
|
|
497
|
-
|
|
574
|
+
|
|
575
|
+
describe('Mask UUID fields with invalid options', function () {
|
|
576
|
+
let testData = [
|
|
577
|
+
{
|
|
578
|
+
title: 'Mask UUID fields with custom options',
|
|
579
|
+
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
580
|
+
outputUuid: '123e4567-e89b-12d3-a456-426614174000'
|
|
581
|
+
}
|
|
582
|
+
];
|
|
583
|
+
|
|
584
|
+
testData.forEach(({ title, input, outputUuid }) => {
|
|
585
|
+
const jsonMaskConfig = JSON.parse(JSON.stringify(Constants.defaultjsonMask2Configs));
|
|
586
|
+
const uuidMaskOptions = JSON.parse(JSON.stringify(Constants.defaultUuidMaskOptions));
|
|
587
|
+
// const defaultUuidMaskOptions = {
|
|
588
|
+
// maskWith: "*",
|
|
589
|
+
// unmaskedStartCharacters: 0,
|
|
590
|
+
// unmaskedEndCharacters: 0
|
|
591
|
+
// };
|
|
592
|
+
uuidMaskOptions['maskWith'] = 'X';
|
|
593
|
+
uuidMaskOptions['unmaskedStartCharacters'] = 8;
|
|
594
|
+
uuidMaskOptions['unmaskedEndCharacters'] = 12;
|
|
595
|
+
jsonMaskConfig['uuidFields'] = ['uuid1.*.invalidField'];
|
|
596
|
+
jsonMaskConfig['uuidMaskOptions'] = uuidMaskOptions;
|
|
597
|
+
it(`${title}`, function () {
|
|
598
|
+
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
599
|
+
expect(masked['credit']).to.equal(input['credit']);
|
|
600
|
+
expect(masked['debit']).to.equal(input['debit']);
|
|
601
|
+
expect(masked['primaryEmail']).to.equal(input['primaryEmail']);
|
|
602
|
+
expect(masked['secondaryEmail']).to.equal(input['secondaryEmail']);
|
|
603
|
+
expect(masked['password']).to.equal(input['password']);
|
|
604
|
+
expect(masked['homePhone']).to.equal(input['homePhone']);
|
|
605
|
+
expect(masked['workPhone']).to.equal(input['workPhone']);
|
|
606
|
+
expect(masked['addressLine1']).to.equal(input['addressLine1']);
|
|
607
|
+
expect(masked['addressLine2']).to.equal(input['addressLine2']);
|
|
608
|
+
expect(masked['uuid1']).to.equal(outputUuid);
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
describe('Test Json mask with .* and [*].', function () {
|
|
614
|
+
const jsonInput = {
|
|
615
|
+
cards: [
|
|
616
|
+
{
|
|
617
|
+
number: '1234-5678-8765-1234'
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
number: '1111-2222-1111-2222'
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
number: '0000-1111-2222-3333'
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
name: 'No card number here'
|
|
627
|
+
}
|
|
628
|
+
],
|
|
629
|
+
emails: {
|
|
630
|
+
primaryEmail: 'primary@Email.com',
|
|
631
|
+
secondaryEmail: 'secondary@Email.com',
|
|
632
|
+
moreEmails: [
|
|
633
|
+
'email1@email.com',
|
|
634
|
+
'email2@email.com',
|
|
635
|
+
'email3@email.com',
|
|
636
|
+
{ childEmail: 'child@child.com', secondChild: { nestedkid: 'hello@hello.com' } }
|
|
637
|
+
]
|
|
638
|
+
},
|
|
639
|
+
array: ['element1', 'element22', 'element333'],
|
|
640
|
+
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJsb2wiLCJuYW1lIjoiVGVzdCIsImlhdCI6ImxvbCJ9.XNDxZcBWWEKYkCiu6XFGmAeuPF7iFnI7Sdv91gVZJMU'
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
let testData = [
|
|
644
|
+
{
|
|
645
|
+
title: 'Mask UUID fields with custom options',
|
|
646
|
+
input: JSON.parse(JSON.stringify(jsonInput)),
|
|
647
|
+
output: {
|
|
648
|
+
cards: [
|
|
649
|
+
{
|
|
650
|
+
number: 'XXXX-XXXX-XXXX-XXXX'
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
number: 'XXXX-XXXX-XXXX-XXXX'
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
number: 'XXXX-XXXX-XXXX-XXXX'
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
name: 'No card number here'
|
|
660
|
+
}
|
|
661
|
+
],
|
|
662
|
+
emails: {
|
|
663
|
+
primaryEmail: '*******@*********',
|
|
664
|
+
secondaryEmail: '*********@*********',
|
|
665
|
+
moreEmails: [
|
|
666
|
+
'******@*********',
|
|
667
|
+
'******@*********',
|
|
668
|
+
'******@*********',
|
|
669
|
+
{
|
|
670
|
+
childEmail: '*****@*********',
|
|
671
|
+
secondChild: {
|
|
672
|
+
nestedkid: '*****@*********'
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
]
|
|
676
|
+
},
|
|
677
|
+
array: ['????????', '?????????', '??????????'],
|
|
678
|
+
jwt: '************.**********.**********'
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
];
|
|
682
|
+
|
|
683
|
+
const jsonMaskConfig = {
|
|
684
|
+
cardMaskOptions: { maskWith: 'X', unmaskedStartDigits: 0, unmaskedEndDigits: 0 },
|
|
685
|
+
|
|
686
|
+
emailMaskOptions: {
|
|
687
|
+
maskWith: '*',
|
|
688
|
+
unmaskedStartCharactersBeforeAt: 0,
|
|
689
|
+
unmaskedEndCharactersAfterAt: 0,
|
|
690
|
+
maskAtTheRate: false
|
|
691
|
+
},
|
|
692
|
+
|
|
693
|
+
stringMaskOptions: {
|
|
694
|
+
maskWith: '?',
|
|
695
|
+
maskOnlyFirstOccurance: false,
|
|
696
|
+
values: [],
|
|
697
|
+
maskAll: true,
|
|
698
|
+
maskSpace: false
|
|
699
|
+
},
|
|
700
|
+
jwtMaskOptions: {
|
|
701
|
+
maskWith: '*',
|
|
702
|
+
maxMaskedCharacters: 32,
|
|
703
|
+
maskDot: false,
|
|
704
|
+
maskHeader: true,
|
|
705
|
+
maskPayload: true,
|
|
706
|
+
maskSignature: true
|
|
707
|
+
},
|
|
708
|
+
|
|
709
|
+
cardFields: ['cards[*].number'],
|
|
710
|
+
emailFields: ['emails.*'],
|
|
711
|
+
stringFields: ['array.*'],
|
|
712
|
+
jwtFields: ['jwt']
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
testData.forEach(({ title, input, output }) => {
|
|
716
|
+
it(`${title}`, function () {
|
|
717
|
+
const masked = maskData.maskJSON2(input, jsonMaskConfig);
|
|
718
|
+
expect(masked['cards'][0].number).to.equal(output['cards'][0].number);
|
|
719
|
+
expect(masked['cards'][1].number).to.equal(output['cards'][1].number);
|
|
720
|
+
expect(masked['cards'][2].number).to.equal(output['cards'][2].number);
|
|
721
|
+
expect(masked['cards'][3].number).to.equal(undefined);
|
|
722
|
+
|
|
723
|
+
expect(masked['emails'].primaryEmail).to.equal(output['emails'].primaryEmail);
|
|
724
|
+
expect(masked['emails'].secondaryEmail).to.equal(output['emails'].secondaryEmail);
|
|
725
|
+
expect(masked['emails'].moreEmails[0]).to.equal(output['emails'].moreEmails[0]);
|
|
726
|
+
expect(masked['emails'].moreEmails[1]).to.equal(output['emails'].moreEmails[1]);
|
|
727
|
+
expect(masked['emails'].moreEmails[2]).to.equal(output['emails'].moreEmails[2]);
|
|
728
|
+
expect(masked['emails'].moreEmails[3].childEmail).to.equal(
|
|
729
|
+
output['emails'].moreEmails[3].childEmail
|
|
730
|
+
);
|
|
731
|
+
expect(masked['emails'].moreEmails[3].secondChild.nestedkid).to.equal(
|
|
732
|
+
output['emails'].moreEmails[3].secondChild.nestedkid
|
|
733
|
+
);
|
|
734
|
+
|
|
735
|
+
expect(masked['array'][0]).to.equal(output['array'][0]);
|
|
736
|
+
expect(masked['array'][1]).to.equal(output['array'][1]);
|
|
737
|
+
expect(masked['array'][2]).to.equal(output['array'][2]);
|
|
738
|
+
|
|
739
|
+
expect(masked['jwt']).to.equal(output['jwt']);
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
});
|