mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Upgrade to okhttp/3.1.2 + tests
This commit is contained in:
parent
814abc60ed
commit
940d622402
@ -69,7 +69,7 @@ dependencies {
|
||||
|
||||
compile project(':MemorizingTrustManager')
|
||||
|
||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.0.1+'
|
||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.1.2'
|
||||
compile 'dnsjava:dnsjava:2.1.7'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'org.slf4j:slf4j-android:1.7.13'
|
||||
|
@ -9,6 +9,7 @@
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import android.os.Build;
|
||||
import android.test.InstrumentationTestCase;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@ -17,15 +18,18 @@ import java.net.Socket;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import de.duenndns.ssl.MemorizingTrustManager;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
|
||||
public class SSLSocketFactoryCompatTest extends TestCase {
|
||||
public class SSLSocketFactoryCompatTest extends InstrumentationTestCase {
|
||||
|
||||
SSLSocketFactoryCompat factory = new SSLSocketFactoryCompat(null);
|
||||
SSLSocketFactoryCompat factory;
|
||||
MockWebServer server = new MockWebServer();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
factory = new SSLSocketFactoryCompat(new MemorizingTrustManager(getInstrumentation().getTargetContext().getApplicationContext()));
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import at.bitfire.dav4android.exception.DavException;
|
||||
import at.bitfire.dav4android.exception.HttpException;
|
||||
import at.bitfire.davdroid.Constants;
|
||||
import at.bitfire.davdroid.ui.setup.DavResourceFinder;
|
||||
import at.bitfire.davdroid.ui.setup.LoginCredentialsFragment;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
@ -29,11 +30,11 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
|
||||
|
||||
public void testGetCurrentUserPrincipal() throws IOException, HttpException, DavException {
|
||||
HttpUrl url = server.url("/dav");
|
||||
ServerInfo serverInfo = new ServerInfo(url.uri(), "admin", "12345", true);
|
||||
DavResourceFinder finder = new DavResourceFinder(Constants.log, getInstrumentation().getTargetContext().getApplicationContext(), serverInfo);
|
||||
LoginCredentialsFragment.LoginCredentials credentials = new LoginCredentialsFragment.LoginCredentials(url.uri(), "admin", "12345", true);
|
||||
DavResourceFinder finder = new DavResourceFinder(getInstrumentation().getTargetContext().getApplicationContext(), credentials);
|
||||
|
||||
// positive test case
|
||||
server.enqueue(new MockResponse()
|
||||
server.enqueue(new MockResponse() // PROPFIND response
|
||||
.setResponseCode(207)
|
||||
.setHeader("Content-Type", "application/xml;charset=utf-8")
|
||||
.setBody("<multistatus xmlns='DAV:'>" +
|
||||
@ -47,10 +48,13 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
|
||||
" </propstat>" +
|
||||
" </response>" +
|
||||
"</multistatus>"));
|
||||
HttpUrl principal = finder.getCurrentUserPrincipal(url);
|
||||
server.enqueue(new MockResponse() // OPTIONS response
|
||||
.setResponseCode(200)
|
||||
.setHeader("DAV", "addressbook"));
|
||||
HttpUrl principal = finder.getCurrentUserPrincipal(url, DavResourceFinder.Service.CARDDAV);
|
||||
assertEquals(url.resolve("/principals/myself"), principal);
|
||||
|
||||
// negative test case
|
||||
// negative test case: no current-user-principal
|
||||
server.enqueue(new MockResponse()
|
||||
.setResponseCode(207)
|
||||
.setHeader("Content-Type", "application/xml;charset=utf-8")
|
||||
@ -60,7 +64,27 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
|
||||
" <status>HTTP/1.0 200 OK</status>" +
|
||||
" </response>" +
|
||||
"</multistatus>"));
|
||||
assertNull(finder.getCurrentUserPrincipal(url));
|
||||
assertNull(finder.getCurrentUserPrincipal(url, DavResourceFinder.Service.CARDDAV));
|
||||
|
||||
// negative test case: requested service not available
|
||||
server.enqueue(new MockResponse() // PROPFIND response
|
||||
.setResponseCode(207)
|
||||
.setHeader("Content-Type", "application/xml;charset=utf-8")
|
||||
.setBody("<multistatus xmlns='DAV:'>" +
|
||||
" <response>" +
|
||||
" <href>/dav</href>" +
|
||||
" <propstat>" +
|
||||
" <prop>" +
|
||||
" <current-user-principal><href>/principals/myself</href></current-user-principal>" +
|
||||
" </prop>" +
|
||||
" <status>HTTP/1.0 200 OK</status>" +
|
||||
" </propstat>" +
|
||||
" </response>" +
|
||||
"</multistatus>"));
|
||||
server.enqueue(new MockResponse() // OPTIONS response
|
||||
.setResponseCode(200)
|
||||
.setHeader("DAV", "addressbook"));
|
||||
assertNull(finder.getCurrentUserPrincipal(url, DavResourceFinder.Service.CALDAV));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,14 +25,16 @@ import java.util.Locale;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import de.duenndns.ssl.MemorizingTrustManager;
|
||||
import lombok.Cleanup;
|
||||
import lombok.NonNull;
|
||||
|
||||
public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
private SSLSocketFactory defaultFactory;
|
||||
private SSLSocketFactory delegate;
|
||||
|
||||
// Android 5.0+ (API level21) provides reasonable default settings
|
||||
// but it still allows SSLv3
|
||||
@ -99,11 +101,11 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public SSLSocketFactoryCompat(MemorizingTrustManager mtm) {
|
||||
public SSLSocketFactoryCompat(@NonNull MemorizingTrustManager mtm) {
|
||||
try {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, (mtm != null) ? new X509TrustManager[] { mtm } : null, null);
|
||||
defaultFactory = sslContext.getSocketFactory();
|
||||
sslContext.init(null, new X509TrustManager[] { mtm }, null);
|
||||
delegate = sslContext.getSocketFactory();
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new AssertionError(); // The system has no TLS. Just give up.
|
||||
}
|
||||
@ -134,7 +136,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
||||
Socket ssl = defaultFactory.createSocket(s, host, port, autoClose);
|
||||
Socket ssl = delegate.createSocket(s, host, port, autoClose);
|
||||
if (ssl instanceof SSLSocket)
|
||||
upgradeTLS((SSLSocket)ssl);
|
||||
return ssl;
|
||||
@ -142,7 +144,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
||||
Socket ssl = defaultFactory.createSocket(host, port);
|
||||
Socket ssl = delegate.createSocket(host, port);
|
||||
if (ssl instanceof SSLSocket)
|
||||
upgradeTLS((SSLSocket)ssl);
|
||||
return ssl;
|
||||
@ -150,7 +152,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
||||
Socket ssl = defaultFactory.createSocket(host, port, localHost, localPort);
|
||||
Socket ssl = delegate.createSocket(host, port, localHost, localPort);
|
||||
if (ssl instanceof SSLSocket)
|
||||
upgradeTLS((SSLSocket)ssl);
|
||||
return ssl;
|
||||
@ -158,7 +160,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress host, int port) throws IOException {
|
||||
Socket ssl = defaultFactory.createSocket(host, port);
|
||||
Socket ssl = delegate.createSocket(host, port);
|
||||
if (ssl instanceof SSLSocket)
|
||||
upgradeTLS((SSLSocket)ssl);
|
||||
return ssl;
|
||||
@ -166,7 +168,7 @@ public class SSLSocketFactoryCompat extends SSLSocketFactory {
|
||||
|
||||
@Override
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
Socket ssl = defaultFactory.createSocket(address, port, localAddress, localPort);
|
||||
Socket ssl = delegate.createSocket(address, port, localAddress, localPort);
|
||||
if (ssl instanceof SSLSocket)
|
||||
upgradeTLS((SSLSocket)ssl);
|
||||
return ssl;
|
||||
|
@ -55,7 +55,7 @@ import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class DavResourceFinder {
|
||||
protected enum Service {
|
||||
public enum Service {
|
||||
CALDAV("caldav"),
|
||||
CARDDAV("carddav");
|
||||
|
||||
@ -314,7 +314,7 @@ public class DavResourceFinder {
|
||||
* @param service required service (may be null, in which case no service check is done)
|
||||
* @return current-user-principal URL that provides required service, or null if none
|
||||
*/
|
||||
protected HttpUrl getCurrentUserPrincipal(HttpUrl url, Service service) throws IOException, HttpException, DavException {
|
||||
public HttpUrl getCurrentUserPrincipal(HttpUrl url, Service service) throws IOException, HttpException, DavException {
|
||||
DavResource dav = new DavResource(log, httpClient, url);
|
||||
dav.propfind(0, CurrentUserPrincipal.NAME);
|
||||
CurrentUserPrincipal currentUserPrincipal = (CurrentUserPrincipal) dav.properties.get(CurrentUserPrincipal.NAME);
|
||||
|
5
app/src/main/res/drawable/ic_sync_dark.xml
Normal file
5
app/src/main/res/drawable/ic_sync_dark.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:alpha="0.54" android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M12,4V1L8,5l4,4V6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zm0,14c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
|
||||
</vector>
|
@ -1 +1 @@
|
||||
Subproject commit 67a8b968f9ed565d2091f78f252cd0475247bf6e
|
||||
Subproject commit 519decc0aa66a5f7d828fd5741b5250649f9a85a
|
@ -1 +1 @@
|
||||
Subproject commit 6e9ab8680d27a9be7fb677c3b755c4550bc3e80a
|
||||
Subproject commit 13ee3ada06635814c80f00b67339a5d51275fe20
|
Loading…
Reference in New Issue
Block a user