Add test cases

This commit is contained in:
Joe Farebrother
2022-11-07 16:05:47 +00:00
parent c3da3a9aef
commit ea3db5d429
12 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:installLocation="auto"
android:versionCode="1"
android:versionName="0.1" >
<application android:networkSecurityConfig="@xml/NetworkSecurityConfig">
</application>
</manifest>

View File

@@ -0,0 +1,12 @@
import java.net.URL;
import java.net.URLConnection;
class Test{
URLConnection test1() throws Exception {
return new URL("https://good.example.com").openConnection();
}
URLConnection test2() throws Exception {
return new URL("https://bad.example.com").openConnection(); // $hasUntrustedResult
}
}

View File

@@ -0,0 +1 @@
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/google-android-9.0.0

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain>good.example.com</domain>
<pin-set expiration="2038/1/19">
<pin digest="SHA-256">...</pin>
</pin-set>
</domain-config>
</network-security-config>

View File

@@ -0,0 +1,23 @@
import java
import TestUtilities.InlineExpectationsTest
import semmle.code.java.security.AndroidCertificatePinningQuery
class Test extends InlineExpectationsTest {
Test() { this = "AndroidMissingCertificatePinningTest" }
override string getARelevantTag() { result = ["hasNoTrustedResult", "hasUntrustedResult"] }
override predicate hasActualResult(Location loc, string el, string tag, string value) {
exists(DataFlow::Node node |
missingPinning(node) and
loc = node.getLocation() and
el = node.toString() and
value = "" and
(
if exists(string x | trustedDomain(x))
then tag = "hasUntrustedResult"
else tag = "hasNoTrustedResult"
)
)
}
}

View File

@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:installLocation="auto"
android:versionCode="1"
android:versionName="0.1" >
<application android:networkSecurityConfig="@xml/NetworkSecurityConfig">
</application>
</manifest>

View File

@@ -0,0 +1,8 @@
import java.net.URL;
import java.net.URLConnection;
class Test{
URLConnection test2() throws Exception {
return new URL("https://example.com").openConnection(); // $hasNoTrustedResult
}
}

View File

@@ -0,0 +1 @@
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../../stubs/google-android-9.0.0

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
</network-security-config>

View File

@@ -0,0 +1,23 @@
import java
import TestUtilities.InlineExpectationsTest
import semmle.code.java.security.AndroidCertificatePinningQuery
class Test extends InlineExpectationsTest {
Test() { this = "AndroidMissingCertificatePinningTest" }
override string getARelevantTag() { result = ["hasNoTrustedResult", "hasUntrustedResult"] }
override predicate hasActualResult(Location loc, string el, string tag, string value) {
exists(DataFlow::Node node |
missingPinning(node) and
loc = node.getLocation() and
el = node.toString() and
value = "" and
(
if exists(string x | trustedDomain(x))
then tag = "hasUntrustedResult"
else tag = "hasNoTrustedResult"
)
)
}
}