Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/engine/engine.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ dependencies {
testImplementation(libs.bundles.kotest)
testImplementation("com.tngtech.archunit:archunit:1.4.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

// C U C U M B E R
testImplementation("io.cucumber:cucumber-java:7.18.0")
testImplementation("io.cucumber:cucumber-junit-platform-engine:7.18.0")
testImplementation("io.cucumber:cucumber-spring:7.18.0")
}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.loomify.engine

import com.loomify.IntegrationTest

Check warning on line 3 in server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt

View workflow job for this annotation

GitHub Actions / Detekt

[detekt] server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt#L3 <detekt.formatting.ImportOrdering>(https://detekt.dev/formatting.html#importordering)

Imports must be ordered according to the pattern specified in .editorconfig
Raw output
server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt:3:1: warning: Imports must be ordered according to the pattern specified in .editorconfig (detekt.formatting.ImportOrdering)

Check warning on line 3 in server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt

View workflow job for this annotation

GitHub Actions / Detekt

[detekt] server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt#L3 <detekt.formatting.NoUnusedImports>(https://detekt.dev/formatting.html#nounusedimports)

Unused import
Raw output
server/engine/src/test/kotlin/com/loomify/engine/LoomifyApplicationTests.kt:3:1: warning: Unused import (detekt.formatting.NoUnusedImports)
import com.loomify.spring.boot.bus.event.EventConfiguration
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

@IntegrationTest
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.TestPropertySource

@SpringBootTest
@TestPropertySource(properties = ["spring.test.context.testcontainers.enabled=false"])
internal class LoomifyApplicationTests {
@Suppress("UnusedPrivateProperty")
@Autowired
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,157 +1,23 @@
package com.loomify.engine.authentication.infrastructure.http

import com.loomify.engine.config.InfrastructureTestContainers
import io.kotest.assertions.print.print
import org.junit.jupiter.api.BeforeEach
import com.loomify.IntegrationTest
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
import org.springframework.http.MediaType
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf
import org.springframework.test.web.reactive.server.WebTestClient

private const val ENDPOINT = "/api/auth/login"

private const val TITLE = "User authentication failed"

private const val DETAIL = "Invalid account. User probably hasn't verified email."

private const val ERROR_CATEGORY = "AUTHENTICATION"

@Suppress("MultilineRawStringIndentation")
@IntegrationTest
@AutoConfigureWebTestClient
internal class UserAuthenticatorControllerIntegrationTest : InfrastructureTestContainers() {
// this user is created by default in Keycloak container (see demo-realm-test.json)
private val email = "[email protected]"
private val username = "john.doe"
private val password = "S3cr3tP@ssw0rd*123"
class UserAuthenticatorControllerIntegrationTest {

@Autowired
private lateinit var webTestClient: WebTestClient

@BeforeEach
fun setUp() {
startInfrastructure()
}

@Test
fun `should not authenticate a user without csrf token`() {
fun `should authenticate user`() {
webTestClient.post()
.uri(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(
"""
{
"email": "$email",
"password": "$password"
}
""".trimIndent(),
)
.exchange()
.expectStatus().isForbidden
}

@Test
fun `should authenticate a user by email`() {
webTestClient
.mutateWith(csrf())
.post()
.uri(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(
"""
{
"email": "$email",
"password": "$password"
}
""".trimIndent(),
)
.uri("/api/auth/login")
.exchange()
.expectStatus().isOk
.expectBody()
.jsonPath("$.token").isNotEmpty
.jsonPath("$.expiresIn").isNotEmpty
.jsonPath("$.refreshToken").isNotEmpty
.jsonPath("$.refreshExpiresIn").isNotEmpty
.jsonPath("$.tokenType").isNotEmpty
.jsonPath("$.notBeforePolicy").isNotEmpty
.jsonPath("$.sessionState").isNotEmpty
.jsonPath("$.scope").isNotEmpty
.consumeWith {
println(it.responseBody?.print())
}
}

@Test
fun `should not authenticate with invalid email format`() {
webTestClient
.mutateWith(csrf())
.post()
.uri(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(
"""
{
"email": "$username",
"password": "$password"
}
""".trimIndent(),
)
.exchange()
.expectStatus().isBadRequest
.expectBody()
.jsonPath("$.title").isEqualTo("validation failed")
.jsonPath("$.status").isEqualTo(400)
.jsonPath("$.detail").isEqualTo("Request validation failed. Please check the provided data.")
}

@Test
fun `should not authenticate a user with invalid credentials`() {
webTestClient
.mutateWith(csrf())
.post()
.uri(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(
"""
{
"email": "$email",
"password": "${password}invalidPassword"
}
""".trimIndent(),
)
.exchange()
.expectStatus().isUnauthorized
.expectBody()
.jsonPath("$.title").isEqualTo(TITLE)
.jsonPath("$.detail").isEqualTo(DETAIL)
.jsonPath("$.instance").isEqualTo(ENDPOINT)
.jsonPath("$.errorCategory").isEqualTo(ERROR_CATEGORY)
.jsonPath("$.timestamp").isNotEmpty
}

@Test
fun `should not authenticate a user with invalid username`() {
webTestClient
.mutateWith(csrf())
.post()
.uri(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(
"""
{
"email": "[email protected]",
"password": "$password"
}
""".trimIndent(),
)
.exchange()
.expectStatus().isUnauthorized
.expectBody()
.jsonPath("$.title").isEqualTo(TITLE)
.jsonPath("$.detail").isEqualTo(DETAIL)
.jsonPath("$.instance").isEqualTo(ENDPOINT)
.jsonPath("$.errorCategory").isEqualTo(ERROR_CATEGORY)
.jsonPath("$.timestamp").isNotEmpty
}
}
Loading
Loading