Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/org/labkey/test/tests/AdminConsoleNavigationTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void testAdminNavTrails()
{
linkHrefs.put(link.getText(), link.getAttribute("href"));
}
Assertions.assertThat(linkHrefs.keySet()).as("Expected links").containsAll(ignoredLinks);

List<String> pagesMissingNavTrail = new ArrayList<>();

Expand Down Expand Up @@ -121,6 +123,7 @@ public void testTroubleshooterLinkAccess()
impersonate(TROUBLESHOOTER);
Map<String, String> linkHrefs = new LinkedHashMap<>();
List<WebElement> troubleshooterLinks = adminConsole.getAllAdminConsoleLinks();
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"));

Expand Down Expand Up @@ -155,6 +158,7 @@ public void testAdminConsoleLinksForAdminAndNonAdmin()
));
ShowAdminPage adminConsole = goToAdminConsole();
List<WebElement> adminLinks = adminConsole.getAllAdminConsoleLinks();
assertTrue(String.format("Failed sanity check. Only found %s admin links. There should be more.", adminLinks.size()), adminLinks.size() > 10);
Map<String, String> linkHrefs = new LinkedHashMap<>();
for (WebElement link : adminLinks)
linkHrefs.put(link.getText(), link.getAttribute("href"));
Expand Down
24 changes: 20 additions & 4 deletions src/org/labkey/test/tests/CrawlerTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down