Skip to content

Commit b76aa79

Browse files
authored
Merge pull request #3622 from fhanik/pr/add-userinfo-test-case
add userinfo test case
2 parents 49bb5a8 + 08b1f12 commit b76aa79

4 files changed

Lines changed: 65 additions & 9 deletions

File tree

scripts/boot/application.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ server:
99
port: 8443
1010
max-http-header-size: 14336
1111
tomcat:
12-
basedir: "${uaa.location.tomcat}"
12+
basedir: "${uaa.boot.location.tomcat}"
1313
connection-timeout: 20000
1414
keep-alive-timeout: 120000
1515
remoteip:
@@ -19,7 +19,7 @@ server:
1919
port-header: "X-Forwarded-Port"
2020
accesslog:
2121
enabled: true
22-
directory: "${uaa.location.tomcat}"
22+
directory: "${uaa.boot.location.tomcat}"
2323
prefix: "localhost_access"
2424
suffix: ".log"
2525
rotate: false
@@ -29,7 +29,7 @@ server:
2929
enabled-protocols: "TLSv1.2,TLSv1.3"
3030
ciphers: "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384"
3131
protocol: TLS
32-
key-store: "${uaa.location.certificate}/uaa_keystore.p12"
32+
key-store: "${uaa.boot.location.certificate}/uaa_keystore.p12"
3333
key-store-type: "PKCS12"
3434
key-alias: "uaa_ssl_cert"
3535
key-store-password: "k0*l*s3cur1tyr0ck$"

scripts/boot/boot-with-tls.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fi
3535
pushd ${SCRIPT_DIR}
3636
java \
3737
-Dlogging.level.org.springframework.security=TRACE \
38-
-Duaa.location.tomcat=${ROOT_DIR}/scripts/boot/tomcat \
39-
-Duaa.location.certificate=${ROOT_DIR}/scripts/certificates \
38+
-Duaa.boot.location.tomcat=${ROOT_DIR}/scripts/boot/tomcat \
39+
-Duaa.boot.location.certificate=${ROOT_DIR}/scripts/certificates \
4040
-Dlogging.config=${ROOT_DIR}/scripts/boot/log4j2.properties \
4141
-DCLOUDFOUNDRY_CONFIG_PATH=${ROOT_DIR}/scripts/cargo \
4242
-DSECRETS_DIR=${ROOT_DIR}/scripts/cargo \

uaa/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,14 @@ bootRun {
237237
dependsOn rootProject.cleanBootTomcatDir
238238
mainClass = "org.cloudfoundry.experimental.boot.UaaBootApplication"
239239
systemProperty("logging.level.org.springframework.security", "TRACE")
240-
systemProperty("server.tomcat.basedir", file("../scripts/boot/tomcat/").getAbsolutePath())
241-
systemProperty("logging.config", file("../scripts/boot/log4j2.properties/").getAbsolutePath())
242-
systemProperty("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("../scripts/cargo").getAbsolutePath()))
240+
systemProperty("logging.config", file("../scripts/boot/log4j2.properties").getAbsolutePath())
241+
systemProperty("uaa.boot.location.tomcat", System.getProperty("uaa.boot.location.tomcat", file("../scripts/boot/tomcat").getAbsolutePath()))
243242
systemProperty("spring.profiles.active", System.getProperty("spring.profiles.active", "hsqldb"))
244243
systemProperty("metrics.perRequestMetrics", System.getProperty("metrics.perRequestMetrics", "true"))
245244
systemProperty("smtp.host", "localhost")
246245
systemProperty("smtp.port", 2525)
247246
systemProperty("java.security.egd", "file:/dev/./urandom")
248-
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("../scripts/cargo").getAbsolutePath())
247+
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("../scripts/boot").getAbsolutePath())
249248
systemProperty("server.servlet.context-path", "/uaa")
250249
systemProperty("statsd.enabled", "true")
251250
}

uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/OIDCLoginIT.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,63 @@ void shadowUserNameDefaultsToOIDCSubjectClaim() {
427427
assertThat(shadowUser.getUserName()).isEqualTo(expectedUsername);
428428
}
429429

430+
@Test
431+
void claimsComeFromUserInfoEndpoint() {
432+
AbstractExternalOAuthIdentityProviderDefinition<?> oldConfig = identityProvider.getConfig();
433+
Map<String, Object> attributeMappings = new HashMap<>(identityProvider.getConfig().getAttributeMappings());
434+
attributeMappings.remove(USER_NAME_ATTRIBUTE_NAME);
435+
oldConfig.setAttributeMappings(attributeMappings);
436+
oldConfig.setLinkText("My Oauth2.0 Provider");
437+
//change the type so that we will use the /userinfo endpoint
438+
identityProvider.setType(OriginKeys.OAUTH20);
439+
updateProvider();
440+
441+
webDriver.get(zoneUrl);
442+
webDriver.clickAndWait(By.linkText(oldConfig.getLinkText()));
443+
444+
webDriver.findElement(By.name("username")).clear();
445+
webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
446+
webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
447+
webDriver.clickAndWait(By.xpath("//input[@value='Sign in']"));
448+
449+
webDriver.get(baseUrl);
450+
Cookie cookie = webDriver.manage().getCookieNamed("JSESSIONID");
451+
452+
ServerRunningExtension localhostServerRunning = ServerRunningExtension.connect();
453+
localhostServerRunning.setHostName("localhost");
454+
455+
String clientId = "client" + new RandomValueStringGenerator(5).generate();
456+
UaaClientDetails client = new UaaClientDetails(clientId, null, "openid", GRANT_TYPE_AUTHORIZATION_CODE, "openid", baseUrl);
457+
client.setClientSecret("clientsecret");
458+
client.setAutoApproveScopes(Collections.singletonList("true"));
459+
IntegrationTestUtils.createClient(adminToken, baseUrl, client);
460+
461+
Map<String, String> authCodeTokenResponse = IntegrationTestUtils.getAuthorizationCodeTokenMap(localhostServerRunning,
462+
clientId,
463+
"clientsecret",
464+
null,
465+
null,
466+
"token id_token",
467+
cookie.getValue(),
468+
baseUrl,
469+
null,
470+
false);
471+
472+
//validate that we have an ID token, and that it contains costCenter and manager values
473+
String idToken = authCodeTokenResponse.get("id_token");
474+
assertThat(idToken).isNotNull();
475+
476+
Jwt idTokenClaims = JwtHelper.decode(idToken);
477+
Map<String, Object> claims = JsonUtils.readValue(idTokenClaims.getClaims(), new TypeReference<>() {});
478+
String expectedUsername = (String) claims.get(SUB);
479+
480+
String anAdminToken = IntegrationTestUtils.getClientCredentialsToken(zoneUrl, zoneClient.getClientId(), zoneClient.getClientSecret());
481+
ScimUser shadowUser = IntegrationTestUtils.getUser(anAdminToken, zoneUrl, identityProvider.getOriginKey(), expectedUsername);
482+
assertThat(shadowUser.getUserName()).isEqualTo(expectedUsername);
483+
//there is no 'scope' attribute exposed on the /userinfo endpoint in this test.
484+
assertThat(shadowUser.getGroups().stream().map(g -> g.getDisplay())).doesNotContain(createdGroup.getDisplayName());
485+
}
486+
430487
@Test
431488
void successfulLoginWithOIDC_and_SAML_Provider_PlusRefreshRotation() throws Exception {
432489
SamlIdentityProviderDefinition saml = IntegrationTestUtils.createSimplePHPSamlIDP("simplesamlphp", OriginKeys.UAA, samlServerConfig.getSamlServerUrl());

0 commit comments

Comments
 (0)