maskdata 1.1.8 → 1.2.0
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/README.md +538 -236
- package/index.js +24 -157
- package/lib/helpers/Constants.js +72 -0
- package/lib/helpers/MaskHelper.js +61 -0
- package/lib/helpers/jsonGetSet.js +14 -0
- package/lib/{cardMask → maskService}/CardMask.js +4 -9
- package/lib/{emailMask → maskService}/EmailMask.js +8 -14
- package/lib/maskService/JsonMask.js +118 -0
- package/lib/maskService/PasswordMask.js +43 -0
- package/lib/maskService/PhoneMask.js +23 -0
- package/lib/maskService/StringMask.js +44 -0
- package/lib/maskService/UuidMask.js +34 -0
- package/package.json +3 -3
- package/{test.js → tests/scribble.js} +87 -3
- package/tests/testCard.js +24 -24
- package/tests/testEmail.js +25 -0
- package/tests/testJsonFields.js +492 -4
- package/tests/testJsonGetSet.js +75 -0
- package/tests/testMaskHelper.js +123 -0
- package/tests/testPassword.js +35 -6
- package/tests/testPhone.js +29 -26
- package/tests/testString.js +21 -24
- package/tests/testUuid.js +104 -0
- package/tests/testReplaceValue.js +0 -35
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MaskHelper = require('../helpers/MaskHelper');
|
|
4
|
+
const Constants = require('../helpers/Constants');
|
|
5
|
+
const uuidFormat = /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/g;
|
|
6
|
+
|
|
7
|
+
class UuidMask {
|
|
8
|
+
static maskUuid(uuid, options) {
|
|
9
|
+
if(!uuid || typeof(uuid) !== 'string' || !uuid.match(uuidFormat) || uuid.length !== 36) return uuid;
|
|
10
|
+
if(!options) {
|
|
11
|
+
options = Constants.defaultUuidMaskOptions;
|
|
12
|
+
} else {
|
|
13
|
+
options = MaskHelper.mapWithDefaultValues(options, Constants.defaultUuidMaskOptions);
|
|
14
|
+
MaskHelper.validateUuidMaskOptions(options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const toBeProcessedUuid = uuid.replaceAll("-", "");
|
|
18
|
+
|
|
19
|
+
const start = toBeProcessedUuid.slice(0, options.unmaskedStartCharacters);
|
|
20
|
+
const end = toBeProcessedUuid.slice(32-options.unmaskedEndCharacters);
|
|
21
|
+
const maskLength = toBeProcessedUuid.length - options.unmaskedStartCharacters - options.unmaskedEndCharacters;
|
|
22
|
+
const tempMaskedUuid = start + (options.maskWith.repeat(maskLength)) + end;
|
|
23
|
+
|
|
24
|
+
let maskedUuid = tempMaskedUuid.slice(0, 8) + "-"
|
|
25
|
+
+ tempMaskedUuid.slice(8, 12) + "-"
|
|
26
|
+
+ tempMaskedUuid.slice(12, 16) + "-"
|
|
27
|
+
+ tempMaskedUuid.slice(16, 20) + "-"
|
|
28
|
+
+ tempMaskedUuid.slice(20);
|
|
29
|
+
|
|
30
|
+
return maskedUuid;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = UuidMask
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maskdata",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Node module to mask various kinds of data in the required formats",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/Sumukha1496/maskdata"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "
|
|
12
|
-
"coverage": "nyc --reporter=
|
|
11
|
+
"test": "mocha tests/test*.js --timeout 5000 --exit",
|
|
12
|
+
"coverage": "nyc --reporter=html --reporter=text npm run test"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"mask",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const MaskData = require('
|
|
1
|
+
const MaskData = require('../index');
|
|
2
2
|
|
|
3
3
|
const passwordMaskOptions = {
|
|
4
4
|
maxMaskedCharacters: 10,
|
|
@@ -53,7 +53,8 @@ console.log(`shortEmail after masking: ${MaskData.maskEmail2(shortEmail, emailMa
|
|
|
53
53
|
console.log("========================================");
|
|
54
54
|
|
|
55
55
|
const jsonMaskOptions = {
|
|
56
|
-
fields: ['password', 'firstName']
|
|
56
|
+
fields: ['password', 'firstName'],
|
|
57
|
+
maxMaskedCharactersStr: 3
|
|
57
58
|
};
|
|
58
59
|
const json = {
|
|
59
60
|
password: "PasswordValue",
|
|
@@ -78,7 +79,7 @@ const nestedAllObject = {
|
|
|
78
79
|
field1: "field1Value",
|
|
79
80
|
level2: {
|
|
80
81
|
field2: "field2Value",
|
|
81
|
-
field3: [ { Hello: "
|
|
82
|
+
field3: [ { Hello: "HelloValue", Hi: "one" }, { Hello: "Hello again" } ],
|
|
82
83
|
level3: {
|
|
83
84
|
field4: "field4Value",
|
|
84
85
|
field5: "field5Value"
|
|
@@ -202,3 +203,86 @@ const maskCardOptions = {
|
|
|
202
203
|
const obj = { cardNumber: "123456789123" ,abc: "abceew" ,efg: "121212" } ;
|
|
203
204
|
const result = MaskData.replaceValue(obj, 'cardNumber', MaskData.maskCard(obj['cardNumber'], maskCardOptions));
|
|
204
205
|
console.log(result);
|
|
206
|
+
|
|
207
|
+
const jsonInput = {
|
|
208
|
+
'credit': '1234-5678-8765-1234',
|
|
209
|
+
'debit': '0000-1111-2222-3333',
|
|
210
|
+
'primaryEmail': 'primary@Email.com',
|
|
211
|
+
'secondaryEmail': 'secondary@Email.com',
|
|
212
|
+
'password': 'dummyPassword',
|
|
213
|
+
'homePhone': "+1 1234567890",
|
|
214
|
+
'workPhone': "+1 9876543210",
|
|
215
|
+
'addressLine1': "This is my addressline 1. This is my home",
|
|
216
|
+
'addressLine2': "AddressLine 2",
|
|
217
|
+
'uuid1': '123e4567-e89b-12d3-a456-426614174000'
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const jsonMaskConfig = {
|
|
221
|
+
cardFields: ['credit', 'debit'],
|
|
222
|
+
emailFields: ['primaryEmail', 'secondaryEmail'],
|
|
223
|
+
passwordFields: ['password'],
|
|
224
|
+
phoneFields: ['homePhone', 'workPhone'],
|
|
225
|
+
stringMaskOptions: {
|
|
226
|
+
maskWith: "*",
|
|
227
|
+
maskOnlyFirstOccurance: false,
|
|
228
|
+
values: ["This"]
|
|
229
|
+
},
|
|
230
|
+
stringFields: ['addressLine1', 'addressLine2'],
|
|
231
|
+
uuidFields: ['uuid1']
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const maskedJsonOutput = MaskData.maskJSON2(jsonInput, jsonMaskConfig);
|
|
235
|
+
console.log(maskedJsonOutput);
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
const jsonInput2 = {
|
|
239
|
+
cards: {
|
|
240
|
+
creditCards: ['1234-5678-8765-1234', '1111-2222-1111-2222'],
|
|
241
|
+
debitCards: ['0000-1111-2222-3333', '2222-1111-3333-4444']
|
|
242
|
+
},
|
|
243
|
+
emails: {
|
|
244
|
+
primaryEmail: 'primary@Email.com',
|
|
245
|
+
secondaryEmail: 'secondary@Email.com'
|
|
246
|
+
},
|
|
247
|
+
passwords: [['dummyPasswordANDdummyPassword', 'dummyPasswordANDdummyPassword']],
|
|
248
|
+
phones: {
|
|
249
|
+
homePhone: "+1 1234567890",
|
|
250
|
+
workPhone: "+1 9876543210",
|
|
251
|
+
},
|
|
252
|
+
address: {
|
|
253
|
+
addressLine1: "This is my addressline 1. This is my home",
|
|
254
|
+
addressLine2: "AddressLine 2"
|
|
255
|
+
},
|
|
256
|
+
uuids: {
|
|
257
|
+
uuid1: '123e4567-e89b-12d3-a456-426614174000'
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const jsonMaskConfig2 = {
|
|
262
|
+
// Card
|
|
263
|
+
cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 2,unmaskedEndDigits: 4 },
|
|
264
|
+
cardFields: ['cards.creditCards[0]', 'cards.creditCards[1]', 'cards.debitCards[0]', 'cards.debitCards[1]'],
|
|
265
|
+
|
|
266
|
+
// Email
|
|
267
|
+
emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 2, unmaskedEndCharactersAfterAt: 2, maskAtTheRate: false },
|
|
268
|
+
emailFields: ['emails.primaryEmail', 'emails.secondaryEmail'],
|
|
269
|
+
|
|
270
|
+
// Password
|
|
271
|
+
passwordMaskOptions: { maskWith: "*", maxMaskedCharacters: 10, unmaskedStartCharacters: 0, unmaskedEndCharacters: 0 },
|
|
272
|
+
passwordFields: ['passwords[0][0]]', 'passwords[0][1]'],
|
|
273
|
+
|
|
274
|
+
// Phone
|
|
275
|
+
phoneMaskOptions: { maskWith: "*", unmaskedStartDigits: 2, unmaskedEndDigits: 1 },
|
|
276
|
+
phoneFields: ['phones.homePhone', 'phones.workPhone'],
|
|
277
|
+
|
|
278
|
+
// String
|
|
279
|
+
stringMaskOptions: { maskWith: "*", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false },
|
|
280
|
+
stringFields: ['address.addressLine1', 'address.addressLine2'],
|
|
281
|
+
|
|
282
|
+
// UUID
|
|
283
|
+
uuidMaskOptions: { maskWith: "*", unmaskedStartCharacters: 4, unmaskedEndCharacters: 2 },
|
|
284
|
+
uuidFields: ['uuids.uuid1']
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const maskedJsonOutput2 = MaskData.maskJSON2(jsonInput2, jsonMaskConfig2);
|
|
288
|
+
console.log(maskedJsonOutput2);
|
package/tests/testCard.js
CHANGED
|
@@ -95,6 +95,30 @@ describe('Masking card numbers', function() {
|
|
|
95
95
|
const masked = maskData.maskCard(input, negativeEndOption);
|
|
96
96
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
97
97
|
});
|
|
98
|
+
|
|
99
|
+
it('test with 0 unmasked start and end digits', function() {
|
|
100
|
+
const _0UnmaskedOption = {
|
|
101
|
+
maskWith: 'x',
|
|
102
|
+
unmaskedStartDigits: 0,
|
|
103
|
+
unmaskedEndDigits: 0
|
|
104
|
+
}
|
|
105
|
+
const input = '1234-5678-1234-5678'
|
|
106
|
+
const output = 'xxxx-xxxx-xxxx-xxxx'
|
|
107
|
+
const masked = maskData.maskCard(input, _0UnmaskedOption);
|
|
108
|
+
expect(masked).to.equal(output);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('test with non number card data', function() {
|
|
112
|
+
const cardMaskOptions = {
|
|
113
|
+
maskWith: 'x',
|
|
114
|
+
unmaskedStartDigits: 1,
|
|
115
|
+
unmaskedEndDigits: 1
|
|
116
|
+
}
|
|
117
|
+
const input = 'm1234-5678-1234-5678'
|
|
118
|
+
const output = 'm1xxx-xxxx-xxxx-xxx8'
|
|
119
|
+
const masked = maskData.maskCard(input, cardMaskOptions);
|
|
120
|
+
expect(masked).to.equal(output);
|
|
121
|
+
});
|
|
98
122
|
});
|
|
99
123
|
|
|
100
124
|
describe('Mask with special input strings', function() {
|
|
@@ -128,29 +152,5 @@ describe('Masking card numbers', function() {
|
|
|
128
152
|
});
|
|
129
153
|
});
|
|
130
154
|
});
|
|
131
|
-
|
|
132
|
-
describe('Mask with special input - input shall throw error', function() {
|
|
133
|
-
|
|
134
|
-
// set with input generating an error / exception
|
|
135
|
-
let testData = [
|
|
136
|
-
{
|
|
137
|
-
title: 'test input as number',
|
|
138
|
-
input: 12,
|
|
139
|
-
output: '12'
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
title: 'test input as array',
|
|
143
|
-
input: ['12'],
|
|
144
|
-
output: '12'
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
|
|
148
|
-
testData.forEach(({title, input, output}) => {
|
|
149
|
-
it(`special input - ${title}`, function() {
|
|
150
|
-
const masked = maskData.maskCard(input, maskOptions);
|
|
151
|
-
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
155
|
});
|
|
156
156
|
});
|
package/tests/testEmail.js
CHANGED
|
@@ -202,5 +202,30 @@ describe('Masking email addresses', function() {
|
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
|
+
|
|
206
|
+
describe('Mask with non string input - input will not be masked', function() {
|
|
207
|
+
|
|
208
|
+
let testData = [
|
|
209
|
+
{
|
|
210
|
+
title: 'test input as number',
|
|
211
|
+
input: 12,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
title: 'test input as array',
|
|
215
|
+
input: ['12'],
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
title: 'test input as object',
|
|
219
|
+
input: {a: 'b', x: 'y'},
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
|
|
223
|
+
testData.forEach(({title, input, output}) => {
|
|
224
|
+
it(`special input - ${title}`, function() {
|
|
225
|
+
const masked = maskData.maskEmail2(input, maskOptions);
|
|
226
|
+
expect(masked).to.equal(input, 'Improper input');
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
205
230
|
});
|
|
206
231
|
});
|