feat: switched-on password rules for the hint, named refusals
The system exposes the switched-on admin password rules. mobile-api serves them to signed-in admins and, rate limited, on an exact public route for the first-login screen. Every admin password path now refuses with PASSWORD_RULE naming the first rule broken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
0b201a51ca
commit
5e68478670
15 files changed
+494
-3
No files matched your search
+53
@@ -0,0 +1,53 @@
|
||||
package com.solvway.mobile.api.controller;
|
||||
|
||||
import com.solvway.core.annotation.AppAuth;
|
||||
import com.solvway.mobile.api.service.PasswordRuleHintService;
|
||||
import com.solvway.mobile.api.useraccess.AdminModule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class PasswordRuleControllerTest {
|
||||
|
||||
private final PasswordRuleHintService service = mock(PasswordRuleHintService.class);
|
||||
private final MockMvc mvc = MockMvcBuilders.standaloneSetup(new PasswordRuleController(service)).build();
|
||||
|
||||
private static Method handler(String name) {
|
||||
return Arrays.stream(PasswordRuleController.class.getDeclaredMethods()).filter(m -> m.getName().equals(name)).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminRoute_needsASignedInAdmin_noModule() throws Exception {
|
||||
Method m = handler("adminActive");
|
||||
assertThat(m.getAnnotation(AppAuth.class).skipValidate()).isFalse();
|
||||
assertThat(m.getAnnotation(AdminModule.class).value()).containsExactly(AdminModule.ANY_ADMIN);
|
||||
when(service.active()).thenReturn(List.of(Map.of("param", "INPUT_LENGTH_MIN", "value", "8")));
|
||||
|
||||
mvc.perform(get("/api/admin/password-rules/active")).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].param").value("INPUT_LENGTH_MIN")).andExpect(jsonPath("$[0].value").value("8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicRoute_skipsSignIn_andGoesThroughTheRateLimitedService() throws Exception {
|
||||
assertThat(handler("publicActive").getAnnotation(AppAuth.class).skipValidate()).isTrue();
|
||||
assertThat(handler("publicActive").getAnnotation(AdminModule.class)).isNull();
|
||||
when(service.publicActive()).thenReturn(List.of(Map.of("param", "SPACE_NOT_ALLOWED")));
|
||||
|
||||
mvc.perform(get("/api/public/password-rules")).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].param").value("SPACE_NOT_ALLOWED"));
|
||||
verify(service).publicActive();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user