Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit f248448

Browse files
committed
Update licenses, naming and apply CR suggestions
1 parent 3a79a86 commit f248448

File tree

9 files changed

+135
-75
lines changed

9 files changed

+135
-75
lines changed

owncloudComLibrary/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
api 'com.github.AppDevNext.Logcat:LogcatCore:2.2.2'
1010

1111
// Moshi
12-
implementation ("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
12+
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {
1313
exclude module: "kotlin-reflect"
1414
}
1515
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion"

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/CookieJarImpl.kt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2021 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
124
package com.owncloud.android.lib.common.http
225

326
import okhttp3.Cookie
@@ -11,27 +34,27 @@ class CookieJarImpl(
1134
fun containsCookieWithName(cookies: List<Cookie>, name: String): Boolean {
1235
for (cookie: Cookie in cookies) {
1336
if (cookie.name == name) {
14-
return true;
37+
return true
1538
}
1639
}
17-
return false;
40+
return false
1841
}
1942

2043
fun getUpdatedCookies(oldCookies: List<Cookie>, newCookies: List<Cookie>): List<Cookie> {
21-
val updatedList = ArrayList<Cookie>(newCookies);
44+
val updatedList = ArrayList<Cookie>(newCookies)
2245
for (oldCookie: Cookie in oldCookies) {
2346
if (!containsCookieWithName(updatedList, oldCookie.name)) {
24-
updatedList.add(oldCookie);
47+
updatedList.add(oldCookie)
2548
}
2649
}
27-
return updatedList;
50+
return updatedList
2851
}
2952

3053
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
3154
// Avoid duplicated cookies but update
3255
val currentCookies: List<Cookie> = sCookieStore[url.host] ?: ArrayList()
33-
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies);
34-
sCookieStore[url.host] = updatedCookies;
56+
val updatedCookies: List<Cookie> = getUpdatedCookies(currentCookies, cookies)
57+
sCookieStore[url.host] = updatedCookies
3558
}
3659

3760
override fun loadForRequest(url: HttpUrl) =

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import okhttp3.HttpUrl;
3434
import okhttp3.OkHttpClient;
3535
import okhttp3.Protocol;
36+
import okhttp3.TlsVersion;
3637
import timber.log.Timber;
3738

3839
import javax.net.ssl.SSLContext;
@@ -41,7 +42,7 @@
4142
import javax.net.ssl.X509TrustManager;
4243
import java.security.KeyManagementException;
4344
import java.security.NoSuchAlgorithmException;
44-
import java.util.Arrays;
45+
import java.util.Collections;
4546
import java.util.HashMap;
4647
import java.util.List;
4748
import java.util.concurrent.TimeUnit;
@@ -80,18 +81,18 @@ public static OkHttpClient getOkHttpClient() {
8081

8182
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
8283
try {
83-
return SSLContext.getInstance("TLSv1.3");
84+
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
8485
} catch (NoSuchAlgorithmException tlsv13Exception) {
8586
try {
8687
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
87-
return SSLContext.getInstance("TLSv1.2");
88+
return SSLContext.getInstance(TlsVersion.TLS_1_2.javaName());
8889
} catch (NoSuchAlgorithmException tlsv12Exception) {
8990
try {
9091
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
91-
return SSLContext.getInstance("TLSv1.1");
92+
return SSLContext.getInstance(TlsVersion.TLS_1_1.javaName());
9293
} catch (NoSuchAlgorithmException tlsv11Exception) {
9394
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
94-
return SSLContext.getInstance("TLSv1");
95+
return SSLContext.getInstance(TlsVersion.TLS_1_0.javaName());
9596
// should be available in any device; see reference of supported protocols in
9697
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
9798
}
@@ -110,7 +111,7 @@ private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFacto
110111
CookieJar cookieJar) {
111112
return new OkHttpClient.Builder()
112113
.addNetworkInterceptor(getLogInterceptor())
113-
.protocols(Arrays.asList(Protocol.HTTP_1_1))
114+
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
114115
.readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
115116
.writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
116117
.connectTimeout(HttpConstants.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
@@ -121,14 +122,6 @@ private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFacto
121122
.build();
122123
}
123124

124-
public Context getContext() {
125-
return sContext;
126-
}
127-
128-
public static void setContext(Context context) {
129-
sContext = context;
130-
}
131-
132125
public static LogInterceptor getLogInterceptor() {
133126
if (sLogInterceptor == null) {
134127
sLogInterceptor = new LogInterceptor();
@@ -140,6 +133,14 @@ public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
140133
return sCookieStore.get(httpUrl.host());
141134
}
142135

136+
public Context getContext() {
137+
return sContext;
138+
}
139+
140+
public static void setContext(Context context) {
141+
sContext = context;
142+
}
143+
143144
public void clearCookies() {
144145
sCookieStore.clear();
145146
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/HttpScheme.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2020 ownCloud GmbH.
2+
* Copyright (C) 2021 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteServerInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2020 ownCloud GmbH.
2+
* Copyright (C) 2021 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/StatusRequester.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2020 ownCloud GmbH.
2+
* Copyright (C) 2021 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2021 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
124
package com.owncloud.android.lib
225

326
import com.owncloud.android.lib.common.http.CookieJarImpl
4-
import junit.framework.Assert.assertEquals
5-
import junit.framework.Assert.assertFalse
6-
import junit.framework.Assert.assertTrue
727
import okhttp3.Cookie
828
import okhttp3.HttpUrl.Companion.toHttpUrl
29+
import org.junit.Assert.assertEquals
30+
import org.junit.Assert.assertFalse
31+
import org.junit.Assert.assertTrue
932
import org.junit.Test
1033

1134
class CookieJarImplTest {
1235

13-
private val oldCookies = ArrayList<Cookie>().apply {
14-
add(COOKIE_A)
15-
add(COOKIE_B_OLD)
16-
}
17-
18-
private val newCookies = ArrayList<Cookie>().apply {
19-
add(COOKIE_B_NEW)
20-
}
21-
22-
private val updatedCookies = ArrayList<Cookie>().apply {
23-
add(COOKIE_A)
24-
add(COOKIE_B_NEW)
25-
}
26-
27-
private val cookieStore = HashMap<String, List<Cookie>>().apply {
28-
put(SOME_HOST, oldCookies)
29-
}
36+
private val oldCookies = listOf(COOKIE_A, COOKIE_B_OLD)
37+
private val newCookies = listOf(COOKIE_B_NEW)
38+
private val updatedCookies = listOf(COOKIE_A, COOKIE_B_NEW)
39+
private val cookieStore = hashMapOf(SOME_HOST to oldCookies)
3040

3141
private val cookieJarImpl = CookieJarImpl(cookieStore)
3242

3343
@Test
34-
fun testContainsCookieWithNameReturnsTrue() {
44+
fun `contains cookie with name - ok - true`() {
3545
assertTrue(cookieJarImpl.containsCookieWithName(oldCookies, COOKIE_B_OLD.name))
3646
}
3747

3848
@Test
39-
fun testContainsCookieWithNameReturnsFalse() {
49+
fun `contains cookie with name - ok - false`() {
4050
assertFalse(cookieJarImpl.containsCookieWithName(newCookies, COOKIE_A.name))
4151
}
4252

4353
@Test
44-
fun testGetUpdatedCookies() {
54+
fun `get updated cookies - ok`() {
4555
val generatedUpdatedCookies = cookieJarImpl.getUpdatedCookies(oldCookies, newCookies)
4656
assertEquals(2, generatedUpdatedCookies.size)
4757
assertEquals(updatedCookies[0], generatedUpdatedCookies[1])
4858
assertEquals(updatedCookies[1], generatedUpdatedCookies[0])
4959
}
5060

5161
@Test
52-
fun testCookieStoreUpdateViaSaveFromResponse() {
62+
fun `store cookie via saveFromResponse - ok`() {
5363
cookieJarImpl.saveFromResponse(SOME_URL, newCookies)
5464
val generatedUpdatedCookies = cookieStore[SOME_HOST]
5565
assertEquals(2, generatedUpdatedCookies?.size)
@@ -58,7 +68,7 @@ class CookieJarImplTest {
5868
}
5969

6070
@Test
61-
fun testLoadForRequest() {
71+
fun `load for request - ok`() {
6272
val cookies = cookieJarImpl.loadForRequest(SOME_URL)
6373
assertEquals(oldCookies[0], cookies[0])
6474
assertEquals(oldCookies[1], cookies[1])
@@ -71,4 +81,4 @@ class CookieJarImplTest {
7181
val COOKIE_B_OLD = Cookie.parse(SOME_URL, "CookieB=CookieOldValueB")!!
7282
val COOKIE_B_NEW = Cookie.parse(SOME_URL, "CookieB=CookieNewValueB")!!
7383
}
74-
}
84+
}

owncloudComLibrary/src/test/java/com/owncloud/android/lib/GetRemoteStatusOperationTest.kt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2021 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
124
package com.owncloud.android.lib
225

326
import android.net.Uri
@@ -59,21 +82,19 @@ class GetRemoteStatusOperationTest {
5982
@Test
6083
fun `build full https url - ok - no https with subdir`() {
6184
assertEquals(
62-
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
63-
Uri.parse(
64-
HTTPS_SOME_OWNCLOUD_WITH_SUBDIR
65-
)
85+
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
86+
GetRemoteStatusOperation.buildFullHttpsUrl(
87+
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR)
6688
)
6789
)
6890
}
6991

7092
@Test
7193
fun `build full https url - ok - no prefix with subdir`() {
7294
assertEquals(
73-
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR), GetRemoteStatusOperation.buildFullHttpsUrl(
74-
Uri.parse(
75-
SOME_OWNCLOUD_WITH_SUBDIR
76-
)
95+
Uri.parse(HTTPS_SOME_OWNCLOUD_WITH_SUBDIR),
96+
GetRemoteStatusOperation.buildFullHttpsUrl(
97+
Uri.parse(SOME_OWNCLOUD_WITH_SUBDIR)
7798
)
7899
)
79100
}
@@ -121,4 +142,4 @@ class GetRemoteStatusOperationTest {
121142
const val HTTP_SOME_IP_WITH_PORT = "$HTTP_PREFIX$SOME_IP_WITH_PORT"
122143
const val HTTPS_SOME_IP_WITH_PORT = "$HTTPS_PREFIX$SOME_IP_WITH_PORT"
123144
}
124-
}
145+
}

0 commit comments

Comments
 (0)