View Javadoc
1   package org.apache.maven.wagon.providers.http;
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 org.apache.http.auth.AuthScope;
23  import org.apache.maven.wagon.shared.http.BasicAuthScope;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  public class BasicAuthScopeTest
28  {
29  
30      /**
31       * Test AuthScope override with no overriding values set. Nothing should
32       * change in original host/port.
33       */
34      @Test
35      public void testGetScopeNothingOverridden()
36      {
37          BasicAuthScope scope = new BasicAuthScope();
38  
39          AuthScope authScope = scope.getScope( "original.host.com", 3456 );
40          Assert.assertEquals( "original.host.com", authScope.getHost() );
41          Assert.assertEquals( 3456, authScope.getPort() );
42          Assert.assertEquals( AuthScope.ANY_REALM, authScope.getRealm() );
43      }
44  
45      /**
46       * Test AuthScope override for all values overridden
47       */
48      @Test
49      public void testGetScopeAllOverridden()
50      {
51          BasicAuthScope scope = new BasicAuthScope();
52          scope.setHost( "override.host.com" );
53          scope.setPort( "1234" );
54          scope.setRealm( "override-realm" );
55          AuthScope authScope = scope.getScope( "original.host.com", 3456 );
56          Assert.assertEquals( "override.host.com", authScope.getHost() );
57          Assert.assertEquals( 1234, authScope.getPort() );
58          Assert.assertEquals( "override-realm", authScope.getRealm() );
59      }
60  
61      /**
62       * Test AuthScope override for all values overridden with "ANY"
63       */
64      @Test
65      public void testGetScopeAllAny()
66      {
67          BasicAuthScope scope = new BasicAuthScope();
68          scope.setHost( "ANY" );
69          scope.setPort( "ANY" );
70          scope.setRealm( "ANY" );
71          AuthScope authScope = scope.getScope( "original.host.com", 3456 );
72          Assert.assertEquals( AuthScope.ANY_HOST, authScope.getHost() );
73          Assert.assertEquals( AuthScope.ANY_PORT, authScope.getPort() );
74          Assert.assertEquals( AuthScope.ANY_REALM, authScope.getRealm() );
75      }
76  
77      /**
78       * Test AuthScope override for realm value overridden
79       */
80      @Test
81      public void testGetScopeRealmOverridden()
82      {
83          BasicAuthScope scope = new BasicAuthScope();
84          scope.setRealm( "override-realm" );
85          AuthScope authScope = scope.getScope( "original.host.com", 3456 );
86          Assert.assertEquals( "original.host.com", authScope.getHost() );
87          Assert.assertEquals( 3456, authScope.getPort() );
88          Assert.assertEquals( "override-realm", authScope.getRealm() );
89      }
90  
91      /**
92       * Test AuthScope where original port is -1, which should result in ANY
93       */
94      @Test
95      public void testGetScopeOriginalPortIsNegativeOne()
96      {
97          BasicAuthScope scope = new BasicAuthScope();
98          AuthScope authScope = scope.getScope( "original.host.com", -1 );
99          Assert.assertEquals( AuthScope.ANY_PORT, authScope.getPort() );
100     }
101 }