Skip to content

Commit

Permalink
Merge branch 'master' into patch-access-token-claims-4
Browse files Browse the repository at this point in the history
  • Loading branch information
shashimalcse authored Dec 18, 2024
2 parents b189049 + cf1d6c8 commit d72214a
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
Expand All @@ -46,6 +45,8 @@
import javax.xml.xpath.XPathExpressionException;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.testng.Assert.assertNotNull;
Expand All @@ -63,7 +64,10 @@ public class IdPSuccessTest extends IdPTestBase {
private static final String OIDC_SCOPES_PLACEHOLDER = "\"<OIDC_SCOPES>\"";
private static final String AUTHENTICATOR_PROPERTIES_PLACEHOLDER = "\"<AUTHENTICATOR_PROPERTIES>\"";
private static final String FEDERATED_AUTHENTICATOR_ID = "Y3VzdG9tQXV0aGVudGljYXRvcg";
private static final String OIDC_AUTHENTICATOR_ID = "T3BlbklEQ29ubmVjdEF1dGhlbnRpY2F0b3I";
private static final String SAML_AUTHENTICATOR_ID = "U0FNTFNTT0F1dGhlbnRpY2F0b3I";
private static final String CUSTOM_IDP_NAME = "Custom Auth IDP";
private static final String SAML_IDP_NAME = "SAML IdP";
private static final String ENDPOINT_URI = "https://abc.com/authenticate";
private static final String UPDATED_ENDPOINT_URI = "https://xyz.com/authenticate";
private static final String USERNAME = "username";
Expand All @@ -76,6 +80,8 @@ public class IdPSuccessTest extends IdPTestBase {
private static final String TRUSTED_TOKEN_ISS_IDP_NAME = "Trusted Token Issuer IdP";
private static final String AUTHENTICATOR_NAME = "GoogleOIDCAuthenticator";
private static final String DEFINED_BY_SYSTEM = "SYSTEM";
private static final String DEFINED_BY_USER = "USER";
private static final String CUSTOM_TAGS = "Custom";
private UserDefinedAuthenticatorPayload userDefinedAuthenticatorPayload;
private String idpCreatePayload;
private String idPId;
Expand Down Expand Up @@ -337,19 +343,30 @@ public void testGetMetaOutboundConnector() throws IOException {
}

@Test
public void testAddIdPWithUserDefinedAuthenticator() throws IOException {
public void testAddIdPWithUserDefinedAuthenticator() throws IOException, XPathExpressionException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
FEDERATED_AUTHENTICATOR_ID + "' }.";

String body = idpCreatePayload.replace(FEDERATED_AUTHENTICATOR_ID_PLACEHOLDER,
userDefinedAuthenticatorPayload.getAuthenticatorId());
body = body.replace(FEDERATED_AUTHENTICATOR_PLACEHOLDER,
userDefinedAuthenticatorPayload.convertToJasonPayload());
body = body.replace(IDP_NAME_PLACEHOLDER, CUSTOM_IDP_NAME);

Response response = getResponseOfPost(IDP_API_BASE_PATH, body);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
.header(HttpHeaders.LOCATION, notNullValue())
.body("name", equalTo(CUSTOM_IDP_NAME))
.body(baseIdentifier + "authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_USER))
.body(baseIdentifier + "tags", hasItems(CUSTOM_TAGS))
.body(baseIdentifier + "self", notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
Expand All @@ -360,6 +377,7 @@ public void testAddIdPWithUserDefinedAuthenticator() throws IOException {
@Test(dependsOnMethods = "testAddIdPWithUserDefinedAuthenticator")
public void testGetUserDefinedAuthenticatorsOfIdP() throws XPathExpressionException {

String baseIdentifier = "authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.";
Response response = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId +
PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH);

Expand All @@ -368,18 +386,18 @@ public void testGetUserDefinedAuthenticatorsOfIdP() throws XPathExpressionExcept
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("defaultAuthenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.name",
equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.isEnabled",
equalTo(true))
.body("authenticators.find { it.authenticatorId == '" + FEDERATED_AUTHENTICATOR_ID + "' }.self",
equalTo(getTenantedRelativePath("/api/server/v1/identity-providers/" +
customIdPId + "/federated-authenticators/" + FEDERATED_AUTHENTICATOR_ID,
context.getContextTenant().getDomain())));
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_USER))
.body(baseIdentifier + "tags", hasItems(CUSTOM_TAGS))
.body(baseIdentifier + "self", equalTo(getTenantedRelativePath(
"/api/server/v1/identity-providers/" + customIdPId +
"/federated-authenticators/" + FEDERATED_AUTHENTICATOR_ID,
context.getContextTenant().getDomain())));
}

@Test(dependsOnMethods = "testGetUserDefinedAuthenticatorsOfIdP")
public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingException {
public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingException, XPathExpressionException {

Response response = getResponseOfPut(IDP_API_BASE_PATH + PATH_SEPARATOR + customIdPId +
PATH_SEPARATOR + IDP_FEDERATED_AUTHENTICATORS_PATH + PATH_SEPARATOR + FEDERATED_AUTHENTICATOR_ID,
Expand All @@ -392,7 +410,9 @@ public void testUpdateUserDefinedAuthenticatorOfIdP() throws JsonProcessingExcep
.statusCode(HttpStatus.SC_OK)
.body("authenticatorId", equalTo(FEDERATED_AUTHENTICATOR_ID))
.body("name", equalTo(new String(Base64.getDecoder().decode(FEDERATED_AUTHENTICATOR_ID))))
.body("definedBy", equalTo("USER"))
.body("isEnabled", equalTo(true))
.body("definedBy", equalTo(DEFINED_BY_USER))
.body("tags", hasItems(CUSTOM_TAGS))
.body("endpoint.uri", equalTo(UPDATED_ENDPOINT_URI))
.body("endpoint.authentication.type", equalTo(AuthenticationType.TypeEnum.BEARER.value()));
}
Expand All @@ -419,7 +439,10 @@ public void testDeleteIdPWithUserDefinedAuthenticator() {
}

@Test(dependsOnMethods = {"testGetMetaOutboundConnector"})
public void testAddIdP() throws IOException {
public void testAddIdP() throws IOException, XPathExpressionException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }.";

String addIdpPayload = readResource("add-idp.json");
String properties = convertDuplicatedPropertiesToJson(
Expand All @@ -431,7 +454,14 @@ public void testAddIdP() throws IOException {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
.header(HttpHeaders.LOCATION, notNullValue())
.body("name", equalTo(IDP_NAME))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().
decode(SAMPLE_FEDERATED_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM))
.body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth"))
.body(baseIdentifier + "self", notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
Expand All @@ -448,7 +478,7 @@ public void addIdPWithoutAuthenticator() throws IOException {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.body("federatedAuthenticators.authenticators", Matchers.emptyIterable())
.body("federatedAuthenticators.authenticators", emptyIterable())
.header(HttpHeaders.LOCATION, notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
Expand All @@ -467,6 +497,9 @@ public void addIdPWithoutAuthenticator() throws IOException {
@Test
public void addIdPWithDuplicatedOIDCScopes() throws IOException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
OIDC_AUTHENTICATOR_ID + "' }.";

String oidcIdpPayload = readResource("add-oidc-idp.json");
String oidcScopesProperties = convertDuplicatedPropertiesToJson(
createAuthenticatorProperties("Scopes","openid country profile"),
Expand All @@ -479,7 +512,14 @@ public void addIdPWithDuplicatedOIDCScopes() throws IOException {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
.header(HttpHeaders.LOCATION, notNullValue())
.body("name", equalTo("OIDC-IdP-1"))
.body(baseIdentifier + "authenticatorId", equalTo(OIDC_AUTHENTICATOR_ID))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(OIDC_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM))
.body(baseIdentifier + "tags", hasItems("OIDC", "APIAuth"))
.body(baseIdentifier + "self", notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
Expand All @@ -496,6 +536,9 @@ public void addIdPWithDuplicatedOIDCScopes() throws IOException {
@Test(dependsOnMethods = "addIdPWithDuplicatedOIDCScopes")
public void addOIDCIdPWithoutOpenidScope() throws IOException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
OIDC_AUTHENTICATOR_ID + "' }.";

String oidcIdpPayload = readResource("add-oidc-idp.json");
String oidcScopesProperties = convertDuplicatedPropertiesToJson(
createAuthenticatorProperties("Scopes","country profile"), null);
Expand All @@ -507,7 +550,14 @@ public void addOIDCIdPWithoutOpenidScope() throws IOException {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
.header(HttpHeaders.LOCATION, notNullValue())
.body("name", equalTo("OIDC-IdP-2"))
.body(baseIdentifier + "authenticatorId", equalTo(OIDC_AUTHENTICATOR_ID))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(OIDC_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM))
.body(baseIdentifier + "tags", hasItems("OIDC", "APIAuth"))
.body(baseIdentifier + "self", notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
Expand All @@ -518,7 +568,10 @@ public void addOIDCIdPWithoutOpenidScope() throws IOException {
}

@Test
public void addSAMLStandardBasedIdP() throws IOException {
public void addSAMLStandardBasedIdP() throws IOException, XPathExpressionException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
SAML_AUTHENTICATOR_ID + "' }.";

String samlIdpPayload = readResource("add-saml-idp.json");
String body = samlIdpPayload.replace(METADATA_SAML_PLACEHOLDER, loadMetadataSamlFile(
Expand All @@ -529,7 +582,14 @@ public void addSAMLStandardBasedIdP() throws IOException {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
.header(HttpHeaders.LOCATION, notNullValue())
.body("name", equalTo(SAML_IDP_NAME))
.body(baseIdentifier + "authenticatorId", equalTo(SAML_AUTHENTICATOR_ID))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().decode(SAML_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM))
.body(baseIdentifier + "tags", hasItems("SAML"))
.body(baseIdentifier + "self", notNullValue());

String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
Expand All @@ -540,7 +600,10 @@ public void addSAMLStandardBasedIdP() throws IOException {
}

@Test(dependsOnMethods = {"testAddIdP"})
public void testGetIdP() throws IOException {
public void testGetIdP() throws IOException, XPathExpressionException {

String baseIdentifier = "federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }.";

Response response = getResponseOfGet(IDP_API_BASE_PATH + PATH_SEPARATOR + idPId);
response.then()
Expand All @@ -552,8 +615,14 @@ public void testGetIdP() throws IOException {
.body("description", equalTo("IDP for Google Federation"))
.body("isEnabled", equalTo(true))
.body("isPrimary", equalTo(false))
.body("federatedAuthenticators.authenticators.find { it.authenticatorId == '" +
SAMPLE_FEDERATED_AUTHENTICATOR_ID + "' }.definedBy", equalTo("SYSTEM"))
.body(baseIdentifier + "name", equalTo(new String(Base64.getDecoder().
decode(SAMPLE_FEDERATED_AUTHENTICATOR_ID))))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "definedBy", equalTo(DEFINED_BY_SYSTEM))
.body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth"))
.body(baseIdentifier + "self", equalTo(getTenantedRelativePath(
"/api/server/v1/identity-providers/" + idPId + "/federated-authenticators/"
+ SAMPLE_FEDERATED_AUTHENTICATOR_ID, context.getContextTenant().getDomain())))
.body("image", equalTo("google-logo-url"))
.body("isFederationHub", equalTo(false))
.body("homeRealmIdentifier", equalTo("localhost"))
Expand Down Expand Up @@ -646,7 +715,9 @@ public void testGetIdPFederatedAuthenticators() throws Exception {
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body(baseIdentifier + "authenticatorId", equalTo(SAMPLE_FEDERATED_AUTHENTICATOR_ID))
.body(baseIdentifier + "name", equalTo("GoogleOIDCAuthenticator"))
.body(baseIdentifier + "tags", hasItems("Social-Login", "APIAuth"))
.body(baseIdentifier + "isEnabled", equalTo(true))
.body(baseIdentifier + "self", equalTo(getTenantedRelativePath(
"/api/server/v1/identity-providers/" + idPId + "/federated-authenticators/" +
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,7 @@

<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.17</identity.api.dispatcher.version>
<identity.server.api.version>1.3.12</identity.server.api.version>
<identity.server.api.version>1.3.15</identity.server.api.version>
<identity.user.api.version>1.3.46</identity.user.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
Expand Down

0 comments on commit d72214a

Please sign in to comment.