2
2
* ownCloud Android client application
3
3
*
4
4
* @author Abel García de Prada
5
+ * @author Juan Carlos Garrote Gascón
5
6
*
6
- * Copyright (C) 2020 ownCloud GmbH.
7
+ * Copyright (C) 2023 ownCloud GmbH.
7
8
*
8
9
* This program is free software: you can redistribute it and/or modify
9
10
* it under the terms of the GNU General Public License version 2,
@@ -23,6 +24,7 @@ package com.owncloud.android.authentication
23
24
import android.accounts.AccountManager.KEY_ACCOUNT_NAME
24
25
import android.accounts.AccountManager.KEY_ACCOUNT_TYPE
25
26
import android.app.Activity.RESULT_OK
27
+ import android.app.Instrumentation
26
28
import android.content.Context
27
29
import android.content.Intent
28
30
import androidx.lifecycle.MutableLiveData
@@ -33,6 +35,7 @@ import androidx.test.espresso.Espresso.onView
33
35
import androidx.test.espresso.action.ViewActions.click
34
36
import androidx.test.espresso.intent.Intents
35
37
import androidx.test.espresso.intent.Intents.intended
38
+ import androidx.test.espresso.intent.matcher.IntentMatchers
36
39
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
37
40
import androidx.test.espresso.matcher.ViewMatchers.Visibility
38
41
import androidx.test.espresso.matcher.ViewMatchers.withId
@@ -41,7 +44,6 @@ import com.owncloud.android.domain.exceptions.NoNetworkConnectionException
41
44
import com.owncloud.android.domain.exceptions.OwncloudVersionNotSupportedException
42
45
import com.owncloud.android.domain.exceptions.ServerNotReachableException
43
46
import com.owncloud.android.domain.exceptions.UnauthorizedException
44
- import com.owncloud.android.domain.server.model.AuthenticationMethod
45
47
import com.owncloud.android.domain.server.model.ServerInfo
46
48
import com.owncloud.android.domain.utils.Event
47
49
import com.owncloud.android.extensions.parseError
@@ -64,7 +66,9 @@ import com.owncloud.android.testutil.OC_ACCOUNT
64
66
import com.owncloud.android.testutil.OC_AUTH_TOKEN_TYPE
65
67
import com.owncloud.android.testutil.OC_BASIC_PASSWORD
66
68
import com.owncloud.android.testutil.OC_BASIC_USERNAME
67
- import com.owncloud.android.testutil.OC_SERVER_INFO
69
+ import com.owncloud.android.testutil.OC_INSECURE_SERVER_INFO_BASIC_AUTH
70
+ import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
71
+ import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BEARER_AUTH
68
72
import com.owncloud.android.utils.CONFIGURATION_SERVER_URL
69
73
import com.owncloud.android.utils.CONFIGURATION_SERVER_URL_INPUT_VISIBILITY
70
74
import com.owncloud.android.utils.NO_MDM_RESTRICTION_YET
@@ -81,6 +85,7 @@ import io.mockk.every
81
85
import io.mockk.mockk
82
86
import io.mockk.unmockkAll
83
87
import io.mockk.verify
88
+ import org.hamcrest.Matchers.allOf
84
89
import org.junit.After
85
90
import org.junit.Assert.assertEquals
86
91
import org.junit.Assert.assertNotNull
@@ -199,14 +204,14 @@ class LoginActivityTest {
199
204
200
205
@Test
201
206
fun initialViewStatus_brandedOptions_webfinger () {
202
- launchTest(webfingerLookupServer = OC_SERVER_INFO .baseUrl)
207
+ launchTest(webfingerLookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
203
208
204
209
assertWebfingerFlowDisplayed(webfingerEnabled = true )
205
210
}
206
211
207
212
@Test
208
213
fun initialViewStatus_brandedOptions_serverInfoInSetup () {
209
- launchTest(showServerUrlInput = false , serverUrl = OC_SERVER_INFO .baseUrl)
214
+ launchTest(showServerUrlInput = false , serverUrl = OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
210
215
211
216
assertViewsDisplayed(
212
217
showHostUrlFrame = false ,
@@ -215,21 +220,21 @@ class LoginActivityTest {
215
220
showEmbeddedCheckServerButton = false
216
221
)
217
222
218
- verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
223
+ verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl, true ) }
219
224
}
220
225
221
226
@Test
222
227
fun initialViewStatus_brandedOptions_serverInfoInSetup_connectionFails () {
223
228
224
- launchTest(showServerUrlInput = false , serverUrl = OC_SERVER_INFO .baseUrl)
229
+ launchTest(showServerUrlInput = false , serverUrl = OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
225
230
226
231
serverInfoLiveData.postValue(Event (UIResult .Error (NoNetworkConnectionException ())))
227
232
228
233
R .id.centeredRefreshButton.isDisplayed(true )
229
234
R .id.centeredRefreshButton.scrollAndClick()
230
235
231
- verify(exactly = 2 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
232
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC .copy(isSecureConnection = true ) )))
236
+ verify(exactly = 2 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl, true ) }
237
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
233
238
234
239
R .id.centeredRefreshButton.isDisplayed(false )
235
240
}
@@ -270,21 +275,21 @@ class LoginActivityTest {
270
275
fun checkServerInfo_clickButton_callGetServerInfo () {
271
276
launchTest()
272
277
273
- R .id.hostUrlInput.typeText(OC_SERVER_INFO .baseUrl)
278
+ R .id.hostUrlInput.typeText(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
274
279
275
280
R .id.embeddedCheckServerButton.scrollAndClick()
276
281
277
- verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
282
+ verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl, true ) }
278
283
}
279
284
280
285
@Test
281
286
fun checkServerInfo_clickLogo_callGetServerInfo () {
282
287
launchTest()
283
- R .id.hostUrlInput.typeText(OC_SERVER_INFO .baseUrl)
288
+ R .id.hostUrlInput.typeText(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
284
289
285
290
R .id.thumbnail.scrollAndClick()
286
291
287
- verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
292
+ verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl, true ) }
288
293
}
289
294
290
295
@Test
@@ -303,15 +308,15 @@ class LoginActivityTest {
303
308
launchTest()
304
309
R .id.hostUrlInput.typeText(" demo.owncloud.com" )
305
310
306
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC .copy(isSecureConnection = true ) )))
311
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
307
312
308
- R .id.hostUrlInput.withText(SERVER_INFO_BASIC .baseUrl)
313
+ R .id.hostUrlInput.withText(SECURE_SERVER_INFO_BASIC .baseUrl)
309
314
}
310
315
311
316
@Test
312
317
fun checkServerInfo_isSuccess_Secure () {
313
318
launchTest()
314
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC .copy(isSecureConnection = true ) )))
319
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
315
320
316
321
with (R .id.server_status_text) {
317
322
isDisplayed(true )
@@ -323,7 +328,7 @@ class LoginActivityTest {
323
328
@Test
324
329
fun checkServerInfo_isSuccess_NotSecure () {
325
330
launchTest()
326
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC .copy(isSecureConnection = false ) )))
331
+ serverInfoLiveData.postValue(Event (UIResult .Success (INSECURE_SERVER_INFO_BASIC )))
327
332
328
333
with (R .id.server_status_text) {
329
334
isDisplayed(true )
@@ -336,34 +341,28 @@ class LoginActivityTest {
336
341
fun checkServerInfo_isSuccess_Basic () {
337
342
launchTest()
338
343
339
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC )))
344
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
340
345
341
346
checkBasicFieldsVisibility(loginButtonShouldBeVisible = false )
342
347
}
343
348
344
349
@Test
345
350
fun checkServerInfo_isSuccess_Bearer () {
351
+ Intents .init ()
346
352
launchTest()
353
+ avoidOpeningChromeCustomTab()
347
354
348
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BEARER )))
355
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BEARER )))
349
356
350
357
checkBearerFieldsVisibility()
351
- }
352
-
353
- @Test
354
- fun checkServerInfo_isSuccess_None () {
355
- launchTest()
356
-
357
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC .copy(authenticationMethod = AuthenticationMethod .NONE ))))
358
-
359
- assertNoneFieldsVisibility()
358
+ Intents .release()
360
359
}
361
360
362
361
@Test
363
362
fun checkServerInfo_isSuccess_basicModifyUrlInput () {
364
363
launchTest()
365
364
366
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC )))
365
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
367
366
368
367
checkBasicFieldsVisibility()
369
368
@@ -388,15 +387,18 @@ class LoginActivityTest {
388
387
389
388
@Test
390
389
fun checkServerInfo_isSuccess_bearerModifyUrlInput () {
390
+ Intents .init ()
391
391
launchTest()
392
+ avoidOpeningChromeCustomTab()
392
393
393
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BEARER )))
394
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BEARER )))
394
395
395
396
checkBearerFieldsVisibility()
396
397
397
398
R .id.hostUrlInput.typeText(" anything" )
398
399
399
400
R .id.auth_status_text.assertVisibility(Visibility .GONE )
401
+ Intents .release()
400
402
}
401
403
402
404
@Test
@@ -459,7 +461,7 @@ class LoginActivityTest {
459
461
fun loginBasic_callLoginBasic () {
460
462
launchTest()
461
463
462
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC )))
464
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
463
465
464
466
R .id.account_username.typeText(OC_BASIC_USERNAME )
465
467
@@ -477,7 +479,7 @@ class LoginActivityTest {
477
479
fun loginBasic_callLoginBasic_trimUsername () {
478
480
launchTest()
479
481
480
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC )))
482
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
481
483
482
484
R .id.account_username.typeText(" $OC_BASIC_USERNAME " )
483
485
@@ -495,7 +497,7 @@ class LoginActivityTest {
495
497
fun loginBasic_showOrHideFields () {
496
498
launchTest()
497
499
498
- serverInfoLiveData.postValue(Event (UIResult .Success (SERVER_INFO_BASIC )))
500
+ serverInfoLiveData.postValue(Event (UIResult .Success (SECURE_SERVER_INFO_BASIC )))
499
501
500
502
R .id.account_username.typeText(OC_BASIC_USERNAME )
501
503
@@ -664,17 +666,17 @@ class LoginActivityTest {
664
666
665
667
launchTest(intent = intentWithAccount)
666
668
667
- baseUrlLiveData.postValue(Event (UIResult .Success (OC_SERVER_INFO .baseUrl)))
669
+ baseUrlLiveData.postValue(Event (UIResult .Success (OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)))
668
670
669
671
with (R .id.hostUrlInput) {
670
- withText(OC_SERVER_INFO .baseUrl)
672
+ withText(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
671
673
assertVisibility(Visibility .VISIBLE )
672
674
isDisplayed(true )
673
675
isEnabled(false )
674
676
isFocusable(false )
675
677
}
676
678
677
- verify(exactly = 0 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
679
+ verify(exactly = 0 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl) }
678
680
}
679
681
680
682
@Test
@@ -686,17 +688,17 @@ class LoginActivityTest {
686
688
687
689
launchTest(intent = intentWithAccount)
688
690
689
- baseUrlLiveData.postValue(Event (UIResult .Success (OC_SERVER_INFO .baseUrl)))
691
+ baseUrlLiveData.postValue(Event (UIResult .Success (OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)))
690
692
691
693
with (R .id.hostUrlInput) {
692
- withText(OC_SERVER_INFO .baseUrl)
694
+ withText(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl)
693
695
assertVisibility(Visibility .VISIBLE )
694
696
isDisplayed(true )
695
697
isEnabled(false )
696
698
isFocusable(false )
697
699
}
698
700
699
- verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SERVER_INFO .baseUrl) }
701
+ verify(exactly = 1 ) { authenticationViewModel.getServerInfo(OC_SECURE_SERVER_INFO_BASIC_AUTH .baseUrl) }
700
702
}
701
703
702
704
@Test
@@ -713,6 +715,11 @@ class LoginActivityTest {
713
715
Intents .release()
714
716
}
715
717
718
+ private fun avoidOpeningChromeCustomTab () {
719
+ Intents .intending(allOf(IntentMatchers .hasAction(Intent .ACTION_VIEW )))
720
+ .respondWith(Instrumentation .ActivityResult (RESULT_OK , null ))
721
+ }
722
+
716
723
private fun checkBasicFieldsVisibility (
717
724
fieldsShouldBeVisible : Boolean = true,
718
725
loginButtonShouldBeVisible : Boolean = false
@@ -747,19 +754,6 @@ class LoginActivityTest {
747
754
}
748
755
}
749
756
750
- private fun assertNoneFieldsVisibility () {
751
- with (R .id.server_status_text) {
752
- isDisplayed(true )
753
- assertVisibility(Visibility .VISIBLE )
754
- withText(R .string.auth_unsupported_auth_method)
755
- }
756
-
757
- R .id.account_username.assertVisibility(Visibility .GONE )
758
- R .id.account_password.assertVisibility(Visibility .GONE )
759
- R .id.loginButton.assertVisibility(Visibility .GONE )
760
- R .id.auth_status_text.assertVisibility(Visibility .GONE )
761
- }
762
-
763
757
private fun assertWebfingerFlowDisplayed (
764
758
webfingerEnabled : Boolean ,
765
759
) {
@@ -803,8 +797,9 @@ class LoginActivityTest {
803
797
}
804
798
805
799
companion object {
806
- val SERVER_INFO_BASIC = OC_SERVER_INFO
807
- val SERVER_INFO_BEARER = OC_SERVER_INFO .copy(authenticationMethod = AuthenticationMethod .BEARER_TOKEN )
800
+ val SECURE_SERVER_INFO_BASIC = OC_SECURE_SERVER_INFO_BASIC_AUTH
801
+ val INSECURE_SERVER_INFO_BASIC = OC_INSECURE_SERVER_INFO_BASIC_AUTH
802
+ val SECURE_SERVER_INFO_BEARER = OC_SECURE_SERVER_INFO_BEARER_AUTH
808
803
private const val CUSTOM_WELCOME_TEXT = " Welcome to this test"
809
804
private const val BRANDED_APP_NAME = " BrandedAppName"
810
805
}
0 commit comments