Skip to content

Commit

Permalink
feat(jans-auth-server): added test when unmet_authentication_requirem…
Browse files Browse the repository at this point in the history
…ents error code is returned #7900

Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
  • Loading branch information
yuriyz committed Apr 2, 2024
1 parent e7e6f24 commit 5c8e37b
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import io.jans.as.model.error.ErrorResponseFactory;
import io.jans.as.server.security.Identity;
import io.jans.as.server.service.*;
import io.jans.as.server.service.external.ExternalAuthenticationService;
import io.jans.as.server.service.external.ExternalAuthzDetailTypeService;
import io.jans.model.AuthenticationScriptUsageType;
import io.jans.model.custom.script.conf.CustomScriptConfiguration;
import io.jans.model.custom.script.model.CustomScript;
import io.jans.model.custom.script.type.auth.DummyPersonAuthenticationType;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.WebApplicationException;
import org.mockito.InjectMocks;
Expand All @@ -18,6 +23,7 @@
import org.testng.annotations.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;

import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -59,6 +65,46 @@ public class AuthorizeRestWebServiceValidatorTest {
@Mock
private ExternalAuthzDetailTypeService externalAuthzDetailTypeService;

@Mock
private ExternalAuthenticationService externalAuthenticationService;

@Test
public void checkAcrScriptIsAvailable_forBuildInAcr_shouldPass() {
AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setAcrValues("simple_password_auth");

authorizeRestWebServiceValidator.checkAcrScriptIsAvailable(authzRequest);
}

@Test
public void checkAcrScriptIsAvailable_whenScriptIsAvailable_shouldPass() {
AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setAcrValues("my_acr");

final CustomScriptConfiguration script = new CustomScriptConfiguration(new CustomScript(), new DummyPersonAuthenticationType(), new HashMap<>());
when(externalAuthenticationService.determineCustomScriptConfiguration(AuthenticationScriptUsageType.INTERACTIVE, authzRequest.getAcrValuesList())).thenReturn(script);

authorizeRestWebServiceValidator.checkAcrScriptIsAvailable(authzRequest);
}

@Test
public void checkAcrScriptIsAvailable_whenScriptIsNotAvailable_shouldFail() {
RedirectUri redirectUri = mock(RedirectUri.class);
when(redirectUri.toString()).thenReturn("http://rp.com");

AuthzRequest authzRequest = new AuthzRequest();
authzRequest.setAcrValues("my_acr");
authzRequest.setRedirectUriResponse(new RedirectUriResponse(redirectUri, "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class)));

try {
authorizeRestWebServiceValidator.checkAcrScriptIsAvailable(authzRequest);
} catch (WebApplicationException e) {
return;
}

fail("Script is not available but exception is not thrown.");
}

@Test
public void validateRequestParameterSupported_whenRequestIsEmpty_shouldPass() {
AuthzRequest authzRequest = new AuthzRequest();
Expand Down

0 comments on commit 5c8e37b

Please sign in to comment.