refactor: 添加 websocket 连接认证拦截器实现点对点指定用户发送消息;移除 easy-captcha 替换为 hutool-captcha验证码实现代码简化;重构认证接口控制层代码。

This commit is contained in:
haoxr
2023-09-12 18:25:16 +08:00
parent 87fcf022ba
commit 9453600715
37 changed files with 290 additions and 358 deletions

View File

@@ -1,42 +0,0 @@
package com.youlai.system.controller;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
class WebsocketControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
void testSendToAll() throws Exception {
String message = "Hello! I'm server. This is a topic message.";
mockMvc.perform(
post("/messages/sendToAll")
.param("message", message)
)
.andExpect(status().isOk());
}
@Test
void testSendToUser() throws Exception {
Long userId = 2L;// 系统管理员用户ID=2
mockMvc.perform(post("/messages/sendToUser/{userId}", userId)
.param("message", "Hello! I'm server. This is a point-to-point message.")
)
//.content(JSONUtil.toJsonStr(webSocketMessage))
//.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
}