Skip to content

Commit

Permalink
Merge branch 'main' into issue-30457-fix-case-sensitivity-for-contain…
Browse files Browse the repository at this point in the history
…er-search
  • Loading branch information
erickgonzalez authored Nov 12, 2024
2 parents 6becd81 + 786c18d commit 02ac1c6
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cicd_3-trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/cicd_comp_semgrep-phase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ 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:
stage-name: "Dependency Tree Scan"
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 {} +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ 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());

return collectorPayloadBean;
}

private Optional<Contentlet> getFileAsset(String uri, Host host, Long languageId) {
protected Optional<Contentlet> getFileAsset(String uri, Host host, Long languageId) {
try {
if (uri.endsWith(".dotsass")) {
final String actualUri = uri.substring(0, uri.lastIndexOf('.')) + ".scss";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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<Contentlet> 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<String, String> fileObject = (Map<String, String>) 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"));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

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;
import com.dotmarketing.business.APILocator;
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;
Expand Down Expand Up @@ -90,7 +85,7 @@ public void collectAsyncVanityData() throws DotDataException, IOException,

final Map<String, Object> expectedDataMap = Map.of(
"event_type", EventType.PAGE_REQUEST.getType(),
"host", testSite.getIdentifier(),
"host", testSite.getHostname(),
"comeFromVanityURL", true,
"language", defaultLanguage.getIsoCode(),
"url", TEST_PAGE_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +70,7 @@ public void collectFileData() throws DotDataException, IOException, DotSecurityE
APILocator.getUserAPI().getAnonymousUser());

final Map<String, Object> expectedDataMap = Map.of(
"host", "localhost:8080",
"host", testSite.getHostname(),
"site", testSite.getIdentifier(),
"language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(),
"event_type", EventType.FILE_REQUEST.getType(),
Expand Down
Loading

0 comments on commit 02ac1c6

Please sign in to comment.