View Javadoc
1   package org.eclipse.aether.util.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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          assertNull( 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          assertNotEquals( digest3, digest1 );
84  
85          Authentication auth4 = new SecretAuthentication( "Key", "value" );
86          String digest4 = newDigest( auth4 );
87          assertNotEquals( digest4, 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          assertNotEquals( auth1, auth3 );
98          assertNotEquals( null, auth1 );
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 }