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.
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ const expect = require('chai').expect;
4
+
5
+ const maskHelper = require('../lib/helpers/MaskHelper');
6
+ const Constants = require('../lib/helpers/Constants');
7
+
8
+ describe('Test helper functions', function() {
9
+
10
+ describe('Test mapWithDefaultValues function', function() {
11
+ it('Test mapWithDefaultValues function', function() {
12
+ const options = maskHelper.mapWithDefaultValues({}, Constants.defaultCardMaskOptions);
13
+ // const defaultCardMaskOptions = {
14
+ // maskWith: "*",
15
+ // unmaskedStartDigits: 4,
16
+ // unmaskedEndDigits: 1
17
+ // };
18
+ expect(options['maskWith']).to.equal("*");
19
+ expect(options['unmaskedStartDigits']).to.equal(4);
20
+ expect(options['unmaskedEndDigits']).to.equal(1);
21
+ });
22
+ });
23
+
24
+ describe('Test getValidatedJsonMask2Configs function', function() {
25
+ it('Test getValidatedJsonMask2Configs function with empty configs', function() {
26
+ const options = maskHelper.getValidatedJsonMask2Configs({}, Constants.defaultjsonMask2Configs);
27
+ // const defaultjsonMask2Configs = {
28
+ // cardMaskOptions: defaultCardMaskOptions,
29
+ // cardFields: [],
30
+ // emailMaskOptions: defaultEmailMask2Options,
31
+ // emailFields: [],
32
+ // passwordMaskOptions: defaultPasswordMaskOptions,
33
+ // passwordFields: [],
34
+ // phoneMaskOptions: defaultPhoneMaskOptions,
35
+ // phoneFields: [],
36
+ // stringMaskOptions: defaultStringMaskOptions,
37
+ // stringFields: [],
38
+ // uuidMaskOptions: defaultUuidMaskOptions,
39
+ // uuidFields: []
40
+ // };
41
+ expect(options['cardMaskOptions']['maskWith']).to.equal("*");
42
+ expect(options['emailMaskOptions']['maskWith']).to.equal("*");
43
+ expect(options['passwordMaskOptions']['maskWith']).to.equal("*");
44
+ expect(options['phoneMaskOptions']['maskWith']).to.equal("*");
45
+ expect(options['stringMaskOptions']['maskWith']).to.equal("*");
46
+ expect(options['uuidMaskOptions']['maskWith']).to.equal("*");
47
+
48
+ expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
49
+ expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
50
+ expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
51
+ expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
52
+ expect(options['stringMaskOptions']['maskAll']).to.equal(false);
53
+ expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
54
+ });
55
+
56
+ it('Test getValidatedJsonMask2Configs function with only the fields list', function() {
57
+ const options = maskHelper.getValidatedJsonMask2Configs({cardFields: ["card1"]}, Constants.defaultjsonMask2Configs);
58
+ // const defaultjsonMask2Configs = {
59
+ // cardMaskOptions: defaultCardMaskOptions,
60
+ // cardFields: [],
61
+ // emailMaskOptions: defaultEmailMask2Options,
62
+ // emailFields: [],
63
+ // passwordMaskOptions: defaultPasswordMaskOptions,
64
+ // passwordFields: [],
65
+ // phoneMaskOptions: defaultPhoneMaskOptions,
66
+ // phoneFields: [],
67
+ // stringMaskOptions: defaultStringMaskOptions,
68
+ // stringFields: [],
69
+ // uuidMaskOptions: defaultUuidMaskOptions,
70
+ // uuidFields: []
71
+ // };
72
+ expect(options['cardMaskOptions']['maskWith']).to.equal("*");
73
+ expect(options['emailMaskOptions']['maskWith']).to.equal("*");
74
+ expect(options['passwordMaskOptions']['maskWith']).to.equal("*");
75
+ expect(options['phoneMaskOptions']['maskWith']).to.equal("*");
76
+ expect(options['stringMaskOptions']['maskWith']).to.equal("*");
77
+ expect(options['uuidMaskOptions']['maskWith']).to.equal("*");
78
+
79
+ expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
80
+ expect(options['cardFields'][0]).to.equal("card1");
81
+ expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
82
+ expect(options['passwordMaskOptions']['maxMaskedCharacters']).to.equal(16);
83
+ expect(options['phoneMaskOptions']['unmaskedStartDigits']).to.equal(4);
84
+ expect(options['stringMaskOptions']['maskAll']).to.equal(false);
85
+ expect(options['uuidMaskOptions']['unmaskedStartCharacters']).to.equal(0);
86
+ });
87
+ });
88
+
89
+ describe('Test getValidatedJsonMask2Configs function', function() {
90
+ it('Test getValidatedJsonMask2Configs function with empty configs', function() {
91
+ const options = maskHelper.getValidatedJsonMask2Configs({}, Constants.defaultjsonMask2Configs);
92
+ // const defaultjsonMask2Configs = {
93
+ // cardMaskOptions: defaultCardMaskOptions,
94
+ // cardFields: [],
95
+ // emailMaskOptions: defaultEmailMask2Options,
96
+ // emailFields: [],
97
+ // passwordMaskOptions: defaultPasswordMaskOptions,
98
+ // passwordFields: [],
99
+ // phoneMaskOptions: defaultPhoneMaskOptions,
100
+ // phoneFields: [],
101
+ // stringMaskOptions: defaultStringMaskOptions,
102
+ // stringFields: [],
103
+ // uuidMaskOptions: defaultUuidMaskOptions,
104
+ // uuidFields: []
105
+ // };
106
+ expect(options['cardMaskOptions']['maskWith']).to.equal("*");
107
+ expect(options['emailMaskOptions']['maskWith']).to.equal("*");
108
+ expect(options['passwordMaskOptions']['maskWith']).to.equal("*");
109
+ expect(options['phoneMaskOptions']['maskWith']).to.equal("*");
110
+ expect(options['stringMaskOptions']['maskWith']).to.equal("*");
111
+ expect(options['uuidMaskOptions']['maskWith']).to.equal("*");
112
+
113
+ expect(options['cardMaskOptions']['unmaskedStartDigits']).to.equal(4);
114
+ expect(options['emailMaskOptions']['unmaskedStartCharactersBeforeAt']).to.equal(3);
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);
119
+
120
+ });
121
+ });
122
+
123
+ });
@@ -87,20 +87,20 @@ describe('Masking password', function() {
87
87
  expect(masked).to.equal(output, 'masked output does not match expected value');
88
88
  });
89
89
 
90
- it('custom mask - test with maxMasked shorter than start + end', function() {
90
+ it('custom mask - test with maxMasked shorter than start + end: No masking done', function() {
91
91
  const shortMaxCharsOption = {
92
92
  maskWith: 'x',
93
93
  maxMaskedCharacters: 6,
94
- unmaskedStartCharacters: 4, // 4+4=8 > 6 --> But this will give more preference to maxMaskedCharacters
94
+ unmaskedStartCharacters: 4, // 4+4=8 > 6
95
95
  unmaskedEndCharacters: 4
96
96
  }
97
97
  const input = '1234-5678-1234-5678'
98
98
  const output = '123478'
99
99
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
100
- expect(masked).to.equal(output, 'masked output does not match expected value');
100
+ expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) shorter than start + end');
101
101
  });
102
102
 
103
- it('custom mask - test with maxMasked equal to start + end', 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,
@@ -110,7 +110,7 @@ describe('Masking password', function() {
110
110
  const input = '1234-abcd-efgh-5678'
111
111
  const output = '12345678'
112
112
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
113
- expect(masked).to.equal(output, 'masked output does not match expected value');
113
+ expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) equal to start + end');
114
114
  });
115
115
  });
116
116
 
@@ -136,8 +136,14 @@ describe('Masking password', function() {
136
136
  title: 'test input null',
137
137
  input: null,
138
138
  output: null
139
- }
139
+ },
140
+ {
141
+ title: 'test input as number',
142
+ input: 12,
143
+ output: '12'
144
+ },
140
145
  ]
146
+
141
147
  testData.forEach(({title, input, output}) => {
142
148
  it(`special input - ${title}`, function() {
143
149
  const masked = maskData.maskPassword(input, maskOptions);
@@ -145,5 +151,28 @@ describe('Masking password', function() {
145
151
  });
146
152
  });
147
153
  });
154
+
155
+ describe('Mask with object type input - input won\'t be masked', function() {
156
+
157
+ let testData = [
158
+ {
159
+ title: 'test input as array',
160
+ input: ['12'],
161
+ output: '12'
162
+ },
163
+ {
164
+ title: 'test input as object',
165
+ input: {a: 'b', x: 'y'},
166
+ output: {a: 'b', x: 'y'}
167
+ }
168
+ ]
169
+
170
+ testData.forEach(({title, input, output}) => {
171
+ it(`special input - ${title}`, function() {
172
+ const masked = maskData.maskPassword(input, maskOptions);
173
+ expect(masked).to.equal(input, 'input won\'t be masked');
174
+ });
175
+ });
176
+ });
148
177
  });
149
178
  });
@@ -50,8 +50,8 @@ describe('Masking phone numbers', function() {
50
50
  let testData = [
51
51
  {
52
52
  title: 'test default string',
53
- input: '1234-5678-1234-5678',
54
- output: '12xxxxxxxxxxxxxx678'
53
+ input: '1234567812345678',
54
+ output: '12xxxxxxxxxxx678'
55
55
  },
56
56
  {
57
57
  title: 'test number length equal than start + end',
@@ -118,7 +118,12 @@ describe('Masking phone numbers', function() {
118
118
  title: 'test input null',
119
119
  input: null,
120
120
  output: null
121
- }
121
+ },
122
+ {
123
+ title: 'test input as number',
124
+ input: 1234567,
125
+ output: '12xxx67'
126
+ },
122
127
  ]
123
128
 
124
129
  testData.forEach(({title, input, output}) => {
@@ -129,28 +134,26 @@ describe('Masking phone numbers', function() {
129
134
  });
130
135
  });
131
136
 
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 array',
138
- // input: ['12', '34'],
139
- // output: 'xx'
140
- // },
141
- // {
142
- // title: 'test input as object',
143
- // input: {a: 'b', x: 'y'},
144
- // output: '12'
145
- // }
146
- // ]
147
-
148
- // testData.forEach(({title, input, output}) => {
149
- // it(`special input - ${title}`, function() {
150
- // const masked = maskData.maskPhone(input, maskOptions);
151
- // expect(masked).to.equal(output, 'masked output does not match expected value');
152
- // });
153
- // });
154
- // });
137
+ describe('Mask with special input - input won\'t be masked', function() {
138
+
139
+ // set with input generating an error / exception
140
+ let testData = [
141
+ {
142
+ title: 'test input as array',
143
+ input: ['12', '34'],
144
+ },
145
+ {
146
+ title: 'test input as object',
147
+ input: {a: 'b', x: 'y'},
148
+ }
149
+ ]
150
+
151
+ testData.forEach(({title, input, output}) => {
152
+ it(`special input - ${title}`, function() {
153
+ const masked = maskData.maskPhone(input, maskOptions);
154
+ expect(masked).to.equal(input, 'input won\'t be masked');
155
+ });
156
+ });
157
+ });
155
158
  });
156
159
  });
@@ -219,7 +219,7 @@ describe('Masking strings', function() {
219
219
  {
220
220
  title: 'test input as number',
221
221
  input: 12,
222
- output: 'xx' // TODO - ok to convert number into string? Or should it fail?
222
+ output: 'xx'
223
223
  },
224
224
  ]
225
225
 
@@ -231,28 +231,25 @@ describe('Masking strings', function() {
231
231
  });
232
232
  });
233
233
 
234
- // describe('Mask with special input - input shall throw error', function() {
235
-
236
- // // set with input generating an error / exception
237
- // let testData = [
238
- // {
239
- // title: 'test input as array',
240
- // input: ['12', 'ab'],
241
- // output: 'xx' // mask method seems to join all strings in the array into on big string and masks it?
242
- // },
243
- // {
244
- // title: 'test input as object',
245
- // input: {a: 'b', x: 'y'},
246
- // output: '12' // json stringified and masked?
247
- // }
248
- // ]
249
-
250
- // testData.forEach(({title, input, output}) => {
251
- // it(`special input - ${title}`, function() {
252
- // const masked = maskData.maskString(input, maskOptions);
253
- // expect(masked).to.equal(output, 'masked output does not match expected value');
254
- // });
255
- // });
256
- // });
234
+ describe('Mask with improper input - input won\'t be masked', function() {
235
+
236
+ let testData = [
237
+ {
238
+ title: 'test input as array',
239
+ input: ['12', 'ab'],
240
+ },
241
+ {
242
+ title: 'test input as object',
243
+ input: {a: 'b', x: 'y'},
244
+ }
245
+ ]
246
+
247
+ testData.forEach(({title, input, output}) => {
248
+ it(`special input - ${title}`, function() {
249
+ const masked = maskData.maskString(input, maskOptions);
250
+ expect(masked).to.equal(input, 'input won\'t be masked');
251
+ });
252
+ });
253
+ });
257
254
  });
258
255
  });
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+ const maskData = require('../index');
3
+ const expect = require('chai').expect;
4
+
5
+ describe('Mask UUID', function() {
6
+
7
+ describe('Mask UUID with default options', function() {
8
+
9
+ // const defaultUuidMaskOptions = {
10
+ // maskWith: "*",
11
+ // unmaskedStartCharacters: 0,
12
+ // unmaskedEndCharacters: 0
13
+ // };
14
+
15
+ let testData = [
16
+ {
17
+ title: 'UUID with lower case alphabets',
18
+ input: '123e4567-e89b-12d3-a456-426614174000',
19
+ output: '********-****-****-****-************'
20
+ },
21
+ {
22
+ title: 'UUID with upper case alphabets',
23
+ input: '123E4567-E89B-12D3-A456-426614174000',
24
+ output: '********-****-****-****-************'
25
+ }
26
+ ]
27
+
28
+ testData.forEach(({title, input, output}) => {
29
+ it(title, function() {
30
+ const masked = maskData.maskUuid(input);
31
+ expect(masked).to.equal(output, 'masked output does not match expected value');
32
+ });
33
+ })
34
+ });
35
+
36
+ describe('Mask UUID with custom options', function() {
37
+
38
+ const customUuidMaskOptions = {
39
+ maskWith: "X",
40
+ unmaskedStartCharacters: 5,
41
+ unmaskedEndCharacters: 13
42
+ };
43
+
44
+ let testData = [
45
+ {
46
+ title: 'UUID with lower case alphabets',
47
+ input: '123e4567-e89b-12d3-a456-426614174000',
48
+ output: '123e4XXX-XXXX-XXXX-XXX6-426614174000'
49
+ },
50
+ {
51
+ title: 'UUID with upper case alphabets',
52
+ input: '123E4567-E89B-12D3-A456-426614174000',
53
+ output: '123E4XXX-XXXX-XXXX-XXX6-426614174000'
54
+ }
55
+ ]
56
+
57
+ testData.forEach(({title, input, output}) => {
58
+ it(title, function() {
59
+ const masked = maskData.maskUuid(input, customUuidMaskOptions);
60
+ expect(masked).to.equal(output);
61
+ });
62
+ });
63
+
64
+ const customUuidMaskOptions2 = { unmaskedStartCharacters: 8, unmaskedEndCharacters: 12};
65
+ it('Edge case1: unmask only the parts of UUID', function() {
66
+ const masked = maskData.maskUuid('123e4567-e89b-12d3-a456-426614174000', customUuidMaskOptions2);
67
+ expect(masked).to.equal('123e4567-****-****-****-426614174000');
68
+ });
69
+
70
+ const customUuidMaskOptions3 = { unmaskedStartCharacters: 32, unmaskedEndCharacters: 0};
71
+ it('Edge case2: unmaskedStartCharacters = 32', function() {
72
+ const masked = maskData.maskUuid('123e4567-e89b-12d3-a456-426614174000', customUuidMaskOptions3);
73
+ expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
74
+ });
75
+
76
+ const customUuidMaskOptions4 = { unmaskedStartCharacters: 0, unmaskedEndCharacters: 32};
77
+ it('Edge case3: unmaskedEndCharacters = 32', function() {
78
+ const masked = maskData.maskUuid('123e4567-e89b-12d3-a456-426614174000', customUuidMaskOptions4);
79
+ expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
80
+ });
81
+
82
+ const customUuidMaskOptions5 = { unmaskedStartCharacters: 33, unmaskedEndCharacters: 5};
83
+ it('Edge case4: unmaskedStartCharacters > 32', function() {
84
+ const masked = maskData.maskUuid('123e4567-e89b-12d3-a456-426614174000', customUuidMaskOptions5);
85
+ expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
86
+ });
87
+
88
+ const customUuidMaskOptions6 = { unmaskedStartCharacters: 1, unmaskedEndCharacters: 33};
89
+ it('Edge case5: unmaskedEndCharacters > 32', function() {
90
+ const masked = maskData.maskUuid('123e4567-e89b-12d3-a456-426614174000', customUuidMaskOptions6);
91
+ expect(masked).to.equal('123e4567-e89b-12d3-a456-426614174000');
92
+ });
93
+
94
+ it('Edge case6: incorrect UUID', function() {
95
+ const masked = maskData.maskUuid('123567-e89b-12d3-a456-4264174000');
96
+ expect(masked).to.equal('123567-e89b-12d3-a456-4264174000', 'No masking done');
97
+ });
98
+
99
+ it('Edge case7: incorrect UUID2', function() {
100
+ const masked = maskData.maskUuid('123e4567-mnop-12d3-a456-426614174000');
101
+ expect(masked).to.equal('123e4567-mnop-12d3-a456-426614174000');
102
+ });
103
+ });
104
+ });
@@ -1,35 +0,0 @@
1
- 'use strict';
2
- const maskData = require('../index');
3
- const expect = require('chai').expect;
4
-
5
- describe('Test Replace value', function() {
6
-
7
- const input = {
8
- name: "John",
9
- age: 33,
10
- married: true
11
- };
12
-
13
- const testData = [
14
- {
15
- title: 'replace integer inside json',
16
- input: input,
17
- inputField: 'age',
18
- output: 65
19
- },
20
- {
21
- title: 'replace string inside json',
22
- input: input,
23
- inputField: 'name',
24
- output: "Sherlock"
25
- }
26
- ];
27
- describe('Test replaceValue positive cases', function() {
28
- testData.forEach(({title, input, inputField, output}) => {
29
- it(`custom mask - ${title}`, function() {
30
- const afterReplacing = maskData.replaceValue(input, inputField, output);
31
- expect(afterReplacing[inputField]).to.equal(output, 'Replaced value same as expected value');
32
- });
33
- });
34
- });
35
- });