Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
blockvote committed Jun 3, 2024
1 parent 37e019b commit 23fd359
Show file tree
Hide file tree
Showing 12 changed files with 681 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.Test

class APIGatewayProxyEventExtensionsTest {

@Test
fun `should add location header`() {
val request = GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "http")
.withHeader("X-Forwarded-Port", "8080")
val request =
GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "http")
.withHeader("X-Forwarded-Port", "8080")

val response = APIGatewayProxyResponseEvent()
.withLocationHeader(request, "/some/path")
val response =
APIGatewayProxyResponseEvent()
.withLocationHeader(request, "/some/path")

then(response.location()).isEqualTo("http://example.com:8080/some/path")
}
Expand All @@ -40,18 +41,20 @@ class APIGatewayProxyEventExtensionsTest {
fun `should add location header with default host and proto and without port`() {
val request = GET()

val response = APIGatewayProxyResponseEvent()
.withLocationHeader(request, "/some/path")
val response =
APIGatewayProxyResponseEvent()
.withLocationHeader(request, "/some/path")

then(response.location()).isEqualTo("http://localhost/some/path")
}

@Test
fun `should omit default https port`() {
val request = GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "https")
.withHeader("X-Forwarded-Port", "443")
val request =
GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "https")
.withHeader("X-Forwarded-Port", "443")

val location = request.location("some/path")

Expand All @@ -60,10 +63,11 @@ class APIGatewayProxyEventExtensionsTest {

@Test
fun `should omit default http port`() {
val request = GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "http")
.withHeader("X-Forwarded-Port", "80")
val request =
GET()
.withHeader("Host", "example.com")
.withHeader("X-Forwarded-Proto", "http")
.withHeader("X-Forwarded-Port", "80")

val location = request.location("/some/path")

Expand Down
1 change: 0 additions & 1 deletion router/src/test/kotlin/io/moia/router/ApiRequestTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
import org.junit.jupiter.api.Test

class ApiRequestTest {

@Test
fun `should match header`() {
val request = APIGatewayProxyRequestEvent().withHeaders(mapOf("Accept" to "application/json"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class JsonDeserializationHandlerTest {

val deserializationHandler = JsonDeserializationHandler(jacksonObjectMapper())

@Test
fun `should support json`() {
assertTrue(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/json")
)
.withHeader("content-type", "application/json"),
),
)
assertTrue(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/vnd.moia.v1+json")
)
.withHeader("content-type", "application/vnd.moia.v1+json"),
),
)
}

Expand All @@ -47,14 +46,14 @@ class JsonDeserializationHandlerTest {
assertFalse(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "image/png")
)
.withHeader("content-type", "image/png"),
),
)
assertFalse(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "text/plain")
)
.withHeader("content-type", "text/plain"),
),
)
}

Expand All @@ -63,14 +62,14 @@ class JsonDeserializationHandlerTest {
assertTrue(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/json; charset=UTF-8")
)
.withHeader("content-type", "application/json; charset=UTF-8"),
),
)
assertTrue(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/vnd.moia.v1+json; charset=UTF-8")
)
.withHeader("content-type", "application/vnd.moia.v1+json; charset=UTF-8"),
),
)
}

Expand All @@ -79,14 +78,14 @@ class JsonDeserializationHandlerTest {
assertFalse(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/json; charset=UTF-16")
)
.withHeader("content-type", "application/json; charset=UTF-16"),
),
)
assertFalse(
deserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/vnd.moia.v1+json; charset=UTF-16")
)
.withHeader("content-type", "application/vnd.moia.v1+json; charset=UTF-16"),
),
)
}
}
26 changes: 14 additions & 12 deletions router/src/test/kotlin/io/moia/router/JwtPermissionHandlerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.Test

@Suppress("ktlint:standard:max-line-length")
class JwtPermissionHandlerTest {

/*
{
"sub": "1234567890",
"name": "John Doe",
"iat": 1516239022,
"scope": "one two"
}
*/
*/
val jwtWithScopeClaimSpace = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJzY29wZSI6Im9uZSB0d28ifQ.2tPrDymXDejHfVjNlVh4XUj22ZuDrKHP6dvWN7JNAWY"

/*
Expand Down Expand Up @@ -58,14 +58,16 @@ class JwtPermissionHandlerTest {

@Test
fun `should extract permissions from custom permissions claim`() {
val handler = JwtPermissionHandler(
accessor = JwtAccessor(
APIGatewayProxyRequestEvent()
.withHeader("Authorization", jwtWithCustomClaimAndSeparator)
),
permissionsClaim = "userRights",
permissionSeparator = ","
)
val handler =
JwtPermissionHandler(
accessor =
JwtAccessor(
APIGatewayProxyRequestEvent()
.withHeader("Authorization", jwtWithCustomClaimAndSeparator),
),
permissionsClaim = "userRights",
permissionSeparator = ",",
)

thenRecognizesRequiredPermissions(handler)
}
Expand Down Expand Up @@ -103,7 +105,7 @@ class JwtPermissionHandlerTest {
JwtPermissionHandler(
JwtAccessor(
APIGatewayProxyRequestEvent()
.withHeader("Authorization", authHeader)
)
.withHeader("Authorization", authHeader),
),
)
}
1 change: 0 additions & 1 deletion router/src/test/kotlin/io/moia/router/MediaTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.Test

class MediaTypeTest {

@Test
fun `should match`() {
then(MediaType.parse("application/json").isCompatibleWith(MediaType.parse("application/json"))).isTrue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.Test

class NoOpPermissionHandlerTest {

@Test
fun `should always return true`() {
val handler = NoOpPermissionHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class PlainTextDeserializationHandlerTest {

@Test
fun `should support text`() {
assertTrue(
PlainTextDeserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "text/plain")
)
.withHeader("content-type", "text/plain"),
),
)
assertTrue(
PlainTextDeserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "text/csv")
)
.withHeader("content-type", "text/csv"),
),
)
}

Expand All @@ -45,14 +44,14 @@ class PlainTextDeserializationHandlerTest {
assertFalse(
PlainTextDeserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "image/png")
)
.withHeader("content-type", "image/png"),
),
)
assertFalse(
PlainTextDeserializationHandler.supports(
APIGatewayProxyRequestEvent()
.withHeader("content-type", "application/json")
)
.withHeader("content-type", "application/json"),
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class PlainTextSerializationHandlerTest {

@Test
fun `should support text`() {
assertTrue(PlainTextSerializationHandler().supports(MediaType.parse("text/plain"), "some"))
Expand Down

0 comments on commit 23fd359

Please sign in to comment.