1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-11 16:33:03 +00:00

Update licenses, naming and apply CR suggestions

This commit is contained in:
Abel García de Prada
2021-02-26 15:22:11 +01:00
parent 3a79a86cd7
commit f248448e08
9 changed files with 135 additions and 75 deletions
@@ -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
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.HttpUrl.Companion.toHttpUrl
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class CookieJarImplTest {
private val oldCookies = ArrayList<Cookie>().apply {
add(COOKIE_A)
add(COOKIE_B_OLD)
}
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 oldCookies = listOf(COOKIE_A, COOKIE_B_OLD)
private val newCookies = listOf(COOKIE_B_NEW)
private val updatedCookies = listOf(COOKIE_A, COOKIE_B_NEW)
private val cookieStore = hashMapOf(SOME_HOST to oldCookies)
private val cookieJarImpl = CookieJarImpl(cookieStore)
@Test
fun testContainsCookieWithNameReturnsTrue() {
fun `contains cookie with name - ok - true`() {
assertTrue(cookieJarImpl.containsCookieWithName(oldCookies, COOKIE_B_OLD.name))
}
@Test
fun testContainsCookieWithNameReturnsFalse() {
fun `contains cookie with name - ok - false`() {
assertFalse(cookieJarImpl.containsCookieWithName(newCookies, COOKIE_A.name))
}
@Test
fun testGetUpdatedCookies() {
fun `get updated cookies - ok`() {
val generatedUpdatedCookies = cookieJarImpl.getUpdatedCookies(oldCookies, newCookies)
assertEquals(2, generatedUpdatedCookies.size)
assertEquals(updatedCookies[0], generatedUpdatedCookies[1])
@@ -49,7 +59,7 @@ class CookieJarImplTest {
}
@Test
fun testCookieStoreUpdateViaSaveFromResponse() {
fun `store cookie via saveFromResponse - ok`() {
cookieJarImpl.saveFromResponse(SOME_URL, newCookies)
val generatedUpdatedCookies = cookieStore[SOME_HOST]
assertEquals(2, generatedUpdatedCookies?.size)
@@ -58,7 +68,7 @@ class CookieJarImplTest {
}
@Test
fun testLoadForRequest() {
fun `load for request - ok`() {
val cookies = cookieJarImpl.loadForRequest(SOME_URL)
assertEquals(oldCookies[0], cookies[0])
assertEquals(oldCookies[1], cookies[1])
@@ -71,4 +81,4 @@ class CookieJarImplTest {
val COOKIE_B_OLD = Cookie.parse(SOME_URL, "CookieB=CookieOldValueB")!!
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
import android.net.Uri
@@ -59,10 +82,9 @@ class GetRemoteStatusOperationTest {
@Test
fun `build full https url - ok - no https with subdir`() {
assertEquals(
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
Uri.parse(
HTTPS_SOME_OWNCLOUD_WITH_SUBDIR
)
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
GetRemoteStatusOperation.buildFullHttpsUrl(
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR)
)
)
}
@@ -70,10 +92,9 @@ class GetRemoteStatusOperationTest {
@Test
fun `build full https url - ok - no prefix with subdir`() {
assertEquals(
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
Uri.parse(
SOME_OWNCLOUD_WITH_SUBDIR
)
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
GetRemoteStatusOperation.buildFullHttpsUrl(
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 HTTPS_SOME_IP_WITH_PORT = "$HTTPS_PREFIX$SOME_IP_WITH_PORT"
}
}
}
@@ -1,5 +1,5 @@
/* 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
* 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.Test
class StatusRequestorTest {
class StatusRequesterTest {
private val requester = StatusRequester()
@Test
@@ -53,40 +53,45 @@ class StatusRequestorTest {
@Test
fun `update location - ok - replace relative path`() {
val newLocation = requester.updateLocationWithRedirectPath(
"$TEST_DOMAIN/some/other/subdir", SUB_PATH
)
val newLocation = requester.updateLocationWithRedirectPath("$TEST_DOMAIN/some/other/subdir", SUB_PATH)
assertEquals("$TEST_DOMAIN$SUB_PATH", newLocation)
}
@Test
fun `check redirect to unsecure connection - ok - redirect to http`() {
assertTrue(requester.isRedirectedToNonSecureConnection(
false, SECURE_DOMAIN, UNSECURE_DOMAIN))
assertTrue(
requester.isRedirectedToNonSecureConnection(false, SECURE_DOMAIN, UNSECURE_DOMAIN
)
)
}
@Test
fun `check redirect to unsecure connection - ko - redirect to https from http`() {
assertFalse(requester.isRedirectedToNonSecureConnection(
false, UNSECURE_DOMAIN, SECURE_DOMAIN))
assertFalse(
requester.isRedirectedToNonSecureConnection(false, UNSECURE_DOMAIN, SECURE_DOMAIN
)
)
}
@Test
fun `check redirect to unsecure connection - ko - from https to https`() {
assertFalse(requester.isRedirectedToNonSecureConnection(
false, SECURE_DOMAIN, SECURE_DOMAIN))
assertFalse(
requester.isRedirectedToNonSecureConnection(false, SECURE_DOMAIN, SECURE_DOMAIN)
)
}
@Test
fun `check redirect to unsecure connection - ok - from https to https with previous http`() {
assertTrue(requester.isRedirectedToNonSecureConnection(
true, SECURE_DOMAIN, SECURE_DOMAIN))
assertTrue(
requester.isRedirectedToNonSecureConnection(true, SECURE_DOMAIN, SECURE_DOMAIN)
)
}
@Test
fun `check redirect to unsecure connection - ok - from http to http`() {
assertFalse(requester.isRedirectedToNonSecureConnection(
false, UNSECURE_DOMAIN, UNSECURE_DOMAIN))
assertFalse(
requester.isRedirectedToNonSecureConnection(false, UNSECURE_DOMAIN, UNSECURE_DOMAIN)
)
}
companion object {