From 24cb5005c923a3ce18379ab7416b1aea02892e56 Mon Sep 17 00:00:00 2001 From: Udara Pathum <46132469+hwupathum@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:17:14 +0530 Subject: [PATCH 1/3] Bump kernel version --- .../CallAnalyticsFunctionImplTest.java | 18 +++++++++++++++ .../choreo/CallChoreoFunctionImplTest.java | 18 +++++++++++++++ .../elk/CallElasticFunctionImplTest.java | 12 ++++++++++ .../http/CookieFunctionImplTest.java | 18 +++++++++++++++ .../http/HTTPGetFunctionImplTest.java | 6 +++++ .../http/HTTPPostFunctionImplTest.java | 6 +++++ .../pom.xml | 2 +- .../SendEmailFunctionImplTest.java | 16 +++++++++++++ .../HasAnyOfTheRolesFunctionImplTest.java | 23 +++++++++++++++---- .../user/HasRoleFunctionImplTest.java | 18 +++++++++++++++ ...IsMemberOfAnyOfGroupsFunctionImplTest.java | 23 +++++++++++++++---- .../utils/GetMaskedValueFunctionImplTest.java | 13 +++++++++++ ...ributeLoginIdentifierFunctionImplTest.java | 12 ++++++++++ pom.xml | 5 ++-- 14 files changed, 177 insertions(+), 13 deletions(-) diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/CallAnalyticsFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/CallAnalyticsFunctionImplTest.java index 03d9b387..6c7bfb75 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/CallAnalyticsFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/CallAnalyticsFunctionImplTest.java @@ -22,6 +22,8 @@ import com.google.gson.JsonObject; import org.graalvm.polyglot.HostAccess; import org.mockito.Mockito; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -37,6 +39,7 @@ import org.wso2.carbon.identity.application.common.model.Property; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.InjectMicroservicePort; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; @@ -47,6 +50,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.ResponseValidator; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.carbon.user.api.UserRealm; @@ -65,6 +69,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -86,6 +91,19 @@ public class CallAnalyticsFunctionImplTest extends JsSequenceHandlerAbstractTest @InjectMicroservicePort private int microServicePort; + @BeforeClass + protected void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/CallChoreoFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/CallChoreoFunctionImplTest.java index 4f11022f..b9f2972a 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/CallChoreoFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/CallChoreoFunctionImplTest.java @@ -34,7 +34,9 @@ import org.apache.commons.logging.LogFactory; import org.graalvm.polyglot.HostAccess; import org.mockito.Mockito; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -49,6 +51,7 @@ import org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.InjectMicroservicePort; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; @@ -62,6 +65,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.ResponseValidator; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.core.service.RealmService; @@ -81,6 +85,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -115,6 +120,19 @@ public class CallChoreoFunctionImplTest extends JsSequenceHandlerAbstractTest { @InjectMicroservicePort private int microServicePort; + @BeforeClass + protected void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/elk/CallElasticFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/elk/CallElasticFunctionImplTest.java index a5e0f0a2..19569b3b 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/elk/CallElasticFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/elk/CallElasticFunctionImplTest.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import org.json.JSONObject; import org.mockito.Mockito; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -33,6 +34,7 @@ import org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService; import org.wso2.carbon.identity.application.common.model.Property; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithMicroService; @@ -42,6 +44,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.msf4j.Response; @@ -56,6 +59,7 @@ import java.util.HashMap; import java.util.Map; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -74,6 +78,12 @@ public class CallElasticFunctionImplTest extends JsSequenceHandlerAbstractTest { @InjectMicroservicePort private int microServicePort; + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeClass @Parameters({"scriptEngine"}) protected void initClass(String scriptEngine) throws Exception { @@ -81,6 +91,8 @@ protected void initClass(String scriptEngine) throws Exception { super.setUp(scriptEngine); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; sequenceHandlerRunner.registerJsFunction("callElastic", new CallElasticFunctionImpl()); + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); } @Test diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/CookieFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/CookieFunctionImplTest.java index 20ce7c06..1e8fd534 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/CookieFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/CookieFunctionImplTest.java @@ -24,6 +24,8 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -40,6 +42,7 @@ import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; @@ -47,6 +50,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerRunner; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; +import org.wso2.carbon.identity.event.services.IdentityEventService; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -55,6 +59,7 @@ import java.util.HashMap; import java.util.Map; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** @@ -65,6 +70,19 @@ @WithRealmService(injectToSingletons = FrameworkServiceDataHolder.class) public class CookieFunctionImplTest extends JsSequenceHandlerAbstractTest { + @BeforeClass + protected void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPGetFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPGetFunctionImplTest.java index 5f17316f..61f28bba 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPGetFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPGetFunctionImplTest.java @@ -47,6 +47,7 @@ import org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.InjectMicroservicePort; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; @@ -57,6 +58,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.ResponseValidator; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import java.util.Date; import java.time.Instant; @@ -74,6 +76,7 @@ import javax.ws.rs.Produces; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.doNothing; @@ -127,12 +130,15 @@ protected void initClass(String scriptEngine) throws Exception { // Mocking the executeHttpMethod method to avoid actual http calls. httpGetFunction = spy(new HTTPGetFunctionImpl()); doNothing().when(httpGetFunction).executeHttpMethod(any(), any(), any()); + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); } @AfterClass protected void tearDown() { unsetAllowedDomains(); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); } @AfterMethod diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPPostFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPPostFunctionImplTest.java index f6d7d73a..c86eabf3 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPPostFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.http/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/http/HTTPPostFunctionImplTest.java @@ -47,6 +47,7 @@ import org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.InjectMicroservicePort; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; @@ -57,6 +58,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.ResponseValidator; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import java.util.Date; import java.time.Instant; @@ -73,6 +75,7 @@ import javax.ws.rs.Produces; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.doNothing; @@ -123,12 +126,15 @@ protected void initClass(String scriptEngine) throws Exception { // Mocking the executeHttpMethod method to avoid actual http calls. httpPostFunction = spy(new HTTPPostFunctionImpl()); doNothing().when(httpPostFunction).executeHttpMethod(any(), any(), any()); + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); } @AfterClass protected void tearDown() { unsetAllowedDomains(); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); } @AfterMethod diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.notification/pom.xml b/components/org.wso2.carbon.identity.conditional.auth.functions.notification/pom.xml index 7169ef29..1b2a6fac 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.notification/pom.xml +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.notification/pom.xml @@ -136,7 +136,7 @@ org.wso2.carbon.identity.event.event; version="${carbon.identity.package.import.version.range}", org.wso2.carbon.identity.event.services; version="${carbon.identity.package.import.version.range}", org.wso2.carbon.identity.event.handler.notification.exception; - version="${identity.event.handler.notification.version}", + version="${identity.event.handler.notification.version.range}", org.wso2.carbon.identity.central.log.mgt.utils; version="${carbon.identity.package.import.version.range}", org.wso2.carbon.user.core.service; version="${carbon.kernel.package.import.version.range}" diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/notification/SendEmailFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/notification/SendEmailFunctionImplTest.java index 11be437b..e09dc335 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/notification/SendEmailFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.notification/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/notification/SendEmailFunctionImplTest.java @@ -20,6 +20,8 @@ import org.mockito.Matchers; import org.mockito.Mockito; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -28,6 +30,7 @@ import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; @@ -43,6 +46,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; import static org.testng.Assert.*; /** @@ -53,6 +57,18 @@ @WithRealmService(injectToSingletons = FrameworkServiceDataHolder.class) public class SendEmailFunctionImplTest extends JsSequenceHandlerAbstractTest { + @BeforeClass + protected void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } @BeforeMethod protected void setUp() throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesFunctionImplTest.java index 2357febf..3a73119a 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasAnyOfTheRolesFunctionImplTest.java @@ -18,7 +18,9 @@ package org.wso2.carbon.identity.conditional.auth.functions.user; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -27,12 +29,14 @@ import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.user.internal.UserFunctionsServiceHolder; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.core.service.RealmService; @@ -40,6 +44,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -52,6 +57,19 @@ public class HasAnyOfTheRolesFunctionImplTest extends JsSequenceHandlerAbstractT @WithRealmService private RealmService realmService; + @BeforeClass + public void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + public void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { @@ -62,11 +80,6 @@ protected void setUp() throws Exception { userRealm.getUserStoreManager().addRole("manager", new String[]{"test_user1", "test_user3"}, null); } - @AfterMethod - public void tearDown() { - - } - @Test(dataProvider = "hasAnyOfTheRolesDataProvider") public void testHasAnyOfTheRoles(String user, boolean steppedUp) throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasRoleFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasRoleFunctionImplTest.java index 53fd21ea..55374542 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasRoleFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/HasRoleFunctionImplTest.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.conditional.auth.functions.user; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -27,6 +29,7 @@ import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; @@ -34,6 +37,7 @@ import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.conditional.auth.functions.user.internal.UserFunctionsServiceHolder; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.core.service.RealmService; @@ -41,6 +45,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -54,6 +59,19 @@ public class HasRoleFunctionImplTest extends JsSequenceHandlerAbstractTest { @WithRealmService private RealmService realmService; + @BeforeClass + public void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + public void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsMemberOfAnyOfGroupsFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsMemberOfAnyOfGroupsFunctionImplTest.java index 84ea0349..7a258e2e 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsMemberOfAnyOfGroupsFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.user/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/user/IsMemberOfAnyOfGroupsFunctionImplTest.java @@ -18,7 +18,9 @@ package org.wso2.carbon.identity.conditional.auth.functions.user; +import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -27,12 +29,14 @@ import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.user.internal.UserFunctionsServiceHolder; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.core.service.RealmService; @@ -40,6 +44,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -52,6 +57,19 @@ public class IsMemberOfAnyOfGroupsFunctionImplTest extends JsSequenceHandlerAbst @WithRealmService private RealmService realmService; + @BeforeClass + protected void setUpMocks() { + + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeMethod protected void setUp() throws Exception { @@ -65,11 +83,6 @@ protected void setUp() throws Exception { new String[]{"user1", "user3"}, null); } - @AfterMethod - public void tearDown() { - - } - @Test(dataProvider = "isMemberOfAnyOfGroupsDataProvider") public void testHasAnyOfTheRoles(String user, boolean steppedUp) throws Exception { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunctionImplTest.java index 805f2fee..34aff9e9 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/GetMaskedValueFunctionImplTest.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.conditional.auth.functions.utils; import org.testng.Assert; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -28,18 +29,22 @@ import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.common.model.ServiceProvider; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; +import org.wso2.carbon.identity.event.services.IdentityEventService; import java.util.Collections; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import static org.mockito.Mockito.mock; + /** * Test class for GetMaskedValueFunctionImplTest. */ @@ -56,6 +61,14 @@ public void setUp(String scriptEngine) throws Exception { CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true; sequenceHandlerRunner.registerJsFunction("getMaskedValue", new GetMaskedValueFunctionImpl()); + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); + } + + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); } @Test(dataProvider = "maskableValueProvider") diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunctionImplTest.java b/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunctionImplTest.java index 9cfef8ef..7fc1e69c 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunctionImplTest.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.utils/src/test/java/org/wso2/carbon/identity/conditional/auth/functions/utils/ResolveMultiAttributeLoginIdentifierFunctionImplTest.java @@ -20,6 +20,7 @@ import org.mockito.Mock; import org.testng.Assert; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Parameters; @@ -31,12 +32,14 @@ import org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig; import org.wso2.carbon.identity.application.common.model.ServiceProvider; import org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig; +import org.wso2.carbon.identity.central.log.mgt.internal.CentralLogMgtServiceComponentHolder; import org.wso2.carbon.identity.common.testng.WithCarbonHome; import org.wso2.carbon.identity.common.testng.WithH2Database; import org.wso2.carbon.identity.common.testng.WithRealmService; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest; import org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsTestException; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.event.services.IdentityEventService; import org.wso2.carbon.identity.multi.attribute.login.mgt.MultiAttributeLoginService; import org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult; import org.wso2.carbon.user.core.common.User; @@ -48,6 +51,7 @@ import javax.servlet.http.HttpServletResponse; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -59,6 +63,12 @@ public class ResolveMultiAttributeLoginIdentifierFunctionImplTest extends JsSequ @Mock private MultiAttributeLoginService multiAttributeLoginServiceMock; + @AfterClass + protected void tearDown() { + + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(null); + } + @BeforeClass @Parameters({"scriptEngine"}) public void setUp(String scriptEngine) throws Exception { @@ -74,6 +84,8 @@ public void setUp(String scriptEngine) throws Exception { frameworkServiceDataHolder.setAccessible(true); FrameworkServiceDataHolder instance = (FrameworkServiceDataHolder) frameworkServiceDataHolder.get(null); instance.setMultiAttributeLoginService(multiAttributeLoginServiceMock); + IdentityEventService identityEventService = mock(IdentityEventService.class); + CentralLogMgtServiceComponentHolder.getInstance().setIdentityEventService(identityEventService); } @DataProvider(name = "loginIdentifierProvider") diff --git a/pom.xml b/pom.xml index 2515431a..23bcba79 100644 --- a/pom.xml +++ b/pom.xml @@ -520,7 +520,7 @@ - 4.9.17 + 4.10.22 [4.6.0, 5.0.0) [1.0.1, 2.0.0) 7.4.7 @@ -529,7 +529,8 @@ [5.14.0, 8.0.0) 1.1.17 [1.5.70,3.0) - [1.0.23,2.0.0) + 1.9.4 + [1.0.23,2.0.0) 2.6.0.wso2v1 1.10.1 From 9375eee59916501412f40cd78c85bfa93fc40527 Mon Sep 17 00:00:00 2001 From: Udara Pathum <46132469+hwupathum@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:23:11 +0530 Subject: [PATCH 2/3] Use getKeystoreInstance from KeystoreUtils --- .../internal/AnalyticsFunctionsServiceComponent.java | 3 ++- .../choreo/internal/ChoreoFunctionServiceComponent.java | 7 +++++-- .../elk/internal/ElasticFunctionsServiceComponent.java | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/internal/AnalyticsFunctionsServiceComponent.java b/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/internal/AnalyticsFunctionsServiceComponent.java index 35a0de48..28b16852 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/internal/AnalyticsFunctionsServiceComponent.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.analytics/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/analytics/internal/AnalyticsFunctionsServiceComponent.java @@ -40,6 +40,7 @@ import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig; import org.wso2.carbon.utils.Axis2ConfigurationContextObserver; +import org.wso2.carbon.utils.security.KeystoreUtils; import java.io.FileInputStream; import java.io.IOException; @@ -91,7 +92,7 @@ protected void activate(ComponentContext context) { String keyStoreType = config.getFirstProperty("Security.TrustStore.Type"); String password = config.getFirstProperty("Security.TrustStore.Password"); try (InputStream keyStoreStream = new FileInputStream(filePath)) { - KeyStore keyStore = KeyStore.getInstance(keyStoreType); // or "PKCS12" + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(keyStoreType); // or "PKCS12" keyStore.load(keyStoreStream, password.toCharArray()); AnalyticsFunctionsServiceHolder.getInstance().setTrustStore(keyStore); } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e) { diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/internal/ChoreoFunctionServiceComponent.java b/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/internal/ChoreoFunctionServiceComponent.java index 76abc95b..6e6aa93a 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/internal/ChoreoFunctionServiceComponent.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.choreo/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/choreo/internal/ChoreoFunctionServiceComponent.java @@ -39,6 +39,7 @@ import org.wso2.carbon.identity.secret.mgt.core.SecretResolveManager; import org.wso2.carbon.identity.secret.mgt.core.SecretResolveManagerImpl; import org.wso2.carbon.utils.Axis2ConfigurationContextObserver; +import org.wso2.carbon.utils.security.KeystoreUtils; import java.io.FileInputStream; import java.io.IOException; @@ -46,6 +47,7 @@ import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; import java.security.cert.CertificateException; /** @@ -87,10 +89,11 @@ protected void activate(ComponentContext context) throws FrameworkException { String keyStoreType = config.getFirstProperty("Security.TrustStore.Type"); String password = config.getFirstProperty("Security.TrustStore.Password"); try (InputStream keyStoreStream = new FileInputStream(filePath)) { - KeyStore keyStore = KeyStore.getInstance(keyStoreType); // or "PKCS12" + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(keyStoreType); // or "PKCS12" keyStore.load(keyStoreStream, password.toCharArray()); ChoreoFunctionServiceHolder.getInstance().setTrustStore(keyStore); - } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e) { + } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException | + NoSuchProviderException e) { LOG.error("Error while loading truststore.", e); throw new FrameworkException("Error while trying to load Key Store.", e); } diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/internal/ElasticFunctionsServiceComponent.java b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/internal/ElasticFunctionsServiceComponent.java index 47f0571e..41f52fe1 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/internal/ElasticFunctionsServiceComponent.java +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/src/main/java/org/wso2/carbon/identity/conditional/auth/functions/elk/internal/ElasticFunctionsServiceComponent.java @@ -37,6 +37,7 @@ import org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent; import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.carbon.identity.governance.common.IdentityConnectorConfig; +import org.wso2.carbon.utils.security.KeystoreUtils; import java.io.IOException; import java.io.InputStream; @@ -83,7 +84,7 @@ protected void activate(ComponentContext context) { String keyStoreType = config.getFirstProperty(SECURITY_TRUSTSTORE_TYPE); String password = config.getFirstProperty(SECURITY_TRUSTSTORE_PASSWORD); try (InputStream keyStoreStream = Files.newInputStream(Paths.get(filePath))) { - KeyStore keyStore = KeyStore.getInstance(keyStoreType); // or "PKCS12" + KeyStore keyStore = KeystoreUtils.getKeystoreInstance(keyStoreType); // or "PKCS12" keyStore.load(keyStoreStream, password.toCharArray()); ElasticFunctionsServiceHolder.getInstance().setTrustStore(keyStore); } catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e) { From 0c558f75e3aee35753b93490c0bb78436666e5ed Mon Sep 17 00:00:00 2001 From: Udara Pathum <46132469+hwupathum@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:52:04 +0530 Subject: [PATCH 3/3] Update dependencies --- .../pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/pom.xml b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/pom.xml index a64b3888..06cd4055 100644 --- a/components/org.wso2.carbon.identity.conditional.auth.functions.elk/pom.xml +++ b/components/org.wso2.carbon.identity.conditional.auth.functions.elk/pom.xml @@ -153,6 +153,7 @@ org.wso2.carbon.identity.event; version="${carbon.identity.package.import.version.range}", org.wso2.carbon.identity.governance; version="${identity.governance.import.version.range}", org.wso2.carbon.identity.governance.common; version="${identity.governance.import.version.range}", + org.wso2.carbon.utils.*;version="${carbon.kernel.package.import.version.range}",