SSLTest.java revision 1a44d5dcabc18cd5ef111f732ccff91683a1a093
1/*
2 * Copyright (C) 2006 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
17package android.net;
18
19import android.net.SSLCertificateSocketFactory;
20import android.test.suitebuilder.annotation.Suppress;
21import junit.framework.TestCase;
22
23import java.io.InputStream;
24import java.io.OutputStream;
25import java.net.Socket;
26
27//This test relies on network resources.
28@Suppress
29public class SSLTest extends TestCase {
30    public void testCertificate() throws Exception {
31        // test www.fortify.net/sslcheck.html
32        Socket ssl = SSLCertificateSocketFactory.getDefault().createSocket("www.fortify.net",443);
33        assertNotNull(ssl);
34
35        OutputStream out = ssl.getOutputStream();
36        assertNotNull(out);
37
38        InputStream in = ssl.getInputStream();
39        assertNotNull(in);
40
41        String get = "GET /sslcheck.html HTTP/1.1\r\nHost: 68.178.217.222\r\n\r\n";
42
43        // System.out.println("going for write...");
44        out.write(get.getBytes());
45
46        byte[] b = new byte[1024];
47        // System.out.println("going for read...");
48        int ret = in.read(b);
49
50        // System.out.println(new String(b));
51    }
52}
53