use of org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant in project BridgeServer2 by Sage-Bionetworks.
the class OAuthProviderServiceTest method makeAccessGrantCallWithScopes.
@Test
public void makeAccessGrantCallWithScopes() throws Exception {
mockAccessGrantCall(200, successJson());
mockIntrospectCall(200, INTROSPECT_RESPONSE_BODY);
OAuthAccessGrant grant = service.requestAccessGrant(PROVIDER_WITH_INTROSPECT, AUTH_TOKEN);
assertEquals(grant.getScopes(), EXPECTED_SCOPE_LIST);
String authHeader = "Basic " + Base64.encodeBase64String((CLIENT_ID + ":" + SECRET).getBytes());
HttpPost thePost = introspectPostCaptor.getValue();
// Test the headers here... they don't need to be tested in every test, they're always the same.
assertEquals(thePost.getURI().toString(), INTROSPECT_ENDPOINT);
assertEquals(thePost.getFirstHeader(OAuthProviderService.AUTHORIZATION_PROP_NAME).getValue(), authHeader);
assertEquals(thePost.getFirstHeader(OAuthProviderService.CONTENT_TYPE_PROP_NAME).getValue(), OAuthProviderService.FORM_ENCODING_VALUE);
String bodyString = EntityUtils.toString(thePost.getEntity());
assertEquals(bodyString, OAuthProviderService.TOKEN_PROP_NAME + "=" + ACCESS_TOKEN);
}
use of org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant in project BridgeServer2 by Sage-Bionetworks.
the class OAuthProviderServiceTest method introspect_GrantWithoutToken.
@Test(expectedExceptions = InvalidEntityException.class)
public void introspect_GrantWithoutToken() {
OAuthAccessGrant grant = OAuthAccessGrant.create();
service.addScopesToAccessGrant(PROVIDER_WITH_INTROSPECT, grant);
}
use of org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant in project BridgeServer2 by Sage-Bionetworks.
the class OAuthProviderServiceTest method refreshAccessGrantCallWithScopes.
@Test
public void refreshAccessGrantCallWithScopes() throws Exception {
mockRefreshCall(200, successJson());
mockIntrospectCall(200, INTROSPECT_RESPONSE_BODY);
OAuthAccessGrant grant = service.refreshAccessGrant(PROVIDER_WITH_INTROSPECT, VENDOR_ID, REFRESH_TOKEN);
assertEquals(grant.getScopes(), EXPECTED_SCOPE_LIST);
String authHeader = "Basic " + Base64.encodeBase64String((CLIENT_ID + ":" + SECRET).getBytes());
HttpPost thePost = introspectPostCaptor.getValue();
// Test the headers here... they don't need to be tested in every test, they're always the same.
assertEquals(thePost.getURI().toString(), INTROSPECT_ENDPOINT);
assertEquals(thePost.getFirstHeader(OAuthProviderService.AUTHORIZATION_PROP_NAME).getValue(), authHeader);
assertEquals(thePost.getFirstHeader(OAuthProviderService.CONTENT_TYPE_PROP_NAME).getValue(), OAuthProviderService.FORM_ENCODING_VALUE);
String bodyString = EntityUtils.toString(thePost.getEntity());
assertEquals(bodyString, OAuthProviderService.TOKEN_PROP_NAME + "=" + ACCESS_TOKEN);
}
use of org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant in project BridgeServer2 by Sage-Bionetworks.
the class OAuthServiceTest method setupDaoWithExpiredGrant.
private void setupDaoWithExpiredGrant() {
OAuthAccessGrant grant = createGrant(EXPIRES_ON.minusHours(4));
when(mockGrantDao.getAccessGrant(TEST_APP_ID, VENDOR_ID, HEALTH_CODE)).thenReturn(grant);
}
use of org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant in project BridgeServer2 by Sage-Bionetworks.
the class OAuthServiceTest method setupValidGrantCall.
private void setupValidGrantCall() {
OAuthAccessGrant grant = createGrant(EXPIRES_ON);
when(mockProviderService.requestAccessGrant(PROVIDER, AUTH_TOKEN)).thenReturn(grant);
}
Aggregations