From a2249454cffdef3d4a06770bca9b974a776000ae Mon Sep 17 00:00:00 2001 From: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> Date: Sat, 10 Oct 2026 12:44:36 +0800 Subject: [PATCH] test(auth): cover public capabilities for all switch states Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com> --- .../controller/LocalAuthControllerTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/skillhub-app/src/test/java/com/iflytek/skillhub/controller/LocalAuthControllerTest.java b/server/skillhub-app/src/test/java/com/iflytek/skillhub/controller/LocalAuthControllerTest.java index d0fca216..582c02e5 100644 --- a/server/skillhub-app/src/test/java/com/iflytek/skillhub/controller/LocalAuthControllerTest.java +++ b/server/skillhub-app/src/test/java/com/iflytek/skillhub/controller/LocalAuthControllerTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.verify; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +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; @@ -23,6 +24,8 @@ import jakarta.servlet.http.Cookie; import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -68,6 +71,21 @@ class LocalAuthControllerTest { given(localAuthSettingsService.current()).willReturn(new LocalAuthSettings(1L, true, true, 0L, null)); } + @ParameterizedTest + @CsvSource({"true,true,true", "true,false,false", "false,true,false", "false,false,false"}) + void publicCapabilitiesReflectBothSettingsWithoutExposingInternalFields( + boolean passwordLogin, boolean selfRegistration, boolean registrationAvailable) throws Exception { + given(localAuthSettingsService.current()).willReturn( + new LocalAuthSettings(1L, passwordLogin, selfRegistration, 7L, null)); + + mockMvc.perform(get("/api/v1/auth/local/capabilities")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.data.passwordLoginEnabled").value(passwordLogin)) + .andExpect(jsonPath("$.data.selfRegistrationEnabled").value(selfRegistration)) + .andExpect(jsonPath("$.data.registrationAvailable").value(registrationAvailable)) + .andExpect(jsonPath("$.data.version").doesNotExist()); + } + @Test void login_returnsCurrentUserEnvelope() throws Exception {