This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new e0b40ef5f5 refactor: replace Spring Value injection with 
ReflectionTestUtils and add delay validation test cases to SignService tests 
(#6917)
e0b40ef5f5 is described below

commit e0b40ef5f51d3d1bbe66372337ee7f63f8650547
Author: Limbo <[email protected]>
AuthorDate: Mon Aug 17 09:52:18 2026 +0800

    refactor: replace Spring Value injection with ReflectionTestUtils and add 
delay validation test cases to SignService tests (#6917)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../sign/service/SignServiceVersionOneTest.java    | 25 ++++++++++++++++------
 .../sign/service/SignServiceVersionTwoTest.java    | 25 ++++++++++++++++------
 2 files changed, 38 insertions(+), 12 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionOneTest.java
 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionOneTest.java
index f076fea3cb..19cd944f4f 100644
--- 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionOneTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionOneTest.java
@@ -41,10 +41,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.mockito.junit.jupiter.MockitoSettings;
 import org.mockito.quality.Strictness;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
 import org.springframework.mock.web.server.MockServerWebExchange;
+import org.springframework.test.util.ReflectionTestUtils;
 import org.springframework.web.server.ServerWebExchange;
 
 import java.util.Collections;
@@ -66,6 +66,8 @@ import static org.mockito.Mockito.mock;
 @MockitoSettings(strictness = Strictness.LENIENT)
 public final class SignServiceVersionOneTest {
 
+    private static final int DELAY = 5;
+
     private SignService signService;
 
     private ServerWebExchange exchange;
@@ -76,12 +78,10 @@ public final class SignServiceVersionOneTest {
 
     private ShenyuContext passed;
 
-    @Value("${shenyu.sign.delay:5}")
-    private int delay;
-
     @BeforeEach
     public void setup() {
         this.signService = new ComposableSignService(new DefaultExtractor(), 
new DefaultSignProvider());
+        ReflectionTestUtils.setField(this.signService, "delay", DELAY);
 
         final String path = "/test-api/demo/test";
         PluginData signData = new PluginData();
@@ -129,6 +129,19 @@ public final class SignServiceVersionOneTest {
         assertEquals(ret, VerifyResult.success());
     }
 
+    @Test
+    public void normalTestWithinConfiguredDelay() {
+        String timestamp = String.valueOf(System.currentTimeMillis() - 
60_000L);
+        this.exchange = 
buildServerWebExchange("http://localhost/test-api/demo/test";,
+                timestamp,
+                appKey,
+                buildSign(secretKey, timestamp, "/test-api/demo/test", null, 
null));
+        this.exchange.getAttributes().put(Constants.CONTEXT, this.passed);
+
+        VerifyResult ret = this.signService.signatureVerify(this.exchange);
+        assertEquals(ret, VerifyResult.success());
+    }
+
     @Test
     public void nullTimestampTest() {
         String timestamp = String.valueOf(System.currentTimeMillis());
@@ -175,7 +188,7 @@ public final class SignServiceVersionOneTest {
 
     @Test
     public void overdueTest() {
-        String errorTimestamp = String.valueOf(System.currentTimeMillis() - 
((long) (delay + 1) * 1000 * 60));
+        String errorTimestamp = String.valueOf(System.currentTimeMillis() - 
((long) (DELAY + 1) * 1000 * 60));
         this.exchange = 
buildServerWebExchange("http://localhost/test-api/demo/test";,
                 errorTimestamp,
                 appKey,
@@ -183,7 +196,7 @@ public final class SignServiceVersionOneTest {
         this.exchange.getAttributes().put(Constants.CONTEXT, this.passed);
 
         VerifyResult ret = this.signService.signatureVerify(this.exchange);
-        assertEquals(ret, 
VerifyResult.fail(String.format(ShenyuResultEnum.SIGN_TIME_IS_TIMEOUT.getMsg(), 
delay)));
+        assertEquals(ret, 
VerifyResult.fail(String.format(ShenyuResultEnum.SIGN_TIME_IS_TIMEOUT.getMsg(), 
DELAY)));
     }
 
     @Test
diff --git 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionTwoTest.java
 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionTwoTest.java
index 9cc83b27d0..62d5ff0233 100644
--- 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionTwoTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/SignServiceVersionTwoTest.java
@@ -41,11 +41,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.mockito.junit.jupiter.MockitoSettings;
 import org.mockito.quality.Strictness;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.http.HttpHeaders;
 import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
 import org.springframework.mock.web.server.MockServerWebExchange;
+import org.springframework.test.util.ReflectionTestUtils;
 import org.springframework.web.server.ServerWebExchange;
 
 import java.net.URI;
@@ -68,6 +68,8 @@ import static org.mockito.Mockito.mock;
 @MockitoSettings(strictness = Strictness.LENIENT)
 public final class SignServiceVersionTwoTest {
 
+    private static final int DELAY = 5;
+
     private SignService signService;
 
     private ServerWebExchange exchange;
@@ -78,12 +80,10 @@ public final class SignServiceVersionTwoTest {
 
     private ShenyuContext passed;
 
-    @Value("${shenyu.sign.delay:5}")
-    private int delay;
-
     @BeforeEach
     public void setup() {
         this.signService = new ComposableSignService(new DefaultExtractor(), 
new DefaultSignProvider());
+        ReflectionTestUtils.setField(this.signService, "delay", DELAY);
 
         final String path = "/test-api/demo/test";
         PluginData signData = new PluginData();
@@ -131,6 +131,19 @@ public final class SignServiceVersionTwoTest {
         assertEquals(ret, VerifyResult.success());
     }
 
+    @Test
+    public void normalTestWithinConfiguredDelay() {
+        String timestamp = String.valueOf(System.currentTimeMillis() - 
60_000L);
+        String parameters = buildParameters(timestamp, appKey);
+        this.exchange = 
buildServerWebExchange("http://localhost/test-api/demo/test";,
+                parameters,
+                buildSign(secretKey, parameters, 
URI.create("http://localhost/test-api/demo/test";), null));
+        this.exchange.getAttributes().put(Constants.CONTEXT, this.passed);
+
+        VerifyResult ret = this.signService.signatureVerify(this.exchange);
+        assertEquals(ret, VerifyResult.success());
+    }
+
     @Test
     public void nullTimestampTest() {
 
@@ -178,7 +191,7 @@ public final class SignServiceVersionTwoTest {
 
     @Test
     public void overdueTest() {
-        String errorTimestamp = String.valueOf(System.currentTimeMillis() - 
((long) (delay + 1) * 1000 * 60));
+        String errorTimestamp = String.valueOf(System.currentTimeMillis() - 
((long) (DELAY + 1) * 1000 * 60));
         String parameters = buildParameters(errorTimestamp, appKey);
         this.exchange = 
buildServerWebExchange("http://localhost/test-api/demo/test";,
                 parameters,
@@ -186,7 +199,7 @@ public final class SignServiceVersionTwoTest {
         this.exchange.getAttributes().put(Constants.CONTEXT, this.passed);
 
         VerifyResult ret = this.signService.signatureVerify(this.exchange);
-        assertEquals(ret, 
VerifyResult.fail(String.format(ShenyuResultEnum.SIGN_TIME_IS_TIMEOUT.getMsg(), 
delay)));
+        assertEquals(ret, 
VerifyResult.fail(String.format(ShenyuResultEnum.SIGN_TIME_IS_TIMEOUT.getMsg(), 
DELAY)));
     }
 
     @Test

Reply via email to