mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge pull request #555 from owncloud/feature/auth_webfinger_flow
Update WebFinger flow
This commit is contained in:
commit
602ab41fcc
@ -75,13 +75,17 @@ class GetInstancesViaWebFingerOperation(
|
|||||||
val response = parseResponse(rawResponse)
|
val response = parseResponse(rawResponse)
|
||||||
Timber.d("Successful WebFinger request: $response")
|
Timber.d("Successful WebFinger request: $response")
|
||||||
val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK)
|
val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK)
|
||||||
operationResult.data = response.links.map { it.href }
|
operationResult.data = response.links?.map { it.href } ?: listOf()
|
||||||
return operationResult
|
return operationResult
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> {
|
||||||
val requestUri = buildRequestUri()
|
val requestUri = buildRequestUri()
|
||||||
val getMethod = GetMethod(URL(requestUri.toString()))
|
val getMethod = GetMethod(URL(requestUri.toString()))
|
||||||
|
|
||||||
|
// First iteration won't follow redirections.
|
||||||
|
getMethod.followRedirects = false
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
val response = getMethod.getResponseBodyAsString()!!
|
val response = getMethod.getResponseBodyAsString()!!
|
||||||
|
@ -29,7 +29,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class WebFingerResponse(
|
data class WebFingerResponse(
|
||||||
val subject: String,
|
val subject: String,
|
||||||
val links: List<LinkItem>
|
val links: List<LinkItem>?
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
|
@ -22,20 +22,20 @@ class WebFingerResponseTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `check rel in too much information - ok`() {
|
fun `check rel in too much information - ok`() {
|
||||||
val response = loadResponses(TOO_MUCH_INFORMATION_JSON)!!
|
val response = loadResponses(TOO_MUCH_INFORMATION_JSON)!!
|
||||||
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
|
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href)
|
||||||
Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links[0].rel)
|
Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links!![0].rel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JsonDataException::class)
|
@Test(expected = JsonDataException::class)
|
||||||
fun `check key value pairs - ko - no href key`() {
|
fun `check key value pairs - ko - no href key`() {
|
||||||
val response = loadResponses(BROKEN_JSON)!!
|
val response = loadResponses(BROKEN_JSON)!!
|
||||||
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
|
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JsonDataException::class)
|
@Test(expected = JsonDataException::class)
|
||||||
fun `check key value pairs - ko - no rel key`() {
|
fun `check key value pairs - ko - no rel key`() {
|
||||||
val response = loadResponses(BROKEN_JSON)!!
|
val response = loadResponses(BROKEN_JSON)!!
|
||||||
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
|
Assert.assertEquals("https://gast.somedomain.de", response.links!![0].href)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user