@@ -310,4 +310,44 @@ describe('secrets detection (default scan mode)', () => {
310310 expect ( res . status ) . toBe ( 0 ) ;
311311 expect ( res . stdout ) . not . toContain ( 'Potential secrets detected in codebase:' ) ;
312312 } ) ;
313+ it ( 'should ignore warnings with dotenv-diff-ignore comments' , ( ) => {
314+ const cwd = tmpDir ( ) ;
315+
316+ fs . writeFileSync ( path . join ( cwd , '.env' ) , 'DUMMY=\n' ) ;
317+ fs . mkdirSync ( path . join ( cwd , 'src' ) , { recursive : true } ) ;
318+ fs . writeFileSync (
319+ path . join ( cwd , 'src' , 'index.ts' ) ,
320+ `
321+ // These should be flagged normally
322+ const service1 = 'https://shouldwarn.com';
323+ const secret1 = "sk_live_abcdefghijklmnopqrstuvwx";
324+
325+ // These should be ignored with comments
326+ const service2 = 'https://exdfdfdfdfdfe.com'; // dotenv-diff-ignore
327+ const service3 = "https://ignored.com/api" /* dotenv-diff-ignore */;
328+ const secret2 = "sk_live_ignoredtoken123"; // dotenv-diff-ignore
329+ const apiKey = 'AKIA1234567890IGNORE' /* dotenv-diff-ignore */;
330+
331+ // Also test high entropy strings
332+ const ignoredEntropy = "highEntropyButIgnored987654321fedcba"; // dotenv-diff-ignore
333+
334+ console.log(service1, service2, service3, secret1, secret2, apiKey, ignoredEntropy);
335+ ` . trimStart ( ) ,
336+ ) ;
337+
338+ const res = runCli ( cwd , [ ] ) ;
339+ expect ( res . status ) . toBe ( 0 ) ;
340+ expect ( res . stdout ) . toContain ( 'Potential secrets detected in codebase:' ) ;
341+
342+ // Should warn about the non-ignored ones
343+ expect ( res . stdout ) . toContain ( 'shouldwarn.com' ) ;
344+ expect ( res . stdout ) . toContain ( 'sk_live_abcdefghijklmnopqrstuvwx' ) ;
345+
346+ // Should NOT warn about the ignored ones
347+ expect ( res . stdout ) . not . toContain ( 'exdfdfdfdfdfe.com' ) ;
348+ expect ( res . stdout ) . not . toContain ( 'ignored.com' ) ;
349+ expect ( res . stdout ) . not . toContain ( 'sk_live_ignoredtoken123' ) ;
350+ expect ( res . stdout ) . not . toContain ( 'AKIA1234567890IGNORE' ) ;
351+ expect ( res . stdout ) . not . toContain ( 'highEntropyButIgnored987654321fedcba' ) ;
352+ } ) ;
313353} ) ;
0 commit comments