maskdata 1.1.10 → 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
+ });
@@ -56,7 +56,7 @@ describe('Masking password', function() {
56
56
  output: '1xxx78'
57
57
  },
58
58
  {
59
- title: 'test string length equal than start + end',
59
+ title: 'test string length equal to start + end',
60
60
  input: '12-345',
61
61
  output: '1xxx45'
62
62
  },
@@ -87,8 +87,7 @@ 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() {
91
- // TODO - should this throw an error? there is no masking at all
90
+ it('custom mask - test with maxMasked shorter than start + end: No masking done', function() {
92
91
  const shortMaxCharsOption = {
93
92
  maskWith: 'x',
94
93
  maxMaskedCharacters: 6,
@@ -98,12 +97,10 @@ describe('Masking password', function() {
98
97
  const input = '1234-5678-1234-5678'
99
98
  const output = '123478'
100
99
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
101
- expect(masked).to.equal(output, 'masked output does not match expected value');
102
- expect.fail('Shall this test fail because options prevent full masking?')
100
+ expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) shorter than start + end');
103
101
  });
104
102
 
105
- it('custom mask - test with maxMasked equal than start + end', function() {
106
- // TODO - should this throw an error? there is no masking at all
103
+ it('custom mask - test with maxMasked equal to start + end: No masking done', function() {
107
104
  const shortMaxCharsOption = {
108
105
  maskWith: 'x',
109
106
  maxMaskedCharacters: 8,
@@ -113,8 +110,7 @@ describe('Masking password', function() {
113
110
  const input = '1234-abcd-efgh-5678'
114
111
  const output = '12345678'
115
112
  const masked = maskData.maskPassword(input, shortMaxCharsOption);
116
- expect(masked).to.equal(output, 'masked output does not match expected value');
117
- expect.fail('Shall this test fail because options prevent full masking?')
113
+ expect(masked).to.equal(output, 'No masking done because maxMasked(max output characters) equal to start + end');
118
114
  });
119
115
  });
120
116
 
@@ -140,7 +136,12 @@ describe('Masking password', function() {
140
136
  title: 'test input null',
141
137
  input: null,
142
138
  output: null
143
- }
139
+ },
140
+ {
141
+ title: 'test input as number',
142
+ input: 12,
143
+ output: '12'
144
+ },
144
145
  ]
145
146
 
146
147
  testData.forEach(({title, input, output}) => {
@@ -151,15 +152,9 @@ describe('Masking password', function() {
151
152
  });
152
153
  });
153
154
 
154
- describe('Mask with special input - input shall throw error', function() {
155
+ describe('Mask with object type input - input won\'t be masked', function() {
155
156
 
156
- // set with input generating an error / exception
157
157
  let testData = [
158
- {
159
- title: 'test input as number',
160
- input: 12,
161
- output: '12'
162
- },
163
158
  {
164
159
  title: 'test input as array',
165
160
  input: ['12'],
@@ -168,14 +163,14 @@ describe('Masking password', function() {
168
163
  {
169
164
  title: 'test input as object',
170
165
  input: {a: 'b', x: 'y'},
171
- output: '12'
166
+ output: {a: 'b', x: 'y'}
172
167
  }
173
168
  ]
174
169
 
175
170
  testData.forEach(({title, input, output}) => {
176
171
  it(`special input - ${title}`, function() {
177
172
  const masked = maskData.maskPassword(input, maskOptions);
178
- expect(masked).to.equal(output, 'masked output does not match expected value');
173
+ expect(masked).to.equal(input, 'input won\'t be masked');
179
174
  });
180
175
  });
181
176
  });
@@ -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',
@@ -122,7 +122,7 @@ describe('Masking phone numbers', function() {
122
122
  {
123
123
  title: 'test input as number',
124
124
  input: 1234567,
125
- output: 'xx' // TODO - ok to convert number into string? Or should it fail?
125
+ output: '12xxx67'
126
126
  },
127
127
  ]
128
128
 
@@ -134,26 +134,24 @@ describe('Masking phone numbers', function() {
134
134
  });
135
135
  });
136
136
 
137
- describe('Mask with special input - input shall throw error', function() {
137
+ describe('Mask with special input - input won\'t be masked', function() {
138
138
 
139
139
  // set with input generating an error / exception
140
140
  let testData = [
141
141
  {
142
142
  title: 'test input as array',
143
143
  input: ['12', '34'],
144
- output: 'xx'
145
144
  },
146
145
  {
147
146
  title: 'test input as object',
148
147
  input: {a: 'b', x: 'y'},
149
- output: '12'
150
148
  }
151
149
  ]
152
150
 
153
151
  testData.forEach(({title, input, output}) => {
154
152
  it(`special input - ${title}`, function() {
155
153
  const masked = maskData.maskPhone(input, maskOptions);
156
- expect(masked).to.equal(output, 'masked output does not match expected value');
154
+ expect(masked).to.equal(input, 'input won\'t be masked');
157
155
  });
158
156
  });
159
157
  });
@@ -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,26 +231,23 @@ describe('Masking strings', function() {
231
231
  });
232
232
  });
233
233
 
234
- describe('Mask with special input - input shall throw error', function() {
234
+ describe('Mask with improper input - input won\'t be masked', function() {
235
235
 
236
- // set with input generating an error / exception
237
236
  let testData = [
238
237
  {
239
238
  title: 'test input as array',
240
239
  input: ['12', 'ab'],
241
- output: 'xx' // mask method seems to join all strings in the array into on big string and masks it?
242
240
  },
243
241
  {
244
242
  title: 'test input as object',
245
243
  input: {a: 'b', x: 'y'},
246
- output: '12' // json stringified and masked?
247
244
  }
248
245
  ]
249
246
 
250
247
  testData.forEach(({title, input, output}) => {
251
248
  it(`special input - ${title}`, function() {
252
249
  const masked = maskData.maskString(input, maskOptions);
253
- expect(masked).to.equal(output, 'masked output does not match expected value');
250
+ expect(masked).to.equal(input, 'input won\'t be masked');
254
251
  });
255
252
  });
256
253
  });
@@ -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,9 +0,0 @@
1
- 'use strict';
2
- const maskData = require('../index');
3
- const expect = require('chai').expect;
4
-
5
- describe('Test replaceValue', function() {
6
-
7
- // TODO - migrate all tests from test.js into mocha tests to fail on error
8
- // TODO - extend tests
9
- });