1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core.wa;
20
21 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26 import java.util.UUID;
27 import org.apache.syncope.common.lib.wa.WebAuthnAccount;
28 import org.apache.syncope.common.lib.wa.WebAuthnDeviceCredential;
29 import org.apache.syncope.core.spring.security.SecureRandomUtils;
30 import org.apache.syncope.fit.AbstractITCase;
31 import org.junit.jupiter.api.Test;
32
33 public class WebAuthnAccountITCase extends AbstractITCase {
34
35 private static WebAuthnAccount createWebAuthnRegisteredAccount() {
36 String id = SecureRandomUtils.generateRandomUUID().toString();
37 String record = "[ {"
38 + " \"userIdentity\" : {"
39 + " \"name\" : \"%s\","
40 + " \"displayName\" : \"%s\""
41 + " },"
42 + " \"credential\" : {"
43 + " \"credentialId\" : \"fFGyV3K5x1\""
44 + " },"
45 + " \"username\" : \"%s\""
46 + " } ]";
47 WebAuthnDeviceCredential credential = new WebAuthnDeviceCredential.Builder().
48 json(String.format(record, id, id, id)).
49 identifier("fFGyV3K5x1").
50 build();
51 return new WebAuthnAccount.Builder().credential(credential).build();
52 }
53
54 @Test
55 public void listAndFind() {
56 String owner = UUID.randomUUID().toString();
57 WebAuthnAccount acct = createWebAuthnRegisteredAccount();
58 WEBAUTHN_REGISTRATION_SERVICE.create(owner, acct);
59 assertFalse(WEBAUTHN_REGISTRATION_SERVICE.list().isEmpty());
60 assertNotNull(WEBAUTHN_REGISTRATION_SERVICE.read(owner));
61 }
62
63 @Test
64 public void deleteByOwner() {
65 String owner = UUID.randomUUID().toString();
66 WebAuthnAccount acct = createWebAuthnRegisteredAccount();
67 WEBAUTHN_REGISTRATION_SERVICE.create(owner, acct);
68 WEBAUTHN_REGISTRATION_SERVICE.delete(owner);
69 assertTrue(WEBAUTHN_REGISTRATION_SERVICE.read(owner).getCredentials().isEmpty());
70 }
71
72 @Test
73 public void deleteByAcct() {
74 String owner = UUID.randomUUID().toString();
75 WebAuthnAccount acct = createWebAuthnRegisteredAccount();
76 WEBAUTHN_REGISTRATION_SERVICE.create(owner, acct);
77 WEBAUTHN_REGISTRATION_SERVICE.delete(owner, acct.getCredentials().get(0).getIdentifier());
78 acct = WEBAUTHN_REGISTRATION_SERVICE.read(owner);
79 assertTrue(acct.getCredentials().isEmpty());
80 }
81
82 @Test
83 public void create() {
84 WebAuthnAccount acct = createWebAuthnRegisteredAccount();
85 assertDoesNotThrow(() -> WEBAUTHN_REGISTRATION_SERVICE.create(UUID.randomUUID().toString(), acct));
86 }
87 }