maskdata 1.3.1 → 1.3.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/MASKDATA_FOR_TYPESCRIPT.md +18 -14
- package/README.md +663 -582
- package/documentation/get_nested_json_property.md +27 -0
- package/documentation/main.md +117 -0
- package/documentation/mask_cards.md +0 -0
- package/documentation/mask_email_id.md +47 -0
- package/documentation/mask_email_id_with_the_default_configuration.md +355 -0
- package/documentation/mask_jwt_token.md +132 -0
- package/documentation/mask_password.md +31 -0
- package/documentation/mask_password_with_the_default_configuration.md +43 -0
- package/documentation/mask_phone_number.md +26 -0
- package/documentation/mask_phone_number_with_the_default_configuration.md +155 -0
- package/documentation/mask_uuid.md +30 -0
- package/documentation/replace_the_value_of_a_json_field.md +220 -0
- package/index.d.ts +8 -0
- package/index.js +5 -0
- package/lib/helpers/Constants.js +4 -1
- package/lib/helpers/MaskHelper.js +34 -6
- package/lib/maskService/JsonMask.js +33 -3
- package/lib/maskService/PasswordMask.js +7 -0
- package/lib/maskService/StringMask.js +9 -1
- package/package.json +6 -4
- package/tests/scribble.js +59 -67
- package/tests/testJsonFields.js +143 -0
- package/tests/testPassword.js +135 -1
- package/tests/testString.js +16 -4
- package/tests/testStringV2.js +134 -0
package/tests/testStringV2.js
CHANGED
|
@@ -10,6 +10,7 @@ describe('Masking String V2', function () {
|
|
|
10
10
|
// maxMaskedCharacters: 256,
|
|
11
11
|
// unmaskedStartCharacters: 0,
|
|
12
12
|
// unmaskedEndCharacters: 0
|
|
13
|
+
// fixedOutputLength: undefined
|
|
13
14
|
// };
|
|
14
15
|
|
|
15
16
|
let testData = [
|
|
@@ -121,6 +122,139 @@ describe('Masking String V2', function () {
|
|
|
121
122
|
});
|
|
122
123
|
});
|
|
123
124
|
|
|
125
|
+
describe('Mask with fixedOutputLength', function () {
|
|
126
|
+
const maskOptions = {
|
|
127
|
+
maskWith: 'X',
|
|
128
|
+
fixedOutputLength: 6
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
let testData = [
|
|
132
|
+
{
|
|
133
|
+
title: 'Random string',
|
|
134
|
+
input: '1234-5678-1234-5678',
|
|
135
|
+
output: 'XXXXXX'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
title: 'input string length equal to fixedOutputLength',
|
|
139
|
+
input: '12-345',
|
|
140
|
+
output: 'XXXXXX'
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
title: 'input string length less than fixedOutputLength',
|
|
144
|
+
input: '12',
|
|
145
|
+
output: 'XXXXXX'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
title: 'input string length greater than fixedOutputLength',
|
|
149
|
+
input: '1234567',
|
|
150
|
+
output: 'XXXXXX'
|
|
151
|
+
}
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
testData.forEach(({ title, input, output }) => {
|
|
155
|
+
it(`custom mask - ${title}`, function () {
|
|
156
|
+
const masked = maskData.maskStringV2(input, maskOptions);
|
|
157
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('custom mask - test with fixedOutputLength and maxMaskedCharacters; No effect from maxMaskedCharacters', function () {
|
|
162
|
+
const option = {
|
|
163
|
+
maskWith: 'x',
|
|
164
|
+
maxMaskedCharacters: 4,
|
|
165
|
+
fixedOutputLength: 6
|
|
166
|
+
};
|
|
167
|
+
const input = '1234-5678-1234-5678';
|
|
168
|
+
const output = 'xxxxxx';
|
|
169
|
+
const masked = maskData.maskStringV2(input, option);
|
|
170
|
+
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('unmaskedStartCharacters + unmaskedEndCharacters < fixedOutputLength; No masking done', function () {
|
|
174
|
+
const shortMaxCharsOption = {
|
|
175
|
+
maskWith: 'x',
|
|
176
|
+
fixedOutputLength: 6,
|
|
177
|
+
unmaskedStartCharacters: 4, // 4+4=8 > 6
|
|
178
|
+
unmaskedEndCharacters: 4
|
|
179
|
+
};
|
|
180
|
+
const input = '1234-5678-1234-5678';
|
|
181
|
+
const output = '123478';
|
|
182
|
+
const masked = maskData.maskStringV2(input, shortMaxCharsOption);
|
|
183
|
+
expect(masked).to.equal(
|
|
184
|
+
output,
|
|
185
|
+
'No masking done because fixedOutputLength shorter than start + end'
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('unmaskedStartCharacters + unmaskedEndCharacters = fixedOutputLength; No masking done', function () {
|
|
190
|
+
const shortMaxCharsOption = {
|
|
191
|
+
maskWith: 'x',
|
|
192
|
+
fixedOutputLength: 8,
|
|
193
|
+
unmaskedStartCharacters: 4, // 4+4=8
|
|
194
|
+
unmaskedEndCharacters: 4
|
|
195
|
+
};
|
|
196
|
+
const input = '1234-abcd-efgh-5678';
|
|
197
|
+
const output = '12345678';
|
|
198
|
+
const masked = maskData.maskStringV2(input, shortMaxCharsOption);
|
|
199
|
+
expect(masked).to.equal(
|
|
200
|
+
output,
|
|
201
|
+
'No masking done because fixedOutputLength equal to start + end'
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
it('fixedOutputLength = null; Treat it as undefined and mask with other default configs', function () {
|
|
205
|
+
const config = {
|
|
206
|
+
maskWith: 'x',
|
|
207
|
+
fixedOutputLength: null
|
|
208
|
+
};
|
|
209
|
+
const input = '1234-abcd-efgh-5678';
|
|
210
|
+
const output = 'xxxxxxxxxxxxxxxxxxx';
|
|
211
|
+
const masked = maskData.maskStringV2(input, config);
|
|
212
|
+
expect(masked).to.equal(
|
|
213
|
+
output,
|
|
214
|
+
'Default config masking should have been done as fixedOutputLength is null and is treated as undefined'
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
it('fixedOutputLength = undefined; Treat it as undefined and mask with other default configs', function () {
|
|
218
|
+
const config = {
|
|
219
|
+
maskWith: 'x',
|
|
220
|
+
fixedOutputLength: undefined
|
|
221
|
+
};
|
|
222
|
+
const input = '1234-abcd-efgh-5678';
|
|
223
|
+
const output = 'xxxxxxxxxxxxxxxxxxx';
|
|
224
|
+
const masked = maskData.maskStringV2(input, config);
|
|
225
|
+
expect(masked).to.equal(
|
|
226
|
+
output,
|
|
227
|
+
'Default config masking should have been done as fixedOutputLength is undefined'
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
it('fixedOutputLength < 0; Treat it as undefined and mask with other default configs', function () {
|
|
231
|
+
const config = {
|
|
232
|
+
maskWith: 'x',
|
|
233
|
+
fixedOutputLength: -1
|
|
234
|
+
};
|
|
235
|
+
const input = '1234-abcd-efgh-5678';
|
|
236
|
+
const output = 'xxxxxxxxxxxxxxxxxxx';
|
|
237
|
+
const masked = maskData.maskStringV2(input, config);
|
|
238
|
+
expect(masked).to.equal(
|
|
239
|
+
output,
|
|
240
|
+
'Default config masking should have been done as fixedOutputLength is negative as is treated as undefined'
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
it('fixedOutputLength = 0; Output length = 0 characters', function () {
|
|
244
|
+
const config = {
|
|
245
|
+
maskWith: 'x',
|
|
246
|
+
fixedOutputLength: 0
|
|
247
|
+
};
|
|
248
|
+
const input = '1234-abcd-efgh-5678';
|
|
249
|
+
const output = '';
|
|
250
|
+
const masked = maskData.maskStringV2(input, config);
|
|
251
|
+
expect(masked).to.equal(
|
|
252
|
+
output,
|
|
253
|
+
'Output length should be 0 as fixedOutputLength is explicitly mentioned as 0'
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
124
258
|
describe('Mask with special input strings', function () {
|
|
125
259
|
const maskOptions = {
|
|
126
260
|
maskWith: 'x',
|