Skip to content

Commit c4de158

Browse files
Add tests
1 parent 16e16f0 commit c4de158

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import android.webkit.WebViewClient;
2+
import android.webkit.WebView;
3+
import android.webkit.SslErrorHandler;
4+
import android.net.http.SslError;
5+
import android.net.http.SslCertificate;
6+
import android.app.AlertDialog;
7+
import android.content.DialogInterface;
8+
import android.app.Activity;
9+
10+
class Test {
11+
class A extends WebViewClient {
12+
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
13+
handler.proceed(); // $hasResult
14+
}
15+
}
16+
17+
interface Validator {
18+
boolean isValid(SslCertificate cert);
19+
}
20+
21+
class B extends WebViewClient {
22+
Validator v;
23+
24+
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
25+
if (this.v.isValid(error.getCertificate())) {
26+
handler.proceed();
27+
}
28+
else {
29+
handler.cancel();
30+
}
31+
}
32+
}
33+
34+
class C extends WebViewClient {
35+
Activity activity;
36+
37+
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
38+
new AlertDialog.Builder(activity).
39+
setTitle("SSL error").
40+
setMessage("SSL error. Connect anyway?").
41+
setPositiveButton("Yes", new DialogInterface.OnClickListener() {
42+
@Override
43+
public void onClick(DialogInterface dialog, int which) {
44+
handler.proceed();
45+
}
46+
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
47+
@Override
48+
public void onClick(DialogInterface dialog, int which) {
49+
handler.cancel();
50+
}
51+
}).show();
52+
}
53+
}
54+
}
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

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

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java
2+
import semmle.code.java.security.AndroidWebViewCertificateValidationQuery
3+
import TestUtilities.InlineExpectationsTest
4+
5+
class WebViewTest extends InlineExpectationsTest {
6+
WebViewTest() { this = "WebViewTest" }
7+
8+
override string getARelevantTag() { result = "hasResult" }
9+
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
exists(OnReceivedSslErrorMethod m |
12+
trustsAllCerts(m) and
13+
location = m.getLocation() and
14+
element = m.toString() and
15+
tag = "hasResult" and
16+
value = ""
17+
)
18+
}
19+
}

0 commit comments

Comments
 (0)