|
1 | 1 | package org.labkey.test.tests; |
2 | 2 |
|
| 3 | +import org.assertj.core.api.Assertions; |
3 | 4 | import org.junit.After; |
4 | 5 | import org.junit.Assert; |
5 | 6 | import org.junit.Assume; |
6 | 7 | import org.junit.BeforeClass; |
7 | 8 | import org.junit.Test; |
8 | 9 | import org.junit.experimental.categories.Category; |
| 10 | +import org.labkey.remoteapi.SimpleGetCommand; |
9 | 11 | import org.labkey.test.BaseWebDriverTest; |
10 | 12 | import org.labkey.test.Locator; |
11 | 13 | import org.labkey.test.Locators; |
@@ -117,18 +119,25 @@ public void testEnforceCsp() throws Exception |
117 | 119 | beginAt(getInjectUrl(Crawler.injectScriptBlock), 10_000); |
118 | 120 |
|
119 | 121 | log("Verify that enforced CSP is also reported"); |
120 | | - CspLogUtil.checkNewCspWarnings(getArtifactCollector()); |
| 122 | + CspLogUtil.checkNewCspWarnings(getArtifactCollector()); // throws CspWarningDetectedException |
121 | 123 | } |
122 | 124 |
|
123 | 125 | @Test (expected = CspLogUtil.CspWarningDetectedException.class) |
124 | | - public void testCspWarning() |
| 126 | + public void testCspWarning() throws Exception |
125 | 127 | { |
126 | 128 | Assume.assumeFalse("Can't test for CSP report", TestProperties.isCspCheckSkipped()); |
127 | 129 |
|
128 | 130 | _cspConfigHelper.setEnforceCsp(false); |
129 | 131 |
|
130 | | - beginAt(WebTestHelper.buildRelativeUrl(MODULE_NAME, getProjectName(), "cspWarning")); |
131 | | - CspLogUtil.checkNewCspWarnings(getArtifactCollector()); |
| 132 | + int initialLength = getCspReportLog().length(); |
| 133 | + |
| 134 | + String cspWarningUrl = WebTestHelper.buildRelativeUrl(MODULE_NAME, getProjectName(), "cspWarning"); |
| 135 | + beginAt(cspWarningUrl); |
| 136 | + |
| 137 | + // 53261: Provide visibility into CSP reports for cloud clients |
| 138 | + Assertions.assertThat(getCspReportLog().substring(initialLength)).as("CSP warning").contains(cspWarningUrl); |
| 139 | + |
| 140 | + CspLogUtil.checkNewCspWarnings(getArtifactCollector()); // throws CspWarningDetectedException |
132 | 141 | } |
133 | 142 |
|
134 | 143 | // Crawler should flag external links without the correct 'rel' attribute |
@@ -188,6 +197,13 @@ protected boolean cspFailFast() |
188 | 197 | return false; |
189 | 198 | } |
190 | 199 |
|
| 200 | + public String getCspReportLog() throws Exception |
| 201 | + { |
| 202 | + return new SimpleGetCommand("admin", "showCspReportLog") |
| 203 | + .execute(createDefaultConnection(), null) |
| 204 | + .getText(); |
| 205 | + } |
| 206 | + |
191 | 207 | @After |
192 | 208 | public void postTest() |
193 | 209 | { |
|
0 commit comments