Skip to content

Commit f118733

Browse files
committed
fix ktor client tests
1 parent 80ccc0d commit f118733

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

kotlin-http-client/kotlin-http-client-ktor/src/main/kotlin/com/linkedplanet/kotlinhttpclient/ktor/KtorHttpClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class KtorHttpClient(
141141
}
142142
) {
143143
url("$baseUrl$url")
144+
header("X-Atlassian-Token", "no-check")
144145
header("Connection", "keep-alive")
145146
header("Cache-Control", "no-cache")
146147
}

kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/AuthenticatedJiraHttpClientFactory.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
package com.linkedplanet.kotlininsightclient
2121

2222
import arrow.core.Either
23-
import arrow.core.left
2423
import arrow.core.right
2524
import com.google.gson.Gson
26-
import com.linkedplanet.kotlininsightclient.api.error.AuthenticationError
2725
import com.linkedplanet.kotlininsightclient.api.error.InsightClientError
2826
import org.http4k.client.Java8HttpClient
2927
import org.http4k.core.Body
@@ -36,6 +34,7 @@ import org.http4k.core.then
3634
import org.http4k.filter.ClientFilters
3735
import org.http4k.filter.cookie.BasicCookieStorage
3836
import org.http4k.filter.cookie.CookieStorage
37+
import java.util.*
3938

4039
/**
4140
* Provides access to Jira itself via a logged in AuthenticatedHttpHandler
@@ -51,26 +50,29 @@ class AuthenticatedJiraHttpClientFactory(
5150
private val httpHandler: HttpHandler = ClientFilters.Cookies(storage = storage).then(Java8HttpClient())
5251
private val gson = Gson()
5352

54-
fun login(credentials: Credentials) : Either<InsightClientError, AuthenticatedHttpHandler> {
53+
fun login(credentials: Credentials): Either<InsightClientError, AuthenticatedHttpHandler> {
54+
val username = credentials.username
55+
val password = credentials.password
5556
val body = gson.toJson(credentials)
5657
val request = Request(Method.POST, "$jiraOrigin/rest/auth/1/session")
5758
.header("content-type", "application/json")
5859
.body(Body(body))
59-
6060
val loginResponse = httpHandler(request)
6161
if (loginResponse.status != Status.OK) {
62-
return AuthenticationError(
63-
"Login failed with HTTP StatusCode:${loginResponse.status.code}"
64-
).left()
65-
} else {
66-
val privateHandler = object : AuthenticatedHttpHandler, HttpHandler by httpHandler {
67-
override fun getWithRelativePath(path: String): Response {
68-
val absolutePath = "$jiraOrigin$path"
69-
return this(Request(Method.GET, absolutePath))
70-
}
62+
println("Continue despite 'session' login failing with HTTP StatusCode:${loginResponse.status.code}")
63+
}
64+
val privateHandler = object : AuthenticatedHttpHandler, HttpHandler by httpHandler {
65+
override fun getWithRelativePath(path: String): Response {
66+
val absolutePath = "$jiraOrigin$path"
67+
val getRequest = Request(Method.GET, absolutePath)
68+
.header(
69+
"Authorization",
70+
"Basic ${Base64.getEncoder().encodeToString("$username:$password".toByteArray())}"
71+
)
72+
return this(getRequest)
7173
}
72-
return privateHandler.right()
7374
}
75+
return privateHandler.right()
7476
}
7577
}
7678

kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightObjectOperatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ interface InsightObjectOperatorTest {
266266
name = "testObjectWithAllDefaultTypes",
267267
testBoolean = false,
268268
testInteger = 72,
269-
testFloat = 3.12345678901234, // only double precision does survive this roundtrip
269+
testFloat = 3.123456789012, // A longer number does not survice the official REST calls
270270
testDate = LocalDate.parse("1984-04-01"),
271271
testDateTime = ZonedDateTime.parse("1983-12-07T14:55:24Z"),
272272
testUrl = setOf("http://127.0.0.1", "http://localhost"),

0 commit comments

Comments
 (0)