From 88e651b0d68ac738f26e8cf89f5c165550a9fa10 Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Wed, 9 Jul 2025 14:30:30 -0700 Subject: [PATCH 1/2] Add regression test for CSP log view --- .../tests/AdminConsoleNavigationTest.java | 6 ++++- src/org/labkey/test/tests/CrawlerTest.java | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/org/labkey/test/tests/AdminConsoleNavigationTest.java b/src/org/labkey/test/tests/AdminConsoleNavigationTest.java index 5e3e5e20cd..3f46cecb63 100644 --- a/src/org/labkey/test/tests/AdminConsoleNavigationTest.java +++ b/src/org/labkey/test/tests/AdminConsoleNavigationTest.java @@ -1,5 +1,6 @@ package org.labkey.test.tests; +import org.assertj.core.api.Assertions; import org.jetbrains.annotations.Nullable; import org.junit.Assert; import org.junit.BeforeClass; @@ -79,13 +80,14 @@ public void testAdminNavTrails() "View Primary Site Log File" // No nav trail )); List adminLinks = ShowAdminPage.beginAt(this).getAllAdminConsoleLinks(); - assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 10); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 20); Map linkHrefs = new HashMap<>(); for (WebElement link : adminLinks) { linkHrefs.put(link.getText(), link.getAttribute("href")); } + Assertions.assertThat(linkHrefs.keySet()).as("Expected links").containsAll(ignoredLinks); List pagesMissingNavTrail = new ArrayList<>(); @@ -121,6 +123,7 @@ public void testTroubleshooterLinkAccess() impersonate(TROUBLESHOOTER); Map linkHrefs = new LinkedHashMap<>(); List troubleshooterLinks = adminConsole.getAllAdminConsoleLinks(); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", troubleshooterLinks.size()), troubleshooterLinks.size() > 20); for (WebElement link : troubleshooterLinks) linkHrefs.put(link.getText(), link.getAttribute("href")); @@ -155,6 +158,7 @@ public void testAdminConsoleLinksForAdminAndNonAdmin() )); ShowAdminPage adminConsole = goToAdminConsole(); List adminLinks = adminConsole.getAllAdminConsoleLinks(); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 20); Map linkHrefs = new LinkedHashMap<>(); for (WebElement link : adminLinks) linkHrefs.put(link.getText(), link.getAttribute("href")); diff --git a/src/org/labkey/test/tests/CrawlerTest.java b/src/org/labkey/test/tests/CrawlerTest.java index bc10407e81..520cd86a7a 100644 --- a/src/org/labkey/test/tests/CrawlerTest.java +++ b/src/org/labkey/test/tests/CrawlerTest.java @@ -1,11 +1,13 @@ package org.labkey.test.tests; +import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.labkey.remoteapi.SimpleGetCommand; import org.labkey.test.BaseWebDriverTest; import org.labkey.test.Locator; import org.labkey.test.Locators; @@ -117,18 +119,25 @@ public void testEnforceCsp() throws Exception beginAt(getInjectUrl(Crawler.injectScriptBlock), 10_000); log("Verify that enforced CSP is also reported"); - CspLogUtil.checkNewCspWarnings(getArtifactCollector()); + CspLogUtil.checkNewCspWarnings(getArtifactCollector()); // throws CspWarningDetectedException } @Test (expected = CspLogUtil.CspWarningDetectedException.class) - public void testCspWarning() + public void testCspWarning() throws Exception { Assume.assumeFalse("Can't test for CSP report", TestProperties.isCspCheckSkipped()); _cspConfigHelper.setEnforceCsp(false); - beginAt(WebTestHelper.buildRelativeUrl(MODULE_NAME, getProjectName(), "cspWarning")); - CspLogUtil.checkNewCspWarnings(getArtifactCollector()); + int initialLength = getCspReportLog().length(); + + String cspWarningUrl = WebTestHelper.buildRelativeUrl(MODULE_NAME, getProjectName(), "cspWarning"); + beginAt(cspWarningUrl); + + // 53261: Provide visibility into CSP reports for cloud clients + Assertions.assertThat(getCspReportLog().substring(initialLength)).as("CSP warning").contains(cspWarningUrl); + + CspLogUtil.checkNewCspWarnings(getArtifactCollector()); // throws CspWarningDetectedException } // Crawler should flag external links without the correct 'rel' attribute @@ -188,6 +197,13 @@ protected boolean cspFailFast() return false; } + public String getCspReportLog() throws Exception + { + return new SimpleGetCommand("admin", "showCspReportLog") + .execute(createDefaultConnection(), null) + .getText(); + } + @After public void postTest() { From ed2f48c8bb21752bff1a597c19ce76e8b1959d56 Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Wed, 9 Jul 2025 14:32:43 -0700 Subject: [PATCH 2/2] Revert link count expectation --- src/org/labkey/test/tests/AdminConsoleNavigationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/labkey/test/tests/AdminConsoleNavigationTest.java b/src/org/labkey/test/tests/AdminConsoleNavigationTest.java index 3f46cecb63..0becdfcc6f 100644 --- a/src/org/labkey/test/tests/AdminConsoleNavigationTest.java +++ b/src/org/labkey/test/tests/AdminConsoleNavigationTest.java @@ -80,7 +80,7 @@ public void testAdminNavTrails() "View Primary Site Log File" // No nav trail )); List adminLinks = ShowAdminPage.beginAt(this).getAllAdminConsoleLinks(); - assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 20); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 10); Map linkHrefs = new HashMap<>(); for (WebElement link : adminLinks) @@ -123,7 +123,7 @@ public void testTroubleshooterLinkAccess() impersonate(TROUBLESHOOTER); Map linkHrefs = new LinkedHashMap<>(); List troubleshooterLinks = adminConsole.getAllAdminConsoleLinks(); - assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", troubleshooterLinks.size()), troubleshooterLinks.size() > 20); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", troubleshooterLinks.size()), troubleshooterLinks.size() > 10); for (WebElement link : troubleshooterLinks) linkHrefs.put(link.getText(), link.getAttribute("href")); @@ -158,7 +158,7 @@ public void testAdminConsoleLinksForAdminAndNonAdmin() )); ShowAdminPage adminConsole = goToAdminConsole(); List adminLinks = adminConsole.getAllAdminConsoleLinks(); - assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 20); + assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 10); Map linkHrefs = new LinkedHashMap<>(); for (WebElement link : adminLinks) linkHrefs.put(link.getText(), link.getAttribute("href"));