-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWikiCspTest.java
More file actions
124 lines (105 loc) · 3.93 KB
/
WikiCspTest.java
File metadata and controls
124 lines (105 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.labkey.test.tests.wiki;
import org.jetbrains.annotations.Nullable;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locators;
import org.labkey.test.categories.Daily;
import org.labkey.test.categories.Wiki;
import org.labkey.test.pages.core.admin.SiteValidationPage;
import org.labkey.test.pages.pipeline.PipelineStatusDetailsPage;
import org.labkey.test.util.CspLogUtil;
import org.labkey.test.util.TextSearcher;
import org.labkey.test.util.WikiHelper;
import org.labkey.test.util.core.admin.CspConfigHelper;
import java.util.Arrays;
import java.util.List;
@Category({Daily.class, Wiki.class})
@BaseWebDriverTest.ClassTimeout(minutes = 2)
public class WikiCspTest extends BaseWebDriverTest
{
private static final String PROJECT_NAME = TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
private static final String WIKI_PAGE_TITLE = "TOC_with_inline";
private static final String WIKI_PAGE_BODY =
// Issue 52483: HTML substitution patterns can throw errors during wiki validation
"${labkey.webPart(partName='Query', schemaName='core', queryName='Users')}\n" +
// Trigger wiki validation warning
"<div onclick=\"alert('bad page')\">Click me</div>";
@BeforeClass
public static void setupProject()
{
WikiCspTest init = getCurrentTest();
init.doSetup();
}
@Override
public List<String> getAssociatedModules()
{
return List.of("Wiki");
}
@Override
protected @Nullable String getProjectName()
{
return PROJECT_NAME;
}
private void doSetup()
{
_containerHelper.createProject(PROJECT_NAME, null);
_containerHelper.enableModules(Arrays.asList("Wiki"));
goToProjectHome();
CspConfigHelper.debugCspWarnings(); // Ensure that CSP violation logs aren't suppressed by de-duping efforts
}
@Override
protected void doCleanup(boolean afterTest)
{
super.doCleanup(afterTest);
if (afterTest)
{
CspConfigHelper.infoCspWarnings();
}
}
@Override
protected void checkLinks()
{
// No-op to avoid triggering the CSP violation during the crawl
}
@Test
public void testCspChecks()
{
goToProjectHome(PROJECT_NAME);
// Issue 51749 - Create a CSP problem and a Wiki table of contents that caused a problem when checked in the background
WikiHelper wikiHelper = new WikiHelper(this);
wikiHelper.createNewWikiPage("HTML");
wikiHelper.setWikiName(WIKI_PAGE_TITLE);
wikiHelper.setWikiTitle(WIKI_PAGE_TITLE);
wikiHelper.setWikiBody(WIKI_PAGE_BODY);
wikiHelper.saveWikiPage();
waitForText("Click me");
waitFor(() ->
{
try
{
CspLogUtil.checkNewCspWarnings(getArtifactCollector());
return false;
}
catch (CspLogUtil.CspWarningDetectedException ignore)
{
return true;
}
}, "Should have triggered a CSP error", WAIT_FOR_PAGE);
SiteValidationPage validationPage = goToAdminConsole().clickSiteValidation();
validationPage.setAllValidators(false);
validationPage.setWikiValidator(true);
PipelineStatusDetailsPage jobPage = validationPage.clickValidateInBackground();
jobPage.waitForComplete(60_000)
.assertLogTextContains("Site validation complete");
jobPage.clickDataLink();
assertNoLabKeyErrors();
TextSearcher textSearcher = new TextSearcher(getText(Locators.bodyPanel()));
assertTextPresent(textSearcher,
"Wiki Validator");
assertTextNotPresent(textSearcher, "Error");
// Issue 51749 - check for expected CSP problem
assertTextPresent(textSearcher, WIKI_PAGE_TITLE + " (" + WIKI_PAGE_TITLE + "): onclick");
}
}