Search in sources :

Example 1 with OAuthAccessGrant

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) OAuthAccessGrant(org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant) Test(org.testng.annotations.Test)

Example 2 with OAuthAccessGrant

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);
}
Also used : OAuthAccessGrant(org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant) Test(org.testng.annotations.Test)

Example 3 with OAuthAccessGrant

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);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) OAuthAccessGrant(org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant) Test(org.testng.annotations.Test)

Example 4 with OAuthAccessGrant

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);
}
Also used : OAuthAccessGrant(org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant)

Example 5 with OAuthAccessGrant

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);
}
Also used : OAuthAccessGrant(org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant)

Aggregations

OAuthAccessGrant (org.sagebionetworks.bridge.models.oauth.OAuthAccessGrant)19 Test (org.testng.annotations.Test)8 HttpPost (org.apache.http.client.methods.HttpPost)5 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)4 Condition (com.amazonaws.services.dynamodbv2.model.Condition)2 ArrayList (java.util.ArrayList)2 NameValuePair (org.apache.http.NameValuePair)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)2 OAuthProvider (org.sagebionetworks.bridge.models.apps.OAuthProvider)2 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 DateTime (org.joda.time.DateTime)1 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)1