Skip to content

Commit

Permalink
Fixing SRA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Feb 5, 2025
1 parent aba3922 commit c43997e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@
import org.apache.http.util.EntityUtils;
import org.apache.syncope.common.lib.OIDCScopeConstants;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.policy.AttrReleasePolicyTO;
import org.apache.syncope.common.lib.policy.DefaultAttrReleasePolicyConf;
import org.apache.syncope.common.lib.to.OIDCRPClientAppTO;
import org.apache.syncope.common.lib.types.ClientAppType;
import org.apache.syncope.common.lib.types.OIDCGrantType;
import org.apache.syncope.common.lib.types.OIDCSubjectType;
import org.apache.syncope.common.lib.types.PolicyType;
import org.apache.syncope.common.rest.api.RESTHeaders;
import org.apache.syncope.common.rest.api.service.wa.WAConfigService;
import org.apereo.cas.oidc.OidcConstants;
Expand All @@ -80,6 +83,37 @@ abstract class AbstractOIDCITCase extends AbstractSRAITCase {

protected static String TOKEN_URI;

protected static AttrReleasePolicyTO getAttrReleasePolicy() {
String description = "SRA attr release policy";

return POLICY_SERVICE.list(PolicyType.ATTR_RELEASE).stream().
map(AttrReleasePolicyTO.class::cast).
filter(policy -> description.equals(policy.getName())
&& policy.getConf() instanceof DefaultAttrReleasePolicyConf).
findFirst().
orElseGet(() -> {
DefaultAttrReleasePolicyConf policyConf = new DefaultAttrReleasePolicyConf();
policyConf.getReleaseAttrs().put("surname", "family_name");
policyConf.getReleaseAttrs().put("fullname", "name");
policyConf.getReleaseAttrs().put("firstname", "given_name");
policyConf.getReleaseAttrs().put("email", "email");
policyConf.getReleaseAttrs().put("groups", "groups");

AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
policy.setName(description);
policy.setConf(policyConf);

Response response = POLICY_SERVICE.create(PolicyType.ATTR_RELEASE, policy);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
fail("Could not create Test Attr Release Policy");
}

return POLICY_SERVICE.read(
PolicyType.ATTR_RELEASE,
response.getHeaderString(RESTHeaders.RESOURCE_KEY));
});
}

protected static void oidcClientAppSetup(
final String appName,
final String sraRegistrationId,
Expand Down Expand Up @@ -136,6 +170,13 @@ protected static void oidcClientAppSetup(
WA_CONFIG_SERVICE.pushToWA(WAConfigService.PushSubject.conf, List.of());
throw new IllegalStateException();
}
metadata = WebClient.create(
WA_ADDRESS + "/actuator/env", ANONYMOUS_USER, ANONYMOUS_KEY, null).
get().readEntity(String.class);
if (!metadata.contains("cas.authn.oidc.core.user-defined-scopes.syncope")) {
WA_CONFIG_SERVICE.pushToWA(WAConfigService.PushSubject.conf, List.of());
throw new IllegalStateException();
}

return true;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.util.EntityUtils;
import org.apache.syncope.common.lib.policy.AttrReleasePolicyTO;
import org.apache.syncope.common.lib.policy.AuthPolicyTO;
import org.apache.syncope.common.lib.policy.DefaultAttrReleasePolicyConf;
import org.apache.syncope.common.lib.policy.DefaultAuthPolicyConf;
import org.apache.syncope.common.lib.to.SRARouteTO;
import org.apache.syncope.common.lib.types.PolicyType;
Expand Down Expand Up @@ -241,37 +239,6 @@ protected static AuthPolicyTO getAuthPolicy() {
});
}

protected static AttrReleasePolicyTO getAttrReleasePolicy() {
String description = "SRA attr release policy";

return POLICY_SERVICE.list(PolicyType.ATTR_RELEASE).stream().
map(AttrReleasePolicyTO.class::cast).
filter(policy -> description.equals(policy.getName())
&& policy.getConf() instanceof DefaultAttrReleasePolicyConf).
findFirst().
orElseGet(() -> {
DefaultAttrReleasePolicyConf policyConf = new DefaultAttrReleasePolicyConf();
policyConf.getAllowedAttrs().add("family_name");
policyConf.getAllowedAttrs().add("name");
policyConf.getAllowedAttrs().add("given_name");
policyConf.getAllowedAttrs().add("email");
policyConf.getAllowedAttrs().add("groups");

AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
policy.setName(description);
policy.setConf(policyConf);

Response response = POLICY_SERVICE.create(PolicyType.ATTR_RELEASE, policy);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
fail("Could not create Test Attr Release Policy");
}

return POLICY_SERVICE.read(
PolicyType.ATTR_RELEASE,
response.getHeaderString(RESTHeaders.RESOURCE_KEY));
});
}

protected static ObjectNode checkGetResponse(
final CloseableHttpResponse response, final String originalRequestURI) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ public RegisteredServiceAttributeReleasePolicy build(final ClientAppTO app, fina
returnMapped.setAllowedAttributes(conf.getReleaseAttrs());
}
}
if (app instanceof OIDCRPClientAppTO rp && !conf.getReleaseAttrs().isEmpty()) {
oidc = buildOidc(rp, conf);
}

ReturnAllowedAttributeReleasePolicy returnAllowed = null;
if (!conf.getAllowedAttrs().isEmpty()) {
Expand Down

0 comments on commit c43997e

Please sign in to comment.