diff --git a/src/main/java/com/gameplatform/server/security/SecurityConfig.java b/src/main/java/com/gameplatform/server/security/SecurityConfig.java index 2cb642b..e956f88 100644 --- a/src/main/java/com/gameplatform/server/security/SecurityConfig.java +++ b/src/main/java/com/gameplatform/server/security/SecurityConfig.java @@ -39,6 +39,7 @@ public class SecurityConfig { .authenticationManager(authenticationManager()) .authorizeExchange(ex -> ex .pathMatchers("/actuator/**").permitAll() + .pathMatchers(HttpMethod.OPTIONS, "/**").permitAll() // 允许所有CORS预检请求 .pathMatchers(HttpMethod.POST, "/api/auth/login").permitAll() .pathMatchers(HttpMethod.GET, "/api/auth/me").permitAll() .pathMatchers(HttpMethod.GET, "/api/link/status").permitAll() // 用户端获取链接状态接口,公开访问 @@ -62,6 +63,7 @@ public class SecurityConfig { log.info(" - JWT过滤器: 已集成到Security链中 (AUTHENTICATION位置)"); log.info(" - 路径权限配置:"); log.info(" * /actuator/** -> 允许所有"); + log.info(" * OPTIONS /** -> 允许所有 (CORS预检请求)"); log.info(" * POST /api/auth/login -> 允许所有"); log.info(" * GET /api/auth/me -> 允许所有"); log.info(" * GET /api/link/status -> 允许所有 (用户端公开接口)"); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 176e945..afdca9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: name: gameplatform-server datasource: - url: jdbc:mysql://localhost:3306/login_task_db?useSSL=false&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true + url: jdbc:mysql://192.140.164.137:3306/login_task_db?useSSL=false&serverTimezone=UTC&characterEncoding=utf8&allowPublicKeyRetrieval=true username: login_task_db password: 3MaXfeWJ4d6cGMrL driver-class-name: com.mysql.cj.jdbc.Driver @@ -70,7 +70,7 @@ script: # 服务器配置 app: - base-url: "http://localhost:18080" # 生产环境需要配置为实际域名 + base-url: "http://192.140.164.137:18080" # 生产环境需要配置为实际域名 image-save-path: "./images" # 图片保存路径 link: diff --git a/src/test/java/com/gameplatform/server/service/link/DeviceTaskUpdateServiceTest.java b/src/test/java/com/gameplatform/server/service/link/DeviceTaskUpdateServiceTest.java index 1c2683f..aac6a7d 100644 --- a/src/test/java/com/gameplatform/server/service/link/DeviceTaskUpdateServiceTest.java +++ b/src/test/java/com/gameplatform/server/service/link/DeviceTaskUpdateServiceTest.java @@ -4,15 +4,18 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.gameplatform.server.mapper.agent.LinkTaskMapper; import com.gameplatform.server.model.dto.device.DeviceStatusResponse; import com.gameplatform.server.model.entity.agent.LinkTask; -import com.gameplatform.server.service.external.ScriptClient; +import com.gameplatform.server.service.image.ImageSaveService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -29,7 +32,7 @@ public class DeviceTaskUpdateServiceTest { private LinkTaskMapper linkTaskMapper; @Mock - private ScriptClient scriptClient; + private ImageSaveService imageSaveService; private ObjectMapper objectMapper; @@ -37,17 +40,7 @@ public class DeviceTaskUpdateServiceTest { void setUp() { MockitoAnnotations.openMocks(this); objectMapper = new ObjectMapper(); - deviceTaskUpdateService = new DeviceTaskUpdateService(linkTaskMapper, scriptClient, objectMapper); - - // 设置ScriptClient mock返回值 - when(scriptClient.getResourceUrl(eq("f1"), eq("首次主页.png"))) - .thenReturn("http://36.138.184.60:12345/f1/首次主页.png"); - when(scriptClient.getResourceUrl(eq("f1"), eq("首次赏金.png"))) - .thenReturn("http://36.138.184.60:12345/f1/首次赏金.png"); - when(scriptClient.getResourceUrl(eq("f1"), eq("中途赏金.png"))) - .thenReturn("http://36.138.184.60:12345/f1/中途赏金.png"); - when(scriptClient.getResourceUrl(eq("f1"), eq("结束赏金.png"))) - .thenReturn("http://36.138.184.60:12345/f1/结束赏金.png"); + deviceTaskUpdateService = new DeviceTaskUpdateService(linkTaskMapper, objectMapper, imageSaveService); } @Test @@ -92,6 +85,13 @@ public class DeviceTaskUpdateServiceTest { when(linkTaskMapper.findByMachineIdAndStatus("f1", "LOGGED_IN")).thenReturn(tasks); when(linkTaskMapper.update(any(LinkTask.class))).thenReturn(1); + Map mockImages = new HashMap<>(); + mockImages.put("homepage", "首次主页.png"); + mockImages.put("firstReward", "首次赏金.png"); + mockImages.put("midReward", "中途赏金.png"); + mockImages.put("endReward", "结束赏金.png"); + when(imageSaveService.downloadAndSaveCompletionImages(anyString(), anyString())) + .thenReturn(Mono.just(mockImages)); // 执行测试 deviceTaskUpdateService.updateTaskByDeviceStatus(deviceInfo); @@ -124,6 +124,13 @@ public class DeviceTaskUpdateServiceTest { when(linkTaskMapper.findByMachineIdAndStatus("f1", "LOGGED_IN")).thenReturn(tasks); when(linkTaskMapper.update(any(LinkTask.class))).thenReturn(1); + Map mockImages = new HashMap<>(); + mockImages.put("homepage", "首次主页.png"); + mockImages.put("firstReward", "首次赏金.png"); + mockImages.put("midReward", "中途赏金.png"); + mockImages.put("endReward", "结束赏金.png"); + when(imageSaveService.downloadAndSaveCompletionImages(anyString(), anyString())) + .thenReturn(Mono.just(mockImages)); // 执行测试 deviceTaskUpdateService.updateTaskByDeviceStatus(deviceInfo);