Skip to content

Commit 80c4c39

Browse files
authored
Expected fix lines mapping doesn't work with multi-file test feature (#361)
Throw an error when there are multiple files and expected fix lines. Issue #359
1 parent 49e4d79 commit 80c4c39

File tree

17 files changed

+613
-11
lines changed

17 files changed

+613
-11
lines changed

core-codemods/src/test/java/io/codemodder/codemods/MavenSecureURLCodemodTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,35 @@
22

33
import io.codemodder.testutils.Metadata;
44
import io.codemodder.testutils.RawFileCodemodTest;
5+
import org.junit.jupiter.api.Nested;
56

67
/**
78
* This test needs to be fixed once this bug is addressed:
89
* https://github.com/pixee/codemodder-java/issues/359
910
*/
10-
@Metadata(
11-
codemodType = MavenSecureURLCodemod.class,
12-
testResourceDir = "maven-non-https-url",
13-
// expectingFixesAtLines = {22, 26, 30},
14-
dependencies = {})
15-
final class MavenSecureURLCodemodTest implements RawFileCodemodTest {}
11+
final class MavenSecureURLCodemodTest {
12+
13+
@Nested
14+
@Metadata(
15+
codemodType = MavenSecureURLCodemod.class,
16+
testResourceDir = "maven-non-https-url/case-1",
17+
expectingFixesAtLines = {22},
18+
dependencies = {})
19+
final class MavenSecureURLCodemodTest1 implements RawFileCodemodTest {}
20+
21+
@Nested
22+
@Metadata(
23+
codemodType = MavenSecureURLCodemod.class,
24+
testResourceDir = "maven-non-https-url/case-2",
25+
expectingFixesAtLines = {22},
26+
dependencies = {})
27+
final class MavenSecureURLCodemodTest2 implements RawFileCodemodTest {}
28+
29+
@Nested
30+
@Metadata(
31+
codemodType = MavenSecureURLCodemod.class,
32+
testResourceDir = "maven-non-https-url/wonky",
33+
expectingFixesAtLines = {26},
34+
dependencies = {})
35+
final class MavenSecureURLCodemodTestWonky implements RawFileCodemodTest {}
36+
}

core-codemods/src/test/resources/maven-non-https-url/out.sarif renamed to core-codemods/src/test/resources/maven-non-https-url/case-1/out.sarif

File renamed without changes.

core-codemods/src/test/resources/maven-non-https-url/pom_insecure_url_1.xml.after renamed to core-codemods/src/test/resources/maven-non-https-url/case-1/pom_insecure_url_1.xml.after

File renamed without changes.

core-codemods/src/test/resources/maven-non-https-url/pom_insecure_url_1.xml.before renamed to core-codemods/src/test/resources/maven-non-https-url/case-1/pom_insecure_url_1.xml.before

File renamed without changes.
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
{
2+
"$schema" : "https://json.schemastore.org/sarif-2.1.0.json",
3+
"version" : "2.1.0",
4+
"runs" : [ {
5+
"tool" : {
6+
"driver" : {
7+
"name" : "CodeQL",
8+
"organization" : "GitHub",
9+
"semanticVersion" : "2.11.6",
10+
"rules" : [ {
11+
"id" : "java/maven/non-https-url",
12+
"name" : "java/maven/non-https-url",
13+
"shortDescription" : {
14+
"text" : "Failure to use HTTPS or SFTP URL in Maven artifact upload/download"
15+
},
16+
"fullDescription" : {
17+
"text" : "Non-HTTPS connections can be intercepted by third parties."
18+
},
19+
"defaultConfiguration" : {
20+
"enabled" : true,
21+
"level" : "error"
22+
},
23+
"properties" : {
24+
"tags" : [ "security", "external/cwe/cwe-300", "external/cwe/cwe-319", "external/cwe/cwe-494", "external/cwe/cwe-829" ],
25+
"description" : "Non-HTTPS connections can be intercepted by third parties.",
26+
"id" : "java/maven/non-https-url",
27+
"kind" : "problem",
28+
"name" : "Failure to use HTTPS or SFTP URL in Maven artifact upload/download",
29+
"precision" : "very-high",
30+
"problem.severity" : "error",
31+
"security-severity" : "8.1"
32+
}
33+
} ]
34+
},
35+
"extensions" : [ {
36+
"name" : "legacy-upgrades",
37+
"semanticVersion" : "0.0.0",
38+
"locations" : [ {
39+
"uri" : "file:///opt/codeql/legacy-upgrades/",
40+
"description" : {
41+
"text" : "The QL pack root directory."
42+
}
43+
}, {
44+
"uri" : "file:///opt/codeql/legacy-upgrades/qlpack.yml",
45+
"description" : {
46+
"text" : "The QL pack definition file."
47+
}
48+
} ]
49+
}, {
50+
"name" : "codeql/java-queries",
51+
"semanticVersion" : "0.4.6+5ae770f33996156df494a9b915139bea4160a120",
52+
"locations" : [ {
53+
"uri" : "file:///home/andrecs/.codeql/packages/codeql/java-queries/0.4.6/",
54+
"description" : {
55+
"text" : "The QL pack root directory."
56+
}
57+
}, {
58+
"uri" : "file:///home/andrecs/.codeql/packages/codeql/java-queries/0.4.6/qlpack.yml",
59+
"description" : {
60+
"text" : "The QL pack definition file."
61+
}
62+
} ]
63+
} ]
64+
},
65+
"artifacts" : [ {
66+
"location" : {
67+
"uri" : "pom_insecure_url_1.xml",
68+
"uriBaseId" : "%SRCROOT%",
69+
"index" : 0
70+
}
71+
}, {
72+
"location" : {
73+
"uri" : "pom_insecure_url_2.xml",
74+
"uriBaseId" : "%SRCROOT%",
75+
"index" : 1
76+
}
77+
}, {
78+
"location" : {
79+
"uri" : "pom_insecure_url_3.xml",
80+
"uriBaseId" : "%SRCROOT%",
81+
"index" : 2
82+
}
83+
}, {
84+
"location" : {
85+
"uri" : "pom_insecure_url_wonky.xml",
86+
"uriBaseId" : "%SRCROOT%",
87+
"index" : 3
88+
}
89+
} ],
90+
"results" : [ {
91+
"ruleId" : "java/maven/non-https-url",
92+
"ruleIndex" : 0,
93+
"rule" : {
94+
"id" : "java/maven/non-https-url",
95+
"index" : 0
96+
},
97+
"message" : {
98+
"text" : "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example"
99+
},
100+
"locations" : [ {
101+
"physicalLocation" : {
102+
"artifactLocation" : {
103+
"uri" : "pom_insecure_url_1.xml",
104+
"uriBaseId" : "%SRCROOT%",
105+
"index" : 0
106+
},
107+
"region" : {
108+
"startLine" : 22,
109+
"startColumn" : 8,
110+
"endLine" : 27,
111+
"endColumn" : 22
112+
}
113+
}
114+
} ],
115+
"partialFingerprints" : {
116+
"primaryLocationLineHash" : "8a4c482c80336490:1",
117+
"primaryLocationStartColumnFingerprint" : "0"
118+
}
119+
}, {
120+
"ruleId" : "java/maven/non-https-url",
121+
"ruleIndex" : 0,
122+
"rule" : {
123+
"id" : "java/maven/non-https-url",
124+
"index" : 0
125+
},
126+
"message" : {
127+
"text" : "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository ftp://insecure-repository.example"
128+
},
129+
"locations" : [ {
130+
"physicalLocation" : {
131+
"artifactLocation" : {
132+
"uri" : "pom_insecure_url_2.xml",
133+
"uriBaseId" : "%SRCROOT%",
134+
"index" : 1
135+
},
136+
"region" : {
137+
"startLine" : 22,
138+
"startColumn" : 8,
139+
"endLine" : 27,
140+
"endColumn" : 22
141+
}
142+
}
143+
} ],
144+
"partialFingerprints" : {
145+
"primaryLocationLineHash" : "c0a34d306173617d:1",
146+
"primaryLocationStartColumnFingerprint" : "0"
147+
}
148+
}, {
149+
"ruleId" : "java/maven/non-https-url",
150+
"ruleIndex" : 0,
151+
"rule" : {
152+
"id" : "java/maven/non-https-url",
153+
"index" : 0
154+
},
155+
"message" : {
156+
"text" : "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example"
157+
},
158+
"locations" : [ {
159+
"physicalLocation" : {
160+
"artifactLocation" : {
161+
"uri" : "pom_insecure_url_3.xml",
162+
"uriBaseId" : "%SRCROOT%",
163+
"index" : 2
164+
},
165+
"region" : {
166+
"startLine" : 22,
167+
"startColumn" : 8,
168+
"endLine" : 27,
169+
"endColumn" : 22
170+
}
171+
}
172+
} ],
173+
"partialFingerprints" : {
174+
"primaryLocationLineHash" : "8a4c482c80336490:1",
175+
"primaryLocationStartColumnFingerprint" : "0"
176+
}
177+
}, {
178+
"ruleId" : "java/maven/non-https-url",
179+
"ruleIndex" : 0,
180+
"rule" : {
181+
"id" : "java/maven/non-https-url",
182+
"index" : 0
183+
},
184+
"message" : {
185+
"text" : "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository ftp://insecure-repository.example"
186+
},
187+
"locations" : [ {
188+
"physicalLocation" : {
189+
"artifactLocation" : {
190+
"uri" : "pom_insecure_url_3.xml",
191+
"uriBaseId" : "%SRCROOT%",
192+
"index" : 2
193+
},
194+
"region" : {
195+
"startLine" : 30,
196+
"startColumn" : 8,
197+
"endLine" : 35,
198+
"endColumn" : 22
199+
}
200+
}
201+
} ],
202+
"partialFingerprints" : {
203+
"primaryLocationLineHash" : "c0a34d306173617d:1",
204+
"primaryLocationStartColumnFingerprint" : "0"
205+
}
206+
}, {
207+
"ruleId" : "java/maven/non-https-url",
208+
"ruleIndex" : 0,
209+
"rule" : {
210+
"id" : "java/maven/non-https-url",
211+
"index" : 0
212+
},
213+
"message" : {
214+
"text" : "Downloading or uploading artifacts over insecure protocol (eg. http or ftp) to/from repository http://insecure-repository.example"
215+
},
216+
"locations" : [ {
217+
"physicalLocation" : {
218+
"artifactLocation" : {
219+
"uri" : "pom_insecure_url_wonky.xml",
220+
"uriBaseId" : "%SRCROOT%",
221+
"index" : 3
222+
},
223+
"region" : {
224+
"startLine" : 26,
225+
"startColumn" : 8,
226+
"endLine" : 37,
227+
"endColumn" : 22
228+
}
229+
}
230+
} ],
231+
"partialFingerprints" : {
232+
"primaryLocationLineHash" : "7697fa5b428ceb56:1",
233+
"primaryLocationStartColumnFingerprint" : "0"
234+
}
235+
} ],
236+
"columnKind" : "utf16CodeUnits",
237+
"properties" : {
238+
"semmle.formatSpecifier" : "sarifv2.1.0"
239+
}
240+
} ]
241+
}

core-codemods/src/test/resources/maven-non-https-url/pom_insecure_url_2.xml.after renamed to core-codemods/src/test/resources/maven-non-https-url/case-2/pom_insecure_url_2.xml.after

File renamed without changes.

core-codemods/src/test/resources/maven-non-https-url/pom_insecure_url_2.xml.before renamed to core-codemods/src/test/resources/maven-non-https-url/case-2/pom_insecure_url_2.xml.before

File renamed without changes.

0 commit comments

Comments
 (0)