@@ -2,89 +2,48 @@ import { getResults } from '../../../../../src/lib/formatters/get-sarif-result';
2
2
import { SEVERITY , TestResult } from '../../../../../src/lib/snyk-test/legacy' ;
3
3
4
4
describe ( 'Retrieving sarif result' , ( ) => {
5
- it ( 'should use the test results path as the location uri when target file is not present' , ( ) => {
6
- let result = getResults (
7
- getTestResult ( {
8
- path : 'alpine:3.18.0' ,
9
- } ) ,
10
- ) ;
11
- expect ( result ) . toEqual ( [
5
+ const cases : Array < [
6
+ string ,
7
+ { path : string ; displayTargetFile ?: string } ,
8
+ { resultLocationUri : string } ,
9
+ ] > = [
10
+ [
11
+ 'should return the path given there is no target file present' ,
12
+ { path : 'alpine' } ,
13
+ { resultLocationUri : 'alpine' } ,
14
+ ] ,
15
+ [
16
+ 'should return the path without colon characters given there is no target file present and the path contains a tag' ,
17
+ { path : 'alpine:3.18.0' } ,
18
+ { resultLocationUri : 'alpine_3.18.0' } ,
19
+ ] ,
20
+ [
21
+ 'should return the path without colon characters given there is no target file present and the path contains a digest' ,
12
22
{
13
- ruleId : 'SNYK-LINUX-EXPAT-450908' ,
14
- level : 'error' ,
15
- message : {
16
- text :
17
- 'This file introduces a vulnerable expat package with a critical severity vulnerability.' ,
18
- } ,
19
- locations : [
20
- {
21
- physicalLocation : {
22
- artifactLocation : { uri : 'alpine:3.18.0' } ,
23
- region : { startLine : 1 } ,
24
- } ,
25
- } ,
26
- ] ,
23
+ path :
24
+ 'alpine@sha256:c0669ef34cdc14332c0f1ab0c2c01acb91d96014b172f1a76f3a39e63d1f0bda' ,
27
25
} ,
28
- ] ) ;
29
-
30
- result = getResults (
31
- getTestResult ( {
32
- path : 'alpine:3.18.0' ,
33
- displayTargetFile : undefined ,
34
- } ) ,
35
- ) ;
36
- expect ( result ) . toEqual ( [
37
26
{
38
- ruleId : 'SNYK-LINUX-EXPAT-450908' ,
39
- level : 'error' ,
40
- message : {
41
- text :
42
- 'This file introduces a vulnerable expat package with a critical severity vulnerability.' ,
43
- } ,
44
- locations : [
45
- {
46
- physicalLocation : {
47
- artifactLocation : { uri : 'alpine:3.18.0' } ,
48
- region : { startLine : 1 } ,
49
- } ,
50
- } ,
51
- ] ,
27
+ resultLocationUri :
28
+ 'alpine@sha256_c0669ef34cdc14332c0f1ab0c2c01acb91d96014b172f1a76f3a39e63d1f0bda' ,
52
29
} ,
53
- ] ) ;
30
+ ] ,
31
+ [
32
+ 'should return the target file given there is a target file present' ,
33
+ { path : 'alpine' , displayTargetFile : 'Dockerfile.test' } ,
34
+ { resultLocationUri : 'Dockerfile.test' } ,
35
+ ] ,
36
+ ] ;
54
37
55
- result = getResults (
38
+ it . each ( cases ) ( '%s' , ( _ , input , want ) => {
39
+ const result = getResults (
56
40
getTestResult ( {
57
- path : 'alpine:3.18.0' ,
58
- displayTargetFile : null ,
41
+ displayTargetFile : input . displayTargetFile ,
42
+ path : input . path ,
59
43
} ) ,
60
44
) ;
61
- expect ( result ) . toEqual ( [
62
- {
63
- ruleId : 'SNYK-LINUX-EXPAT-450908' ,
64
- level : 'error' ,
65
- message : {
66
- text :
67
- 'This file introduces a vulnerable expat package with a critical severity vulnerability.' ,
68
- } ,
69
- locations : [
70
- {
71
- physicalLocation : {
72
- artifactLocation : { uri : 'alpine:3.18.0' } ,
73
- region : { startLine : 1 } ,
74
- } ,
75
- } ,
76
- ] ,
77
- } ,
78
- ] ) ;
79
- } ) ;
80
45
81
- it ( 'should use the target file as the location uri when target file is present' , ( ) => {
82
- const actualResult = getResults (
83
- getTestResult ( {
84
- displayTargetFile : 'Dockerfile.test' ,
85
- } ) ,
86
- ) ;
87
- expect ( actualResult ) . toEqual ( [
46
+ expect ( result ) . toEqual ( [
88
47
{
89
48
ruleId : 'SNYK-LINUX-EXPAT-450908' ,
90
49
level : 'error' ,
@@ -95,7 +54,7 @@ describe('Retrieving sarif result', () => {
95
54
locations : [
96
55
{
97
56
physicalLocation : {
98
- artifactLocation : { uri : 'Dockerfile.test' } ,
57
+ artifactLocation : { uri : want . resultLocationUri } ,
99
58
region : { startLine : 1 } ,
100
59
} ,
101
60
} ,
0 commit comments