@Test
        void verifyOperation() throws Throwable {
            val surrogateService = new SimpleSurrogateAuthenticationService(Map.of(), servicesManager,
                casProperties, principalAccessStrategyEnforcer, applicationContext);
            val principal = RegisteredServiceTestUtils.getPrincipal(UUID.randomUUID().toString(),
                Map.of("membership", List.of("faculty", "superadmin"),
                    SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, List.of(true)));
            assertTrue(surrogateService.canImpersonate(UUID.randomUUID().toString(), principal, Optional.empty()));

            val registeredService = RegisteredServiceTestUtils.getRegisteredService(UUID.randomUUID().toString());
            val accessStrategy = new SurrogateRegisteredServiceAccessStrategy();
            accessStrategy.setSurrogateRequiredAttributes(Map.of("impersonation", Set.of("yes")));
            registeredService.setAccessStrategy(accessStrategy);
            servicesManager.save(registeredService);
            assertThrows(PrincipalException.class, () -> surrogateService.canImpersonate(UUID.randomUUID().toString(), principal,
                Optional.of(RegisteredServiceTestUtils.getService(registeredService.getServiceId()))));
            
            val registeredService2 = RegisteredServiceTestUtils.getRegisteredService(UUID.randomUUID().toString());
            registeredService2.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy());
            registeredService2.setSurrogatePolicy(new DefaultRegisteredServiceSurrogatePolicy().setEnabled(false));
            servicesManager.save(registeredService2);
            assertFalse(surrogateService.canImpersonate(UUID.randomUUID().toString(), principal,
                Optional.of(RegisteredServiceTestUtils.getService(registeredService2.getServiceId()))));

        }
This is {@link SimpleSurrogateAuthenticationServiceTests}.

@author Misagh Moayyed
@since 5.3.0
support/cas-server-support-surrogate-authentication/src/test/java/org/apereo/cas/authentication/surrogate/SimpleSurrogateAuthenticationServiceTests.java