diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperation.kt new file mode 100644 index 00000000..e74f50b5 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperation.kt @@ -0,0 +1,39 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2022 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.owncloud.android.lib.resources.webfinger + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperation +import com.owncloud.android.lib.common.operations.RemoteOperationResult + +class GetOCInstanceViaWebfingerOperation( + private val rel:String, + private val resource:String +) : RemoteOperation() { + + override fun run(client: OwnCloudClient?): RemoteOperationResult { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponse.kt new file mode 100644 index 00000000..fcf9bf84 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponse.kt @@ -0,0 +1,39 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2022 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.owncloud.android.lib.resources.webfinger.responses + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class WebfingerJrdResponse ( + val subject:String, + val links:List +) + +@JsonClass(generateAdapter = true) +data class LinkItem( + val href:String, + val rel:String +) \ No newline at end of file diff --git a/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt index 3981ab5b..fad1178a 100644 --- a/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt +++ b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt @@ -25,6 +25,7 @@ package com.owncloud.android.lib.resources.shares.responses import com.owncloud.android.lib.resources.CommonOcsResponse +import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.Types diff --git a/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperationTest.kt b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperationTest.kt new file mode 100644 index 00000000..d4f84a83 --- /dev/null +++ b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperationTest.kt @@ -0,0 +1,11 @@ +package com.owncloud.android.lib.resources.webfinger + +import android.os.Build +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [Build.VERSION_CODES.O], manifest = Config.NONE) +class GetOCInstanceViaWebfingerOperationTest { +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponseTest.kt b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponseTest.kt new file mode 100644 index 00000000..9704326a --- /dev/null +++ b/owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/webfinger/responses/WebfingerResponseTest.kt @@ -0,0 +1,51 @@ +package com.owncloud.android.lib.resources.webfinger.responses + +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonDataException +import com.squareup.moshi.Moshi +import org.junit.Assert +import org.junit.Assert.assertThrows +import org.junit.Before +import org.junit.Test +import java.io.File + +class WebfingerResponseTest { + lateinit var adapter: JsonAdapter + + private fun loadResponses(fileName: String) = + adapter.fromJson(File(fileName).readText()) + + @Before + fun prepare() { + val moshi = Moshi.Builder().build() + adapter = moshi.adapter(WebfingerJrdResponse::class.java) + } + + @Test + fun `check rel in to much information - ok - correct rell is returned`() { + val response = loadResponses(TO_MUCH_INFORMATION_JSON)!! + Assert.assertEquals("https://gast.somedomain.de", response.links[0].href) + Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links[0].rel) + } + + @Test(expected = JsonDataException::class) + fun `check key value pairs - ko - no href key`() { + val response = loadResponses(BROKEN_JSON)!! + Assert.assertEquals("https://gast.somedomain.de", response.links[0].href) + } + + @Test(expected = JsonDataException::class) + fun `check key value pairs - ko - no rel key`() { + val response = loadResponses(BROKEN_JSON)!! + Assert.assertEquals("https://gast.somedomain.de", response.links[0].href) + } + + companion object { + val RESOURCES_PATH = + "src/test/responses/com.owncloud.android.lib.resources.webfinger.responses" + val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/simple_response.json" + val TO_MUCH_INFORMATION_JSON = "$RESOURCES_PATH/to_much_information_response.json" + val BROKEN_JSON = "$RESOURCES_PATH/broken_response.json" + val NOT_CONTAINING_RELEVANT_INFORMATION_JSON = "$RESOURCES_PATH/not_containing_relevant_info_response.json" + } +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/broken_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/broken_response.json new file mode 100644 index 00000000..85dd2279 --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/broken_response.json @@ -0,0 +1,15 @@ +{ + "subject": "acct:bob@example.com", + "aliases": [ + "https://www.example.com/~bob/" + ], + "properties": { + "http://example.com/ns/role": "employee" + }, + "links": [ + { + "lel": "http://webfinger.example/rel/profile-page", + "foo": "https://www.example.com/~bob/" + } + ] +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/not_containing_releavant_info_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/not_containing_releavant_info_response.json new file mode 100644 index 00000000..cae2ae74 --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/not_containing_releavant_info_response.json @@ -0,0 +1,10 @@ +{ + "subject": "acct:peter.sine@gurken.xxx", + "links" : + [ + { + "rel" : "http://webfinger.example/rel/businesscard", + "href" : "https://www.example.com/~bob/bob.vcf" + } + ] +} \ No newline at end of file diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/simple_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/simple_response.json new file mode 100644 index 00000000..a7e18f2c --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/simple_response.json @@ -0,0 +1,9 @@ +{ + "links": [ + { + "href": "https://gast.somedomain.de", + "rel": "http://webfinger.owncloud/rel/server-instance" + } + ], + "subject": "acct:peter.sine@gurken.xxx" +} diff --git a/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/to_much_information_response.json b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/to_much_information_response.json new file mode 100644 index 00000000..be02c6ad --- /dev/null +++ b/owncloudComLibrary/src/test/responses/com.owncloud.android.lib.resources.webfinger.responses/to_much_information_response.json @@ -0,0 +1,27 @@ +{ + "subject": "acct:peter.sine@gurken.xxx", + "aliases" : + [ + "https://www.example.com/~bob/" + ], + "properties" : + { + "http://example.com/ns/role" : "employee" + }, + "gurken": { + "whatever": 42 + }, + "links" : + [ + { + "gurken": "sallat", + "href": "https://gast.somedomain.de", + "rel": "http://webfinger.owncloud/rel/server-instance" + }, + { + "gurken": "sallat", + "rel" : "http://webfinger.example/rel/businesscard", + "href" : "https://www.example.com/~bob/bob.vcf" + } + ] +} \ No newline at end of file