刘光辉
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package jnpf.dmsPermission;
 
import org.junit.jupiter.api.Test;
 
import java.util.UUID;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
 
class DmsFileCenterCursorCodecTest {
    private final DmsPermissionProperties properties = properties();
    private final DmsFileCenterCursorCodec codec = new DmsFileCenterCursorCodec(properties);
    private final UUID parentId = UUID.fromString("018f0000-0000-7000-8000-000000000101");
    private final UUID documentId = UUID.fromString("018f0000-0000-7000-8000-000000000102");
    private final UUID id = UUID.fromString("018f0000-0000-7000-8000-000000000103");
 
    @Test
    void roundTripsBoundCursor() {
        String fingerprint = codec.fingerprint("质量");
        String value = codec.encode("HISTORICAL_FOLDER", "tenant-1", "user-1", parentId,
                fingerprint, new DmsFileCenterCursorCodec.Cursor("文件A", documentId, 9L, id));
 
        DmsFileCenterCursorCodec.Cursor decoded = codec.decode(value, "HISTORICAL_FOLDER",
                "tenant-1", "user-1", parentId, fingerprint);
 
        assertEquals("文件A", decoded.getName());
        assertEquals(documentId, decoded.getDocumentId());
        assertEquals(9L, decoded.getVersionNo());
        assertEquals(id, decoded.getId());
    }
 
    @Test
    void rejectsTamperingAndCrossUserReplay() {
        String fingerprint = codec.fingerprint(null);
        String value = codec.encode("FOLDER", "tenant-1", "user-1", parentId, fingerprint,
                new DmsFileCenterCursorCodec.Cursor("A", null, null, id));
 
        assertThrows(DmsPermissionException.class,
                () -> codec.decode(value + "x", "FOLDER", "tenant-1", "user-1", parentId, fingerprint));
        assertThrows(DmsPermissionException.class,
                () -> codec.decode(value, "FOLDER", "tenant-1", "user-2", parentId, fingerprint));
    }
 
    private DmsPermissionProperties properties() {
        DmsPermissionProperties value = new DmsPermissionProperties();
        value.setCursorSigningSecret("0123456789abcdef0123456789abcdef");
        return value;
    }
}