diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e22d6d..b17fcfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.1 (November 6, 2019) + +Modified `scanFiles` function to return a list of file names where credit card numbers are found. + ## 1.0.0 (October 29, 2019) Initial release! :tada: diff --git a/package.json b/package.json index 2fca017..7af80f6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ccscan", "description": "Scan files for credit card numbers", - "version": "1.0.0", + "version": "1.0.1", "author": "Neo Financial Engineering ", "license": "MIT", "main": "build/app.js", diff --git a/src/app.ts b/src/app.ts index a1e067f..245afb7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -105,9 +105,9 @@ const scanFile = async (fileName: string, args: Args): Promise => { } }; -const scanFiles = async (args: Args): Promise => { +const scanFiles = async (args: Args): Promise => { const mergedArgs = { ...defaultArgs, ...args }; - let found = false; + const found = []; try { const pattern = [mergedArgs.files, '!node_modules']; @@ -121,7 +121,7 @@ const scanFiles = async (args: Args): Promise => { for (const fileName of files) { if (await scanFile(fileName, mergedArgs)) { - found = true; + found.push(fileName); } } @@ -149,7 +149,7 @@ const run = async (): Promise => { type: 'string' }), handler: async (args: Args): Promise => { - if (await scanFiles(args)) { + if ((await scanFiles(args)).length > 0) { process.exit(1); } } diff --git a/test/app.test.ts b/test/app.test.ts index 518cb03..84d86be 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -6,7 +6,7 @@ let consoleLogSpy: jest.SpyInstance; const formatConsoleOutput = (consoleOutput: string[][]): string[] => { return consoleOutput.map((line: string[]): string => stripAnsi(line[0])); -} +}; beforeAll(() => { consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); @@ -22,7 +22,9 @@ afterEach(() => { describe('TypeScript', () => { test('card numbers are detected', async () => { - expect(await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}' })).toEqual(true); + expect(await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}' })).toEqual([ + 'test/fixtures/typescript/bad.ts' + ]); expect(consoleLogSpy).toHaveBeenCalledTimes(12); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); @@ -30,14 +32,14 @@ describe('TypeScript', () => { test('card numbers are detected in silent mode', async () => { expect( await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}', silent: true }) - ).toEqual(true); + ).toEqual(['test/fixtures/typescript/bad.ts']); expect(consoleLogSpy).not.toHaveBeenCalled(); }); test('card numbers are detected in verbose mode', async () => { expect( await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}', verbose: true }) - ).toEqual(true); + ).toEqual(['test/fixtures/typescript/bad.ts']); expect(consoleLogSpy).toHaveBeenCalledTimes(14); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); @@ -45,13 +47,13 @@ describe('TypeScript', () => { test('card-like numbers are detected when luhn check is disabled', async () => { expect( await scanFiles({ files: '**/test/fixtures/typescript/*.{ts,js}', 'luhn-check': false }) - ).toEqual(true); + ).toEqual(['test/fixtures/typescript/bad.ts', 'test/fixtures/typescript/questionable.ts']); expect(consoleLogSpy).toHaveBeenCalledTimes(23); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); test('card numbers are not detected when no files match pattern', async () => { - expect(await scanFiles({ files: '**/test/fixtures/typescript/*.js' })).toEqual(false); + expect(await scanFiles({ files: '**/test/fixtures/typescript/*.js' })).toEqual([]); expect(consoleLogSpy).toHaveBeenCalledTimes(0); }); @@ -61,14 +63,16 @@ describe('TypeScript', () => { files: '**/test/fixtures/typescript/*.{ts,js}', exclude: ['test/fixtures/typescript'] }) - ).toEqual(false); + ).toEqual([]); expect(consoleLogSpy).toHaveBeenCalledTimes(0); }); }); describe('JavaScript', () => { test('card numbers are detected', async () => { - expect(await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}' })).toEqual(true); + expect(await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}' })).toEqual([ + 'test/fixtures/javascript/bad.js' + ]); expect(consoleLogSpy).toHaveBeenCalledTimes(12); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); @@ -76,14 +80,14 @@ describe('JavaScript', () => { test('card numbers are detected in silent mode', async () => { expect( await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}', silent: true }) - ).toEqual(true); + ).toEqual(['test/fixtures/javascript/bad.js']); expect(consoleLogSpy).not.toHaveBeenCalled(); }); test('card numbers are detected in verbose mode', async () => { expect( await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}', verbose: true }) - ).toEqual(true); + ).toEqual(['test/fixtures/javascript/bad.js']); expect(consoleLogSpy).toHaveBeenCalledTimes(14); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); @@ -91,13 +95,13 @@ describe('JavaScript', () => { test('card-like numbers are detected when luhn check is disabled', async () => { expect( await scanFiles({ files: '**/test/fixtures/javascript/*.{ts,js}', 'luhn-check': false }) - ).toEqual(true); + ).toEqual(['test/fixtures/javascript/bad.js', 'test/fixtures/javascript/questionable.js']); expect(consoleLogSpy).toHaveBeenCalledTimes(23); expect(formatConsoleOutput(consoleLogSpy.mock.calls)).toMatchSnapshot(); }); test('card numbers are not detected when no files match pattern', async () => { - expect(await scanFiles({ files: '**/test/fixtures/javascript/*.ts' })).toEqual(false); + expect(await scanFiles({ files: '**/test/fixtures/javascript/*.ts' })).toEqual([]); expect(consoleLogSpy).toHaveBeenCalledTimes(0); }); @@ -107,7 +111,7 @@ describe('JavaScript', () => { files: '**/test/fixtures/javascript/*.{ts,js}', exclude: ['test/fixtures/javascript'] }) - ).toEqual(false); + ).toEqual([]); expect(consoleLogSpy).toHaveBeenCalledTimes(0); }); });