From c43997e03d626323250bc3641b577f2bdb68b6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Wed, 5 Feb 2025 17:41:14 +0100 Subject: [PATCH] Fixing SRA tests --- .../syncope/fit/sra/AbstractOIDCITCase.java | 41 +++++++++++++++++++ .../syncope/fit/sra/AbstractSRAITCase.java | 33 --------------- .../mapping/DefaultAttrReleaseMapper.java | 3 -- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractOIDCITCase.java b/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractOIDCITCase.java index 2f5ae3042cc..c01f6087a06 100644 --- a/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractOIDCITCase.java +++ b/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractOIDCITCase.java @@ -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; @@ -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, @@ -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) { diff --git a/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractSRAITCase.java b/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractSRAITCase.java index 2e979013c9d..bb7c74c6e4f 100644 --- a/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractSRAITCase.java +++ b/fit/wa-reference/src/test/java/org/apache/syncope/fit/sra/AbstractSRAITCase.java @@ -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; @@ -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 { diff --git a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/DefaultAttrReleaseMapper.java b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/DefaultAttrReleaseMapper.java index e25d1643410..07cb261d3e5 100644 --- a/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/DefaultAttrReleaseMapper.java +++ b/wa/bootstrap/src/main/java/org/apache/syncope/wa/bootstrap/mapping/DefaultAttrReleaseMapper.java @@ -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()) {