mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-26 09:16:22 +00:00
Update licenses, naming and apply CR suggestions
This commit is contained in:
parent
3a79a86cd7
commit
f248448e08
@ -9,7 +9,7 @@ dependencies {
|
|||||||
api 'com.github.AppDevNext.Logcat:LogcatCore:2.2.2'
|
api 'com.github.AppDevNext.Logcat:LogcatCore:2.2.2'
|
||||||
|
|
||||||
// Moshi
|
// Moshi
|
||||||
implementation ("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
|
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
|
||||||
exclude module: "kotlin-reflect"
|
exclude module: "kotlin-reflect"
|
||||||
}
|
}
|
||||||
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
|
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"
|
||||||
|
@ -1,3 +1,26 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package com.owncloud.android.lib.common.http
|
package com.owncloud.android.lib.common.http
|
||||||
|
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
@ -11,27 +34,27 @@ class CookieJarImpl(
|
|||||||
fun containsCookieWithName(cookies: List<Cookie>, name: String): Boolean {
|
fun containsCookieWithName(cookies: List<Cookie>, name: String): Boolean {
|
||||||
for (cookie: Cookie in cookies) {
|
for (cookie: Cookie in cookies) {
|
||||||
if (cookie.name == name) {
|
if (cookie.name == name) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUpdatedCookies(oldCookies: List<Cookie>, newCookies: List<Cookie>): List<Cookie> {
|
fun getUpdatedCookies(oldCookies: List<Cookie>, newCookies: List<Cookie>): List<Cookie> {
|
||||||
val updatedList = ArrayList<Cookie>(newCookies);
|
val updatedList = ArrayList<Cookie>(newCookies)
|
||||||
for (oldCookie: Cookie in oldCookies) {
|
for (oldCookie: Cookie in oldCookies) {
|
||||||
if (!containsCookieWithName(updatedList, oldCookie.name)) {
|
if (!containsCookieWithName(updatedList, oldCookie.name)) {
|
||||||
updatedList.add(oldCookie);
|
updatedList.add(oldCookie)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return updatedList;
|
return updatedList
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
|
||||||
// Avoid duplicated cookies but update
|
// Avoid duplicated cookies but update
|
||||||
val currentCookies: List<Cookie> = sCookieStore[url.host] ?: ArrayList()
|
val currentCookies: List<Cookie> = sCookieStore[url.host] ?: ArrayList()
|
||||||
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies);
|
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies)
|
||||||
sCookieStore[url.host] = updatedCookies;
|
sCookieStore[url.host] = updatedCookies
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadForRequest(url: HttpUrl) =
|
override fun loadForRequest(url: HttpUrl) =
|
||||||
|
@ -33,6 +33,7 @@ import okhttp3.CookieJar;
|
|||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Protocol;
|
import okhttp3.Protocol;
|
||||||
|
import okhttp3.TlsVersion;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
@ -41,7 +42,7 @@ import javax.net.ssl.TrustManager;
|
|||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -80,18 +81,18 @@ public class HttpClient {
|
|||||||
|
|
||||||
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
|
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
|
||||||
try {
|
try {
|
||||||
return SSLContext.getInstance("TLSv1.3");
|
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
|
||||||
} catch (NoSuchAlgorithmException tlsv13Exception) {
|
} catch (NoSuchAlgorithmException tlsv13Exception) {
|
||||||
try {
|
try {
|
||||||
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
|
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
|
||||||
return SSLContext.getInstance("TLSv1.2");
|
return SSLContext.getInstance(TlsVersion.TLS_1_2.javaName());
|
||||||
} catch (NoSuchAlgorithmException tlsv12Exception) {
|
} catch (NoSuchAlgorithmException tlsv12Exception) {
|
||||||
try {
|
try {
|
||||||
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
|
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
|
||||||
return SSLContext.getInstance("TLSv1.1");
|
return SSLContext.getInstance(TlsVersion.TLS_1_1.javaName());
|
||||||
} catch (NoSuchAlgorithmException tlsv11Exception) {
|
} catch (NoSuchAlgorithmException tlsv11Exception) {
|
||||||
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
|
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
|
||||||
return SSLContext.getInstance("TLSv1");
|
return SSLContext.getInstance(TlsVersion.TLS_1_0.javaName());
|
||||||
// should be available in any device; see reference of supported protocols in
|
// should be available in any device; see reference of supported protocols in
|
||||||
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
|
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ public class HttpClient {
|
|||||||
CookieJar cookieJar) {
|
CookieJar cookieJar) {
|
||||||
return new OkHttpClient.Builder()
|
return new OkHttpClient.Builder()
|
||||||
.addNetworkInterceptor(getLogInterceptor())
|
.addNetworkInterceptor(getLogInterceptor())
|
||||||
.protocols(Arrays.asList(Protocol.HTTP_1_1))
|
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
|
||||||
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
.connectTimeout(HttpConstants.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
.connectTimeout(HttpConstants.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
@ -121,14 +122,6 @@ public class HttpClient {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context getContext() {
|
|
||||||
return sContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContext(Context context) {
|
|
||||||
sContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LogInterceptor getLogInterceptor() {
|
public static LogInterceptor getLogInterceptor() {
|
||||||
if (sLogInterceptor == null) {
|
if (sLogInterceptor == null) {
|
||||||
sLogInterceptor = new LogInterceptor();
|
sLogInterceptor = new LogInterceptor();
|
||||||
@ -140,6 +133,14 @@ public class HttpClient {
|
|||||||
return sCookieStore.get(httpUrl.host());
|
return sCookieStore.get(httpUrl.host());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Context getContext() {
|
||||||
|
return sContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setContext(Context context) {
|
||||||
|
sContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
public void clearCookies() {
|
public void clearCookies() {
|
||||||
sCookieStore.clear();
|
sCookieStore.clear();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -1,47 +1,57 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package com.owncloud.android.lib
|
package com.owncloud.android.lib
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.CookieJarImpl
|
import com.owncloud.android.lib.common.http.CookieJarImpl
|
||||||
import junit.framework.Assert.assertEquals
|
|
||||||
import junit.framework.Assert.assertFalse
|
|
||||||
import junit.framework.Assert.assertTrue
|
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class CookieJarImplTest {
|
class CookieJarImplTest {
|
||||||
|
|
||||||
private val oldCookies = ArrayList<Cookie>().apply {
|
private val oldCookies = listOf(COOKIE_A, COOKIE_B_OLD)
|
||||||
add(COOKIE_A)
|
private val newCookies = listOf(COOKIE_B_NEW)
|
||||||
add(COOKIE_B_OLD)
|
private val updatedCookies = listOf(COOKIE_A, COOKIE_B_NEW)
|
||||||
}
|
private val cookieStore = hashMapOf(SOME_HOST to oldCookies)
|
||||||
|
|
||||||
private val newCookies = ArrayList<Cookie>().apply {
|
|
||||||
add(COOKIE_B_NEW)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val updatedCookies = ArrayList<Cookie>().apply {
|
|
||||||
add(COOKIE_A)
|
|
||||||
add(COOKIE_B_NEW)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val cookieStore = HashMap<String, List<Cookie>>().apply {
|
|
||||||
put(SOME_HOST, oldCookies)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val cookieJarImpl = CookieJarImpl(cookieStore)
|
private val cookieJarImpl = CookieJarImpl(cookieStore)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testContainsCookieWithNameReturnsTrue() {
|
fun `contains cookie with name - ok - true`() {
|
||||||
assertTrue(cookieJarImpl.containsCookieWithName(oldCookies, COOKIE_B_OLD.name))
|
assertTrue(cookieJarImpl.containsCookieWithName(oldCookies, COOKIE_B_OLD.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testContainsCookieWithNameReturnsFalse() {
|
fun `contains cookie with name - ok - false`() {
|
||||||
assertFalse(cookieJarImpl.containsCookieWithName(newCookies, COOKIE_A.name))
|
assertFalse(cookieJarImpl.containsCookieWithName(newCookies, COOKIE_A.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetUpdatedCookies() {
|
fun `get updated cookies - ok`() {
|
||||||
val generatedUpdatedCookies = cookieJarImpl.getUpdatedCookies(oldCookies, newCookies)
|
val generatedUpdatedCookies = cookieJarImpl.getUpdatedCookies(oldCookies, newCookies)
|
||||||
assertEquals(2, generatedUpdatedCookies.size)
|
assertEquals(2, generatedUpdatedCookies.size)
|
||||||
assertEquals(updatedCookies[0], generatedUpdatedCookies[1])
|
assertEquals(updatedCookies[0], generatedUpdatedCookies[1])
|
||||||
@ -49,7 +59,7 @@ class CookieJarImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCookieStoreUpdateViaSaveFromResponse() {
|
fun `store cookie via saveFromResponse - ok`() {
|
||||||
cookieJarImpl.saveFromResponse(SOME_URL, newCookies)
|
cookieJarImpl.saveFromResponse(SOME_URL, newCookies)
|
||||||
val generatedUpdatedCookies = cookieStore[SOME_HOST]
|
val generatedUpdatedCookies = cookieStore[SOME_HOST]
|
||||||
assertEquals(2, generatedUpdatedCookies?.size)
|
assertEquals(2, generatedUpdatedCookies?.size)
|
||||||
@ -58,7 +68,7 @@ class CookieJarImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLoadForRequest() {
|
fun `load for request - ok`() {
|
||||||
val cookies = cookieJarImpl.loadForRequest(SOME_URL)
|
val cookies = cookieJarImpl.loadForRequest(SOME_URL)
|
||||||
assertEquals(oldCookies[0], cookies[0])
|
assertEquals(oldCookies[0], cookies[0])
|
||||||
assertEquals(oldCookies[1], cookies[1])
|
assertEquals(oldCookies[1], cookies[1])
|
||||||
@ -71,4 +81,4 @@ class CookieJarImplTest {
|
|||||||
val COOKIE_B_OLD = Cookie.parse(SOME_URL, "CookieB=CookieOldValueB")!!
|
val COOKIE_B_OLD = Cookie.parse(SOME_URL, "CookieB=CookieOldValueB")!!
|
||||||
val COOKIE_B_NEW = Cookie.parse(SOME_URL, "CookieB=CookieNewValueB")!!
|
val COOKIE_B_NEW = Cookie.parse(SOME_URL, "CookieB=CookieNewValueB")!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,26 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
package com.owncloud.android.lib
|
package com.owncloud.android.lib
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -59,10 +82,9 @@ class GetRemoteStatusOperationTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `build full https url - ok - no https with subdir`() {
|
fun `build full https url - ok - no https with subdir`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
|
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
|
||||||
Uri.parse(
|
GetRemoteStatusOperation.buildFullHttpsUrl(
|
||||||
HTTPS_SOME_OWNCLOUD_WITH_SUBDIR
|
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -70,10 +92,9 @@ class GetRemoteStatusOperationTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `build full https url - ok - no prefix with subdir`() {
|
fun `build full https url - ok - no prefix with subdir`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
|
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
|
||||||
Uri.parse(
|
GetRemoteStatusOperation.buildFullHttpsUrl(
|
||||||
SOME_OWNCLOUD_WITH_SUBDIR
|
Uri.parse(SOME_OWNCLOUD_WITH_SUBDIR)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -121,4 +142,4 @@ class GetRemoteStatusOperationTest {
|
|||||||
const val HTTP_SOME_IP_WITH_PORT = "$HTTP_PREFIX$SOME_IP_WITH_PORT"
|
const val HTTP_SOME_IP_WITH_PORT = "$HTTP_PREFIX$SOME_IP_WITH_PORT"
|
||||||
const val HTTPS_SOME_IP_WITH_PORT = "$HTTPS_PREFIX$SOME_IP_WITH_PORT"
|
const val HTTPS_SOME_IP_WITH_PORT = "$HTTPS_PREFIX$SOME_IP_WITH_PORT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2021 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -30,7 +30,7 @@ import org.junit.Assert.assertFalse
|
|||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class StatusRequestorTest {
|
class StatusRequesterTest {
|
||||||
private val requester = StatusRequester()
|
private val requester = StatusRequester()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -53,40 +53,45 @@ class StatusRequestorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `update location - ok - replace relative path`() {
|
fun `update location - ok - replace relative path`() {
|
||||||
val newLocation = requester.updateLocationWithRedirectPath(
|
val newLocation = requester.updateLocationWithRedirectPath("$TEST_DOMAIN/some/other/subdir", SUB_PATH)
|
||||||
"$TEST_DOMAIN/some/other/subdir", SUB_PATH
|
|
||||||
)
|
|
||||||
assertEquals("$TEST_DOMAIN$SUB_PATH", newLocation)
|
assertEquals("$TEST_DOMAIN$SUB_PATH", newLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check redirect to unsecure connection - ok - redirect to http`() {
|
fun `check redirect to unsecure connection - ok - redirect to http`() {
|
||||||
assertTrue(requester.isRedirectedToNonSecureConnection(
|
assertTrue(
|
||||||
false, SECURE_DOMAIN, UNSECURE_DOMAIN))
|
requester.isRedirectedToNonSecureConnection(false, SECURE_DOMAIN, UNSECURE_DOMAIN
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check redirect to unsecure connection - ko - redirect to https from http`() {
|
fun `check redirect to unsecure connection - ko - redirect to https from http`() {
|
||||||
assertFalse(requester.isRedirectedToNonSecureConnection(
|
assertFalse(
|
||||||
false, UNSECURE_DOMAIN, SECURE_DOMAIN))
|
requester.isRedirectedToNonSecureConnection(false, UNSECURE_DOMAIN, SECURE_DOMAIN
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check redirect to unsecure connection - ko - from https to https`() {
|
fun `check redirect to unsecure connection - ko - from https to https`() {
|
||||||
assertFalse(requester.isRedirectedToNonSecureConnection(
|
assertFalse(
|
||||||
false, SECURE_DOMAIN, SECURE_DOMAIN))
|
requester.isRedirectedToNonSecureConnection(false, SECURE_DOMAIN, SECURE_DOMAIN)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check redirect to unsecure connection - ok - from https to https with previous http`() {
|
fun `check redirect to unsecure connection - ok - from https to https with previous http`() {
|
||||||
assertTrue(requester.isRedirectedToNonSecureConnection(
|
assertTrue(
|
||||||
true, SECURE_DOMAIN, SECURE_DOMAIN))
|
requester.isRedirectedToNonSecureConnection(true, SECURE_DOMAIN, SECURE_DOMAIN)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check redirect to unsecure connection - ok - from http to http`() {
|
fun `check redirect to unsecure connection - ok - from http to http`() {
|
||||||
assertFalse(requester.isRedirectedToNonSecureConnection(
|
assertFalse(
|
||||||
false, UNSECURE_DOMAIN, UNSECURE_DOMAIN))
|
requester.isRedirectedToNonSecureConnection(false, UNSECURE_DOMAIN, UNSECURE_DOMAIN)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
Loading…
x
Reference in New Issue
Block a user