Skip to content

Commit cdf964e

Browse files
gcondraAndroid (Google) Code Review
authored andcommitted
Merge "Fix bad isinstance check in X509TrustManagerExtensions and add test." into jb-mr1-dev
2 parents 6b58fde + cb4c581 commit cdf964e

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

core/java/android/net/X509TrustManagerExtensions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class X509TrustManagerExtensions {
4343
* @throws IllegalArgumentException If tm is an unsupported TrustManager type.
4444
*/
4545
public X509TrustManagerExtensions(X509TrustManager tm) throws IllegalArgumentException {
46-
if (mDelegate instanceof TrustManagerImpl) {
46+
if (tm instanceof TrustManagerImpl) {
4747
mDelegate = (TrustManagerImpl) tm;
4848
} else {
4949
throw new IllegalArgumentException("tm is not a supported type of X509TrustManager");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.net.http;
18+
19+
import java.security.KeyStore;
20+
import java.security.cert.X509Certificate;
21+
22+
import javax.net.ssl.X509TrustManager;
23+
24+
import junit.framework.TestCase;
25+
26+
import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
27+
28+
public class X509TrustManagerExtensionsTest extends TestCase {
29+
30+
private class NotATrustManagerImpl implements X509TrustManager {
31+
32+
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
33+
34+
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
35+
36+
public X509Certificate[] getAcceptedIssuers() {
37+
return new X509Certificate[0];
38+
}
39+
}
40+
41+
public void testBadCast() throws Exception {
42+
NotATrustManagerImpl ntmi = new NotATrustManagerImpl();
43+
try {
44+
X509TrustManagerExtensions tme = new X509TrustManagerExtensions(ntmi);
45+
} catch (IllegalArgumentException ignored) {
46+
return;
47+
}
48+
fail();
49+
}
50+
51+
public void testGoodCast() throws Exception {
52+
String defaultType = KeyStore.getDefaultType();
53+
TrustManagerImpl tmi = new TrustManagerImpl(KeyStore.getInstance(defaultType));
54+
X509TrustManagerExtensions tme = new X509TrustManagerExtensions(tmi);
55+
}
56+
}

0 commit comments

Comments
 (0)