刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
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"));
    }
}