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/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
|
+
});
|