1616'use strict' ;
1717
1818require ( `../../system-test/_setup` ) ;
19+ const path = require ( 'path' ) ;
1920
2021const cmd = 'node inspect' ;
22+ const cwd = path . join ( __dirname , `..` ) ;
2123
2224// inspect_string
2325test ( `should inspect a string` , async ( t ) => {
24- const output = await runAsync ( `${ cmd } string "I'm Gary and my email is gary@example.com"` ) ;
26+ const output = await runAsync ( `${ cmd } string "I'm Gary and my email is gary@example.com"` , cwd ) ;
2527 t . regex ( output , / " n a m e " : " E M A I L _ A D D R E S S " / ) ;
2628} ) ;
2729
2830test ( `should handle a string with no sensitive data` , async ( t ) => {
29- const output = await runAsync ( `${ cmd } string "foo"` ) ;
31+ const output = await runAsync ( `${ cmd } string "foo"` , cwd ) ;
3032 t . is ( output , 'undefined' ) ;
3133} ) ;
3234
3335test ( `should report string inspection handling errors` , async ( t ) => {
34- const output = await runAsync ( `${ cmd } string "I'm Gary and my email is gary@example.com" -a foo` ) ;
36+ const output = await runAsync ( `${ cmd } string "I'm Gary and my email is gary@example.com" -a foo` , cwd ) ;
3537 t . regex ( output , / E r r o r i n i n s p e c t S t r i n g / ) ;
3638} ) ;
3739
3840// inspect_file
3941test ( `should inspect a local text file` , async ( t ) => {
40- const output = await runAsync ( `${ cmd } file resources/test.txt` ) ;
42+ const output = await runAsync ( `${ cmd } file resources/test.txt` , cwd ) ;
4143 t . regex ( output , / " n a m e " : " P H O N E _ N U M B E R " / ) ;
4244 t . regex ( output , / " n a m e " : " E M A I L _ A D D R E S S " / ) ;
4345} ) ;
4446
4547test ( `should inspect a local image file` , async ( t ) => {
46- const output = await runAsync ( `${ cmd } file resources/test.png` ) ;
48+ const output = await runAsync ( `${ cmd } file resources/test.png` , cwd ) ;
4749 t . regex ( output , / " n a m e " : " P H O N E _ N U M B E R " / ) ;
4850} ) ;
4951
5052test ( `should handle a local file with no sensitive data` , async ( t ) => {
51- const output = await runAsync ( `${ cmd } file resources/harmless.txt` ) ;
53+ const output = await runAsync ( `${ cmd } file resources/harmless.txt` , cwd ) ;
5254 t . is ( output , 'undefined' ) ;
5355} ) ;
5456
5557test ( `should report local file handling errors` , async ( t ) => {
56- const output = await runAsync ( `${ cmd } file resources/harmless.txt -a foo` ) ;
58+ const output = await runAsync ( `${ cmd } file resources/harmless.txt -a foo` , cwd ) ;
5759 t . regex ( output , / E r r o r i n i n s p e c t F i l e / ) ;
5860} ) ;
5961
6062// inspect_gcs_file
6163test . serial ( `should inspect a GCS text file` , async ( t ) => {
62- const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp test.txt` ) ;
64+ const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp test.txt` , cwd ) ;
6365 t . regex ( output , / " n a m e " : " P H O N E _ N U M B E R " / ) ;
6466 t . regex ( output , / " n a m e " : " E M A I L _ A D D R E S S " / ) ;
6567} ) ;
6668
6769test . serial ( `should inspect multiple GCS text files` , async ( t ) => {
68- const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp *.txt` ) ;
70+ const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp *.txt` , cwd ) ;
6971 t . regex ( output , / " n a m e " : " P H O N E _ N U M B E R " / ) ;
7072 t . regex ( output , / " n a m e " : " E M A I L _ A D D R E S S " / ) ;
7173 t . regex ( output , / " n a m e " : " C R E D I T _ C A R D _ N U M B E R " / ) ;
7274} ) ;
7375
7476test . serial ( `should accept try limits for inspecting GCS files` , async ( t ) => {
75- const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp test.txt --tries 0` ) ;
77+ const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp test.txt --tries 0` , cwd ) ;
7678 t . regex ( output , / p o l l i n g t i m e d o u t / ) ;
7779} ) ;
7880
7981test . serial ( `should handle a GCS file with no sensitive data` , async ( t ) => {
80- const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp harmless.txt` ) ;
82+ const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp harmless.txt` , cwd ) ;
8183 t . is ( output , 'undefined' ) ;
8284} ) ;
8385
8486test . serial ( `should report GCS file handling errors` , async ( t ) => {
85- const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp harmless.txt -a foo` ) ;
87+ const output = await runAsync ( `${ cmd } gcsFile nodejs-docs-samples-dlp harmless.txt -a foo` , cwd ) ;
8688 t . regex ( output , / E r r o r i n i n s p e c t G C S F i l e / ) ;
8789} ) ;
8890
8991// inspect_datastore
9092test . serial ( `should inspect Datastore` , async ( t ) => {
91- const output = await runAsync ( `${ cmd } datastore Person --namespaceId DLP` ) ;
93+ const output = await runAsync ( `${ cmd } datastore Person --namespaceId DLP` , cwd ) ;
9294 t . regex ( output , / " n a m e " : " P H O N E _ N U M B E R " / ) ;
9395 t . regex ( output , / " n a m e " : " E M A I L _ A D D R E S S " / ) ;
9496} ) ;
9597
9698test . serial ( `should accept try limits for inspecting Datastore` , async ( t ) => {
97- const output = await runAsync ( `${ cmd } datastore Person --namespaceId DLP --tries 0` ) ;
99+ const output = await runAsync ( `${ cmd } datastore Person --namespaceId DLP --tries 0` , cwd ) ;
98100 t . regex ( output , / p o l l i n g t i m e d o u t / ) ;
99101} ) ;
100102
101103test . serial ( `should handle Datastore with no sensitive data` , async ( t ) => {
102- const output = await runAsync ( `${ cmd } datastore Harmless --namespaceId DLP` ) ;
104+ const output = await runAsync ( `${ cmd } datastore Harmless --namespaceId DLP` , cwd ) ;
103105 t . is ( output , 'undefined' ) ;
104106} ) ;
105107
106108test . serial ( `should report Datastore file handling errors` , async ( t ) => {
107- const output = await runAsync ( `${ cmd } datastore Harmless --namespaceId DLP -a foo` ) ;
109+ const output = await runAsync ( `${ cmd } datastore Harmless --namespaceId DLP -a foo` , cwd ) ;
108110 t . regex ( output , / E r r o r i n i n s p e c t D a t a s t o r e / ) ;
109111} ) ;
110112
111113// CLI options
112114test ( `should have a minLikelihood option` , async ( t ) => {
113- const promiseA = runAsync ( `${ cmd } string "My phone number is (123) 456-7890." -m POSSIBLE` ) ;
114- const promiseB = runAsync ( `${ cmd } string "My phone number is (123) 456-7890." -m UNLIKELY` ) ;
115+ const promiseA = runAsync ( `${ cmd } string "My phone number is (123) 456-7890." -m POSSIBLE` , cwd ) ;
116+ const promiseB = runAsync ( `${ cmd } string "My phone number is (123) 456-7890." -m UNLIKELY` , cwd ) ;
115117
116118 const outputA = await promiseA ;
117119 t . truthy ( outputA ) ;
@@ -122,8 +124,8 @@ test(`should have a minLikelihood option`, async (t) => {
122124} ) ;
123125
124126test ( `should have a maxFindings option` , async ( t ) => {
125- const promiseA = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -f 1` ) ;
126- const promiseB = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -f 2` ) ;
127+ const promiseA = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -f 1` , cwd ) ;
128+ const promiseB = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -f 2` , cwd ) ;
127129
128130 const outputA = await promiseA ;
129131 t . not ( outputA . includes ( 'PHONE_NUMBER' ) , outputA . includes ( 'EMAIL_ADDRESS' ) ) ; // Exactly one of these should be included
@@ -134,8 +136,8 @@ test(`should have a maxFindings option`, async (t) => {
134136} ) ;
135137
136138test ( `should have an option to include quotes` , async ( t ) => {
137- const promiseA = runAsync ( `${ cmd } string "My phone number is (223) 456-7890." -q false` ) ;
138- const promiseB = runAsync ( `${ cmd } string "My phone number is (223) 456-7890."` ) ;
139+ const promiseA = runAsync ( `${ cmd } string "My phone number is (223) 456-7890." -q false` , cwd ) ;
140+ const promiseB = runAsync ( `${ cmd } string "My phone number is (223) 456-7890."` , cwd ) ;
139141
140142 const outputA = await promiseA ;
141143 t . truthy ( outputA ) ;
@@ -146,8 +148,8 @@ test(`should have an option to include quotes`, async (t) => {
146148} ) ;
147149
148150test ( `should have an option to filter results by infoType` , async ( t ) => {
149- const promiseA = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890."` ) ;
150- const promiseB = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -t PHONE_NUMBER` ) ;
151+ const promiseA = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890."` , cwd ) ;
152+ const promiseB = runAsync ( `${ cmd } string "My email is gary@example.com and my phone number is (223) 456-7890." -t PHONE_NUMBER` , cwd ) ;
151153
152154 const outputA = await promiseA ;
153155 t . regex ( outputA , / E M A I L _ A D D R E S S / ) ;
@@ -159,7 +161,7 @@ test(`should have an option to filter results by infoType`, async (t) => {
159161} ) ;
160162
161163test ( `should have an option for custom auth tokens` , async ( t ) => {
162- const output = await runAsync ( `${ cmd } string "My name is Gary and my phone number is (223) 456-7890." -a foo` ) ;
164+ const output = await runAsync ( `${ cmd } string "My name is Gary and my phone number is (223) 456-7890." -a foo` , cwd ) ;
163165 t . regex ( output , / E r r o r i n i n s p e c t S t r i n g / ) ;
164166 t . regex ( output , / i n v a l i d a u t h e n t i c a t i o n / ) ;
165167} ) ;
0 commit comments