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/testJsonGetSet.js
CHANGED
|
@@ -2,74 +2,107 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Test getValue', function() {
|
|
6
|
-
describe('Test get JSON field values', function() {
|
|
7
|
-
|
|
5
|
+
describe('Test getValue', function () {
|
|
6
|
+
describe('Test get JSON field values', function () {
|
|
8
7
|
let testData = [
|
|
9
8
|
{
|
|
10
9
|
title: 'test getting a string field from json',
|
|
11
|
-
input: {
|
|
10
|
+
input: {
|
|
11
|
+
stringField: 'StringValue',
|
|
12
|
+
booleanField: true,
|
|
13
|
+
numberField: 1000,
|
|
14
|
+
objectField: [1, 2, 3, 4]
|
|
15
|
+
},
|
|
12
16
|
fieldToGet: 'stringField',
|
|
13
17
|
output: 'StringValue'
|
|
14
18
|
},
|
|
15
19
|
{
|
|
16
20
|
title: 'test getting a boolean field from json',
|
|
17
|
-
input: {
|
|
21
|
+
input: {
|
|
22
|
+
stringField: 'StringValue',
|
|
23
|
+
booleanField: true,
|
|
24
|
+
numberField: 1000,
|
|
25
|
+
objectField: [1, 2, 3, 4]
|
|
26
|
+
},
|
|
18
27
|
fieldToGet: 'booleanField',
|
|
19
28
|
output: true
|
|
20
29
|
},
|
|
21
30
|
{
|
|
22
31
|
title: 'test getting a number field from json',
|
|
23
|
-
input: {
|
|
32
|
+
input: {
|
|
33
|
+
stringField: 'StringValue',
|
|
34
|
+
booleanField: true,
|
|
35
|
+
numberField: 1000,
|
|
36
|
+
objectField: [1, 2, 3, 4]
|
|
37
|
+
},
|
|
24
38
|
fieldToGet: 'numberField',
|
|
25
39
|
output: 1000
|
|
26
40
|
}
|
|
27
|
-
]
|
|
41
|
+
];
|
|
28
42
|
|
|
29
|
-
testData.forEach(({title, input, fieldToGet, output}) => {
|
|
30
|
-
it(`default mask - ${title}`, function() {
|
|
43
|
+
testData.forEach(({ title, input, fieldToGet, output }) => {
|
|
44
|
+
it(`default mask - ${title}`, function () {
|
|
31
45
|
const jsonFieldValue = maskData.getInnerProperty(input, fieldToGet);
|
|
32
46
|
expect(jsonFieldValue).to.equal(output, 'Expected json property found');
|
|
33
47
|
});
|
|
34
|
-
})
|
|
48
|
+
});
|
|
35
49
|
});
|
|
36
50
|
});
|
|
37
51
|
|
|
38
|
-
describe('Test replaceValue', function() {
|
|
39
|
-
describe('Test replace json field Value', function() {
|
|
40
|
-
|
|
52
|
+
describe('Test replaceValue', function () {
|
|
53
|
+
describe('Test replace json field Value', function () {
|
|
41
54
|
let testData = [
|
|
42
55
|
{
|
|
43
56
|
title: 'test replacing a string field value from json',
|
|
44
|
-
input: {
|
|
57
|
+
input: {
|
|
58
|
+
stringField: 'StringValue',
|
|
59
|
+
booleanField: true,
|
|
60
|
+
numberField: 1000,
|
|
61
|
+
objectField: [1, 2, 3, 4]
|
|
62
|
+
},
|
|
45
63
|
fieldToReplace: 'stringField',
|
|
46
64
|
output: 'NewStringValue'
|
|
47
65
|
},
|
|
48
66
|
{
|
|
49
67
|
title: 'test replacing a boolean field value from json',
|
|
50
|
-
input: {
|
|
68
|
+
input: {
|
|
69
|
+
stringField: 'StringValue',
|
|
70
|
+
booleanField: true,
|
|
71
|
+
numberField: 1000,
|
|
72
|
+
objectField: [1, 2, 3, 4]
|
|
73
|
+
},
|
|
51
74
|
fieldToReplace: 'booleanField',
|
|
52
75
|
output: false
|
|
53
76
|
},
|
|
54
77
|
{
|
|
55
78
|
title: 'test replacing a number field value from json',
|
|
56
|
-
input: {
|
|
79
|
+
input: {
|
|
80
|
+
stringField: 'StringValue',
|
|
81
|
+
booleanField: true,
|
|
82
|
+
numberField: 1000,
|
|
83
|
+
objectField: [1, 2, 3, 4]
|
|
84
|
+
},
|
|
57
85
|
fieldToReplace: 'numberField',
|
|
58
86
|
output: 1111
|
|
59
87
|
},
|
|
60
88
|
{
|
|
61
89
|
title: 'test replacing a object field value from json',
|
|
62
|
-
input: {
|
|
90
|
+
input: {
|
|
91
|
+
stringField: 'StringValue',
|
|
92
|
+
booleanField: true,
|
|
93
|
+
numberField: 1000,
|
|
94
|
+
objectField: [1, 2, 3, 4]
|
|
95
|
+
},
|
|
63
96
|
fieldToReplace: 'objectField',
|
|
64
97
|
output: false
|
|
65
98
|
}
|
|
66
|
-
]
|
|
99
|
+
];
|
|
67
100
|
|
|
68
|
-
testData.forEach(({title, input, fieldToReplace, output}) => {
|
|
69
|
-
it(`default mask - ${title}`, function() {
|
|
101
|
+
testData.forEach(({ title, input, fieldToReplace, output }) => {
|
|
102
|
+
it(`default mask - ${title}`, function () {
|
|
70
103
|
const jsonAfterReplacing = maskData.replaceValue(input, fieldToReplace, output);
|
|
71
104
|
expect(jsonAfterReplacing[fieldToReplace]).to.equal(output, 'Expected json property found');
|
|
72
105
|
});
|
|
73
|
-
})
|
|
106
|
+
});
|
|
74
107
|
});
|
|
75
108
|
});
|
package/tests/testJwt.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const maskData = require('../index');
|
|
3
|
+
const BadOption = require('../lib/ExceptionsHandler/BadOption');
|
|
4
|
+
const expect = require('chai').expect;
|
|
5
|
+
|
|
6
|
+
describe('Masking JWT tokens', function () {
|
|
7
|
+
describe('Mask JWT token with default options', function () {
|
|
8
|
+
// default options are this - let tests fail when defaults change
|
|
9
|
+
// const defaultJwtMaskOptions = {
|
|
10
|
+
// maskWith: '*',
|
|
11
|
+
// maxMaskedCharacters: 512,
|
|
12
|
+
// maskDot: true,
|
|
13
|
+
// maskHeader: true,
|
|
14
|
+
// maskPayload: true,
|
|
15
|
+
// maskSignature: true
|
|
16
|
+
// };
|
|
17
|
+
|
|
18
|
+
let testData = [
|
|
19
|
+
{
|
|
20
|
+
title: 'Random JWT token',
|
|
21
|
+
input:
|
|
22
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
23
|
+
output:
|
|
24
|
+
'*********************************************************************************************************'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: 'invalid but valid syntax JWT',
|
|
28
|
+
input: 'a.b.c',
|
|
29
|
+
output: '*****'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'longer than 512 chars',
|
|
33
|
+
input:
|
|
34
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQtbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
35
|
+
output:
|
|
36
|
+
'********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: 'Invalid JWT. Do not mask',
|
|
40
|
+
input: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9',
|
|
41
|
+
output: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: 'Invalid JWT2. Do not mask',
|
|
45
|
+
input: '..eyJpYXQiOjE1MTYyMzkwMjJ9',
|
|
46
|
+
output: '..eyJpYXQiOjE1MTYyMzkwMjJ9'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
title: 'empty jwt. Do not mask',
|
|
50
|
+
input: '',
|
|
51
|
+
output: ''
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: 'length less than 5 chars jwt. Do not mask',
|
|
55
|
+
input: 'a.b.',
|
|
56
|
+
output: 'a.b.'
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
testData.forEach(({ title, input, output }) => {
|
|
61
|
+
it(`default mask - ${title}`, function () {
|
|
62
|
+
const masked = maskData.maskJwt(input);
|
|
63
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
64
|
+
expect(masked.length).to.equal(
|
|
65
|
+
input.length >= 512 ? 512 : input.length,
|
|
66
|
+
'masked output length does not match expected value'
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('Mask JWT with custom options', function () {
|
|
73
|
+
const jwtMaskOptions = {
|
|
74
|
+
maskWith: '*',
|
|
75
|
+
maxMaskedCharacters: 512,
|
|
76
|
+
maskDot: false,
|
|
77
|
+
maskHeader: false,
|
|
78
|
+
maskPayload: false,
|
|
79
|
+
maskSignature: false
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
let testData = [
|
|
83
|
+
{
|
|
84
|
+
title: 'Mask only dots',
|
|
85
|
+
input:
|
|
86
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
87
|
+
output:
|
|
88
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9*eyJpYXQiOjE1MTYyMzkwMjJ9*tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
89
|
+
configKey: 'maskDot',
|
|
90
|
+
configValue: true
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title: 'Mask only header',
|
|
94
|
+
input:
|
|
95
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
96
|
+
output:
|
|
97
|
+
'************************************.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
98
|
+
configKey: 'maskHeader',
|
|
99
|
+
configValue: true
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
title: 'Mask only payload',
|
|
103
|
+
input:
|
|
104
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
105
|
+
output:
|
|
106
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.************************.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
107
|
+
configKey: 'maskPayload',
|
|
108
|
+
configValue: true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
title: 'Mask only signature',
|
|
112
|
+
input:
|
|
113
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
114
|
+
output:
|
|
115
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.*******************************************',
|
|
116
|
+
configKey: 'maskSignature',
|
|
117
|
+
configValue: true
|
|
118
|
+
}
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
testData.forEach(({ title, input, output, configKey, configValue }) => {
|
|
122
|
+
const config = JSON.parse(JSON.stringify(jwtMaskOptions));
|
|
123
|
+
config[configKey] = configValue;
|
|
124
|
+
it(`default mask - ${title}`, function () {
|
|
125
|
+
const masked = maskData.maskJwt(input, config);
|
|
126
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('Unmask part of the JWT', function () {
|
|
132
|
+
const jwtMaskOptions = {
|
|
133
|
+
maskWith: '*',
|
|
134
|
+
maxMaskedCharacters: 512,
|
|
135
|
+
maskDot: false,
|
|
136
|
+
maskHeader: true,
|
|
137
|
+
maskPayload: true,
|
|
138
|
+
maskSignature: true
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
let testData = [
|
|
142
|
+
{
|
|
143
|
+
title: 'Mask header and body',
|
|
144
|
+
input:
|
|
145
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
146
|
+
output:
|
|
147
|
+
'************************************.************************.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
148
|
+
configKey: 'maskSignature',
|
|
149
|
+
configValue: false
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
title: 'Mask header and signature',
|
|
153
|
+
input:
|
|
154
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
155
|
+
output:
|
|
156
|
+
'************************************.eyJpYXQiOjE1MTYyMzkwMjJ9.*******************************************',
|
|
157
|
+
configKey: 'maskPayload',
|
|
158
|
+
configValue: false
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
title: 'Mask body and signature',
|
|
162
|
+
input:
|
|
163
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1MTYyMzkwMjJ9.tbDepxpstvGdW8TC3G8zg4B6rUYAOvfzdceoH48wgRQ',
|
|
164
|
+
output:
|
|
165
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.************************.*******************************************',
|
|
166
|
+
configKey: 'maskHeader',
|
|
167
|
+
configValue: false
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
testData.forEach(({ title, input, output, configKey, configValue }) => {
|
|
172
|
+
const config = JSON.parse(JSON.stringify(jwtMaskOptions));
|
|
173
|
+
config[configKey] = configValue;
|
|
174
|
+
it(`custom mask2 - ${title}`, function () {
|
|
175
|
+
const masked = maskData.maskJwt(input, config);
|
|
176
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('Test maxMaskedCharacters', function () {
|
|
182
|
+
const jwtMaskOptions = {
|
|
183
|
+
maskWith: '*',
|
|
184
|
+
maxMaskedCharacters: 512,
|
|
185
|
+
maskDot: true,
|
|
186
|
+
maskHeader: true,
|
|
187
|
+
maskPayload: true,
|
|
188
|
+
maskSignature: true
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
let testData = [
|
|
192
|
+
{
|
|
193
|
+
title: 'Mask with maxMaskedCharacters=1',
|
|
194
|
+
input: 'abcd.efgh.hijk',
|
|
195
|
+
output: '***',
|
|
196
|
+
maxMaskedCharacters: 1,
|
|
197
|
+
maskDot: true
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
title: 'Mask with maxMaskedCharacters=1',
|
|
201
|
+
input: 'abcd.efgh.hijk',
|
|
202
|
+
output: '*..',
|
|
203
|
+
maxMaskedCharacters: 1,
|
|
204
|
+
maskDot: false
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
testData.forEach(({ title, input, output, maxMaskedCharacters, maskDot }) => {
|
|
209
|
+
const config = JSON.parse(JSON.stringify(jwtMaskOptions));
|
|
210
|
+
config['maxMaskedCharacters'] = maxMaskedCharacters;
|
|
211
|
+
config['maskDot'] = maskDot;
|
|
212
|
+
it(`custom mask2 - ${title}`, function () {
|
|
213
|
+
const masked = maskData.maskJwt(input, config);
|
|
214
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('Mask with non string inputs - input will not be masked', function () {
|
|
220
|
+
const jwtMaskOptions = {
|
|
221
|
+
maskWith: '*',
|
|
222
|
+
maxMaskedCharacters: 512,
|
|
223
|
+
maskDot: false,
|
|
224
|
+
maskHeader: true,
|
|
225
|
+
maskPayload: true,
|
|
226
|
+
maskSignature: true
|
|
227
|
+
};
|
|
228
|
+
let testData = [
|
|
229
|
+
{
|
|
230
|
+
title: 'test input as number',
|
|
231
|
+
input: 12
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
title: 'test input as array',
|
|
235
|
+
input: ['12']
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
title: 'test input as object',
|
|
239
|
+
input: { a: 'b', x: 'y' }
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
title: 'test input as boolean',
|
|
243
|
+
input: false
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
title: 'undefined jwt. Do not mask',
|
|
247
|
+
input: undefined
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
title: 'null jwt. Do not mask',
|
|
251
|
+
input: null
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
|
|
255
|
+
testData.forEach(({ title, input }) => {
|
|
256
|
+
it(`non string input - ${title}`, function () {
|
|
257
|
+
const masked = maskData.maskJwt(input, jwtMaskOptions);
|
|
258
|
+
expect(masked).to.equal(input, 'Improper input');
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
});
|
package/tests/testMaskHelper.js
CHANGED
|
@@ -5,119 +5,125 @@ const expect = require('chai').expect;
|
|
|
5
5
|
const maskHelper = require('../lib/helpers/MaskHelper');
|
|
6
6
|
const Constants = require('../lib/helpers/Constants');
|
|
7
7
|
|
|
8
|
-
describe('Test helper functions', function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
expect(options['unmaskedEndDigits']).to.equal(1);
|
|
8
|
+
describe('Test helper functions', function () {
|
|
9
|
+
describe('Test mapWithDefaultValues function', function () {
|
|
10
|
+
it('Test mapWithDefaultValues function', function () {
|
|
11
|
+
const options = maskHelper.mapWithDefaultValues({}, Constants.defaultCardMaskOptions);
|
|
12
|
+
// const defaultCardMaskOptions = {
|
|
13
|
+
// maskWith: "*",
|
|
14
|
+
// unmaskedStartDigits: 4,
|
|
15
|
+
// unmaskedEndDigits: 1
|
|
16
|
+
// };
|
|
17
|
+
expect(options['maskWith']).to.equal('*');
|
|
18
|
+
expect(options['unmaskedStartDigits']).to.equal(4);
|
|
19
|
+
expect(options['unmaskedEndDigits']).to.equal(1);
|
|
21
20
|
});
|
|
22
21
|
});
|
|
23
22
|
|
|
24
|
-
describe('Test getValidatedJsonMask2Configs function', function() {
|
|
25
|
-
it('Test getValidatedJsonMask2Configs function with empty configs', function() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
describe('Test getValidatedJsonMask2Configs function', function () {
|
|
24
|
+
it('Test getValidatedJsonMask2Configs function with empty configs', function () {
|
|
25
|
+
const options = maskHelper.getValidatedJsonMask2Configs(
|
|
26
|
+
{},
|
|
27
|
+
Constants.defaultjsonMask2Configs
|
|
28
|
+
);
|
|
29
|
+
// const defaultjsonMask2Configs = {
|
|
30
|
+
// cardMaskOptions: defaultCardMaskOptions,
|
|
31
|
+
// cardFields: [],
|
|
32
|
+
// emailMaskOptions: defaultEmailMask2Options,
|
|
33
|
+
// emailFields: [],
|
|
34
|
+
// passwordMaskOptions: defaultPasswordMaskOptions,
|
|
35
|
+
// passwordFields: [],
|
|
36
|
+
// phoneMaskOptions: defaultPhoneMaskOptions,
|
|
37
|
+
// phoneFields: [],
|
|
38
|
+
// stringMaskOptions: defaultStringMaskOptions,
|
|
39
|
+
// stringFields: [],
|
|
40
|
+
// uuidMaskOptions: defaultUuidMaskOptions,
|
|
41
|
+
// uuidFields: []
|
|
42
|
+
// };
|
|
43
|
+
expect(options['cardMaskOptions']['maskWith']).to.equal('*');
|
|
44
|
+
expect(options['emailMaskOptions']['maskWith']).to.equal('*');
|
|
45
|
+
expect(options['passwordMaskOptions']['maskWith']).to.equal('*');
|
|
46
|
+
expect(options['phoneMaskOptions']['maskWith']).to.equal('*');
|
|
47
|
+
expect(options['stringMaskOptions']['maskWith']).to.equal('*');
|
|
48
|
+
expect(options['uuidMaskOptions']['maskWith']).to.equal('*');
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
51
|
+
expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
|
|
52
|
+
expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
|
|
53
|
+
expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
54
|
+
expect(options['stringMaskOptions']['maskAll']).to.equal(false);
|
|
55
|
+
expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
it('Test getValidatedJsonMask2Configs function with only the fields list', function() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
it('Test getValidatedJsonMask2Configs function with only the fields list', function () {
|
|
59
|
+
const options = maskHelper.getValidatedJsonMask2Configs(
|
|
60
|
+
{ cardFields: ['card1'] },
|
|
61
|
+
Constants.defaultjsonMask2Configs
|
|
62
|
+
);
|
|
63
|
+
// const defaultjsonMask2Configs = {
|
|
64
|
+
// cardMaskOptions: defaultCardMaskOptions,
|
|
65
|
+
// cardFields: [],
|
|
66
|
+
// emailMaskOptions: defaultEmailMask2Options,
|
|
67
|
+
// emailFields: [],
|
|
68
|
+
// passwordMaskOptions: defaultPasswordMaskOptions,
|
|
69
|
+
// passwordFields: [],
|
|
70
|
+
// phoneMaskOptions: defaultPhoneMaskOptions,
|
|
71
|
+
// phoneFields: [],
|
|
72
|
+
// stringMaskOptions: defaultStringMaskOptions,
|
|
73
|
+
// stringFields: [],
|
|
74
|
+
// uuidMaskOptions: defaultUuidMaskOptions,
|
|
75
|
+
// uuidFields: []
|
|
76
|
+
// };
|
|
77
|
+
expect(options['cardMaskOptions']['maskWith']).to.equal('*');
|
|
78
|
+
expect(options['emailMaskOptions']['maskWith']).to.equal('*');
|
|
79
|
+
expect(options['passwordMaskOptions']['maskWith']).to.equal('*');
|
|
80
|
+
expect(options['phoneMaskOptions']['maskWith']).to.equal('*');
|
|
81
|
+
expect(options['stringMaskOptions']['maskWith']).to.equal('*');
|
|
82
|
+
expect(options['uuidMaskOptions']['maskWith']).to.equal('*');
|
|
78
83
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
85
|
+
expect(options['cardFields'][0]).to.equal('card1');
|
|
86
|
+
expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
|
|
87
|
+
expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
|
|
88
|
+
expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
89
|
+
expect(options['stringMaskOptions']['maskAll']).to.equal(false);
|
|
90
|
+
expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
|
|
86
91
|
});
|
|
87
92
|
});
|
|
88
93
|
|
|
89
|
-
describe('Test getValidatedJsonMask2Configs function', function() {
|
|
90
|
-
it('Test getValidatedJsonMask2Configs function with empty configs', function() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
|
|
116
|
-
expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
117
|
-
expect(options['stringMaskOptions']['maskAll']).to.equal(false);
|
|
118
|
-
expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
|
|
94
|
+
describe('Test getValidatedJsonMask2Configs function', function () {
|
|
95
|
+
it('Test getValidatedJsonMask2Configs function with empty configs', function () {
|
|
96
|
+
const options = maskHelper.getValidatedJsonMask2Configs(
|
|
97
|
+
{},
|
|
98
|
+
Constants.defaultjsonMask2Configs
|
|
99
|
+
);
|
|
100
|
+
// const defaultjsonMask2Configs = {
|
|
101
|
+
// cardMaskOptions: defaultCardMaskOptions,
|
|
102
|
+
// cardFields: [],
|
|
103
|
+
// emailMaskOptions: defaultEmailMask2Options,
|
|
104
|
+
// emailFields: [],
|
|
105
|
+
// passwordMaskOptions: defaultPasswordMaskOptions,
|
|
106
|
+
// passwordFields: [],
|
|
107
|
+
// phoneMaskOptions: defaultPhoneMaskOptions,
|
|
108
|
+
// phoneFields: [],
|
|
109
|
+
// stringMaskOptions: defaultStringMaskOptions,
|
|
110
|
+
// stringFields: [],
|
|
111
|
+
// uuidMaskOptions: defaultUuidMaskOptions,
|
|
112
|
+
// uuidFields: []
|
|
113
|
+
// };
|
|
114
|
+
expect(options['cardMaskOptions']['maskWith']).to.equal('*');
|
|
115
|
+
expect(options['emailMaskOptions']['maskWith']).to.equal('*');
|
|
116
|
+
expect(options['passwordMaskOptions']['maskWith']).to.equal('*');
|
|
117
|
+
expect(options['phoneMaskOptions']['maskWith']).to.equal('*');
|
|
118
|
+
expect(options['stringMaskOptions']['maskWith']).to.equal('*');
|
|
119
|
+
expect(options['uuidMaskOptions']['maskWith']).to.equal('*');
|
|
119
120
|
|
|
121
|
+
expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
122
|
+
expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
|
|
123
|
+
expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
|
|
124
|
+
expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
|
|
125
|
+
expect(options['stringMaskOptions']['maskAll']).to.equal(false);
|
|
126
|
+
expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
|
|
120
127
|
});
|
|
121
128
|
});
|
|
122
|
-
|
|
123
|
-
});
|
|
129
|
+
});
|