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