use of com.microsoft.identity.common.adal.internal.net.HttpWebResponse in project azure-activedirectory-library-for-android by AzureAD.
the class OauthTests method testRefreshTokenWebResponseDeviceChallengeHeaderEmpty.
@SuppressWarnings("unchecked")
@Test
public void testRefreshTokenWebResponseDeviceChallengeHeaderEmpty() throws IOException {
IWebRequestHandler mockWebRequest = mock(IWebRequestHandler.class);
Map<String, List<String>> headers = getHeader(AuthenticationConstants.Broker.CHALLENGE_REQUEST_HEADER, " ");
HttpWebResponse responseChallenge = new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, headers);
when(mockWebRequest.sendPost(eq(new URL(TEST_AUTHORITY + "/oauth2/token")), Mockito.<String, String>anyMap(), any(byte[].class), eq("application/x-www-form-urlencoded"))).thenReturn(responseChallenge);
// send request
MockAuthenticationCallback testResult = refreshToken(getValidAuthenticationRequest(), mockWebRequest, "testRefreshToken");
// Verify that callback can receive this error
assertNotNull("Callback has error", testResult.getException());
assertNotNull(testResult.getException());
assertTrue(testResult.getException() instanceof AuthenticationException);
assertEquals("Check error message", "Challenge header is empty", testResult.getException().getMessage());
}
use of com.microsoft.identity.common.adal.internal.net.HttpWebResponse in project azure-activedirectory-library-for-android by AzureAD.
the class AuthenticationParamsTests method testParseResponseNegative.
/**
* test private method to make sure parsing is right
*/
@Test
public void testParseResponseNegative() throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_OK, null, null), AuthenticationParameters.AUTH_HEADER_WRONG_STATUS);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, null), AuthenticationParameters.AUTH_HEADER_MISSING);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "v")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer nonsense")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer ")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", " Bearer")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", " Bearer ")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "\t Bearer ")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer test ")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bear gets=honey ")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer =,=,")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer some text here,")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer authorization_uri= ")), AuthenticationParameters.AUTH_HEADER_MISSING_AUTHORITY);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearerauthorization_uri=something")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearerauthorization_uri=\"https://www.something.com\"")), AuthenticationParameters.AUTH_HEADER_INVALID_FORMAT);
callParseResponseForException(new HttpWebResponse(HttpURLConnection.HTTP_UNAUTHORIZED, null, getHeader("WWW-Authenticate", "Bearer \t authorization_uri=,something=a ")), AuthenticationParameters.AUTH_HEADER_MISSING_AUTHORITY);
}
use of com.microsoft.identity.common.adal.internal.net.HttpWebResponse in project azure-activedirectory-library-for-android by AzureAD.
the class WebFingerMetadataRequestorTests method testParseMetadata.
@Test
public void testParseMetadata() throws AuthenticationException {
HttpWebResponse mockWebResponse = Mockito.mock(HttpWebResponse.class);
Mockito.when(mockWebResponse.getBody()).thenReturn(RESPONSE);
WebFingerMetadata metadata = new WebFingerMetadataRequestor().parseMetadata(mockWebResponse);
assertEquals("https://fs.lindft6.com", metadata.getSubject());
assertNotNull(metadata.getLinks());
assertEquals(1, metadata.getLinks().size());
assertEquals("http://schemas.microsoft.com/rel/trusted-realm", metadata.getLinks().get(0).getRel());
assertEquals("https://fs.lindft6.com", metadata.getLinks().get(0).getHref());
}
use of com.microsoft.identity.common.adal.internal.net.HttpWebResponse in project azure-activedirectory-library-for-android by AzureAD.
the class WebRequestHandlerTests method testGetRequest.
@Test
public void testGetRequest() throws IOException {
Logger.d(TAG, "test get" + android.os.Process.myTid());
final HttpURLConnection mockedConnection = Mockito.mock(HttpURLConnection.class);
HttpUrlConnectionFactory.setMockedHttpUrlConnection(mockedConnection);
Util.prepareMockedUrlConnection(mockedConnection);
Mockito.when(mockedConnection.getInputStream()).thenReturn(Util.createInputStream("testabc-value123"));
Mockito.when(mockedConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
final WebRequestHandler request = new WebRequestHandler();
HttpWebResponse httpResponse = request.sendGet(getUrl(TEST_WEBAPI_URL), getTestHeaders("testabc", "value123"));
assertNotNull(httpResponse != null);
assertTrue("status is 200", httpResponse.getStatusCode() == HttpURLConnection.HTTP_OK);
String responseMsg = httpResponse.getBody();
assertTrue("request header check", responseMsg.contains("testabc-value123"));
}
use of com.microsoft.identity.common.adal.internal.net.HttpWebResponse in project azure-activedirectory-library-for-android by AzureAD.
the class WebRequestHandlerTests method testClientTraceInHeaders.
/**
* WebService returns the request headers in the response
*/
@Test
public void testClientTraceInHeaders() throws IOException {
Logger.d(TAG, "test get" + android.os.Process.myTid());
final HttpURLConnection mockedConnection = Mockito.mock(HttpURLConnection.class);
HttpUrlConnectionFactory.setMockedHttpUrlConnection(mockedConnection);
Util.prepareMockedUrlConnection(mockedConnection);
Mockito.when(mockedConnection.getInputStream()).thenReturn(Util.createInputStream(AAD.ADAL_ID_PLATFORM + "-Android" + "dummy string" + AAD.ADAL_ID_VERSION + "-" + AuthenticationContext.getVersionName()));
Mockito.when(mockedConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
final WebRequestHandler request = new WebRequestHandler();
HttpWebResponse httpResponse = request.sendGet(getUrl(TEST_WEBAPI_URL), getTestHeaders("testClientTraceInHeaders", "valueYes"));
assertNotNull(httpResponse != null);
assertTrue("status is 200", httpResponse.getStatusCode() == HttpURLConnection.HTTP_OK);
String responseMsg = httpResponse.getBody();
assertTrue("request header check", responseMsg.contains(AAD.ADAL_ID_PLATFORM + "-Android"));
assertTrue("request header check", responseMsg.contains(AAD.ADAL_ID_VERSION + "-" + AuthenticationContext.getVersionName()));
}
Aggregations