Skip to content

Commit f66b3fe

Browse files
committed
test: update tests and add new ones for new Kiteworsk setup logic
1 parent 349d5f6 commit f66b3fe

3 files changed

Lines changed: 62 additions & 4 deletions

File tree

owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/implementation/OCRemoteOAuthDataSourceTest.kt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Abel García de Prada
5-
* Copyright (C) 2021 ownCloud GmbH.
5+
* @author Jorge Aguado Recio
6+
*
7+
* Copyright (C) 2025 ownCloud GmbH.
68
*
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -32,6 +34,7 @@ import com.owncloud.android.lib.resources.oauth.services.OIDCService
3234
import com.owncloud.android.testutil.OC_SECURE_BASE_URL
3335
import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION
3436
import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION_REQUEST
37+
import com.owncloud.android.testutil.oauth.OC_OIDC_KITEWORKS_SERVER_CONFIGURATION
3538
import com.owncloud.android.testutil.oauth.OC_OIDC_SERVER_CONFIGURATION
3639
import com.owncloud.android.testutil.oauth.OC_TOKEN_REQUEST_ACCESS
3740
import com.owncloud.android.testutil.oauth.OC_TOKEN_RESPONSE
@@ -63,14 +66,18 @@ class OCRemoteOAuthDataSourceTest {
6366
}
6467

6568
@Test
66-
fun `performOIDCDiscovery returns a OIDCServerConfiguration`() {
69+
fun `performOIDCDiscovery returns a OIDCServerConfiguration when the server is from ownCloud`() {
6770
val oidcDiscoveryResult: RemoteOperationResult<OIDCDiscoveryResponse> =
6871
createRemoteOperationResultMock(data = OC_REMOTE_OIDC_DISCOVERY_RESPONSE, isSuccess = true)
6972

7073
every {
7174
oidcService.getOIDCServerDiscovery(ocClientMocked)
7275
} returns oidcDiscoveryResult
7376

77+
every {
78+
ocClientMocked.isKiteworksServer
79+
} returns false
80+
7481
val oidcDiscovery = remoteOAuthDataSource.performOIDCDiscovery(OC_SECURE_BASE_URL)
7582

7683
assertNotNull(oidcDiscovery)
@@ -82,6 +89,30 @@ class OCRemoteOAuthDataSourceTest {
8289
}
8390
}
8491

92+
@Test
93+
fun `performOIDCDiscovery returns a OIDCServerConfiguration when the server is from Kiteworks`() {
94+
val oidcDiscoveryResult: RemoteOperationResult<OIDCDiscoveryResponse> =
95+
createRemoteOperationResultMock(data = OC_REMOTE_OIDC_DISCOVERY_RESPONSE, isSuccess = true)
96+
97+
every {
98+
oidcService.getOIDCServerDiscovery(ocClientMocked)
99+
} returns oidcDiscoveryResult
100+
101+
every {
102+
ocClientMocked.isKiteworksServer
103+
} returns true
104+
105+
val oidcDiscovery = remoteOAuthDataSource.performOIDCDiscovery(OC_SECURE_BASE_URL)
106+
107+
assertNotNull(oidcDiscovery)
108+
assertEquals(OC_OIDC_KITEWORKS_SERVER_CONFIGURATION, oidcDiscovery)
109+
110+
verify(exactly = 1) {
111+
clientManager.getClientForAnonymousCredentials(OC_SECURE_BASE_URL, false)
112+
oidcService.getOIDCServerDiscovery(ocClientMocked)
113+
}
114+
}
115+
85116
@Test
86117
fun `performTokenRequest returns a TokenResponse`() {
87118
val tokenResponseResult: RemoteOperationResult<TokenResponse> =

owncloudData/src/test/java/com/owncloud/android/data/server/datasources/implementation/OCRemoteServerInfoDataSourceTest.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*
44
* @author Abel García de Prada
55
* @author Juan Carlos Garrote Gascón
6+
* @author Jorge Aguado Recio
67
*
7-
* Copyright (C) 2024 ownCloud GmbH.
8+
* Copyright (C) 2025 ownCloud GmbH.
89
*
910
* This program is free software: you can redistribute it and/or modify
1011
* it under the terms of the GNU General Public License version 2,
@@ -39,6 +40,7 @@ import com.owncloud.android.testutil.OC_INSECURE_SERVER_INFO_BASIC_AUTH
3940
import com.owncloud.android.testutil.OC_INSECURE_SERVER_INFO_BEARER_AUTH
4041
import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
4142
import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BEARER_AUTH
43+
import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_OIDC_AUTH
4244
import com.owncloud.android.utils.createRemoteOperationResultMock
4345
import io.mockk.every
4446
import io.mockk.mockk
@@ -98,6 +100,25 @@ class OCRemoteServerInfoDataSourceTest {
98100
verify { ocServerInfoService.checkPathExistence(OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, false, ocClientMocked) }
99101
}
100102

103+
@Test
104+
fun `getAuthenticationMethod returns bearer authentication when the server is Kiteworks`() {
105+
val expectedValue = AuthenticationMethod.BEARER_TOKEN
106+
prepareAuthorizationMethodToBeRetrieved(expectedValue)
107+
108+
every {
109+
ocClientMocked.isKiteworksServer
110+
} returns true
111+
112+
val currentValue = ocRemoteServerInfoDatasource.getAuthenticationMethod(OC_SECURE_SERVER_INFO_OIDC_AUTH.baseUrl)
113+
114+
assertNotNull(expectedValue)
115+
assertEquals(expectedValue, currentValue)
116+
117+
verify {
118+
ocServerInfoService.checkPathExistence(OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, false, ocClientMocked)
119+
}
120+
}
121+
101122
@Test
102123
fun `getAuthenticationMethod returns none method`() {
103124
val expectedValue = AuthenticationMethod.NONE

owncloudTestUtil/src/main/java/com/owncloud/android/testutil/oauth/OIDCServerConfiguration.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* ownCloud Android client application
33
*
44
* @author Abel García de Prada
5-
* Copyright (C) 2021 ownCloud GmbH.
5+
* @author Jorge Aguado Recio
6+
*
7+
* Copyright (C) 2025 ownCloud GmbH.
68
*
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -44,3 +46,7 @@ val OC_OIDC_SERVER_CONFIGURATION = OIDCServerConfiguration(
4446
tokenEndpointAuthMethodsSupported = listOf(),
4547
userInfoEndpoint = "https://owncloud.server/userinfo"
4648
)
49+
50+
val OC_OIDC_KITEWORKS_SERVER_CONFIGURATION = OC_OIDC_SERVER_CONFIGURATION.copy(
51+
isKiteworksServer = true
52+
)

0 commit comments

Comments
 (0)