Skip to content

Commit ea3db5d

Browse files
Add test cases
1 parent c3da3a9 commit ea3db5d

File tree

12 files changed

+101
-0
lines changed

12 files changed

+101
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.app"
3+
android:installLocation="auto"
4+
android:versionCode="1"
5+
android:versionName="0.1" >
6+
7+
<application android:networkSecurityConfig="@xml/NetworkSecurityConfig">
8+
</application>
9+
10+
</manifest>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.net.URL;
2+
import java.net.URLConnection;
3+
4+
class Test{
5+
URLConnection test1() throws Exception {
6+
return new URL("https://good.example.com").openConnection();
7+
}
8+
9+
URLConnection test2() throws Exception {
10+
return new URL("https://bad.example.com").openConnection(); // $hasUntrustedResult
11+
}
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/google-android-9.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<domain-config>
4+
<domain>good.example.com</domain>
5+
<pin-set expiration="2038/1/19">
6+
<pin digest="SHA-256">...</pin>
7+
</pin-set>
8+
</domain-config>
9+
</network-security-config>

java/ql/test/query-tests/security/CWE-295/AndroidMissingCertificatePinning_/Test1/test.expected

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java
2+
import TestUtilities.InlineExpectationsTest
3+
import semmle.code.java.security.AndroidCertificatePinningQuery
4+
5+
class Test extends InlineExpectationsTest {
6+
Test() { this = "AndroidMissingCertificatePinningTest" }
7+
8+
override string getARelevantTag() { result = ["hasNoTrustedResult", "hasUntrustedResult"] }
9+
10+
override predicate hasActualResult(Location loc, string el, string tag, string value) {
11+
exists(DataFlow::Node node |
12+
missingPinning(node) and
13+
loc = node.getLocation() and
14+
el = node.toString() and
15+
value = "" and
16+
(
17+
if exists(string x | trustedDomain(x))
18+
then tag = "hasUntrustedResult"
19+
else tag = "hasNoTrustedResult"
20+
)
21+
)
22+
}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.app"
3+
android:installLocation="auto"
4+
android:versionCode="1"
5+
android:versionName="0.1" >
6+
7+
<application android:networkSecurityConfig="@xml/NetworkSecurityConfig">
8+
</application>
9+
10+
</manifest>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.net.URL;
2+
import java.net.URLConnection;
3+
4+
class Test{
5+
URLConnection test2() throws Exception {
6+
return new URL("https://example.com").openConnection(); // $hasNoTrustedResult
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/google-android-9.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
4+
</network-security-config>

0 commit comments

Comments
 (0)