刘光辉
15 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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"));
    }
}