@Test
        void verifyServiceAttributeFilterAllAttributes() throws Throwable {
            val policy = new ReturnAllAttributeReleasePolicy();
            policy.setPrincipalIdAttribute("principalId");
            val mockPrincipal = mock(Principal.class);

            val map = new HashMap<String, List<Object>>();
            map.put(ATTR_1, List.of(VALUE_1));
            map.put(ATTR_2, List.of(VALUE_2));
            map.put(ATTR_3, Arrays.asList("v3", "v4"));

            when(mockPrincipal.getAttributes()).thenReturn(map);
            when(mockPrincipal.getId()).thenReturn(PRINCIPAL_ID);

            val registeredService = CoreAttributesTestUtils.getRegisteredService();
            when(registeredService.getUsernameAttributeProvider()).thenReturn(new RegisteredServiceUsernameAttributeProvider() {
                @Serial
                private static final long serialVersionUID = 771643288929352964L;

                @Override
                public String resolveUsername(final RegisteredServiceUsernameProviderContext context) {
                    return context.getPrincipal().getId();
                }
            });
            val context = RegisteredServiceAttributeReleasePolicyContext.builder()
                .registeredService(registeredService)
                .service(CoreAttributesTestUtils.getService())
                .applicationContext(applicationContext)
                .principal(mockPrincipal)
                .build();
            val attr = policy.getAttributes(context);
            assertEquals(attr.size(), map.size() + 1);

            val data = SerializationUtils.serialize(policy);
            val p2 = SerializationUtils.deserializeAndCheckObject(data, ReturnAllAttributeReleasePolicy.class);
            assertNotNull(p2);
        }
Attribute filtering policy tests.

@author Misagh Moayyed
@since 4.0.0
core/cas-server-core-authentication-attributes/src/test/java/org/apereo/cas/services/RegisteredServiceAttributeReleasePolicyTests.java