Skip to content

Commit

Permalink
used topinambur basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Coser committed Mar 23, 2020
1 parent c54f7fd commit caced7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.5.2"
testImplementation "net.wuerl.kotlin:assertj-core-kotlin:0.2.1"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
testImplementation "com.github.DaikonWeb:topinambur:1.1.3"
testImplementation "com.github.DaikonWeb:topinambur:1.2.3"
}

test {
Expand Down
16 changes: 5 additions & 11 deletions src/test/kotlin/daikon/BasicAuthenticationHttpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import daikon.core.HttpStatus.OK_200
import daikon.core.HttpStatus.UNAUTHORIZED_401
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import topinambur.Basic
import topinambur.http
import java.nio.charset.StandardCharsets.UTF_8
import java.util.*

class BasicAuthenticationHttpTest {

Expand All @@ -33,7 +32,7 @@ class BasicAuthenticationHttpTest {
.get("/") { _, res -> res.status(OK_200)}
.start().use {
assertThat(local("/").http.get().statusCode).isEqualTo(UNAUTHORIZED_401)
assertThat(local("/").http.get(headers = basicAuth("Marco", "secret")).statusCode).isEqualTo(OK_200)
assertThat(local("/").http.get(auth = Basic("Marco", "secret")).statusCode).isEqualTo(OK_200)
}
}

Expand All @@ -44,8 +43,8 @@ class BasicAuthenticationHttpTest {
.basicAuth("/")
.get("/") { _, res -> res.status(OK_200)}
.start().use {
assertThat(local("/").http.get(headers = basicAuth("Marco", "wrong")).statusCode).isEqualTo(UNAUTHORIZED_401)
assertThat(local("/").http.get(headers = basicAuth("wrong", "secret")).statusCode).isEqualTo(UNAUTHORIZED_401)
assertThat(local("/").http.get(auth = Basic("Marco", "wrong")).statusCode).isEqualTo(UNAUTHORIZED_401)
assertThat(local("/").http.get(auth = Basic("wrong", "secret")).statusCode).isEqualTo(UNAUTHORIZED_401)
}
}

Expand All @@ -56,12 +55,7 @@ class BasicAuthenticationHttpTest {
.basicAuth("/")
.get("/") { _, res -> res.status(OK_200)}
.start().use {
assertThat(local("/").http.get(headers = basicAuth("ìù", "èéàò")).statusCode).isEqualTo(OK_200)
assertThat(local("/").http.get(auth = Basic("ìù", "èéàò")).statusCode).isEqualTo(OK_200)
}
}

private fun basicAuth(user: String, password: String): Map<String, String> {
val base64 = String(Base64.getEncoder().encode("$user:$password".toByteArray()), UTF_8)
return mapOf("Authorization" to "Basic $base64")
}
}

0 comments on commit caced7f

Please sign in to comment.