Skip to content

Commit 5d1edd4

Browse files
Add unit tests
1 parent 9098428 commit 5d1edd4

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java
2+
import TestUtilities.InlineExpectationsTest
3+
import semmle.code.java.dataflow.DataFlow
4+
import semmle.code.java.security.AndroidLocalAuthQuery
5+
6+
module InsecureAuthTest implements TestSig {
7+
string getARelevantTag() { result = "insecure-auth" }
8+
9+
predicate hasActualResult(Location location, string element, string tag, string value) {
10+
tag = "insecure-auth" and
11+
exists(AuthenticationSuccessCallback cb | not exists(cb.getAResultUse()) |
12+
cb.getLocation() = location and
13+
element = cb.toString() and
14+
value = ""
15+
)
16+
}
17+
}
18+
19+
import MakeTest<InsecureAuthTest>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import android.hardware.biometrics.BiometricPrompt;
2+
import android.hardware.fingerprint.FingerprintManager;
3+
4+
class TestA {
5+
public static void useKey(BiometricPrompt.CryptoObject key) {}
6+
7+
8+
// GOOD: result is used
9+
class Test1 extends BiometricPrompt.AuthenticationCallback {
10+
@Override
11+
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
12+
TestA.useKey(result.getCryptoObject());
13+
}
14+
}
15+
16+
// BAD: result is not used
17+
class Test2 extends BiometricPrompt.AuthenticationCallback {
18+
@Override
19+
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) { // $insecure-auth
20+
21+
}
22+
}
23+
24+
// BAD: result is only used in a super call
25+
class Test3 extends BiometricPrompt.AuthenticationCallback {
26+
@Override
27+
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) { // $insecure-auth
28+
super.onAuthenticationSucceeded(result);
29+
}
30+
}
31+
32+
// GOOD: result is used
33+
class Test4 extends BiometricPrompt.AuthenticationCallback {
34+
@Override
35+
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
36+
super.onAuthenticationSucceeded(result);
37+
TestA.useKey(result.getCryptoObject());
38+
}
39+
}
40+
41+
// GOOD: result is used in a super call to a class other than the base class
42+
class Test5 extends Test1 {
43+
@Override
44+
public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
45+
super.onAuthenticationSucceeded(result);
46+
}
47+
}
48+
}
49+
50+
class TestB {
51+
public static void useKey(FingerprintManager.CryptoObject key) {}
52+
53+
54+
// GOOD: result is used
55+
class Test1 extends FingerprintManager.AuthenticationCallback {
56+
@Override
57+
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
58+
TestB.useKey(result.getCryptoObject());
59+
}
60+
}
61+
62+
// BAD: result is not used
63+
class Test2 extends FingerprintManager.AuthenticationCallback {
64+
@Override
65+
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { // $insecure-auth
66+
67+
}
68+
}
69+
70+
// BAD: result is only used in a super call
71+
class Test3 extends FingerprintManager.AuthenticationCallback {
72+
@Override
73+
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { // $insecure-auth
74+
super.onAuthenticationSucceeded(result);
75+
}
76+
}
77+
78+
// GOOD: result is used
79+
class Test4 extends FingerprintManager.AuthenticationCallback {
80+
@Override
81+
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
82+
super.onAuthenticationSucceeded(result);
83+
TestB.useKey(result.getCryptoObject());
84+
}
85+
}
86+
87+
// GOOD: result is used in a super call to a class other than the base class
88+
class Test5 extends Test1 {
89+
@Override
90+
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
91+
super.onAuthenticationSucceeded(result);
92+
}
93+
}
94+
}
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

0 commit comments

Comments
 (0)