18
18
const path = require ( 'path' ) ;
19
19
const { assert} = require ( 'chai' ) ;
20
20
const fs = require ( 'fs' ) ;
21
- const execa = require ( 'execa' ) ;
21
+ const cp = require ( 'child_process' ) ;
22
+
23
+ const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
22
24
23
25
const cmd = 'node deid.js' ;
24
- const exec = async cmd => {
25
- const res = await execa . shell ( cmd ) ;
26
- if ( res . stderr ) {
27
- throw new Error ( res . stderr ) ;
28
- }
29
- return res . stdout ;
30
- } ;
31
26
const harmfulString = 'My SSN is 372819127' ;
32
27
const harmlessString = 'My favorite color is blue' ;
33
28
const surrogateType = 'SSN_TOKEN' ;
@@ -42,110 +37,110 @@ const dateFields = 'birth_date register_date';
42
37
43
38
describe ( 'deid' , ( ) => {
44
39
// deidentify_masking
45
- it ( 'should mask sensitive data in a string' , async ( ) => {
46
- const output = await exec ( `${ cmd } deidMask "${ harmfulString } " -m x -n 5` ) ;
47
- assert . strictEqual ( output , 'My SSN is xxxxx9127' ) ;
40
+ it ( 'should mask sensitive data in a string' , ( ) => {
41
+ const output = execSync ( `${ cmd } deidMask "${ harmfulString } " -m x -n 5` ) ;
42
+ assert . include ( output , 'My SSN is xxxxx9127' ) ;
48
43
} ) ;
49
44
50
- it ( 'should ignore insensitive data when masking a string' , async ( ) => {
51
- const output = await exec ( `${ cmd } deidMask "${ harmlessString } "` ) ;
52
- assert . strictEqual ( output , harmlessString ) ;
45
+ it ( 'should ignore insensitive data when masking a string' , ( ) => {
46
+ const output = execSync ( `${ cmd } deidMask "${ harmlessString } "` ) ;
47
+ assert . include ( output , harmlessString ) ;
53
48
} ) ;
54
49
55
- it ( 'should handle masking errors' , async ( ) => {
56
- const output = await exec ( `${ cmd } deidMask "${ harmfulString } " -n -1` ) ;
57
- assert . match ( output , / E r r o r i n d e i d e n t i f y W i t h M a s k / ) ;
50
+ it ( 'should handle masking errors' , ( ) => {
51
+ const output = execSync ( `${ cmd } deidMask "${ harmfulString } " -n -1` ) ;
52
+ assert . include ( output , ' Error in deidentifyWithMask' ) ;
58
53
} ) ;
59
54
60
55
// deidentify_fpe
61
- it ( 'should FPE encrypt sensitive data in a string' , async ( ) => {
62
- const output = await exec (
56
+ it ( 'should FPE encrypt sensitive data in a string' , ( ) => {
57
+ const output = execSync (
63
58
`${ cmd } deidFpe "${ harmfulString } " ${ wrappedKey } ${ keyName } -a NUMERIC`
64
59
) ;
65
60
assert . match ( output , / M y S S N i s \d { 9 } / ) ;
66
- assert . notStrictEqual ( output , harmfulString ) ;
61
+ assert . notInclude ( output , harmfulString ) ;
67
62
} ) ;
68
63
69
- it ( 'should use surrogate info types in FPE encryption' , async ( ) => {
70
- const output = await exec (
64
+ it ( 'should use surrogate info types in FPE encryption' , ( ) => {
65
+ const output = execSync (
71
66
`${ cmd } deidFpe "${ harmfulString } " ${ wrappedKey } ${ keyName } -a NUMERIC -s ${ surrogateType } `
72
67
) ;
73
68
assert . match ( output , / M y S S N i s S S N _ T O K E N \( 9 \) : \d { 9 } / ) ;
74
69
labeledFPEString = output ;
75
70
} ) ;
76
71
77
- it ( 'should ignore insensitive data when FPE encrypting a string' , async ( ) => {
78
- const output = await exec (
72
+ it ( 'should ignore insensitive data when FPE encrypting a string' , ( ) => {
73
+ const output = execSync (
79
74
`${ cmd } deidFpe "${ harmlessString } " ${ wrappedKey } ${ keyName } `
80
75
) ;
81
- assert . strictEqual ( output , harmlessString ) ;
76
+ assert . include ( output , harmlessString ) ;
82
77
} ) ;
83
78
84
- it ( 'should handle FPE encryption errors' , async ( ) => {
85
- const output = await exec (
79
+ it ( 'should handle FPE encryption errors' , ( ) => {
80
+ const output = execSync (
86
81
`${ cmd } deidFpe "${ harmfulString } " ${ wrappedKey } BAD_KEY_NAME`
87
82
) ;
88
83
assert . match ( output , / E r r o r i n d e i d e n t i f y W i t h F p e / ) ;
89
84
} ) ;
90
85
91
86
// reidentify_fpe
92
- it ( 'should FPE decrypt surrogate-typed sensitive data in a string' , async ( ) => {
87
+ it ( 'should FPE decrypt surrogate-typed sensitive data in a string' , ( ) => {
93
88
assert . ok ( labeledFPEString , 'Verify that FPE encryption succeeded.' ) ;
94
- const output = await exec (
89
+ const output = execSync (
95
90
`${ cmd } reidFpe "${ labeledFPEString } " ${ surrogateType } ${ wrappedKey } ${ keyName } -a NUMERIC`
96
91
) ;
97
- assert . strictEqual ( output , harmfulString ) ;
92
+ assert . include ( output , harmfulString ) ;
98
93
} ) ;
99
94
100
- it ( 'should handle FPE decryption errors' , async ( ) => {
101
- const output = await exec (
95
+ it ( 'should handle FPE decryption errors' , ( ) => {
96
+ const output = execSync (
102
97
`${ cmd } reidFpe "${ harmfulString } " ${ surrogateType } ${ wrappedKey } BAD_KEY_NAME -a NUMERIC`
103
98
) ;
104
99
assert . match ( output , / E r r o r i n r e i d e n t i f y W i t h F p e / ) ;
105
100
} ) ;
106
101
107
102
// deidentify_date_shift
108
- it ( 'should date-shift a CSV file' , async ( ) => {
103
+ it ( 'should date-shift a CSV file' , ( ) => {
109
104
const outputCsvFile = 'dates.actual.csv' ;
110
- const output = await exec (
105
+ const output = execSync (
111
106
`${ cmd } deidDateShift "${ csvFile } " "${ outputCsvFile } " ${ dateShiftAmount } ${ dateShiftAmount } ${ dateFields } `
112
107
) ;
113
- assert . match (
108
+ assert . include (
114
109
output ,
115
- new RegExp ( `Successfully saved date-shift output to ${ outputCsvFile } ` )
110
+ `Successfully saved date-shift output to ${ outputCsvFile } `
116
111
) ;
117
- assert . notStrictEqual (
112
+ assert . notInclude (
118
113
fs . readFileSync ( outputCsvFile ) . toString ( ) ,
119
114
fs . readFileSync ( csvFile ) . toString ( )
120
115
) ;
121
116
} ) ;
122
117
123
- it ( 'should date-shift a CSV file using a context field' , async ( ) => {
118
+ it ( 'should date-shift a CSV file using a context field' , ( ) => {
124
119
const outputCsvFile = 'dates-context.actual.csv' ;
125
120
const expectedCsvFile =
126
121
'system-test/resources/date-shift-context.expected.csv' ;
127
- const output = await exec (
122
+ const output = execSync (
128
123
`${ cmd } deidDateShift "${ csvFile } " "${ outputCsvFile } " ${ dateShiftAmount } ${ dateShiftAmount } ${ dateFields } -f ${ csvContextField } -n ${ keyName } -w ${ wrappedKey } `
129
124
) ;
130
- assert . match (
125
+ assert . include (
131
126
output ,
132
- new RegExp ( `Successfully saved date-shift output to ${ outputCsvFile } ` )
127
+ `Successfully saved date-shift output to ${ outputCsvFile } `
133
128
) ;
134
- assert . strictEqual (
129
+ assert . include (
135
130
fs . readFileSync ( outputCsvFile ) . toString ( ) ,
136
131
fs . readFileSync ( expectedCsvFile ) . toString ( )
137
132
) ;
138
133
} ) ;
139
134
140
- it ( 'should require all-or-none of {contextField, wrappedKey, keyName}' , async ( ) => {
141
- const output = await exec (
135
+ it ( 'should require all-or-none of {contextField, wrappedKey, keyName}' , ( ) => {
136
+ const output = execSync (
142
137
`${ cmd } deidDateShift "${ csvFile } " "${ tempOutputFile } " ${ dateShiftAmount } ${ dateShiftAmount } ${ dateFields } -f ${ csvContextField } -n ${ keyName } `
143
138
) ;
144
139
assert . match ( output , / Y o u m u s t s e t e i t h e r A L L o r N O N E o f / ) ;
145
140
} ) ;
146
141
147
- it ( 'should handle date-shift errors' , async ( ) => {
148
- const output = await exec (
142
+ it ( 'should handle date-shift errors' , ( ) => {
143
+ const output = execSync (
149
144
`${ cmd } deidDateShift "${ csvFile } " "${ tempOutputFile } " ${ dateShiftAmount } ${ dateShiftAmount } `
150
145
) ;
151
146
assert . match ( output , / E r r o r i n d e i d e n t i f y W i t h D a t e S h i f t / ) ;
0 commit comments