@Test
    void verifyAuthenticateNotAuthorized() throws Throwable {
        val context = MockRequestContext.create(applicationContext);
        WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());

        val attributes = new LinkedHashMap<String, List<Object>>();
        attributes.put(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, List.of(true));
        attributes.putAll(CoreAuthenticationTestUtils.getAttributeRepository().getBackingMap());

        val p = CoreAuthenticationTestUtils.getPrincipal("casuser", attributes);
        WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(p), context);

        val creds = new UsernamePasswordCredential();
        creds.assignPassword("Mellon");
        creds.setUsername("casuser");
        creds.getCredentialMetadata().addTrait(new SurrogateCredentialTrait("unknown-user"));
        WebUtils.putCredential(context, creds);

        val builder = mock(AuthenticationResultBuilder.class);
        when(builder.getInitialAuthentication()).thenReturn(Optional.of(CoreAuthenticationTestUtils.getAuthentication("casuser")));
        when(builder.collect(any(Authentication.class))).thenReturn(builder);

        WebUtils.putAuthenticationResultBuilder(builder, context);
        assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, loadSurrogatesListAction.execute(context).getId());
    }
This is {@link LoadSurrogatesListActionTests}.

@author Misagh Moayyed
@since 5.3.0
support/cas-server-support-surrogate-webflow/src/test/java/org/apereo/cas/web/flow/action/LoadSurrogatesListActionTests.java