-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/kotlin/com/vauthenticator/server/login/workflow/LoginWorkflowEngineTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.vauthenticator.server.login.workflow | ||
|
||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.just | ||
import io.mockk.runs | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpSession | ||
import org.junit.jupiter.api.Assertions.assertSame | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class LoginWorkflowEngineTest { | ||
|
||
@MockK | ||
lateinit var defaultSuccessHandler: AuthenticationSuccessHandler | ||
|
||
@MockK | ||
lateinit var firstLoginWorkflowHandler: LoginWorkflowHandler | ||
|
||
@MockK | ||
lateinit var secondLoginWorkflowHandler: LoginWorkflowHandler | ||
|
||
@MockK | ||
lateinit var session: HttpSession | ||
|
||
@MockK | ||
lateinit var request: HttpServletRequest | ||
|
||
@Test | ||
fun `when a login workflow runs`() { | ||
val loginWorkflowHandlers = listOf( | ||
firstLoginWorkflowHandler, | ||
secondLoginWorkflowHandler | ||
) | ||
|
||
every { session.getAttribute("CompositeLoginWorkflowEngine_index") } returns 0 andThen 1 andThen 2 | ||
every { session.setAttribute("CompositeLoginWorkflowEngine_index", 1) } just runs | ||
every { session.setAttribute("CompositeLoginWorkflowEngine_index", 2) } just runs | ||
|
||
val uut = CompositeLoginWorkflowEngine(loginWorkflowHandlers, defaultSuccessHandler) | ||
|
||
assertSame(firstLoginWorkflowHandler, uut.workflowsNextHop(session)) | ||
assertSame(secondLoginWorkflowHandler, uut.workflowsNextHop(session)) | ||
assertSame(DefaultLoginWorkflowHandler, uut.workflowsNextHop(session)) | ||
} | ||
} |