fix(account): route login landing to dashboard

This commit is contained in:
sechmachine
2026-08-15 01:22:21 +07:00
parent a18d8e1d3d
commit c4656a8880
4 changed files with 83 additions and 11 deletions
@@ -0,0 +1,78 @@
# Test Evidence: Authenticated dashboard landing
- **Test type:** Web
- **Requirement IDs:** `I1-UI-03, I1-UI-04`
- **Scenario IDs:** `I1-UI-04 authentication integration follow-up`
- **Test class/method:** `com.lab.labtimesheet.feature.account.controller.AuthenticationWebIntegrationTest.projectLoginPageSupportsFailureNormalizedSuccessAndLogout`
- **Implementation commit:** `this milestone commit`
## Protected behavior
Successful database authentication retains the established `/` success target, and an authenticated GET `/` immediately redirects to the shared role-dashboard route `/dashboard` instead of rendering a standalone dead-end page. Login failure, normalized-email authentication, CSRF, and logout remain covered by the same production-shaped flow.
## Test method
MockMvc logs in through the production Spring Security filter chain using a case-and-whitespace variant of the bootstrapped Admin email. It reuses the resulting authenticated session for GET `/` and asserts the redirect target. The same test continues through the production logout handler. PostgreSQL 18.4 backs the account and session authentication setup.
## Hand-derived expected result
The successful form login redirects to `/`. Following that landing URL with the authenticated session returns a 3xx response whose location is `/dashboard`; it does not resolve `home.html`. Logout still redirects to `/login?logout` and clears authentication.
## RED
**Command**
```text
export JAVA_HOME=/opt/homebrew/opt/openjdk@25
export PATH="$JAVA_HOME/bin:/opt/homebrew/opt/node@24/bin:$PATH"
export DOCKER_HOST=unix:///Users/sechmachine/.orbstack/run/docker.sock
./mvnw -Dtest=AuthenticationWebIntegrationTest test
```
**Observed result**
```text
Authenticated GET / invoked HomeController#home and rendered view "home".
Response status was 200; expected a 3xx redirect to /dashboard.
AuthenticationWebIntegrationTest.java:76 expected:<REDIRECTION> but was:<SUCCESSFUL>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
BUILD FAILURE
```
## GREEN
**Command**
```text
export JAVA_HOME=/opt/homebrew/opt/openjdk@25
export PATH="$JAVA_HOME/bin:/opt/homebrew/opt/node@24/bin:$PATH"
export DOCKER_HOST=unix:///Users/sechmachine/.orbstack/run/docker.sock
./mvnw -Dtest=AuthenticationWebIntegrationTest test
```
**Observed result**
```text
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
PostgreSQL: 18.4
```
## Affected suite
**Command and result**
```text
export JAVA_HOME=/opt/homebrew/opt/openjdk@25
export PATH="$JAVA_HOME/bin:/opt/homebrew/opt/node@24/bin:$PATH"
export DOCKER_HOST=unix:///Users/sechmachine/.orbstack/run/docker.sock
./mvnw test
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
PostgreSQL: 18.4
```
## External-test boundaries
The `/dashboard` endpoint and its role-specific content remain owned and tested by Reporting. This test proves only the authenticated platform handoff to that route. It is not a real-browser/accessibility test and does not change dashboard styling, authorization, account activation, or email delivery.
@@ -7,6 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping;
class HomeController { class HomeController {
@GetMapping("/") @GetMapping("/")
String home() { String home() {
return "home"; return "redirect:/dashboard";
} }
} }
-10
View File
@@ -1,10 +0,0 @@
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="utf-8"><title>Lab Timesheet</title></head>
<body>
<main>
<h1>Lab Timesheet</h1>
<form method="post" th:action="@{/logout}"><button type="submit">Sign out</button></form>
</main>
</body>
</html>
@@ -72,6 +72,10 @@ class AuthenticationWebIntegrationTest {
.andReturn(); .andReturn();
var session = (MockHttpSession) login.getRequest().getSession(false); var session = (MockHttpSession) login.getRequest().getSession(false);
mockMvc.perform(get("/").session(session))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/dashboard"));
mockMvc.perform(post("/logout").session(session).with(csrf())) mockMvc.perform(post("/logout").session(session).with(csrf()))
.andExpect(status().is3xxRedirection()) .andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/login?logout")) .andExpect(redirectedUrl("/login?logout"))