use of org.apache.harmony.xnet.provider.jsse.OpenSSLContextImpl in project android_frameworks_base by ParanoidAndroid.
the class SSLSocketTest method testFileBasedClientSessionCache.
public void testFileBasedClientSessionCache() throws IOException, KeyManagementException {
OpenSSLContextImpl context = new OpenSSLContextImpl();
String tmpDir = System.getProperty("java.io.tmpdir");
if (tmpDir == null) {
fail("Please set 'java.io.tmpdir' system property.");
}
File cacheDir = new File(tmpDir + "/" + SSLSocketTest.class.getName() + "/cache");
deleteDir(cacheDir);
SSLClientSessionCache fileCache = FileClientSessionCache.usingDirectory(cacheDir);
try {
ClientSessionCacheProxy cacheProxy = new ClientSessionCacheProxy(fileCache);
context.engineInit(null, null, null);
context.engineGetClientSessionContext().setPersistentCache(cacheProxy);
SSLSocketFactory socketFactory = context.engineGetSocketFactory();
context.engineGetClientSessionContext().setSessionCacheSize(1);
makeRequests(socketFactory);
List<String> expected = Arrays.asList("unsuccessful get www.fortify.net", "put www.fortify.net", "unsuccessful get www.paypal.com", "put www.paypal.com", "unsuccessful get www.yellownet.ch", "put www.yellownet.ch", // but the sessions will still be in the persistent cache.
"successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch");
assertEquals(expected, cacheProxy.ops);
// Try again now that file-based cache is populated.
fileCache = FileClientSessionCache.usingDirectory(cacheDir);
cacheProxy = new ClientSessionCacheProxy(fileCache);
context.engineInit(null, null, null);
context.engineGetClientSessionContext().setPersistentCache(cacheProxy);
socketFactory = context.engineGetSocketFactory();
context.engineGetClientSessionContext().setSessionCacheSize(1);
makeRequests(socketFactory);
expected = Arrays.asList("successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch", "successful get www.fortify.net", "successful get www.paypal.com", "successful get www.yellownet.ch");
assertEquals(expected, cacheProxy.ops);
} finally {
deleteDir(cacheDir);
}
}
Aggregations