fix(platform): address round 2 review findings

This commit is contained in:
sechmachine
2026-08-15 03:13:12 +07:00
parent 98688dec7e
commit 06dba4fb13
11 changed files with 329 additions and 13 deletions
@@ -0,0 +1,21 @@
package com.lab.labtimesheet.config;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.Clock;
import java.time.Instant;
import java.time.LocalDate;
import org.junit.jupiter.api.Test;
class TimeConfigurationTest {
@Test
void utcInstantAtVietnamMidnightUsesTheNewLocalBusinessDate() {
Clock applicationClock = new TimeConfiguration().applicationClock();
Instant vietnamMidnight = Instant.parse("2026-08-14T17:00:00Z");
LocalDate businessDate = LocalDate.now(Clock.fixed(vietnamMidnight, applicationClock.getZone()));
assertThat(businessDate).isEqualTo(LocalDate.of(2026, 8, 15));
}
}
@@ -176,6 +176,37 @@ class AccountWebIntegrationTest {
.andExpect(content().string(org.hamcrest.Matchers.containsString("Duplicate Mentor")));
}
@Test
void duplicateNormalizedStudentCodeIsReportedOnStudentCodeRatherThanEmail() throws Exception {
mockMvc.perform(post("/admin/accounts")
.with(user("admin@example.com").roles("ADMIN"))
.with(csrf())
.param("email", "first-intern@example.com")
.param("displayName", "First Intern")
.param("role", "INTERN")
.param("studentCode", "STU-ROUND-2")
.param("internshipStart", "2026-08-01")
.param("internshipEnd", "2026-12-31"))
.andExpect(status().is3xxRedirection());
mockMvc.perform(post("/admin/accounts")
.with(user("admin@example.com").roles("ADMIN"))
.with(csrf())
.param("email", "second-intern@example.com")
.param("displayName", "Second Intern")
.param("role", "INTERN")
.param("studentCode", " stu-round-2 ")
.param("internshipStart", "2026-08-01")
.param("internshipEnd", "2026-12-31"))
.andExpect(status().isOk())
.andExpect(view().name("accounts/new"))
.andExpect(content().string(org.hamcrest.Matchers.containsString(
"An Intern with this student code already exists")))
.andExpect(content().string(org.hamcrest.Matchers.not(
org.hamcrest.Matchers.containsString("this email already exists"))))
.andExpect(content().string(org.hamcrest.Matchers.containsString("Second Intern")));
}
@Test
void additionalAdminActivatesAndAuthenticatesWithoutChangingTheFirstAdmin() throws Exception {
mockMvc.perform(post("/admin/accounts")
@@ -157,7 +157,8 @@ class SmtpOnboardingWebIntegrationTest {
.with(user("admin@example.com").roles("ADMIN")))
.andReturn().getResponse().getContentAsString();
String draftId = html.replaceAll("(?s).*name=\"draftId\" value=\"([0-9]+)\".*", "$1");
probe.failureMessage = "Connection refused by the configured SMTP server";
String rawDiagnostic = "AUTH rejected for smtp-secret-raw-diagnostic";
probe.failureMessage = rawDiagnostic;
mockMvc.perform(post("/admin/smtp/test")
.with(user("admin@example.com").roles("ADMIN"))
@@ -166,7 +167,9 @@ class SmtpOnboardingWebIntegrationTest {
.andExpect(status().isOk())
.andExpect(view().name("smtp/form"))
.andExpect(content().string(org.hamcrest.Matchers.containsString(
"Connection refused by the configured SMTP server")))
"SMTP test failed. Verify the draft settings and server availability, then try again.")))
.andExpect(content().string(org.hamcrest.Matchers.not(
org.hamcrest.Matchers.containsString(rawDiagnostic))))
.andExpect(content().string(org.hamcrest.Matchers.not(
org.hamcrest.Matchers.containsString("Activate SMTP"))));
}