maskdata 1.2.2 → 1.2.3
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 +64 -146
- package/index.d.ts +76 -72
- package/index.js +6 -3
- package/lib/ExceptionsHandler/BadOption.js +2 -2
- package/lib/helpers/Constants.js +47 -48
- package/lib/helpers/MaskHelper.js +119 -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 +163 -87
- 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 +14 -7
- package/tests/scribble.js +298 -126
- package/tests/testCard.js +35 -40
- package/tests/testEmail.js +46 -53
- package/tests/testJsonFields.js +668 -231
- package/tests/testJsonGetSet.js +54 -21
- 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/testPhone.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Masking phone numbers', function() {
|
|
6
|
-
|
|
7
|
-
describe('Mask with default options', function() {
|
|
8
|
-
|
|
5
|
+
describe('Masking phone numbers', function () {
|
|
6
|
+
describe('Mask with default options', function () {
|
|
9
7
|
// default options are this - let tests fail when defaults change
|
|
10
8
|
// const phoneMaskOptions = {
|
|
11
9
|
// maskWith: "*",
|
|
@@ -29,21 +27,20 @@ describe('Masking phone numbers', function() {
|
|
|
29
27
|
input: '1234',
|
|
30
28
|
output: '1234'
|
|
31
29
|
}
|
|
32
|
-
]
|
|
30
|
+
];
|
|
33
31
|
|
|
34
|
-
testData.forEach(({title, input, output}) => {
|
|
35
|
-
it(`default mask - ${title}`, function() {
|
|
32
|
+
testData.forEach(({ title, input, output }) => {
|
|
33
|
+
it(`default mask - ${title}`, function () {
|
|
36
34
|
const masked = maskData.maskPhone(input);
|
|
37
35
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
38
36
|
});
|
|
39
|
-
})
|
|
37
|
+
});
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
describe('Mask with custom options', function() {
|
|
43
|
-
|
|
40
|
+
describe('Mask with custom options', function () {
|
|
44
41
|
const maskOptions = {
|
|
45
42
|
maskWith: 'x',
|
|
46
|
-
unmaskedStartDigits: 2,
|
|
43
|
+
unmaskedStartDigits: 2, // use different numbers for start / end to check correct masking
|
|
47
44
|
unmaskedEndDigits: 3
|
|
48
45
|
};
|
|
49
46
|
|
|
@@ -63,50 +60,48 @@ describe('Masking phone numbers', function() {
|
|
|
63
60
|
input: '1234',
|
|
64
61
|
output: '1234'
|
|
65
62
|
}
|
|
66
|
-
]
|
|
63
|
+
];
|
|
67
64
|
|
|
68
|
-
testData.forEach(({title, input, output}) => {
|
|
69
|
-
it(`custom mask - ${title}`, function() {
|
|
65
|
+
testData.forEach(({ title, input, output }) => {
|
|
66
|
+
it(`custom mask - ${title}`, function () {
|
|
70
67
|
const masked = maskData.maskPhone(input, maskOptions);
|
|
71
68
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
72
69
|
});
|
|
73
70
|
});
|
|
74
71
|
|
|
75
|
-
it('test with negative unmaskedStartDigits', function() {
|
|
72
|
+
it('test with negative unmaskedStartDigits', function () {
|
|
76
73
|
const negativeStartOption = {
|
|
77
74
|
maskWith: 'x',
|
|
78
|
-
unmaskedStartDigits: -2,
|
|
75
|
+
unmaskedStartDigits: -2, // internal set to 0
|
|
79
76
|
unmaskedEndDigits: 3
|
|
80
|
-
}
|
|
81
|
-
const input = '1234-5678'
|
|
82
|
-
const output = 'xxxxxx678'
|
|
77
|
+
};
|
|
78
|
+
const input = '1234-5678';
|
|
79
|
+
const output = 'xxxxxx678';
|
|
83
80
|
const masked = maskData.maskPhone(input, negativeStartOption);
|
|
84
81
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
85
82
|
});
|
|
86
83
|
|
|
87
|
-
it('test with negative unmaskedEndDigits', function() {
|
|
84
|
+
it('test with negative unmaskedEndDigits', function () {
|
|
88
85
|
const negativeEndOption = {
|
|
89
86
|
maskWith: 'x',
|
|
90
87
|
unmaskedStartDigits: 2,
|
|
91
|
-
unmaskedEndDigits: -3
|
|
92
|
-
}
|
|
93
|
-
const input = '1234-5678'
|
|
94
|
-
const output = '12xxxxxxx'
|
|
88
|
+
unmaskedEndDigits: -3 // internal set to 0
|
|
89
|
+
};
|
|
90
|
+
const input = '1234-5678';
|
|
91
|
+
const output = '12xxxxxxx';
|
|
95
92
|
const masked = maskData.maskPhone(input, negativeEndOption);
|
|
96
93
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
97
94
|
});
|
|
98
95
|
});
|
|
99
96
|
|
|
100
|
-
describe('Mask with special input strings', function() {
|
|
101
|
-
|
|
97
|
+
describe('Mask with special input strings', function () {
|
|
102
98
|
const maskOptions = {
|
|
103
|
-
maskWith:
|
|
99
|
+
maskWith: 'x',
|
|
104
100
|
unmaskedStartDigits: 2,
|
|
105
101
|
unmaskedEndDigits: 2
|
|
106
102
|
};
|
|
107
103
|
|
|
108
|
-
describe('Mask with special input - input will generate an output', function() {
|
|
109
|
-
|
|
104
|
+
describe('Mask with special input - input will generate an output', function () {
|
|
110
105
|
// first set with input generating an masked output
|
|
111
106
|
let testData = [
|
|
112
107
|
{
|
|
@@ -123,35 +118,34 @@ describe('Masking phone numbers', function() {
|
|
|
123
118
|
title: 'test input as number',
|
|
124
119
|
input: 1234567,
|
|
125
120
|
output: '12xxx67'
|
|
126
|
-
}
|
|
127
|
-
]
|
|
121
|
+
}
|
|
122
|
+
];
|
|
128
123
|
|
|
129
|
-
testData.forEach(({title, input, output}) => {
|
|
130
|
-
it(`special input - ${title}`, function() {
|
|
124
|
+
testData.forEach(({ title, input, output }) => {
|
|
125
|
+
it(`special input - ${title}`, function () {
|
|
131
126
|
const masked = maskData.maskPhone(input, maskOptions);
|
|
132
127
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
133
128
|
});
|
|
134
129
|
});
|
|
135
130
|
});
|
|
136
131
|
|
|
137
|
-
describe(
|
|
138
|
-
|
|
132
|
+
describe("Mask with special input - input won't be masked", function () {
|
|
139
133
|
// set with input generating an error / exception
|
|
140
134
|
let testData = [
|
|
141
135
|
{
|
|
142
136
|
title: 'test input as array',
|
|
143
|
-
input: ['12', '34']
|
|
137
|
+
input: ['12', '34']
|
|
144
138
|
},
|
|
145
139
|
{
|
|
146
140
|
title: 'test input as object',
|
|
147
|
-
input: {a: 'b', x: 'y'}
|
|
141
|
+
input: { a: 'b', x: 'y' }
|
|
148
142
|
}
|
|
149
|
-
]
|
|
143
|
+
];
|
|
150
144
|
|
|
151
|
-
testData.forEach(({title, input, output}) => {
|
|
152
|
-
it(`special input - ${title}`, function() {
|
|
145
|
+
testData.forEach(({ title, input, output }) => {
|
|
146
|
+
it(`special input - ${title}`, function () {
|
|
153
147
|
const masked = maskData.maskPhone(input, maskOptions);
|
|
154
|
-
expect(masked).to.equal(input,
|
|
148
|
+
expect(masked).to.equal(input, "input won't be masked");
|
|
155
149
|
});
|
|
156
150
|
});
|
|
157
151
|
});
|
package/tests/testString.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Masking strings', function() {
|
|
6
|
-
|
|
5
|
+
describe('Masking strings', function () {
|
|
7
6
|
// common strings without output - used as base for all tests below
|
|
8
7
|
let testData = [
|
|
9
8
|
{
|
|
@@ -21,10 +20,9 @@ describe('Masking strings', function() {
|
|
|
21
20
|
input: 'this is a\nstring with newline',
|
|
22
21
|
output: ''
|
|
23
22
|
}
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
describe('Mask with default options', function() {
|
|
23
|
+
];
|
|
27
24
|
|
|
25
|
+
describe('Mask with default options', function () {
|
|
28
26
|
// default options are this - let tests fail when defaults change
|
|
29
27
|
// const defaultStringMaskOptions = {
|
|
30
28
|
// maskWith: "*",
|
|
@@ -40,19 +38,18 @@ describe('Masking strings', function() {
|
|
|
40
38
|
localTestData[1].output = localTestData[1].input;
|
|
41
39
|
localTestData[2].output = localTestData[2].input;
|
|
42
40
|
|
|
43
|
-
localTestData.forEach(({title, input, output}) => {
|
|
44
|
-
it(`default mask - ${title}`, function() {
|
|
41
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
42
|
+
it(`default mask - ${title}`, function () {
|
|
45
43
|
const masked = maskData.maskString(input);
|
|
46
44
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
47
45
|
});
|
|
48
|
-
})
|
|
46
|
+
});
|
|
49
47
|
});
|
|
50
48
|
|
|
51
|
-
describe('Mask with custom options - maskWith, maskSpace', function() {
|
|
52
|
-
|
|
49
|
+
describe('Mask with custom options - maskWith, maskSpace', function () {
|
|
53
50
|
// only maskWith and maskSpace set
|
|
54
51
|
const maskOptions = {
|
|
55
|
-
maskWith:
|
|
52
|
+
maskWith: '?',
|
|
56
53
|
maskOnlyFirstOccurance: false,
|
|
57
54
|
values: [],
|
|
58
55
|
maskAll: false,
|
|
@@ -65,19 +62,18 @@ describe('Masking strings', function() {
|
|
|
65
62
|
localTestData[1].output = localTestData[1].input;
|
|
66
63
|
localTestData[2].output = localTestData[2].input;
|
|
67
64
|
|
|
68
|
-
localTestData.forEach(({title, input, output}) => {
|
|
69
|
-
it(`custom mask - ${title}`, function() {
|
|
65
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
66
|
+
it(`custom mask - ${title}`, function () {
|
|
70
67
|
const masked = maskData.maskString(input, maskOptions);
|
|
71
68
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
72
69
|
});
|
|
73
70
|
});
|
|
74
71
|
});
|
|
75
72
|
|
|
76
|
-
describe('Mask with custom options - maskWith, maskAll, no spaces', function() {
|
|
77
|
-
|
|
73
|
+
describe('Mask with custom options - maskWith, maskAll, no spaces', function () {
|
|
78
74
|
// only maskWith, maskAll set
|
|
79
75
|
const maskOptions = {
|
|
80
|
-
maskWith:
|
|
76
|
+
maskWith: '?',
|
|
81
77
|
maskOnlyFirstOccurance: false,
|
|
82
78
|
values: [],
|
|
83
79
|
maskAll: true,
|
|
@@ -86,21 +82,20 @@ describe('Masking strings', function() {
|
|
|
86
82
|
|
|
87
83
|
const localTestData = JSON.parse(JSON.stringify(testData));
|
|
88
84
|
localTestData[0].output = '???? ?? ? ?????????? ??????';
|
|
89
|
-
localTestData[1].output = '?'.repeat(localTestData[1].input.length);
|
|
85
|
+
localTestData[1].output = '?'.repeat(localTestData[1].input.length); // no space here
|
|
90
86
|
localTestData[2].output = '???? ?? ???????? ???? ???????';
|
|
91
87
|
|
|
92
|
-
localTestData.forEach(({title, input, output}) => {
|
|
93
|
-
it(`custom mask - ${title}`, function() {
|
|
88
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
89
|
+
it(`custom mask - ${title}`, function () {
|
|
94
90
|
const masked = maskData.maskString(input, maskOptions);
|
|
95
91
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
96
92
|
});
|
|
97
93
|
});
|
|
98
94
|
});
|
|
99
95
|
|
|
100
|
-
describe('Mask with custom options - maskWith multiple chars, maskAll, maskSpace', function() {
|
|
101
|
-
|
|
96
|
+
describe('Mask with custom options - maskWith multiple chars, maskAll, maskSpace', function () {
|
|
102
97
|
// only maskWith, maskAll set
|
|
103
|
-
const maskChar =
|
|
98
|
+
const maskChar = '??'; // mask every char in input string with two chars in output
|
|
104
99
|
const maskOptions = {
|
|
105
100
|
maskWith: maskChar,
|
|
106
101
|
maskOnlyFirstOccurance: false,
|
|
@@ -114,18 +109,17 @@ describe('Masking strings', function() {
|
|
|
114
109
|
localTestData[1].output = maskChar.repeat(localTestData[1].input.length);
|
|
115
110
|
localTestData[2].output = maskChar.repeat(localTestData[2].input.length);
|
|
116
111
|
|
|
117
|
-
localTestData.forEach(({title, input, output}) => {
|
|
118
|
-
it(`custom mask - ${title}`, function() {
|
|
112
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
113
|
+
it(`custom mask - ${title}`, function () {
|
|
119
114
|
const masked = maskData.maskString(input, maskOptions);
|
|
120
115
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
121
116
|
});
|
|
122
117
|
});
|
|
123
118
|
});
|
|
124
119
|
|
|
125
|
-
describe('Mask with custom options - values and maskAll set, no spaces', function() {
|
|
126
|
-
|
|
120
|
+
describe('Mask with custom options - values and maskAll set, no spaces', function () {
|
|
127
121
|
const maskOptions = {
|
|
128
|
-
maskWith:
|
|
122
|
+
maskWith: 'x',
|
|
129
123
|
maskOnlyFirstOccurance: false,
|
|
130
124
|
values: ['is', 'ing'],
|
|
131
125
|
maskAll: true,
|
|
@@ -135,21 +129,20 @@ describe('Masking strings', function() {
|
|
|
135
129
|
// expected: values ignored and all masked, space remains
|
|
136
130
|
const localTestData = JSON.parse(JSON.stringify(testData));
|
|
137
131
|
localTestData[0].output = 'xxxx xx x xxxxxxxxxx xxxxxx';
|
|
138
|
-
localTestData[1].output = 'x'.repeat(localTestData[1].input.length);
|
|
132
|
+
localTestData[1].output = 'x'.repeat(localTestData[1].input.length); // no spaces here
|
|
139
133
|
localTestData[2].output = 'xxxx xx xxxxxxxx xxxx xxxxxxx';
|
|
140
134
|
|
|
141
|
-
localTestData.forEach(({title, input, output}) => {
|
|
142
|
-
it(`custom mask - ${title}`, function() {
|
|
135
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
136
|
+
it(`custom mask - ${title}`, function () {
|
|
143
137
|
const masked = maskData.maskString(input, maskOptions);
|
|
144
138
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
145
139
|
});
|
|
146
140
|
});
|
|
147
141
|
});
|
|
148
142
|
|
|
149
|
-
describe('Mask with custom options - values and all occurrences', function() {
|
|
150
|
-
|
|
143
|
+
describe('Mask with custom options - values and all occurrences', function () {
|
|
151
144
|
const maskOptions = {
|
|
152
|
-
maskWith:
|
|
145
|
+
maskWith: '*',
|
|
153
146
|
maskOnlyFirstOccurance: false,
|
|
154
147
|
values: ['is', 'ing'],
|
|
155
148
|
maskAll: false,
|
|
@@ -161,18 +154,17 @@ describe('Masking strings', function() {
|
|
|
161
154
|
localTestData[1].output = 'th****astr***';
|
|
162
155
|
localTestData[2].output = 'th** ** a\nstr*** with newline';
|
|
163
156
|
|
|
164
|
-
localTestData.forEach(({title, input, output}) => {
|
|
165
|
-
it(`custom mask - ${title}`, function() {
|
|
157
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
158
|
+
it(`custom mask - ${title}`, function () {
|
|
166
159
|
const masked = maskData.maskString(input, maskOptions);
|
|
167
160
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
168
161
|
});
|
|
169
162
|
});
|
|
170
163
|
});
|
|
171
164
|
|
|
172
|
-
describe('Mask with custom options - values and first occureances', function() {
|
|
173
|
-
|
|
165
|
+
describe('Mask with custom options - values and first occureances', function () {
|
|
174
166
|
const maskOptions = {
|
|
175
|
-
maskWith:
|
|
167
|
+
maskWith: '*',
|
|
176
168
|
maskOnlyFirstOccurance: true,
|
|
177
169
|
values: ['is', 'ing'],
|
|
178
170
|
maskAll: false,
|
|
@@ -184,26 +176,24 @@ describe('Masking strings', function() {
|
|
|
184
176
|
localTestData[1].output = 'th**isastr***';
|
|
185
177
|
localTestData[2].output = 'th** is a\nstr*** with newline';
|
|
186
178
|
|
|
187
|
-
localTestData.forEach(({title, input, output}) => {
|
|
188
|
-
it(`custom mask - ${title}`, function() {
|
|
179
|
+
localTestData.forEach(({ title, input, output }) => {
|
|
180
|
+
it(`custom mask - ${title}`, function () {
|
|
189
181
|
const masked = maskData.maskString(input, maskOptions);
|
|
190
182
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
191
183
|
});
|
|
192
184
|
});
|
|
193
185
|
});
|
|
194
186
|
|
|
195
|
-
describe('Mask with special input strings', function() {
|
|
196
|
-
|
|
187
|
+
describe('Mask with special input strings', function () {
|
|
197
188
|
const maskOptions = {
|
|
198
|
-
maskWith:
|
|
189
|
+
maskWith: 'x',
|
|
199
190
|
maskOnlyFirstOccurance: true,
|
|
200
191
|
values: [],
|
|
201
192
|
maskAll: true,
|
|
202
193
|
maskSpace: true
|
|
203
194
|
};
|
|
204
195
|
|
|
205
|
-
describe('Mask with special input - input will generate an output', function() {
|
|
206
|
-
|
|
196
|
+
describe('Mask with special input - input will generate an output', function () {
|
|
207
197
|
// first set with input generating an masked output
|
|
208
198
|
let testData = [
|
|
209
199
|
{
|
|
@@ -220,34 +210,33 @@ describe('Masking strings', function() {
|
|
|
220
210
|
title: 'test input as number',
|
|
221
211
|
input: 12,
|
|
222
212
|
output: 'xx'
|
|
223
|
-
}
|
|
224
|
-
]
|
|
213
|
+
}
|
|
214
|
+
];
|
|
225
215
|
|
|
226
|
-
testData.forEach(({title, input, output}) => {
|
|
227
|
-
it(`special input - ${title}`, function() {
|
|
216
|
+
testData.forEach(({ title, input, output }) => {
|
|
217
|
+
it(`special input - ${title}`, function () {
|
|
228
218
|
const masked = maskData.maskString(input, maskOptions);
|
|
229
219
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
230
220
|
});
|
|
231
221
|
});
|
|
232
222
|
});
|
|
233
223
|
|
|
234
|
-
describe(
|
|
235
|
-
|
|
224
|
+
describe("Mask with improper input - input won't be masked", function () {
|
|
236
225
|
let testData = [
|
|
237
226
|
{
|
|
238
227
|
title: 'test input as array',
|
|
239
|
-
input: ['12', 'ab']
|
|
228
|
+
input: ['12', 'ab']
|
|
240
229
|
},
|
|
241
230
|
{
|
|
242
231
|
title: 'test input as object',
|
|
243
|
-
input: {a: 'b', x: 'y'}
|
|
232
|
+
input: { a: 'b', x: 'y' }
|
|
244
233
|
}
|
|
245
|
-
]
|
|
234
|
+
];
|
|
246
235
|
|
|
247
|
-
testData.forEach(({title, input, output}) => {
|
|
248
|
-
it(`special input - ${title}`, function() {
|
|
236
|
+
testData.forEach(({ title, input, output }) => {
|
|
237
|
+
it(`special input - ${title}`, function () {
|
|
249
238
|
const masked = maskData.maskString(input, maskOptions);
|
|
250
|
-
expect(masked).to.equal(input,
|
|
239
|
+
expect(masked).to.equal(input, "input won't be masked");
|
|
251
240
|
});
|
|
252
241
|
});
|
|
253
242
|
});
|
package/tests/testUuid.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Mask UUID', function() {
|
|
6
|
-
|
|
7
|
-
describe('Mask UUID with default options', function() {
|
|
8
|
-
|
|
5
|
+
describe('Mask UUID', function () {
|
|
6
|
+
describe('Mask UUID with default options', function () {
|
|
9
7
|
// const defaultUuidMaskOptions = {
|
|
10
8
|
// maskWith: "*",
|
|
11
9
|
// unmaskedStartCharacters: 0,
|
|
@@ -23,22 +21,21 @@ describe('Mask UUID', function() {
|
|
|
23
21
|
input: '123E4567-E89B-12D3-A456-426614174000',
|
|
24
22
|
output: '********-****-****-****-************'
|
|
25
23
|
}
|
|
26
|
-
]
|
|
24
|
+
];
|
|
27
25
|
|
|
28
|
-
testData.forEach(({title, input, output}) => {
|
|
29
|
-
it(title, function() {
|
|
26
|
+
testData.forEach(({ title, input, output }) => {
|
|
27
|
+
it(title, function () {
|
|
30
28
|
const masked = maskData.maskUuid(input);
|
|
31
29
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
32
30
|
});
|
|
33
|
-
})
|
|
31
|
+
});
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
describe('Mask UUID with custom options', function() {
|
|
37
|
-
|
|
34
|
+
describe('Mask UUID with custom options', function () {
|
|
38
35
|
const customUuidMaskOptions = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
maskWith: 'X',
|
|
37
|
+
unmaskedStartCharacters: 5,
|
|
38
|
+
unmaskedEndCharacters: 13
|
|
42
39
|
};
|
|
43
40
|
|
|
44
41
|
let testData = [
|
|
@@ -52,53 +49,68 @@ describe('Mask UUID', function() {
|
|
|
52
49
|
input: '123E4567-E89B-12D3-A456-426614174000',
|
|
53
50
|
output: '123E4XXX-XXXX-XXXX-XXX6-426614174000'
|
|
54
51
|
}
|
|
55
|
-
]
|
|
52
|
+
];
|
|
56
53
|
|
|
57
|
-
testData.forEach(({title, input, output}) => {
|
|
58
|
-
it(title, function() {
|
|
54
|
+
testData.forEach(({ title, input, output }) => {
|
|
55
|
+
it(title, function () {
|
|
59
56
|
const masked = maskData.maskUuid(input, customUuidMaskOptions);
|
|
60
57
|
expect(masked).to.equal(output);
|
|
61
58
|
});
|
|
62
59
|
});
|
|
63
60
|
|
|
64
|
-
const customUuidMaskOptions2 = { unmaskedStartCharacters: 8, unmaskedEndCharacters: 12};
|
|
65
|
-
it('Edge case1: unmask only the parts of UUID', function() {
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const customUuidMaskOptions2 = { unmaskedStartCharacters: 8, unmaskedEndCharacters: 12 };
|
|
62
|
+
it('Edge case1: unmask only the parts of UUID', function () {
|
|
63
|
+
const masked = maskData.maskUuid(
|
|
64
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
65
|
+
customUuidMaskOptions2
|
|
66
|
+
);
|
|
67
|
+
expect(masked).to.equal('123e4567-****-****-****-426614174000');
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
const customUuidMaskOptions3 = { unmaskedStartCharacters: 32, unmaskedEndCharacters: 0};
|
|
71
|
-
it('Edge case2: unmaskedStartCharacters = 32', function() {
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const customUuidMaskOptions3 = { unmaskedStartCharacters: 32, unmaskedEndCharacters: 0 };
|
|
71
|
+
it('Edge case2: unmaskedStartCharacters = 32', function () {
|
|
72
|
+
const masked = maskData.maskUuid(
|
|
73
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
74
|
+
customUuidMaskOptions3
|
|
75
|
+
);
|
|
76
|
+
expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
|
|
74
77
|
});
|
|
75
78
|
|
|
76
|
-
const customUuidMaskOptions4 = { unmaskedStartCharacters: 0, unmaskedEndCharacters: 32};
|
|
77
|
-
it('Edge case3: unmaskedEndCharacters = 32', function() {
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const customUuidMaskOptions4 = { unmaskedStartCharacters: 0, unmaskedEndCharacters: 32 };
|
|
80
|
+
it('Edge case3: unmaskedEndCharacters = 32', function () {
|
|
81
|
+
const masked = maskData.maskUuid(
|
|
82
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
83
|
+
customUuidMaskOptions4
|
|
84
|
+
);
|
|
85
|
+
expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
|
|
80
86
|
});
|
|
81
87
|
|
|
82
|
-
const customUuidMaskOptions5 = { unmaskedStartCharacters: 33, unmaskedEndCharacters: 5};
|
|
83
|
-
it('Edge case4: unmaskedStartCharacters > 32', function() {
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
const customUuidMaskOptions5 = { unmaskedStartCharacters: 33, unmaskedEndCharacters: 5 };
|
|
89
|
+
it('Edge case4: unmaskedStartCharacters > 32', function () {
|
|
90
|
+
const masked = maskData.maskUuid(
|
|
91
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
92
|
+
customUuidMaskOptions5
|
|
93
|
+
);
|
|
94
|
+
expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
|
|
86
95
|
});
|
|
87
96
|
|
|
88
|
-
const customUuidMaskOptions6 = { unmaskedStartCharacters: 1, unmaskedEndCharacters: 33};
|
|
89
|
-
it('Edge case5: unmaskedEndCharacters > 32', function() {
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
const customUuidMaskOptions6 = { unmaskedStartCharacters: 1, unmaskedEndCharacters: 33 };
|
|
98
|
+
it('Edge case5: unmaskedEndCharacters > 32', function () {
|
|
99
|
+
const masked = maskData.maskUuid(
|
|
100
|
+
'123e4567-e89b-12d3-a456-426614174000',
|
|
101
|
+
customUuidMaskOptions6
|
|
102
|
+
);
|
|
103
|
+
expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
|
|
92
104
|
});
|
|
93
105
|
|
|
94
|
-
it('Edge case6: incorrect UUID', function() {
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
it('Edge case6: incorrect UUID', function () {
|
|
107
|
+
const masked = maskData.maskUuid('123567-e89b-12d3-a456-4264174000');
|
|
108
|
+
expect(masked).to.equal('123567-e89b-12d3-a456-4264174000', 'No masking done');
|
|
97
109
|
});
|
|
98
110
|
|
|
99
|
-
it('Edge case7: incorrect UUID2', function() {
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
it('Edge case7: incorrect UUID2', function () {
|
|
112
|
+
const masked = maskData.maskUuid('123e4567-mnop-12d3-a456-426614174000');
|
|
113
|
+
expect(masked).to.equal('123e4567-mnop-12d3-a456-426614174000');
|
|
102
114
|
});
|
|
103
115
|
});
|
|
104
|
-
});
|
|
116
|
+
});
|