1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package waffle.windows.auth;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 import waffle.windows.auth.impl.WindowsAccountImpl;
34
35
36
37
38 class WindowsAccountTest {
39
40
41 private static final Logger LOGGER = LoggerFactory.getLogger(WindowsAccountTest.class);
42
43
44
45
46 @Test
47 void testGetCurrentUsername() {
48 final String currentUsername = WindowsAccountImpl.getCurrentUsername();
49 WindowsAccountTest.LOGGER.info("Current username: {}", currentUsername);
50 assertThat(currentUsername).isNotEmpty();
51 }
52
53
54
55
56 @Test
57 void testGetCurrentAccount() {
58 final String currentUsername = WindowsAccountImpl.getCurrentUsername();
59 final IWindowsAccount account = new WindowsAccountImpl(currentUsername);
60 assertThat(account.getName()).isNotEmpty();
61 WindowsAccountTest.LOGGER.info("Name: {}", account.getName());
62 assertThat(account.getDomain()).isNotEmpty();
63 WindowsAccountTest.LOGGER.info("Domain: {}", account.getDomain());
64 assertThat(account.getFqn()).isNotEmpty();
65 WindowsAccountTest.LOGGER.info("Fqn: {}", account.getFqn());
66 assertThat(account.getSidString()).isNotEmpty();
67 WindowsAccountTest.LOGGER.info("Sid: {}", account.getSidString());
68
69 Assertions.assertTrue(currentUsername.equalsIgnoreCase(account.getFqn()));
70 Assertions.assertTrue(currentUsername.endsWith("\\" + account.getName()));
71
72 Assertions.assertTrue(currentUsername.toLowerCase().startsWith(account.getDomain().toLowerCase() + "\\"));
73 }
74 }