From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-dms/jnpf-dms-biz/src/test/java/jnpf/dmsPermission/DmsTrustedServiceGuardTest.java |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/jnpf-dms/jnpf-dms-biz/src/test/java/jnpf/dmsPermission/DmsTrustedServiceGuardTest.java b/jnpf-dms/jnpf-dms-biz/src/test/java/jnpf/dmsPermission/DmsTrustedServiceGuardTest.java
new file mode 100644
index 0000000..44c2856
--- /dev/null
+++ b/jnpf-dms/jnpf-dms-biz/src/test/java/jnpf/dmsPermission/DmsTrustedServiceGuardTest.java
@@ -0,0 +1,32 @@
+package jnpf.dmsPermission;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class DmsTrustedServiceGuardTest {
+
+    @Test
+    void failsClosedWhenWhitelistIsEmpty() {
+        DmsPermissionProperties properties = new DmsPermissionProperties();
+        DmsTrustedServiceGuard guard = new DmsTrustedServiceGuard(properties);
+
+        DmsPermissionException exception = assertThrows(DmsPermissionException.class,
+                () -> guard.requireAllowed("jnpf-file"));
+
+        assertEquals(DmsPermissionError.TRUSTED_SERVICE_REQUIRED, exception.getError());
+    }
+
+    @Test
+    void acceptsOnlyExactConfiguredServiceId() {
+        DmsPermissionProperties properties = new DmsPermissionProperties();
+        properties.setResourceRegistrationServiceIds(Collections.singleton("jnpf-file"));
+        DmsTrustedServiceGuard guard = new DmsTrustedServiceGuard(properties);
+
+        assertEquals("jnpf-file", guard.requireAllowed(" jnpf-file "));
+        assertThrows(DmsPermissionException.class, () -> guard.requireAllowed("JNPF-FILE"));
+    }
+}

--
Gitblit v1.8.0