Skip to content

Commit 73e3df9

Browse files
simplify tests
1 parent 9c704a9 commit 73e3df9

File tree

4 files changed

+12
-46
lines changed

4 files changed

+12
-46
lines changed

sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/security/web/MimeNosniffCheck.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import org.sonarsource.analyzer.commons.xml.XPathBuilder;
2121
import org.sonarsource.analyzer.commons.xml.XmlFile;
2222
import org.w3c.dom.Document;
23+
import org.w3c.dom.Element;
2324
import org.w3c.dom.NodeList;
2425

2526
import javax.xml.xpath.XPathExpression;
27+
import java.util.Collections;
2628

2729
/**
2830
* Ensure that the X-Content-Type-Options header is set to "nosniff" to prevent MIME type sniffing.
@@ -55,7 +57,10 @@ protected void scanWebConfig(XmlFile file) {
5557
.stream()
5658
.findFirst()
5759
.ifPresent(target ->
58-
reportIssue(target, "Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true."));
60+
reportIssue(
61+
XmlFile.nameLocation((Element) target),
62+
"Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.",
63+
Collections.emptyList()));
5964
}
6065
}
6166
}

sonar-xml-plugin/src/test/resources/checks/MimeNosniffCheck/webconfig-missing-nosniff/web.config

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,11 @@
22
<configuration>
33
<system.webServer>
44
<httpProtocol>
5-
<customHeaders> <!-- Noncompliant -->
5+
<customHeaders> <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
6+
<!-- ^^^^^^^^^^^^^ -->
67
<remove name="X-Powered-By" />
78
<add name="X-Frame-Options" value="SAMEORIGIN" />
89
</customHeaders>
910
</httpProtocol>
1011
</system.webServer>
11-
<location path="." inheritInChildApplications="false">
12-
<system.webServer>
13-
<handlers>
14-
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
15-
resourceType="Unspecified" />
16-
</handlers>
17-
<aspNetCore processPath="bin\Debug\net8.0\WebApp.exe" arguments="" stdoutLogEnabled="false"
18-
hostingModel="InProcess">
19-
<environmentVariables>
20-
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="443" />
21-
</environmentVariables>
22-
</aspNetCore>
23-
</system.webServer>
24-
</location>
2512
</configuration>
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<configuration> <!-- Noncompliant -->
3-
<location path="." inheritInChildApplications="false">
4-
<system.webServer>
5-
<handlers>
6-
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
7-
resourceType="Unspecified" />
8-
</handlers>
9-
<aspNetCore processPath="bin\Debug\net8.0\WebApp.exe" arguments="" stdoutLogEnabled="false"
10-
hostingModel="InProcess">
11-
<environmentVariables>
12-
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="443" />
13-
</environmentVariables>
14-
</aspNetCore>
15-
</system.webServer>
16-
</location>
2+
<configuration> <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
3+
<!-- ^[sc=2;ec=14] -->
174
</configuration>

sonar-xml-plugin/src/test/resources/checks/MimeNosniffCheck/webconfig-other-value/web.config

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,10 @@
22
<configuration>
33
<system.webServer>
44
<httpProtocol>
5-
<customHeaders> <!-- Noncompliant -->
5+
<customHeaders> <!-- Noncompliant {{Global <httpCookies> tag is missing or its 'httpOnlyCookies' attribute is not set to true.}} -->
6+
<!-- ^^^^^^^^^^^^^ -->
67
<add name="X-Content-Type-Options" value="yes"/>
78
</customHeaders>
89
</httpProtocol>
910
</system.webServer>
10-
<location path="." inheritInChildApplications="false">
11-
<system.webServer>
12-
<handlers>
13-
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
14-
resourceType="Unspecified" />
15-
</handlers>
16-
<aspNetCore processPath="bin\Debug\net8.0\WebApp.exe" arguments="" stdoutLogEnabled="false"
17-
hostingModel="InProcess">
18-
<environmentVariables>
19-
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="443" />
20-
</environmentVariables>
21-
</aspNetCore>
22-
</system.webServer>
23-
</location>
2411
</configuration>

0 commit comments

Comments
 (0)