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/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/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
|
+
});
|
package/tests/testPassword.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
const maskData = require('../index');
|
|
3
3
|
const expect = require('chai').expect;
|
|
4
4
|
|
|
5
|
-
describe('Masking password', function() {
|
|
6
|
-
|
|
7
|
-
describe('Mask with default options', function() {
|
|
8
|
-
|
|
5
|
+
describe('Masking password', function () {
|
|
6
|
+
describe('Mask with default options', function () {
|
|
9
7
|
// default options are this - let tests fail when defaults change
|
|
10
8
|
// const defaultPasswordMaskOptions = {
|
|
11
9
|
// maskWith: "*",
|
|
@@ -18,7 +16,7 @@ describe('Masking password', function() {
|
|
|
18
16
|
{
|
|
19
17
|
title: 'test default string',
|
|
20
18
|
input: '1234-5678-1234-5678',
|
|
21
|
-
output: '****************'
|
|
19
|
+
output: '****************' // equal maxMaskedChars
|
|
22
20
|
},
|
|
23
21
|
{
|
|
24
22
|
title: 'test string shorter than maxMasked',
|
|
@@ -28,24 +26,23 @@ describe('Masking password', function() {
|
|
|
28
26
|
{
|
|
29
27
|
title: 'test longer than maxMasked',
|
|
30
28
|
input: '1234567890abcdefghijkl',
|
|
31
|
-
output: '****************'
|
|
29
|
+
output: '****************' // equal maxMaskedChars
|
|
32
30
|
}
|
|
33
|
-
]
|
|
31
|
+
];
|
|
34
32
|
|
|
35
|
-
testData.forEach(({title, input, output}) => {
|
|
36
|
-
it(`default mask - ${title}`, function() {
|
|
33
|
+
testData.forEach(({ title, input, output }) => {
|
|
34
|
+
it(`default mask - ${title}`, function () {
|
|
37
35
|
const masked = maskData.maskPassword(input);
|
|
38
36
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
39
37
|
});
|
|
40
|
-
})
|
|
38
|
+
});
|
|
41
39
|
});
|
|
42
40
|
|
|
43
|
-
describe('Mask with custom options - maskWith, maxMaskedChars', function() {
|
|
44
|
-
|
|
41
|
+
describe('Mask with custom options - maskWith, maxMaskedChars', function () {
|
|
45
42
|
const maskOptions = {
|
|
46
|
-
maskWith:
|
|
43
|
+
maskWith: 'x',
|
|
47
44
|
maxMaskedCharacters: 6,
|
|
48
|
-
unmaskedStartCharacters: 1,
|
|
45
|
+
unmaskedStartCharacters: 1, // use different numbers for start / end to check correct masking
|
|
49
46
|
unmaskedEndCharacters: 2
|
|
50
47
|
};
|
|
51
48
|
|
|
@@ -65,66 +62,70 @@ describe('Masking password', function() {
|
|
|
65
62
|
input: '12',
|
|
66
63
|
output: '12'
|
|
67
64
|
}
|
|
68
|
-
]
|
|
65
|
+
];
|
|
69
66
|
|
|
70
|
-
testData.forEach(({title, input, output}) => {
|
|
71
|
-
it(`custom mask - ${title}`, function() {
|
|
67
|
+
testData.forEach(({ title, input, output }) => {
|
|
68
|
+
it(`custom mask - ${title}`, function () {
|
|
72
69
|
const masked = maskData.maskPassword(input, maskOptions);
|
|
73
70
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
74
71
|
});
|
|
75
72
|
});
|
|
76
73
|
|
|
77
|
-
it('custom mask - test with negative unmaskedStartDigits', function() {
|
|
74
|
+
it('custom mask - test with negative unmaskedStartDigits', function () {
|
|
78
75
|
const negativeStartOption = {
|
|
79
76
|
maskWith: 'x',
|
|
80
77
|
maxMaskedCharacters: 6,
|
|
81
|
-
unmaskedStartCharacters: -2,
|
|
78
|
+
unmaskedStartCharacters: -2, // internal set to 0
|
|
82
79
|
unmaskedEndCharacters: 2
|
|
83
|
-
}
|
|
84
|
-
const input = '1234-5678-1234-5678'
|
|
85
|
-
const output = 'xxxx78'
|
|
80
|
+
};
|
|
81
|
+
const input = '1234-5678-1234-5678';
|
|
82
|
+
const output = 'xxxx78';
|
|
86
83
|
const masked = maskData.maskPassword(input, negativeStartOption);
|
|
87
84
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
88
85
|
});
|
|
89
86
|
|
|
90
|
-
it('custom mask - test with maxMasked shorter than start + end: No masking done', function() {
|
|
87
|
+
it('custom mask - test with maxMasked shorter than start + end: No masking done', function () {
|
|
91
88
|
const shortMaxCharsOption = {
|
|
92
89
|
maskWith: 'x',
|
|
93
90
|
maxMaskedCharacters: 6,
|
|
94
|
-
unmaskedStartCharacters: 4,
|
|
91
|
+
unmaskedStartCharacters: 4, // 4+4=8 > 6
|
|
95
92
|
unmaskedEndCharacters: 4
|
|
96
|
-
}
|
|
97
|
-
const input = '1234-5678-1234-5678'
|
|
98
|
-
const output = '123478'
|
|
93
|
+
};
|
|
94
|
+
const input = '1234-5678-1234-5678';
|
|
95
|
+
const output = '123478';
|
|
99
96
|
const masked = maskData.maskPassword(input, shortMaxCharsOption);
|
|
100
|
-
expect(masked).to.equal(
|
|
97
|
+
expect(masked).to.equal(
|
|
98
|
+
output,
|
|
99
|
+
'No masking done because maxMasked(max output characters) shorter than start + end'
|
|
100
|
+
);
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
it('custom mask - test with maxMasked equal to start + end: No masking done', function() {
|
|
103
|
+
it('custom mask - test with maxMasked equal to start + end: No masking done', function () {
|
|
104
104
|
const shortMaxCharsOption = {
|
|
105
105
|
maskWith: 'x',
|
|
106
106
|
maxMaskedCharacters: 8,
|
|
107
|
-
unmaskedStartCharacters: 4,
|
|
107
|
+
unmaskedStartCharacters: 4, // 4+4=8
|
|
108
108
|
unmaskedEndCharacters: 4
|
|
109
|
-
}
|
|
110
|
-
const input = '1234-abcd-efgh-5678'
|
|
111
|
-
const output = '12345678'
|
|
109
|
+
};
|
|
110
|
+
const input = '1234-abcd-efgh-5678';
|
|
111
|
+
const output = '12345678';
|
|
112
112
|
const masked = maskData.maskPassword(input, shortMaxCharsOption);
|
|
113
|
-
expect(masked).to.equal(
|
|
113
|
+
expect(masked).to.equal(
|
|
114
|
+
output,
|
|
115
|
+
'No masking done because maxMasked(max output characters) equal to start + end'
|
|
116
|
+
);
|
|
114
117
|
});
|
|
115
118
|
});
|
|
116
119
|
|
|
117
|
-
describe('Mask with special input strings', function() {
|
|
118
|
-
|
|
120
|
+
describe('Mask with special input strings', function () {
|
|
119
121
|
const maskOptions = {
|
|
120
|
-
maskWith:
|
|
122
|
+
maskWith: 'x',
|
|
121
123
|
maxMaskedCharacters: 6,
|
|
122
124
|
unmaskedStartCharacters: 2,
|
|
123
125
|
unmaskedEndCharacters: 2
|
|
124
126
|
};
|
|
125
127
|
|
|
126
|
-
describe('Mask with special input - input will generate an output', function() {
|
|
127
|
-
|
|
128
|
+
describe('Mask with special input - input will generate an output', function () {
|
|
128
129
|
// first set with input generating an masked output
|
|
129
130
|
let testData = [
|
|
130
131
|
{
|
|
@@ -141,19 +142,18 @@ describe('Masking password', function() {
|
|
|
141
142
|
title: 'test input as number',
|
|
142
143
|
input: 12,
|
|
143
144
|
output: '12'
|
|
144
|
-
}
|
|
145
|
-
]
|
|
145
|
+
}
|
|
146
|
+
];
|
|
146
147
|
|
|
147
|
-
testData.forEach(({title, input, output}) => {
|
|
148
|
-
it(`special input - ${title}`, function() {
|
|
148
|
+
testData.forEach(({ title, input, output }) => {
|
|
149
|
+
it(`special input - ${title}`, function () {
|
|
149
150
|
const masked = maskData.maskPassword(input, maskOptions);
|
|
150
151
|
expect(masked).to.equal(output, 'masked output does not match expected value');
|
|
151
152
|
});
|
|
152
153
|
});
|
|
153
154
|
});
|
|
154
155
|
|
|
155
|
-
describe(
|
|
156
|
-
|
|
156
|
+
describe("Mask with object type input - input won't be masked", function () {
|
|
157
157
|
let testData = [
|
|
158
158
|
{
|
|
159
159
|
title: 'test input as array',
|
|
@@ -162,15 +162,15 @@ describe('Masking password', function() {
|
|
|
162
162
|
},
|
|
163
163
|
{
|
|
164
164
|
title: 'test input as object',
|
|
165
|
-
input: {a: 'b', x: 'y'},
|
|
166
|
-
output: {a: 'b', x: 'y'}
|
|
165
|
+
input: { a: 'b', x: 'y' },
|
|
166
|
+
output: { a: 'b', x: 'y' }
|
|
167
167
|
}
|
|
168
|
-
]
|
|
168
|
+
];
|
|
169
169
|
|
|
170
|
-
testData.forEach(({title, input, output}) => {
|
|
171
|
-
it(`special input - ${title}`, function() {
|
|
170
|
+
testData.forEach(({ title, input, output }) => {
|
|
171
|
+
it(`special input - ${title}`, function () {
|
|
172
172
|
const masked = maskData.maskPassword(input, maskOptions);
|
|
173
|
-
expect(masked).to.equal(input,
|
|
173
|
+
expect(masked).to.equal(input, "input won't be masked");
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
176
|
});
|