diff --git a/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/CollectionListRefresherTest.kt b/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/CollectionListRefresherTest.kt
index 83fa34376..7b35f11d3 100644
--- a/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/CollectionListRefresherTest.kt
+++ b/app/src/androidTest/kotlin/at/bitfire/davdroid/servicedetection/CollectionListRefresherTest.kt
@@ -37,19 +37,6 @@ import javax.inject.Inject
@HiltAndroidTest
class CollectionListRefresherTest {
- companion object {
- private const val PATH_CALDAV = "/caldav"
- private const val PATH_CARDDAV = "/carddav"
-
- private const val SUBPATH_PRINCIPAL = "/principal"
- private const val SUBPATH_PRINCIPAL_INACCESSIBLE = "/inaccessible-principal"
- private const val SUBPATH_PRINCIPAL_WITHOUT_COLLECTIONS = "/principal2"
- private const val SUBPATH_ADDRESSBOOK_HOMESET = "/addressbooks-homeset"
- private const val SUBPATH_ADDRESSBOOK_HOMESET_EMPTY = "/addressbooks-homeset-empty"
- private const val SUBPATH_ADDRESSBOOK = "/addressbooks/my-contacts"
- private const val SUBPATH_ADDRESSBOOK_INACCESSIBLE = "/addressbooks/inaccessible-contacts"
- }
-
@get:Rule
var hiltRule = HiltAndroidRule(this)
@@ -100,9 +87,23 @@ class CollectionListRefresherTest {
// Query home sets
refresherFactory.create(service, client.okHttpClient).discoverHomesets(baseUrl)
- // Check home sets have been saved to database
- assertEquals(mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET/"), db.homeSetDao().getByService(service.id).first().url)
- assertEquals(1, db.homeSetDao().getByService(service.id).size)
+ // Check home set has been saved correctly to database
+ val savedHomesets = db.homeSetDao().getByService(service.id)
+ assertEquals(2, savedHomesets.size)
+
+ // Home set from current-user-principal
+ val personalHomeset = savedHomesets[1]
+ assertEquals(mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL/"), personalHomeset.url)
+ assertEquals(service.id, personalHomeset.serviceId)
+ // personal should be true for homesets detected at first query of current-user-principal (Even if they occur in a group principal as well!!!)
+ assertEquals(true, personalHomeset.personal)
+
+ // Home set found in a group principal
+ val groupHomeset = savedHomesets[0]
+ assertEquals(mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_NON_PERSONAL/"), groupHomeset.url)
+ assertEquals(service.id, groupHomeset.serviceId)
+ // personal should be false for homesets not detected at the first query of current-user-principal (IE. in groups)
+ assertEquals(false, groupHomeset.personal)
}
@@ -114,7 +115,7 @@ class CollectionListRefresherTest {
// save homeset in DB
val homesetId = db.homeSetDao().insert(
- HomeSet(id=0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(id=0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
// Refresh
@@ -248,7 +249,7 @@ class CollectionListRefresherTest {
// save a homeset in DB
val homesetId = db.homeSetDao().insert(
- HomeSet(id=0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(id=0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
// place collection in DB - as part of the homeset
@@ -482,7 +483,7 @@ class CollectionListRefresherTest {
url = mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/")
)
val homesets = listOf(
- HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -506,7 +507,7 @@ class CollectionListRefresherTest {
url = mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/")
)
val homesets = listOf(
- HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -531,7 +532,7 @@ class CollectionListRefresherTest {
url = url
)
val homesets = listOf(
- HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -555,7 +556,7 @@ class CollectionListRefresherTest {
url = mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/")
)
val homesets = listOf(
- HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, false, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -579,7 +580,7 @@ class CollectionListRefresherTest {
url = mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK/")
)
val homesets = listOf(
- HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -604,7 +605,7 @@ class CollectionListRefresherTest {
url = collectionUrl
)
val homesets = listOf(
- HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET"))
+ HomeSet(0, service.id, true, mockServer.url("$PATH_CARDDAV$SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL"))
)
val refresher = refresherFactory.create(service, client.okHttpClient)
@@ -620,6 +621,20 @@ class CollectionListRefresherTest {
return db.serviceDao().get(serviceId)
}
+ companion object {
+ private const val PATH_CALDAV = "/caldav"
+ private const val PATH_CARDDAV = "/carddav"
+
+ private const val SUBPATH_PRINCIPAL = "/principal"
+ private const val SUBPATH_PRINCIPAL_INACCESSIBLE = "/inaccessible-principal"
+ private const val SUBPATH_PRINCIPAL_WITHOUT_COLLECTIONS = "/principal2"
+ private const val SUBPATH_GROUPPRINCIPAL_0 = "/groups/0"
+ private const val SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL = "/addressbooks-homeset"
+ private const val SUBPATH_ADDRESSBOOK_HOMESET_NON_PERSONAL = "/addressbooks-homeset-non-personal"
+ private const val SUBPATH_ADDRESSBOOK_HOMESET_EMPTY = "/addressbooks-homeset-empty"
+ private const val SUBPATH_ADDRESSBOOK = "/addressbooks/my-contacts"
+ private const val SUBPATH_ADDRESSBOOK_INACCESSIBLE = "/addressbooks/inaccessible-contacts"
+ }
class TestDispatcher(
private val logger: Logger
@@ -640,8 +655,11 @@ class CollectionListRefresherTest {
"" +
"Mr. Wobbles" +
"" +
- " ${PATH_CARDDAV}${SUBPATH_ADDRESSBOOK_HOMESET}" +
- ""
+ " ${PATH_CARDDAV}${SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL}" +
+ "" +
+ "" +
+ " ${PATH_CARDDAV}${SUBPATH_GROUPPRINCIPAL_0}" +
+ ""
PATH_CARDDAV + SUBPATH_PRINCIPAL_WITHOUT_COLLECTIONS ->
"" +
@@ -649,8 +667,16 @@ class CollectionListRefresherTest {
"" +
"Mr. Wobbles Jr."
+ PATH_CARDDAV + SUBPATH_GROUPPRINCIPAL_0 ->
+ "" +
+ "All address books" +
+ "" +
+ " ${PATH_CARDDAV}${SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL}" +
+ " ${PATH_CARDDAV}${SUBPATH_ADDRESSBOOK_HOMESET_NON_PERSONAL}" +
+ ""
+
PATH_CARDDAV + SUBPATH_ADDRESSBOOK,
- PATH_CARDDAV + SUBPATH_ADDRESSBOOK_HOMESET ->
+ PATH_CARDDAV + SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL ->
"" +
" " +
" " +
@@ -661,6 +687,17 @@ class CollectionListRefresherTest {
" ${PATH_CARDDAV + SUBPATH_PRINCIPAL}" +
""
+ PATH_CARDDAV + SUBPATH_ADDRESSBOOK_HOMESET_NON_PERSONAL ->
+ "" +
+ " " +
+ " " +
+ "" +
+ "Freds Contacts (not mine)" +
+ "Not personal contacts" +
+ "" +
+ " ${PATH_CARDDAV + SUBPATH_PRINCIPAL}" + // OK, user is allowed to own non-personal contacts
+ ""
+
PATH_CALDAV + SUBPATH_PRINCIPAL ->
"" +
" urn:unknown-entry" +
@@ -676,7 +713,7 @@ class CollectionListRefresherTest {
var responseBody = ""
var responseCode = 207
when (path) {
- PATH_CARDDAV + SUBPATH_ADDRESSBOOK_HOMESET ->
+ PATH_CARDDAV + SUBPATH_ADDRESSBOOK_HOMESET_PERSONAL ->
responseBody =
"" +
"" +