From b919bba716fde157d91edb97a11bc6aaa8c59be5 Mon Sep 17 00:00:00 2001 From: spbolton Date: Mon, 11 Nov 2024 19:15:30 +0000 Subject: [PATCH 1/2] ci(semgrep): Fix trunk workflow for semgrep step passing artifact run id (#30610) (#30620) ### Proposed Changes * Error in trunk workflow due to artifact run id not being passed into semgrep workflow https://github.com/dotCMS/core/actions/runs/11782551202/job/32817867816#step:3:228 --- .github/workflows/cicd_3-trunk.yml | 2 ++ .github/workflows/cicd_comp_semgrep-phase.yml | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd_3-trunk.yml b/.github/workflows/cicd_3-trunk.yml index 08653f7dfe6..9c9ff3928d7 100644 --- a/.github/workflows/cicd_3-trunk.yml +++ b/.github/workflows/cicd_3-trunk.yml @@ -97,6 +97,8 @@ jobs: needs: [ initialize, test ] if: always() && !failure() && !cancelled() && vars.DISABLE_SEMGREP != 'true' uses: ./.github/workflows/cicd_comp_semgrep-phase.yml + with: + artifact-run-id: ${{ needs.initialize.outputs.artifact-run-id }} secrets: SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} diff --git a/.github/workflows/cicd_comp_semgrep-phase.yml b/.github/workflows/cicd_comp_semgrep-phase.yml index 3b66b60f976..71ca1356a6b 100644 --- a/.github/workflows/cicd_comp_semgrep-phase.yml +++ b/.github/workflows/cicd_comp_semgrep-phase.yml @@ -33,7 +33,7 @@ jobs: with: fetch-depth: 0 - # Prepare Maven environment and run SonarQube analysis + # Create dependency files for semgrep analysis - name: Build Dependency Tre uses: ./.github/actions/core-cicd/maven-job with: @@ -41,6 +41,8 @@ jobs: artifacts-from: ${{ inputs.artifact-run-id }} require-main: true github-token: ${{ secrets.GITHUB_TOKEN }} + require-graalvm: false + requires-node: false maven-args: dependency:tree -DoutputFile=maven_dep_tree.txt - name: Create Zip File run: find . -type f -name 'maven_dep_tree.txt' -exec zip -r dependency-tree.zip {} + From 786c18daf87fd3ba298a5013d1f4c2b7e5ac9659 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 11 Nov 2024 19:28:42 -0600 Subject: [PATCH 2/2] #30454 normalizing the host values to hostname (#30539) Normalizing the host values to hostname all the times --- .../collectors/CustomerEventCollector.java | 2 +- .../track/collectors/FilesCollector.java | 4 +- .../track/collectors/PageDetailCollector.java | 2 +- .../track/collectors/PagesCollector.java | 5 +- .../CustomerEventCollectorTest.java | 62 ++++++++++++++ .../track/collectors/FilesCollectorTest.java | 81 +++++++++++++++++++ .../track/collectors/PagesCollectorTest.java | 70 ++++++++++++++++ .../AsyncVanitiesCollectorTest.java | 7 +- .../track/collectors/FilesCollectorTest.java | 12 +-- .../collectors/PageDetailCollectorTest.java | 14 +--- .../track/collectors/PagesCollectorTest.java | 16 +--- .../collectors/SyncVanitiesCollectorTest.java | 15 +--- .../WebEventsCollectorServiceImplTest.java | 34 ++------ 13 files changed, 238 insertions(+), 86 deletions(-) create mode 100644 dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java create mode 100644 dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java create mode 100644 dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java index 520e4260353..df617f3d984 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CustomerEventCollector.java @@ -26,7 +26,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa final Host site = (Host) collectorContextMap.get("currentHost"); final String language = (String)collectorContextMap.get("lang"); collectorPayloadBean.put("url", uri); - collectorPayloadBean.put("host", host); + collectorPayloadBean.put("host", Objects.nonNull(site)?site.getHostname():host); collectorPayloadBean.put("language", language); collectorPayloadBean.put("site", null != site?site.getIdentifier():"unknown"); final String eventType = (String)collectorContextMap.get("eventType") == null? diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java index 9408ab91420..650aaf003a2 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java @@ -63,7 +63,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put("object", fileObject); collectorPayloadBean.put("url", uri); - collectorPayloadBean.put("host", host); + collectorPayloadBean.put("host", Objects.nonNull(site)?site.getHostname():host); collectorPayloadBean.put("language", language); collectorPayloadBean.put("site", null != site?site.getIdentifier():"unknown"); collectorPayloadBean.put("event_type", EventType.FILE_REQUEST.getType()); @@ -71,7 +71,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa return collectorPayloadBean; } - private Optional getFileAsset(String uri, Host host, Long languageId) { + protected Optional getFileAsset(String uri, Host host, Long languageId) { try { if (uri.endsWith(".dotsass")) { final String actualUri = uri.substring(0, uri.lastIndexOf('.')) + ".scss"; diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java index bb2cfc357bd..8c1d2718680 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PageDetailCollector.java @@ -86,7 +86,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put("language", language); if (Objects.nonNull(site)) { - collectorPayloadBean.put("host", site.getIdentifier()); + collectorPayloadBean.put("host", site.getHostname()); } return collectorPayloadBean; } diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java index ce2f62c642e..3cbadce39d7 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/PagesCollector.java @@ -53,7 +53,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa final String language = (String)collectorContextMap.get("lang"); final PageMode pageMode = (PageMode)collectorContextMap.get("pageMode"); final HashMap pageObject = new HashMap<>(); - + collectorPayloadBean.put("event_type", EventType.PAGE_REQUEST.getType()); if (Objects.nonNull(uri) && Objects.nonNull(site) && Objects.nonNull(languageId)) { final boolean isUrlMap = isUrlMap(collectorContextMap); @@ -82,7 +82,6 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa this.pageAPI.getPageByPath(uri, site, languageId, true)).get(); pageObject.put("id", page.getIdentifier()); pageObject.put("title", page.getTitle()); - collectorPayloadBean.put("event_type", EventType.PAGE_REQUEST.getType()); } pageObject.put("url", uri); } @@ -92,7 +91,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa collectorPayloadBean.put("language", language); if (Objects.nonNull(site)) { - collectorPayloadBean.put("host", site.getIdentifier()); + collectorPayloadBean.put("host", site.getHostname()); } return collectorPayloadBean; diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java new file mode 100644 index 00000000000..c75f7135008 --- /dev/null +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java @@ -0,0 +1,62 @@ +package com.dotcms.analytics.track.collectors; + +import com.dotcms.analytics.track.matchers.RequestMatcher; +import com.dotmarketing.beans.Host; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +/** + * Test for the CustomerEventCollector class + * @author jsanca + * + */ +public class CustomerEventCollectorTest { + + /** + * Method to test: CustomerEventCollector#collect + * Given Scenario: Fill the preconditions and check the collect bean is properly filled + * ExpectedResult: the CollectorPayloadBean should be filled properly + */ + @Test + public void test_collect_easy_path() throws IOException { + + final CustomerEventCollector customerEventCollector = new CustomerEventCollector(); + final Host host = new Host(); + host.setIdentifier("1"); + host.setHostname("www.dotcms.com"); + final CollectorContextMap collectorContextMap = new CollectorContextMap() { + @Override + public Object get(final String key) { + switch (key) { + case "uri": + return "/test-path"; + case "host": + return "www2.dotcms.com"; + case "currentHost": + return host; + case "lang": + return "en"; + case "eventType": + return null; + } + return null; + } + + @Override + public RequestMatcher getRequestMatcher() { + return null; + } + }; + + final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); + customerEventCollector.collect(collectorContextMap, collectorPayloadBean); + + Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); + Assert.assertEquals("en", collectorPayloadBean.get("language")); + Assert.assertEquals("1", collectorPayloadBean.get("site")); + Assert.assertEquals(EventType.CUSTOM_USER_EVENT.getType(), collectorPayloadBean.get("event_type")); + } +} diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java new file mode 100644 index 00000000000..3a55d6f02b6 --- /dev/null +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java @@ -0,0 +1,81 @@ +package com.dotcms.analytics.track.collectors; + +import com.dotcms.analytics.track.matchers.RequestMatcher; +import com.dotmarketing.beans.Host; +import com.dotmarketing.portlets.contentlet.model.Contentlet; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Map; +import java.util.Optional; + +/** + * Test for the FilesCollector class + * @author jsanca + * + */ +public class FilesCollectorTest { + + /** + * Method to test: FilesCollector#collect + * Given Scenario: Fill the preconditions and check the collect bean is properly filled + * ExpectedResult: the CollectorPayloadBean should be filled properly + */ + @Test + public void test_collect_easy_path() throws IOException { + + final FilesCollector filesCollector = new FilesCollector() { + @Override + protected Optional getFileAsset(String uri, Host host, Long languageId) { + final Contentlet contentlet = Mockito.mock(Contentlet.class); + Mockito.when(contentlet.getIdentifier()).thenReturn("1"); + Mockito.when(contentlet.getTitle()).thenReturn("Test"); + return Optional.ofNullable(contentlet); + } + }; + final Host host = new Host(); + host.setIdentifier("1"); + host.setHostname("www.dotcms.com"); + final CollectorContextMap collectorContextMap = new CollectorContextMap() { + @Override + public Object get(final String key) { + switch (key) { + case "uri": + return "/test-path"; + case "host": + return "www2.dotcms.com"; + case "currentHost": + return host; + case "lang": + return "en"; + case "langId": + return 1L; + case "eventType": + return null; + } + return null; + } + + @Override + public RequestMatcher getRequestMatcher() { + return null; + } + }; + + final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); + filesCollector.collect(collectorContextMap, collectorPayloadBean); + + final Map fileObject = (Map) collectorPayloadBean.get("object"); + Assert.assertNotNull(fileObject); + Assert.assertEquals("1", fileObject.get("id")); + Assert.assertEquals("Test", fileObject.get("title")); + Assert.assertEquals("/test-path", fileObject.get("url")); + Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); + Assert.assertEquals("en", collectorPayloadBean.get("language")); + Assert.assertEquals("1", collectorPayloadBean.get("site")); + Assert.assertEquals(EventType.FILE_REQUEST.getType(), collectorPayloadBean.get("event_type")); + } +} diff --git a/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java new file mode 100644 index 00000000000..7668e4a8b83 --- /dev/null +++ b/dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -0,0 +1,70 @@ +package com.dotcms.analytics.track.collectors; + +import com.dotcms.analytics.track.matchers.RequestMatcher; +import com.dotmarketing.beans.Host; +import com.dotmarketing.cms.urlmap.URLMapAPIImpl; +import com.dotmarketing.portlets.contentlet.model.Contentlet; +import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Map; +import java.util.Optional; + +/** + * Test for the {@link PagesCollector} class + * @author jsanca + * + */ +public class PagesCollectorTest { + + /** + * Method to test: PagesCollector#collect + * Given Scenario: Fill the preconditions and check the collect bean is properly filled + * ExpectedResult: the CollectorPayloadBean should be filled properly + */ + @Test + public void test_collect_easy_path() throws IOException { + + final PagesCollector pagesCollector = new PagesCollector(Mockito.mock(HTMLPageAssetAPI.class), Mockito.mock(URLMapAPIImpl.class)); + final Host host = new Host(); + host.setIdentifier("1"); + host.setHostname("www.dotcms.com"); + final CollectorContextMap collectorContextMap = new CollectorContextMap() { + @Override + public Object get(final String key) { + switch (key) { + case "uri": + return "/test-path"; + case "host": + return "www2.dotcms.com"; + case "currentHost": + return host; + case "lang": + return "en"; + case "langId": + return null; + case "eventType": + return null; + } + return null; + } + + @Override + public RequestMatcher getRequestMatcher() { + return null; + } + }; + + + final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); + pagesCollector.collect(collectorContextMap, collectorPayloadBean); + + Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); + Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); + Assert.assertEquals("en", collectorPayloadBean.get("language")); + Assert.assertEquals(EventType.PAGE_REQUEST.getType(), collectorPayloadBean.get("event_type")); + } +} diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java index 41634a2fcf9..8635612928e 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/AsyncVanitiesCollectorTest.java @@ -2,10 +2,7 @@ import com.dotcms.IntegrationTestBase; import com.dotcms.LicenseTestUtil; -import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.HTMLPageDataGen; import com.dotcms.datagen.SiteDataGen; -import com.dotcms.util.FiltersUtil; import com.dotcms.util.IntegrationTestInitService; import com.dotcms.vanityurl.model.CachedVanityUrl; import com.dotmarketing.beans.Host; @@ -13,10 +10,8 @@ import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.filters.Constants; -import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; import com.dotmarketing.portlets.languagesmanager.model.Language; -import com.dotmarketing.portlets.templates.model.Template; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; import org.junit.BeforeClass; @@ -90,7 +85,7 @@ public void collectAsyncVanityData() throws DotDataException, IOException, final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "comeFromVanityURL", true, "language", defaultLanguage.getIsoCode(), "url", TEST_PAGE_URL, diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java index 827b923619e..e8d544f63dc 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java @@ -4,31 +4,25 @@ import com.dotcms.JUnit4WeldRunner; import com.dotcms.LicenseTestUtil; import com.dotcms.analytics.track.matchers.FilesRequestMatcher; -import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.FileAssetDataGen; -import com.dotcms.datagen.FolderDataGen; import com.dotcms.datagen.SiteDataGen; import com.dotcms.util.IntegrationTestInitService; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; -import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.fileassets.business.FileAsset; -import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; -import javax.enterprise.context.ApplicationScoped; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.HashMap; import java.util.Map; -import org.junit.runner.RunWith; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -76,7 +70,7 @@ public void collectFileData() throws DotDataException, IOException, DotSecurityE APILocator.getUserAPI().getAnonymousUser()); final Map expectedDataMap = Map.of( - "host", "localhost:8080", + "host", testSite.getHostname(), "site", testSite.getIdentifier(), "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "event_type", EventType.FILE_REQUEST.getType(), diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java index 4586f863dde..a03992d5450 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java @@ -6,36 +6,28 @@ import com.dotcms.analytics.track.matchers.PagesAndUrlMapsRequestMatcher; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.FolderDataGen; -import com.dotcms.datagen.HTMLPageDataGen; import com.dotcms.datagen.SiteDataGen; import com.dotcms.util.IntegrationTestInitService; -import com.dotcms.visitor.filter.characteristics.CharacterWebAPI; -import com.dotcms.visitor.filter.characteristics.GDPRCharacter; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; -import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; import com.dotmarketing.portlets.languagesmanager.model.Language; -import com.dotmarketing.portlets.templates.model.Template; import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; -import javax.enterprise.context.ApplicationScoped; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.net.UnknownHostException; -import java.util.HashMap; import java.util.Map; -import org.junit.runner.RunWith; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -109,7 +101,7 @@ public void testPageDetailCollector() throws DotDataException, UnknownHostExcept final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "language", language.getIsoCode(), "url", TEST_URL_MAP_DETAIL_PAGE_URL, "object", Map.of( diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java index ff1de6696bf..934269c2399 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -6,36 +6,28 @@ import com.dotcms.analytics.track.matchers.PagesAndUrlMapsRequestMatcher; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.FolderDataGen; -import com.dotcms.datagen.HTMLPageDataGen; import com.dotcms.datagen.SiteDataGen; import com.dotcms.util.IntegrationTestInitService; -import com.dotcms.visitor.filter.characteristics.CharacterWebAPI; -import com.dotcms.visitor.filter.characteristics.GDPRCharacter; import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; -import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; -import com.dotmarketing.portlets.templates.model.Template; import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; -import io.vavr.API; -import javax.enterprise.context.ApplicationScoped; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.net.UnknownHostException; import java.util.HashMap; import java.util.Map; -import org.junit.runner.RunWith; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -91,7 +83,7 @@ public void collectPageData() throws DotDataException, UnknownHostException { final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "url", TEST_PAGE_URL, "object", Map.of( @@ -157,7 +149,7 @@ public void collectUrlMapPageData() throws DotDataException, UnknownHostExceptio final Map expectedDataMap = Map.of( "event_type", EventType.URL_MAP.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "url", TEST_URL_MAP_DETAIL_PAGE_URL, "object", Map.of( diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java index 0c677978688..636e6cbfe1a 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java @@ -3,12 +3,7 @@ import com.dotcms.IntegrationTestBase; import com.dotcms.JUnit4WeldRunner; import com.dotcms.LicenseTestUtil; -import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.FileAssetDataGen; -import com.dotcms.datagen.FolderDataGen; -import com.dotcms.datagen.HTMLPageDataGen; import com.dotcms.datagen.SiteDataGen; -import com.dotcms.util.FiltersUtil; import com.dotcms.util.IntegrationTestInitService; import com.dotcms.vanityurl.model.CachedVanityUrl; import com.dotmarketing.beans.Host; @@ -16,26 +11,20 @@ import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.filters.Constants; -import com.dotmarketing.portlets.contentlet.model.Contentlet; -import com.dotmarketing.portlets.fileassets.business.FileAsset; -import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; import com.dotmarketing.portlets.languagesmanager.model.Language; -import com.dotmarketing.portlets.templates.model.Template; -import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; -import javax.enterprise.context.ApplicationScoped; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.runner.RunWith; +import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.HashMap; import java.util.Map; import java.util.Optional; -import org.junit.runner.RunWith; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java index 9798517ddb8..e80bf21f71b 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java @@ -9,20 +9,13 @@ import com.dotcms.analytics.track.matchers.PagesAndUrlMapsRequestMatcher; import com.dotcms.analytics.track.matchers.RequestMatcher; import com.dotcms.analytics.track.matchers.VanitiesRequestMatcher; -import com.dotcms.concurrent.DotConcurrentFactory; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.ContentletDataGen; -import com.dotcms.datagen.FileAssetDataGen; -import com.dotcms.datagen.FolderDataGen; -import com.dotcms.datagen.HTMLPageDataGen; import com.dotcms.datagen.SiteDataGen; -import com.dotcms.enterprise.cluster.ClusterFactory; -import com.dotcms.jitsu.AnalyticsEventsPayload; import com.dotcms.jitsu.EventLogRunnable; import com.dotcms.jitsu.EventLogSubmitter; import com.dotcms.jitsu.EventsPayload; import com.dotcms.security.apps.AppSecrets; -import com.dotcms.util.FiltersUtil; import com.dotcms.util.IntegrationTestInitService; import com.dotcms.util.JsonUtil; import com.dotcms.vanityurl.model.CachedVanityUrl; @@ -35,42 +28,27 @@ import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; import com.dotmarketing.portlets.fileassets.business.FileAsset; -import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; import com.dotmarketing.portlets.languagesmanager.model.Language; -import com.dotmarketing.portlets.templates.model.Template; import com.dotmarketing.util.Config; -import com.dotmarketing.util.PageMode; import com.dotmarketing.util.UUIDUtil; -import com.dotmarketing.util.UtilMethods; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import javax.enterprise.context.ApplicationScoped; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; +import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.Serializable; -import java.net.UnknownHostException; import java.util.Map; import java.util.Optional; -import java.util.Set; import static com.dotcms.analytics.app.AnalyticsApp.ANALYTICS_APP_CONFIG_URL_KEY; import static com.dotcms.analytics.app.AnalyticsApp.ANALYTICS_APP_READ_URL_KEY; import static com.dotcms.analytics.app.AnalyticsApp.ANALYTICS_APP_WRITE_URL_KEY; -import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Verifies that the {@link WebEventsCollectorService} class is working as expected. @@ -157,7 +135,7 @@ public void testBasicProfileCollector() throws DotDataException, IOException { final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "url", TEST_PAGE_URL, "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "object", Map.of( @@ -202,7 +180,7 @@ public void testPagesCollector() throws DotDataException, IOException { final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "url", TEST_PAGE_URL, "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "object", Map.of( @@ -266,7 +244,7 @@ public void testPageDetailCollector() throws DotDataException, IOException { ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "language", language.getIsoCode(), "url", TEST_URL_MAP_DETAIL_PAGE_URL, "object", Map.of( @@ -375,7 +353,7 @@ public void testAsyncVanitiesCollector() throws DotDataException, IOException, D final Map expectedDataMap = Map.of( "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getIdentifier(), + "host", testSite.getHostname(), "comeFromVanityURL", true, "language", defaultLanguage.getIsoCode(), "url", TEST_PAGE_URL, @@ -428,7 +406,7 @@ public void testFilesCollector() throws DotDataException, IOException, DotSecuri ".txt","Sample content for my test file", "parent-folder-for-file", testSite); final Map expectedDataMap = Map.of( - "host", "localhost:8080", + "host", testSite.getHostname(), "site", testSite.getIdentifier(), "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), "event_type", EventType.FILE_REQUEST.getType(),