-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
167 changed files
with
10,632 additions
and
1,049 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...rg/cloudfoundry/identity/client/integration/IdentityZoneConfigurationIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* ***************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.client.integration; | ||
|
||
import org.cloudfoundry.identity.client.UaaContext; | ||
import org.cloudfoundry.identity.client.UaaContextFactory; | ||
import org.cloudfoundry.identity.client.token.GrantType; | ||
import org.cloudfoundry.identity.client.token.TokenRequest; | ||
import org.cloudfoundry.identity.uaa.zone.IdentityZone; | ||
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.net.URI; | ||
|
||
import static org.cloudfoundry.identity.client.integration.ClientIntegrationTestUtilities.GENERATOR; | ||
import static org.cloudfoundry.identity.client.integration.ClientIntegrationTestUtilities.UAA_URI; | ||
import static org.springframework.http.HttpMethod.POST; | ||
|
||
public class IdentityZoneConfigurationIntegrationTest { | ||
|
||
private UaaContextFactory factory; | ||
|
||
@Rule | ||
public IsUAAListeningRule uaaListeningRule = new IsUAAListeningRule(UAA_URI, false); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
factory = | ||
UaaContextFactory.factory(new URI(UAA_URI)) | ||
.authorizePath("/oauth/authorize") | ||
.tokenPath("/oauth/token"); | ||
} | ||
|
||
@Test | ||
public void create_zone_without_client_api() throws Exception { | ||
TokenRequest clientCredentials = factory.tokenRequest() | ||
.setClientId("identity") | ||
.setClientSecret("identitysecret") | ||
.setGrantType(GrantType.CLIENT_CREDENTIALS); | ||
|
||
UaaContext context = factory.authenticate(clientCredentials); | ||
|
||
String zoneId = GENERATOR.generate(); | ||
IdentityZone zone = new IdentityZone() | ||
.setId(zoneId) | ||
.setName(zoneId) | ||
.setSubdomain(zoneId) | ||
.setConfig(new IdentityZoneConfiguration()); | ||
|
||
ResponseEntity<IdentityZone> created = context.getRestTemplate().exchange( | ||
UAA_URI+"/identity-zones", | ||
POST, | ||
new HttpEntity<>(zone), | ||
IdentityZone.class | ||
); | ||
|
||
Assert.assertEquals(HttpStatus.CREATED, created.getStatusCode()); | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...nt-lib/src/test/java/org/cloudfoundry/identity/client/integration/IsUAAListeningRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
*******************************************************************************/ | ||
package org.cloudfoundry.identity.client.integration; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.Assume; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
import org.springframework.web.util.UriComponents; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.io.IOException; | ||
import java.net.Socket; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class IsUAAListeningRule implements TestRule { | ||
private static Log logger = LogFactory.getLog(IsUAAListeningRule.class); | ||
|
||
private static Map<String,Boolean> sharedStatuses = new HashMap<>(); | ||
|
||
private final String baseUrl; | ||
private final boolean forceIntegrationTests; | ||
|
||
public IsUAAListeningRule(String baseUrl, boolean forceIntegrationTests) { | ||
this.baseUrl = baseUrl; | ||
this.forceIntegrationTests = forceIntegrationTests; | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement statement, Description description) { | ||
Assume.assumeTrue("Test ignored as the server cannot be reached at " + baseUrl, forceIntegrationTests || getStatus()); | ||
return statement; | ||
} | ||
|
||
private synchronized Boolean getStatus() { | ||
Boolean available = sharedStatuses.get(baseUrl); | ||
if (available == null) { | ||
available = connectionAvailable(); | ||
sharedStatuses.put(baseUrl, available); | ||
} | ||
return available; | ||
} | ||
|
||
private boolean connectionAvailable() { | ||
UriComponents components = UriComponentsBuilder.fromHttpUrl(baseUrl).build(); | ||
String host = components.getHost(); | ||
int port = components.getPort(); | ||
|
||
logger.info("Testing connectivity for " + baseUrl); | ||
try (Socket socket = new Socket(host, port)) { | ||
logger.info("Connectivity test succeeded for " + baseUrl); | ||
return true; | ||
|
||
} catch (IOException e) { | ||
logger.warn("Connectivity test failed for " + baseUrl, e); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.