Skip to content

Commit

Permalink
feat(scan): update serializing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
artur committed May 13, 2024
1 parent 5a83d5d commit 740a27c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/Commands/RunScan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ describe('RunScan', () => {
expect(act).toThrowError(SyntaxError);
});
});

describe('serializeWarnings', () => {
it('should print warnings correctly', () => {
// arrange
const input = [
{
message: 'Notice: Warning 1',
code: '1'
},
{
message: 'Notice: Warning 2',
code: '2'
}
];

// act
const result = RunScan.serializeWarnings(input);

// assert
expect(result).toEqual('Notice: Warning 1\nNotice: Warning 2');
});
});
});
11 changes: 7 additions & 4 deletions src/Commands/RunScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
ScanConfig,
Scans,
TestType,
ATTACK_PARAM_LOCATIONS_DEFAULT
ATTACK_PARAM_LOCATIONS_DEFAULT,
ScanWarning
} from '../Scan';
import { Helpers, logger } from '../Utils';
import { Arguments, Argv, CommandModule } from 'yargs';
Expand Down Expand Up @@ -37,6 +38,10 @@ export class RunScan implements CommandModule {
});
}

public static serializeWarnings(warnings: ScanWarning[]): string {
return `${warnings.map((warning) => warning.message).join('\n')}`;
}

public builder(argv: Argv): Argv {
return argv
.option('token', {
Expand Down Expand Up @@ -199,9 +204,7 @@ export class RunScan implements CommandModule {
console.log(scanId);

if (warnings.length) {
logger.warn(
`Scan has been started with warnings: ${warnings.join(', ')}`
);
logger.warn(RunScan.serializeWarnings(warnings));
}

process.exit(0);
Expand Down
10 changes: 6 additions & 4 deletions src/Scan/Scans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ export interface StorageFile {
type: SourceType;
}

export interface ScanWarning {
code: string;
message: string;
}

export interface ScanCreateResponse {
id: string;
warnings?: {
code: string;
message: string;
}[];
warnings: ScanWarning[];
}

export interface Scans {
Expand Down

0 comments on commit 740a27c

Please sign in to comment.