summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorGeremy Condra <gcondra@google.com>2012-09-18 13:35:29 -0700
committerGeremy Condra <gcondra@google.com>2012-09-18 13:43:32 -0700
commitcb4c5819758a7e2951bd4818383f7c5e10a5f016 (patch)
tree82b5990d0a1894dfd802edde43bd2036ff6aacec /core/tests
parent00bc4c0b6723bda12e846f9f1f729acb79a389a1 (diff)
downloadframeworks_base-cb4c5819758a7e2951bd4818383f7c5e10a5f016.zip
frameworks_base-cb4c5819758a7e2951bd4818383f7c5e10a5f016.tar.gz
frameworks_base-cb4c5819758a7e2951bd4818383f7c5e10a5f016.tar.bz2
Fix bad isinstance check in X509TrustManagerExtensions and add test.
Change-Id: I333957186655b2543a637dafa8c51b0bba9d4dfb
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/coretests/src/android/net/http/X509TrustManagerExtensionsTest.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/net/http/X509TrustManagerExtensionsTest.java b/core/tests/coretests/src/android/net/http/X509TrustManagerExtensionsTest.java
new file mode 100644
index 0000000..b2e1895
--- /dev/null
+++ b/core/tests/coretests/src/android/net/http/X509TrustManagerExtensionsTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.http;
+
+import java.security.KeyStore;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
+
+public class X509TrustManagerExtensionsTest extends TestCase {
+
+ private class NotATrustManagerImpl implements X509TrustManager {
+
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {}
+
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {}
+
+ public X509Certificate[] getAcceptedIssuers() {
+ return new X509Certificate[0];
+ }
+ }
+
+ public void testBadCast() throws Exception {
+ NotATrustManagerImpl ntmi = new NotATrustManagerImpl();
+ try {
+ X509TrustManagerExtensions tme = new X509TrustManagerExtensions(ntmi);
+ } catch (IllegalArgumentException ignored) {
+ return;
+ }
+ fail();
+ }
+
+ public void testGoodCast() throws Exception {
+ String defaultType = KeyStore.getDefaultType();
+ TrustManagerImpl tmi = new TrustManagerImpl(KeyStore.getInstance(defaultType));
+ X509TrustManagerExtensions tme = new X509TrustManagerExtensions(tmi);
+ }
+}