@@ -26,39 +26,68 @@ package com.owncloud.android.lib
26
26
27
27
import com.owncloud.android.lib.resources.status.StatusRequester
28
28
import org.junit.Assert.assertEquals
29
+ import org.junit.Assert.assertFalse
30
+ import org.junit.Assert.assertTrue
29
31
import org.junit.Test
30
32
31
33
class StatusRequestorTest {
32
- private val requestor = StatusRequester ()
34
+ private val requester = StatusRequester ()
33
35
34
36
@Test
35
37
fun `update location - ok - absolute path` () {
36
- val newLocation = requestor .updateLocationWithRedirectPath(TEST_DOMAIN , " $TEST_DOMAIN$SUB_PATH " )
38
+ val newLocation = requester .updateLocationWithRedirectPath(TEST_DOMAIN , " $TEST_DOMAIN$SUB_PATH " )
37
39
assertEquals(" $TEST_DOMAIN$SUB_PATH " , newLocation)
38
40
}
39
41
40
42
@Test
41
43
fun `update location - ok - smaller absolute path` () {
42
- val newLocation = requestor .updateLocationWithRedirectPath(" $TEST_DOMAIN$SUB_PATH " , TEST_DOMAIN )
44
+ val newLocation = requester .updateLocationWithRedirectPath(" $TEST_DOMAIN$SUB_PATH " , TEST_DOMAIN )
43
45
assertEquals(TEST_DOMAIN , newLocation)
44
46
}
45
47
46
48
@Test
47
49
fun `update location - ok - relative path` () {
48
- val newLocation = requestor .updateLocationWithRedirectPath(TEST_DOMAIN , SUB_PATH )
50
+ val newLocation = requester .updateLocationWithRedirectPath(TEST_DOMAIN , SUB_PATH )
49
51
assertEquals(" $TEST_DOMAIN$SUB_PATH " , newLocation)
50
52
}
51
53
52
54
@Test
53
55
fun `update location - ok - replace relative path` () {
54
- val newLocation = requestor .updateLocationWithRedirectPath(
56
+ val newLocation = requester .updateLocationWithRedirectPath(
55
57
" $TEST_DOMAIN /some/other/subdir" , SUB_PATH
56
58
)
57
59
assertEquals(" $TEST_DOMAIN$SUB_PATH " , newLocation)
58
60
}
59
61
62
+ @Test
63
+ fun `check redirect to unsecure connection - ok - redirect to http` () {
64
+ assertTrue(requester.isRedirectedToNonSecureConnection(
65
+ false , SECURE_DOMAIN , UNSECURE_DOMAIN ))
66
+ }
67
+
68
+ @Test
69
+ fun `check redirect to unsecure connection - ko - redirect to https from http` () {
70
+ assertFalse(requester.isRedirectedToNonSecureConnection(
71
+ false , UNSECURE_DOMAIN , SECURE_DOMAIN ))
72
+ }
73
+
74
+ @Test
75
+ fun `check redirect to unsecure connection - ko - from https to https` () {
76
+ assertFalse(requester.isRedirectedToNonSecureConnection(
77
+ false , SECURE_DOMAIN , SECURE_DOMAIN ))
78
+ }
79
+
80
+ @Test
81
+ fun `check redirect to unsecure connection - ok - from https to https with previous http` () {
82
+ assertTrue(requester.isRedirectedToNonSecureConnection(
83
+ true , SECURE_DOMAIN , SECURE_DOMAIN ))
84
+ }
85
+
60
86
companion object {
61
87
const val TEST_DOMAIN = " https://cloud.somewhere.com"
62
88
const val SUB_PATH = " /subdir"
89
+
90
+ const val SECURE_DOMAIN = " https://cloud.somewhere.com"
91
+ const val UNSECURE_DOMAIN = " http://somewhereelse.org"
63
92
}
64
93
}
0 commit comments