mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 18:41:13 +08:00
feat: add whitelist register mode
This commit is contained in:
@@ -2,6 +2,7 @@ package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.*;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,6 +37,8 @@ class AuthControllerTest {
|
||||
private CaptchaService captchaService;
|
||||
@MockBean
|
||||
private GoogleAuthService googleAuthService;
|
||||
@MockBean
|
||||
private RegisterModeService registerModeService;
|
||||
|
||||
@Test
|
||||
void registerSendsEmail() throws Exception {
|
||||
@@ -43,11 +46,12 @@ class AuthControllerTest {
|
||||
user.setEmail("a@b.com");
|
||||
user.setUsername("u");
|
||||
user.setVerificationCode("123456");
|
||||
Mockito.when(userService.register(eq("u"), eq("a@b.com"), eq("p"))).thenReturn(user);
|
||||
Mockito.when(registerModeService.getRegisterMode()).thenReturn(RegisterMode.DIRECT);
|
||||
Mockito.when(userService.register(eq("u"), eq("a@b.com"), eq("p"), any(), eq(RegisterMode.DIRECT))).thenReturn(user);
|
||||
|
||||
mockMvc.perform(post("/api/auth/register")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"username\":\"u\",\"email\":\"a@b.com\",\"password\":\"p\"}"))
|
||||
.content("{\"username\":\"u\",\"email\":\"a@b.com\",\"password\":\"p\",\"reason\":\"test reason more than twenty\"}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.message").exists());
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "app.register.mode=DIRECT")
|
||||
class ComplexFlowIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -33,7 +34,7 @@ class ComplexFlowIntegrationTest {
|
||||
HttpHeaders h = new HttpHeaders();
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||
Map.of("username", username, "email", email, "password", "pass123", "reason", "integration test reason more than twenty"), h), Map.class);
|
||||
User u = users.findByUsername(username).orElseThrow();
|
||||
if (u.getVerificationCode() != null) {
|
||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||
|
||||
@@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Integration tests for review publish mode. */
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "app.post.publish-mode=REVIEW")
|
||||
properties = {"app.post.publish-mode=REVIEW","app.register.mode=DIRECT"})
|
||||
class PublishModeIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -34,7 +34,7 @@ class PublishModeIntegrationTest {
|
||||
HttpHeaders h = new HttpHeaders();
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||
Map.of("username", username, "email", email, "password", "pass123", "reason", "integration test reason more than twenty"), h), Map.class);
|
||||
User u = users.findByUsername(username).orElseThrow();
|
||||
if (u.getVerificationCode() != null) {
|
||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||
|
||||
@@ -16,7 +16,8 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "app.register.mode=DIRECT")
|
||||
class SearchIntegrationTest {
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
@@ -29,7 +30,7 @@ class SearchIntegrationTest {
|
||||
HttpHeaders h = new HttpHeaders();
|
||||
h.setContentType(MediaType.APPLICATION_JSON);
|
||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||
Map.of("username", username, "email", email, "password", "pass123", "reason", "integration test reason more than twenty"), h), Map.class);
|
||||
User u = users.findByUsername(username).orElseThrow();
|
||||
if (u.getVerificationCode() != null) {
|
||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||
|
||||
Reference in New Issue
Block a user