use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method authorizedRequest.
@Test
public void authorizedRequest() throws InterruptedException, JSONException {
mEndPoint.enqueueUserInfoSuccess();
Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint);
HashMap<String, String> properties = new HashMap<>();
properties.put("state", CUSTOM_STATE);
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<JSONObject, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.authorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, cb);
latch.await();
RecordedRequest recordedRequest = mEndPoint.takeRequest();
assertNotNull(cb.getResult());
JSONObject result = cb.getResult();
assertThat(recordedRequest.getHeader("state"), is(CUSTOM_STATE));
assertNull(cb.getException());
assertEquals("John Doe", result.getString("name"));
assertEquals("Jimmy", result.getString("nickname"));
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method introspectTokenFailure.
@Test
public void introspectTokenFailure() throws InterruptedException {
mEndPoint.enqueueReturnInvalidClient();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<IntrospectInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.introspectToken(ACCESS_TOKEN, TokenTypeHint.ACCESS_TOKEN, cb);
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method requestsAreRunInSerial.
@Test
public void requestsAreRunInSerial() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
MockRequestCallback<UserInfo, AuthorizationException> userProfileCallback = new MockRequestCallback<>(latch);
mEndPoint.enqueueUserInfoSuccess();
mSessionClient.getUserProfile(userProfileCallback);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> refreshCallback = new MockRequestCallback<>(latch);
mSessionClient.refreshToken(refreshCallback);
latch.await();
UserInfo userInfoResult = userProfileCallback.getResult();
assertNotNull(userInfoResult);
assertEquals("John Doe", userInfoResult.get("name"));
assertEquals("Jimmy", userInfoResult.get("nickname"));
Tokens result = refreshCallback.getResult();
TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
assertEquals(original.getIdToken(), result.getIdToken());
assertEquals(original.getRefreshToken(), result.getRefreshToken());
assertEquals(original.getIdToken(), result.getIdToken());
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method authorizedRequestFailure.
@Test
public void authorizedRequestFailure() throws InterruptedException, JSONException {
mEndPoint.enqueueReturnInvalidClient();
Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint);
HashMap<String, String> properties = new HashMap<>();
properties.put("state", CUSTOM_STATE);
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<JSONObject, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.authorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, cb);
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
}
use of com.okta.oidc.util.AuthorizationException in project okta-oidc-android by okta.
the class SessionClientImplTest method getUserProfile.
@Test
public void getUserProfile() throws InterruptedException, JSONException {
mEndPoint.enqueueUserInfoSuccess();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<UserInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.getUserProfile(cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
UserInfo result = cb.getResult();
assertThat(recordedRequest.getHeader("Authorization"), is("Bearer " + ACCESS_TOKEN));
assertThat(recordedRequest.getHeader("Accept"), is(ConnectionParameters.JSON_CONTENT_TYPE));
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertNotNull(result);
assertEquals("John Doe", result.get("name"));
assertEquals("Jimmy", result.get("nickname"));
}
Aggregations