1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.repository;
20
21 import org.eclipse.aether.RepositorySystemSession;
22 import org.eclipse.aether.internal.test.util.TestUtils;
23 import org.eclipse.aether.repository.Authentication;
24 import org.eclipse.aether.repository.AuthenticationContext;
25 import org.eclipse.aether.repository.AuthenticationDigest;
26 import org.eclipse.aether.repository.RemoteRepository;
27 import org.junit.jupiter.api.Test;
28
29 import static org.junit.jupiter.api.Assertions.*;
30
31 public class SecretAuthenticationTest {
32
33 private RepositorySystemSession newSession() {
34 return TestUtils.newSession();
35 }
36
37 private RemoteRepository newRepo(Authentication auth) {
38 return new RemoteRepository.Builder("test", "default", "http://localhost")
39 .setAuthentication(auth)
40 .build();
41 }
42
43 private AuthenticationContext newContext(Authentication auth) {
44 return AuthenticationContext.forRepository(newSession(), newRepo(auth));
45 }
46
47 private String newDigest(Authentication auth) {
48 return AuthenticationDigest.forRepository(newSession(), newRepo(auth));
49 }
50
51 @Test
52 void testConstructor_CopyChars() {
53 char[] value = {'v', 'a', 'l'};
54 new SecretAuthentication("key", value);
55 assertArrayEquals(new char[] {'v', 'a', 'l'}, value);
56 }
57
58 @Test
59 void testFill() {
60 Authentication auth = new SecretAuthentication("key", "value");
61 try (AuthenticationContext context = newContext(auth)) {
62 assertNull(context.get("another-key"));
63 assertEquals("value", context.get("key"));
64 }
65 }
66
67 @Test
68 void testDigest() {
69 Authentication auth1 = new SecretAuthentication("key", "value");
70 Authentication auth2 = new SecretAuthentication("key", "value");
71 String digest1 = newDigest(auth1);
72 String digest2 = newDigest(auth2);
73 assertEquals(digest1, digest2);
74
75 Authentication auth3 = new SecretAuthentication("key", "Value");
76 String digest3 = newDigest(auth3);
77 assertNotEquals(digest3, digest1);
78
79 Authentication auth4 = new SecretAuthentication("Key", "value");
80 String digest4 = newDigest(auth4);
81 assertNotEquals(digest4, digest1);
82 }
83
84 @Test
85 void testEquals() {
86 Authentication auth1 = new SecretAuthentication("key", "value");
87 Authentication auth2 = new SecretAuthentication("key", "value");
88 Authentication auth3 = new SecretAuthentication("key", "Value");
89 assertEquals(auth1, auth2);
90 assertNotEquals(auth1, auth3);
91 assertNotEquals(null, auth1);
92 }
93
94 @Test
95 void testHashCode() {
96 Authentication auth1 = new SecretAuthentication("key", "value");
97 Authentication auth2 = new SecretAuthentication("key", "value");
98 assertEquals(auth1.hashCode(), auth2.hashCode());
99 }
100 }