Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check template parameter prefix is @ #95

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions __tests__/trivy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TrivyCmdOption } from '../src/interface';
import { removeTrivyCmd } from './helper';

const downloader = new Downloader();
const template = path.join(__dirname, '../src/template/default.tpl');
const template = `@${path.join(__dirname, '../src/template/default.tpl')}`;

describe('Trivy scan', () => {
let trivyPath: string;
Expand All @@ -29,7 +29,9 @@ describe('Trivy scan', () => {
template
};
const result = scan(trivyPath, image, option) as string;
expect(result.length).toBeGreaterThanOrEqual(1);
expect(result).toContain(
'knqyf263/vuln-image (alpine 3.7.1) - Trivy Report'
);
});

test('without ignoreUnfixed', () => {
Expand All @@ -40,6 +42,8 @@ describe('Trivy scan', () => {
template
};
const result: string = scan(trivyPath, image, option) as string;
expect(result.length).toBeGreaterThanOrEqual(1);
expect(result).toContain(
'knqyf263/vuln-image (alpine 3.7.1) - Trivy Report'
);
});
});
2 changes: 1 addition & 1 deletion src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Inputs {
vulnType: core.getInput('vuln_type').replace(/\s+/g, ''),
ignoreUnfixed: core.getInput('ignore_unfixed').toLowerCase() === 'true',
template:
core.getInput('template') || `${__dirname}/template/default.tpl`
core.getInput('template') || `@${__dirname}/template/default.tpl`
}
};

Expand Down
4 changes: 0 additions & 4 deletions src/template/default.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<table>
{{- range . }}
<tr class="group-header"><th colspan="6">{{ escapeXML .Type }}</th></tr>
{{- if (eq (len .Vulnerabilities) 0) }}
<tr><th colspan="6">No Vulnerabilities found</th></tr>
{{- else }}
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
Expand All @@ -26,7 +23,6 @@
{{- end }}
</td>
</tr>
{{- end }}
{{- end }}
{{- end }}
</table>
8 changes: 7 additions & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs';
import * as core from '@actions/core';
import { TrivyCmdOption, Validator } from './interface';

export class TrivyCmdOptionValidator implements Validator {
Expand Down Expand Up @@ -49,7 +50,12 @@ export class TrivyCmdOptionValidator implements Validator {
}

private validateTemplate(): void {
const template = this.option.template;
if (!this.option.template.startsWith('@')) {
core.warning('template parameter prefix must be "@"');
this.option.template = `@${this.option.template}`;
}

const template = this.option.template.replace('@', '');

const exists = fs.existsSync(template);
if (!exists) {
Expand Down