Properly name instance and method variables of AuthExchange
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1695265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
86aa813080
commit
b1f2b6825a
|
@ -86,7 +86,7 @@ public class HttpAuthenticator {
|
|||
final HttpHost host,
|
||||
final ChallengeType challengeType,
|
||||
final HttpResponse response,
|
||||
final AuthExchange authState,
|
||||
final AuthExchange authExchange,
|
||||
final HttpContext context) {
|
||||
final int challengeCode;
|
||||
switch (challengeType) {
|
||||
|
@ -104,22 +104,22 @@ public class HttpAuthenticator {
|
|||
|
||||
if (response.getStatusLine().getStatusCode() == challengeCode) {
|
||||
this.log.debug("Authentication required");
|
||||
if (authState.getState() == AuthExchange.State.SUCCESS) {
|
||||
if (authExchange.getState() == AuthExchange.State.SUCCESS) {
|
||||
clearCache(host, clientContext);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
switch (authState.getState()) {
|
||||
switch (authExchange.getState()) {
|
||||
case CHALLENGED:
|
||||
case HANDSHAKE:
|
||||
this.log.debug("Authentication succeeded");
|
||||
authState.setState(AuthExchange.State.SUCCESS);
|
||||
updateCache(host, authState.getAuthScheme(), clientContext);
|
||||
authExchange.setState(AuthExchange.State.SUCCESS);
|
||||
updateCache(host, authExchange.getAuthScheme(), clientContext);
|
||||
break;
|
||||
case SUCCESS:
|
||||
break;
|
||||
default:
|
||||
authState.setState(AuthExchange.State.UNCHALLENGED);
|
||||
authExchange.setState(AuthExchange.State.UNCHALLENGED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class HttpAuthenticator {
|
|||
final ChallengeType challengeType,
|
||||
final HttpResponse response,
|
||||
final AuthenticationStrategy authStrategy,
|
||||
final AuthExchange authState,
|
||||
final AuthExchange authExchange,
|
||||
final HttpContext context) {
|
||||
|
||||
if (this.log.isDebugEnabled()) {
|
||||
|
@ -177,21 +177,21 @@ public class HttpAuthenticator {
|
|||
if (challengeMap.isEmpty()) {
|
||||
this.log.debug("Response contains no valid authentication challenges");
|
||||
clearCache(host, clientContext);
|
||||
authState.reset();
|
||||
authExchange.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (authState.getState()) {
|
||||
switch (authExchange.getState()) {
|
||||
case FAILURE:
|
||||
return false;
|
||||
case SUCCESS:
|
||||
authState.reset();
|
||||
authExchange.reset();
|
||||
break;
|
||||
case CHALLENGED:
|
||||
case HANDSHAKE:
|
||||
Asserts.notNull(authState.getAuthScheme(), "AuthScheme");
|
||||
Asserts.notNull(authExchange.getAuthScheme(), "AuthScheme");
|
||||
case UNCHALLENGED:
|
||||
final AuthScheme authScheme = authState.getAuthScheme();
|
||||
final AuthScheme authScheme = authExchange.getAuthScheme();
|
||||
if (authScheme != null) {
|
||||
final String id = authScheme.getName();
|
||||
final AuthChallenge challenge = challengeMap.get(id.toLowerCase(Locale.ROOT));
|
||||
|
@ -204,21 +204,21 @@ public class HttpAuthenticator {
|
|||
this.log.warn(ex.getMessage());
|
||||
}
|
||||
clearCache(host, clientContext);
|
||||
authState.reset();
|
||||
authExchange.reset();
|
||||
return false;
|
||||
}
|
||||
if (authScheme.isChallengeComplete()) {
|
||||
this.log.debug("Authentication failed");
|
||||
clearCache(host, clientContext);
|
||||
authState.reset();
|
||||
authState.setState(AuthExchange.State.FAILURE);
|
||||
authExchange.reset();
|
||||
authExchange.setState(AuthExchange.State.FAILURE);
|
||||
return false;
|
||||
} else {
|
||||
authState.setState(AuthExchange.State.HANDSHAKE);
|
||||
authExchange.setState(AuthExchange.State.HANDSHAKE);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
authState.reset();
|
||||
authExchange.reset();
|
||||
// Retry authentication with a different scheme
|
||||
}
|
||||
}
|
||||
|
@ -250,9 +250,9 @@ public class HttpAuthenticator {
|
|||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Selected authentication options: " + authOptions);
|
||||
}
|
||||
authState.reset();
|
||||
authState.setState(AuthExchange.State.CHALLENGED);
|
||||
authState.setOptions(authOptions);
|
||||
authExchange.reset();
|
||||
authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
authExchange.setOptions(authOptions);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -263,10 +263,10 @@ public class HttpAuthenticator {
|
|||
final HttpHost host,
|
||||
final ChallengeType challengeType,
|
||||
final HttpRequest request,
|
||||
final AuthExchange authState,
|
||||
final AuthExchange authExchange,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
AuthScheme authScheme = authState.getAuthScheme();
|
||||
switch (authState.getState()) {
|
||||
AuthScheme authScheme = authExchange.getAuthScheme();
|
||||
switch (authExchange.getState()) {
|
||||
case FAILURE:
|
||||
return;
|
||||
case SUCCESS:
|
||||
|
@ -279,11 +279,11 @@ public class HttpAuthenticator {
|
|||
Asserts.notNull(authScheme, "AuthScheme");
|
||||
break;
|
||||
case CHALLENGED:
|
||||
final Queue<AuthScheme> authOptions = authState.getAuthOptions();
|
||||
final Queue<AuthScheme> authOptions = authExchange.getAuthOptions();
|
||||
if (authOptions != null) {
|
||||
while (!authOptions.isEmpty()) {
|
||||
authScheme = authOptions.remove();
|
||||
authState.select(authScheme);
|
||||
authExchange.select(authScheme);
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Generating response to an authentication challenge using "
|
||||
+ authScheme.getName() + " scheme");
|
||||
|
|
|
@ -88,8 +88,8 @@ public class DefaultUserTokenHandler implements UserTokenHandler {
|
|||
return userPrincipal;
|
||||
}
|
||||
|
||||
private static Principal getAuthPrincipal(final AuthExchange authState) {
|
||||
final AuthScheme scheme = authState.getAuthScheme();
|
||||
private static Principal getAuthPrincipal(final AuthExchange authExchange) {
|
||||
final AuthScheme scheme = authExchange.getAuthScheme();
|
||||
if (scheme != null && scheme.isConnectionBased()) {
|
||||
return scheme.getPrincipal();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ import org.mockito.Mockito;
|
|||
@SuppressWarnings({"boxing","static-access"})
|
||||
public class TestHttpAuthenticator {
|
||||
|
||||
private AuthExchange authState;
|
||||
private AuthExchange authExchange;
|
||||
private AuthScheme authScheme;
|
||||
private HttpContext context;
|
||||
private HttpHost defaultHost;
|
||||
|
@ -74,7 +74,7 @@ public class TestHttpAuthenticator {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.authState = new AuthExchange();
|
||||
this.authExchange = new AuthExchange();
|
||||
this.authScheme = Mockito.mock(AuthScheme.class);
|
||||
Mockito.when(this.authScheme.getName()).thenReturn("Basic");
|
||||
Mockito.when(this.authScheme.isChallengeComplete()).thenReturn(Boolean.TRUE);
|
||||
|
@ -94,11 +94,11 @@ public class TestHttpAuthenticator {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAuthState() throws Exception {
|
||||
public void testUpdateAuthExchange() throws Exception {
|
||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||
Mockito.verifyZeroInteractions(this.authCache);
|
||||
}
|
||||
|
||||
|
@ -107,11 +107,11 @@ public class TestHttpAuthenticator {
|
|||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||
response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||
|
||||
this.authState.select(this.authScheme);
|
||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
||||
this.authExchange.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||
|
||||
Assert.assertTrue(this.httpAuthenticator.isChallenged(
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||
|
||||
Mockito.verify(this.authCache).remove(this.defaultHost);
|
||||
}
|
||||
|
@ -121,19 +121,19 @@ public class TestHttpAuthenticator {
|
|||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authState.getState());
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authExchange.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthenticationNotRequestedSuccess1() throws Exception {
|
||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
this.authState.select(this.authScheme);
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authState.getState());
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authExchange.getState());
|
||||
|
||||
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
||||
}
|
||||
|
@ -141,12 +141,12 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthenticationNotRequestedSuccess2() throws Exception {
|
||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
this.authState.select(this.authScheme);
|
||||
this.authState.setState(AuthExchange.State.HANDSHAKE);
|
||||
this.authExchange.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.HANDSHAKE);
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.isChallenged(
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authState.getState());
|
||||
this.defaultHost, ChallengeType.TARGET, response, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.SUCCESS, this.authExchange.getState());
|
||||
|
||||
Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
|
||||
}
|
||||
|
@ -165,10 +165,10 @@ public class TestHttpAuthenticator {
|
|||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||
|
||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
||||
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||
Assert.assertNotNull(options);
|
||||
final AuthScheme authScheme1 = options.poll();
|
||||
Assert.assertNotNull(authScheme1);
|
||||
|
@ -192,10 +192,10 @@ public class TestHttpAuthenticator {
|
|||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||
|
||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
||||
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||
Assert.assertNotNull(options);
|
||||
final AuthScheme authScheme1 = options.poll();
|
||||
Assert.assertNotNull(authScheme1);
|
||||
|
@ -211,7 +211,7 @@ public class TestHttpAuthenticator {
|
|||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -224,7 +224,7 @@ public class TestHttpAuthenticator {
|
|||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -237,7 +237,7 @@ public class TestHttpAuthenticator {
|
|||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -247,15 +247,15 @@ public class TestHttpAuthenticator {
|
|||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
|
||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
|
||||
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authState.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(this.authScheme);
|
||||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||
|
||||
Mockito.verify(this.authCache).remove(host);
|
||||
}
|
||||
|
@ -267,14 +267,14 @@ public class TestHttpAuthenticator {
|
|||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
|
||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
|
||||
|
||||
this.authState.setState(AuthExchange.State.FAILURE);
|
||||
this.authExchange.setState(AuthExchange.State.FAILURE);
|
||||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -287,12 +287,12 @@ public class TestHttpAuthenticator {
|
|||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authState.select(new BasicScheme());
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(new BasicScheme());
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authState.getState());
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.FAILURE, this.authExchange.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -305,13 +305,13 @@ public class TestHttpAuthenticator {
|
|||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authState.select(new DigestScheme());
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(new DigestScheme());
|
||||
|
||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
|
||||
Assert.assertEquals(AuthExchange.State.HANDSHAKE, this.authState.getState());
|
||||
Assert.assertEquals(AuthExchange.State.HANDSHAKE, this.authExchange.getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -326,14 +326,14 @@ public class TestHttpAuthenticator {
|
|||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authState.select(new BasicScheme());
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(new BasicScheme());
|
||||
|
||||
Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authState.getState());
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
Assert.assertEquals(AuthExchange.State.CHALLENGED, this.authExchange.getState());
|
||||
|
||||
final Queue<AuthScheme> options = this.authState.getAuthOptions();
|
||||
final Queue<AuthScheme> options = this.authExchange.getAuthOptions();
|
||||
Assert.assertNotNull(options);
|
||||
final AuthScheme authScheme1 = options.poll();
|
||||
Assert.assertNotNull(authScheme1);
|
||||
|
@ -347,24 +347,24 @@ public class TestHttpAuthenticator {
|
|||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
|
||||
response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "blah blah blah"));
|
||||
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
|
||||
final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
|
||||
|
||||
Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
|
||||
host, ChallengeType.TARGET, response, authStrategy, this.authExchange, this.context));
|
||||
|
||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authState.getState());
|
||||
Assert.assertNull(this.authState.getAuthScheme());
|
||||
Assert.assertEquals(AuthExchange.State.UNCHALLENGED, this.authExchange.getState());
|
||||
Assert.assertNull(this.authExchange.getAuthScheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthFailureState() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.FAILURE);
|
||||
this.authState.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.FAILURE);
|
||||
this.authExchange.select(this.authScheme);
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
|
||||
|
@ -377,15 +377,15 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthChallengeStateNoOption() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authState.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.select(this.authScheme);
|
||||
|
||||
Mockito.when(this.authScheme.generateAuthResponse(
|
||||
Mockito.eq(defaultHost),
|
||||
Mockito.any(HttpRequest.class),
|
||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
}
|
||||
|
@ -393,20 +393,20 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthChallengeStateOneOptions() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
||||
authOptions.add(this.authScheme);
|
||||
this.authState.setOptions(authOptions);
|
||||
this.authExchange.setOptions(authOptions);
|
||||
|
||||
Mockito.when(this.authScheme.generateAuthResponse(
|
||||
Mockito.eq(defaultHost),
|
||||
Mockito.any(HttpRequest.class),
|
||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
|
||||
Assert.assertNull(this.authState.getAuthOptions());
|
||||
Assert.assertSame(this.authScheme, this.authExchange.getAuthScheme());
|
||||
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||
|
||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthChallengeStateMultipleOption() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.CHALLENGED);
|
||||
this.authExchange.setState(AuthExchange.State.CHALLENGED);
|
||||
|
||||
final LinkedList<AuthScheme> authOptions = new LinkedList<>();
|
||||
final AuthScheme authScheme1 = Mockito.mock(AuthScheme.class);
|
||||
|
@ -429,12 +429,12 @@ public class TestHttpAuthenticator {
|
|||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||
authOptions.add(authScheme1);
|
||||
authOptions.add(authScheme2);
|
||||
this.authState.setOptions(authOptions);
|
||||
this.authExchange.setOptions(authOptions);
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertSame(authScheme2, this.authState.getAuthScheme());
|
||||
Assert.assertNull(this.authState.getAuthOptions());
|
||||
Assert.assertSame(authScheme2, this.authExchange.getAuthScheme());
|
||||
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||
|
||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
}
|
||||
|
@ -442,8 +442,8 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthSuccess() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
||||
this.authState.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||
this.authExchange.select(this.authScheme);
|
||||
|
||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
|
||||
Mockito.when(this.authScheme.generateAuthResponse(
|
||||
|
@ -451,10 +451,10 @@ public class TestHttpAuthenticator {
|
|||
Mockito.any(HttpRequest.class),
|
||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
|
||||
Assert.assertNull(this.authState.getAuthOptions());
|
||||
Assert.assertSame(this.authScheme, this.authExchange.getAuthScheme());
|
||||
Assert.assertNull(this.authExchange.getAuthOptions());
|
||||
|
||||
Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
}
|
||||
|
@ -462,8 +462,8 @@ public class TestHttpAuthenticator {
|
|||
@Test
|
||||
public void testAuthSuccessConnectionBased() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/");
|
||||
this.authState.setState(AuthExchange.State.SUCCESS);
|
||||
this.authState.select(this.authScheme);
|
||||
this.authExchange.setState(AuthExchange.State.SUCCESS);
|
||||
this.authExchange.select(this.authScheme);
|
||||
|
||||
Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(this.authScheme.generateAuthResponse(
|
||||
|
@ -471,7 +471,7 @@ public class TestHttpAuthenticator {
|
|||
Mockito.any(HttpRequest.class),
|
||||
Mockito.any(HttpContext.class))).thenReturn("stuff");
|
||||
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
|
||||
this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authExchange, context);
|
||||
|
||||
Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
|
||||
|
||||
|
|
Loading…
Reference in New Issue