From 2ab9a14f3f0883bffdd173111f10574a12d5aed1 Mon Sep 17 00:00:00 2001 From: pmm Date: Tue, 15 Apr 2025 15:17:02 +0530 Subject: [PATCH] [MNT-24859] Test cases added --- .../extensions/webscripts/index.get | 10 ---- ...viceAdminConsoleAuthenticatorUnitTest.java | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) delete mode 100644 remote-api/src/main/resources/alfresco/templates/webscripts/org/springframework/extensions/webscripts/index.get diff --git a/remote-api/src/main/resources/alfresco/templates/webscripts/org/springframework/extensions/webscripts/index.get b/remote-api/src/main/resources/alfresco/templates/webscripts/org/springframework/extensions/webscripts/index.get deleted file mode 100644 index 7deda89b5e..0000000000 --- a/remote-api/src/main/resources/alfresco/templates/webscripts/org/springframework/extensions/webscripts/index.get +++ /dev/null @@ -1,10 +0,0 @@ - - -function main() -{ - status.code = 301; - status.location = url.serviceContext + Admin.getDefaultToolURI(); - status.redirect = true; -} - -main(); \ No newline at end of file diff --git a/repository/src/test/java/org/alfresco/repo/security/authentication/identityservice/admin/IdentityServiceAdminConsoleAuthenticatorUnitTest.java b/repository/src/test/java/org/alfresco/repo/security/authentication/identityservice/admin/IdentityServiceAdminConsoleAuthenticatorUnitTest.java index 6d1ca62de4..5cc6cc31b6 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authentication/identityservice/admin/IdentityServiceAdminConsoleAuthenticatorUnitTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authentication/identityservice/admin/IdentityServiceAdminConsoleAuthenticatorUnitTest.java @@ -173,6 +173,28 @@ public class IdentityServiceAdminConsoleAuthenticatorUnitTest assertTrue(authenticationRequest.getValue().contains("state")); } + @Test + public void shouldCallAuthChallengeWebScriptHome() throws IOException + { + String redirectPath = "/alfresco/s/index"; + + when(identityServiceConfig.getAdminConsoleScopes()).thenReturn(Set.of("openid", "email", "profile", "offline_access")); + when(identityServiceConfig.getWebScriptHomeRedirectPath()).thenReturn(redirectPath); + ArgumentCaptor authenticationRequest = ArgumentCaptor.forClass(String.class); + String expectedUri = "http://localhost:8999/auth?client_id=alfresco&redirect_uri=%s%s&response_type=code&scope=" + .formatted("http://localhost:8080", redirectPath); + + authenticator.requestAuthentication(request, response); + + verify(response).sendRedirect(authenticationRequest.capture()); + assertTrue(authenticationRequest.getValue().contains(expectedUri)); + assertTrue(authenticationRequest.getValue().contains("openid")); + assertTrue(authenticationRequest.getValue().contains("profile")); + assertTrue(authenticationRequest.getValue().contains("email")); + assertTrue(authenticationRequest.getValue().contains("offline_access")); + assertTrue(authenticationRequest.getValue().contains("state")); + } + @Test public void shouldCallAuthChallengeWithAudience() throws IOException { @@ -197,6 +219,30 @@ public class IdentityServiceAdminConsoleAuthenticatorUnitTest assertTrue(authenticationRequest.getValue().contains("state")); } + @Test + public void shouldCallAuthChallengeWebScriptHomeWithAudience() throws IOException + { + String audience = "http://localhost:8082"; + String redirectPath = "/alfresco/s/index"; + when(identityServiceConfig.getAudience()).thenReturn(audience); + when(identityServiceConfig.getWebScriptHomeRedirectPath()).thenReturn(redirectPath); + when(identityServiceConfig.getAdminConsoleScopes()).thenReturn(Set.of("openid", "email", "profile", "offline_access")); + ArgumentCaptor authenticationRequest = ArgumentCaptor.forClass(String.class); + String expectedUri = "http://localhost:8999/auth?client_id=alfresco&redirect_uri=%s%s&response_type=code&scope=" + .formatted("http://localhost:8080", redirectPath); + + authenticator.requestAuthentication(request, response); + + verify(response).sendRedirect(authenticationRequest.capture()); + assertTrue(authenticationRequest.getValue().contains(expectedUri)); + assertTrue(authenticationRequest.getValue().contains("openid")); + assertTrue(authenticationRequest.getValue().contains("profile")); + assertTrue(authenticationRequest.getValue().contains("email")); + assertTrue(authenticationRequest.getValue().contains("offline_access")); + assertTrue(authenticationRequest.getValue().contains("audience=%s".formatted(audience))); + assertTrue(authenticationRequest.getValue().contains("state")); + } + @Test public void shouldResetCookiesAndCallAuthChallenge() throws IOException {