Search in sources :

Example 1 with OAuth2CredentialFlowState

use of io.syndesis.server.credential.OAuth2CredentialFlowState in project syndesis by syndesisio.

the class CredentialITCase method shouldApplyOAuthPropertiesToNewlyCreatedConnections.

@Test
public void shouldApplyOAuthPropertiesToNewlyCreatedConnections() {
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("test-provider").key("key").accessGrant(new AccessGrant("token")).build();
    final HttpHeaders cookies = persistAsCookie(flowState);
    final Connection newConnection = new Connection.Builder().name("Test connection").connectorId("http").build();
    final ResponseEntity<Connection> connectionResponse = http(HttpMethod.POST, "/api/v1/connections", newConnection, Connection.class, tokenRule.validToken(), cookies, HttpStatus.OK);
    assertThat(connectionResponse.hasBody()).as("Should contain created connection").isTrue();
    final Connection createdConnection = connectionResponse.getBody();
    assertThat(createdConnection.isDerived()).isTrue();
    assertThat(createdConnection.getConfiguredProperties()).containsOnly(entry("accessToken", "token"), entry("clientId", "appId"), entry("clientSecret", "appSecret"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) AccessGrant(org.springframework.social.oauth2.AccessGrant) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Connection(io.syndesis.common.model.connection.Connection) OAuth2CredentialFlowState(io.syndesis.server.credential.OAuth2CredentialFlowState) Test(org.junit.Test)

Example 2 with OAuth2CredentialFlowState

use of io.syndesis.server.credential.OAuth2CredentialFlowState in project syndesis by syndesisio.

the class CredentialITCase method callbackErrorsShouldBeHandeled.

@Test
public void callbackErrorsShouldBeHandeled() {
    final String credentialKey = UUID.randomUUID().toString();
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("test-provider").key(credentialKey).returnUrl(URI.create("/ui#state")).build();
    final HttpHeaders cookies = persistAsCookie(flowState);
    final ResponseEntity<Void> callbackResponse = http(HttpMethod.GET, "/api/v1/credentials/callback?denied=something", null, Void.class, null, cookies, HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.getStatusCode()).as("Status should be temporarry redirect (307)").isEqualTo(HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.hasBody()).as("Should not contain HTTP body").isFalse();
    assertThat(callbackResponse.getHeaders().getLocation().toString()).matches("http.?://localhost:[0-9]*/api/v1/ui#%7B%22connectorId%22:%22test-provider%22,%22message%22:%22Unable%20to%20update%20the%20state%20of%20authorization%22,%22status%22:%22FAILURE%22%7D");
    final List<String> receivedCookies = callbackResponse.getHeaders().get("Set-Cookie");
    assertThat(receivedCookies).hasSize(1);
    assertThat(receivedCookies.get(0)).isEqualTo("cred-o2-" + credentialKey + "=\"\"; path=/; secure; HttpOnly; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:00 GMT");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) OAuth2CredentialFlowState(io.syndesis.server.credential.OAuth2CredentialFlowState) Test(org.junit.Test)

Example 3 with OAuth2CredentialFlowState

use of io.syndesis.server.credential.OAuth2CredentialFlowState in project syndesis by syndesisio.

the class CredentialITCase method shouldReceiveCallbacksFromResourceProviders.

@Test
public void shouldReceiveCallbacksFromResourceProviders() {
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("test-provider").key(UUID.randomUUID().toString()).returnUrl(URI.create("/ui#state")).build();
    final HttpHeaders cookies = persistAsCookie(flowState);
    final ResponseEntity<Void> callbackResponse = http(HttpMethod.GET, "/api/v1/credentials/callback?state=test-state&code=code", null, Void.class, null, cookies, HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.getStatusCode()).as("Status should be temporarry redirect (307)").isEqualTo(HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.hasBody()).as("Should not contain HTTP body").isFalse();
    assertThat(callbackResponse.getHeaders().getLocation().toString()).matches("http.?://localhost:[0-9]*/api/v1/ui#%7B%22connectorId%22:%22test-provider%22,%22message%22:%22Successfully%20authorized%20Syndesis's%20access%22,%22status%22:%22SUCCESS%22%7D");
    final List<String> receivedCookies = callbackResponse.getHeaders().get("Set-Cookie");
    assertThat(receivedCookies).hasSize(1);
    final OAuth2CredentialFlowState endingFlowState = clientSideState.restoreFrom(Cookie.valueOf(receivedCookies.get(0)), OAuth2CredentialFlowState.class);
    // AccessGrant does not implement equals/hashCode
    assertThat(endingFlowState).isEqualToIgnoringGivenFields(new OAuth2CredentialFlowState.Builder().createFrom(flowState).code("code").build(), "accessGrant");
    assertThat(endingFlowState.getAccessGrant()).isEqualToComparingFieldByField(new AccessGrant("token"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) AccessGrant(org.springframework.social.oauth2.AccessGrant) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) OAuth2CredentialFlowState(io.syndesis.server.credential.OAuth2CredentialFlowState) Test(org.junit.Test)

Aggregations

OAuth2CredentialFlowState (io.syndesis.server.credential.OAuth2CredentialFlowState)3 Test (org.junit.Test)3 HttpHeaders (org.springframework.http.HttpHeaders)3 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)3 AccessGrant (org.springframework.social.oauth2.AccessGrant)2 Connection (io.syndesis.common.model.connection.Connection)1