Search in sources :

Example 26 with HttpResponse

use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockServerResponse method getMockTokenFailureInvalidGrantResponse.

public static HttpResponse getMockTokenFailureInvalidGrantResponse() {
    final MicrosoftTokenErrorResponse tokenErrorResponse = new MicrosoftTokenErrorResponse();
    tokenErrorResponse.setError("invalid_grant");
    tokenErrorResponse.setErrorDescription("AADSTS70000: Provided grant is invalid or malformed");
    tokenErrorResponse.setErrorCodes(new ArrayList<Long>(Arrays.asList(70000L)));
    tokenErrorResponse.setTimeStamp("2019-10-23 21:05:16Z");
    tokenErrorResponse.setTraceId("8497799a-e9f9-402f-a951-7060b5014600");
    tokenErrorResponse.setCorrelationId("390d7507-c607-4f05-bb8a-51a2a7a6282b");
    tokenErrorResponse.setErrorUri("https://login.microsoftonline.com/error?code=70000");
    tokenErrorResponse.setSubError("");
    final String mockResponse = ObjectMapper.serializeObjectToJsonString(tokenErrorResponse);
    final HttpResponse response = new HttpResponse(400, mockResponse, new HashMap<String, List<String>>());
    return response;
}
Also used : MicrosoftTokenErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse) List(java.util.List) ArrayList(java.util.ArrayList)

Example 27 with HttpResponse

use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockServerResponse method getMockTokenSuccessResponse.

public static HttpResponse getMockTokenSuccessResponse() {
    final MicrosoftTokenResponse mockTokenResponse = new MicrosoftTokenResponse();
    mockTokenResponse.setTokenType("Bearer");
    mockTokenResponse.setScope("User.Read");
    mockTokenResponse.setExpiresIn(defaultTokenExpiryInSec);
    mockTokenResponse.setExtExpiresIn(defaultTokenExpiryInSec);
    mockTokenResponse.setAccessToken("b06d0810-12ff-4a4e-850b-4bda1540d895");
    mockTokenResponse.setRefreshToken("6b80f5b5-d53c-4c46-992d-66c5dcd4cfb1");
    mockTokenResponse.setIdToken(MockTokenCreator.createMockIdToken());
    mockTokenResponse.setClientInfo(MockTokenCreator.createMockRawClientInfo());
    final String mockResponse = ObjectMapper.serializeObjectToJsonString(mockTokenResponse);
    return new HttpResponse(200, mockResponse, new HashMap<>());
}
Also used : MicrosoftTokenResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenResponse) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse)

Example 28 with HttpResponse

use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockDelayedResponseStrategy method makeHttpResponseFromResponseObject.

public HttpResponse makeHttpResponseFromResponseObject(final Object obj) {
    final String httpResponseBody = ObjectMapper.serializeObjectToJsonString(obj);
    final HashMap<String, List<String>> responseHeaders = new HashMap<>();
    responseHeaders.put(AuthenticationConstants.HeaderField.X_MS_CLITELEM, new ArrayList<>(Collections.singleton("1,0,0,,")));
    final HttpResponse httpResponse = new HttpResponse(200, httpResponseBody, responseHeaders);
    return httpResponse;
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with HttpResponse

use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockDelayedResponseStrategy method performTokenRequest.

@Override
protected HttpResponse performTokenRequest(final MicrosoftStsTokenRequest tokenRequest) {
    final TokenResult tokenResult = getTokenResult();
    final TokenResponse tokenResponse = tokenResult.getTokenResponse();
    try {
        Thread.sleep(RESPONSE_DELAY);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    final HttpResponse httpResponse = makeHttpResponseFromResponseObject(tokenResponse);
    return httpResponse;
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MockTokenResponse(com.microsoft.identity.internal.testutils.mocks.MockTokenResponse) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse)

Aggregations

HttpResponse (com.microsoft.identity.common.internal.net.HttpResponse)29 IOException (java.io.IOException)10 HttpURLConnection (java.net.HttpURLConnection)10 InOrder (org.mockito.InOrder)10 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Test (org.junit.Test)5 MicrosoftTokenErrorResponse (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenErrorResponse)4 URL (java.net.URL)3 MicrosoftTokenResponse (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenResponse)2 TokenResponse (com.microsoft.identity.common.internal.providers.oauth2.TokenResponse)2 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)2 MockTokenResponse (com.microsoft.identity.internal.testutils.mocks.MockTokenResponse)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 Uri (android.net.Uri)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ServiceException (com.microsoft.identity.common.exception.ServiceException)1 MicrosoftTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest)1