diff --git a/data/reports/knitr_no_scriptpad.rhtml b/data/reports/knitr_no_scriptpad.rhtml index 1442cd2065..1b3d5c69a1 100644 --- a/data/reports/knitr_no_scriptpad.rhtml +++ b/data/reports/knitr_no_scriptpad.rhtml @@ -93,5 +93,11 @@ end.rcode-->

Well, everything seems to be working. Let's ask R what is the value of π? Of course it is .

+Nonce check: FAIL + + + \ No newline at end of file diff --git a/data/reports/knitr_no_scriptpad.rmd b/data/reports/knitr_no_scriptpad.rmd index 691a947b9c..78ba8eb048 100644 --- a/data/reports/knitr_no_scriptpad.rmd +++ b/data/reports/knitr_no_scriptpad.rmd @@ -113,6 +113,12 @@ library(knitr) knit('knitr-minimal.Rmd') ``` +Nonce check: FAIL + + + ## Conclusion Markdown is super easy to write. Go to **knitr** [homepage](http://yihui.name/knitr) for details. \ No newline at end of file diff --git a/data/reports/nonce_check.rhtml b/data/reports/nonce_check.rhtml new file mode 100644 index 0000000000..7efb90bd76 --- /dev/null +++ b/data/reports/nonce_check.rhtml @@ -0,0 +1,15 @@ + + + + Test script nonce in Knitr HTML + + + +Nonce check: FAIL + + + + + \ No newline at end of file diff --git a/modules/scriptpad/resources/reports/schemas/script_rhtml.rhtml b/modules/scriptpad/resources/reports/schemas/script_rhtml.rhtml index 77e8cfec5d..f9bc5fc814 100644 --- a/modules/scriptpad/resources/reports/schemas/script_rhtml.rhtml +++ b/modules/scriptpad/resources/reports/schemas/script_rhtml.rhtml @@ -87,5 +87,11 @@ end.rcode-->

Well, everything seems to be working. Let's ask R what is the value of π? Of course it is .

+Nonce check: FAIL + + + \ No newline at end of file diff --git a/modules/scriptpad/resources/reports/schemas/script_rmd.rmd b/modules/scriptpad/resources/reports/schemas/script_rmd.rmd index 5729f20b1c..f136b7616b 100644 --- a/modules/scriptpad/resources/reports/schemas/script_rmd.rmd +++ b/modules/scriptpad/resources/reports/schemas/script_rmd.rmd @@ -108,6 +108,12 @@ library(knitr) knit('knitr-minimal.Rmd') ``` +Nonce check: FAIL + + + ## Conclusion Markdown is super easy to write. Go to **knitr** [homepage](http://yihui.name/knitr) for details. \ No newline at end of file diff --git a/src/org/labkey/test/TestFileUtils.java b/src/org/labkey/test/TestFileUtils.java index 6a4a3ae4eb..b9a1228ceb 100644 --- a/src/org/labkey/test/TestFileUtils.java +++ b/src/org/labkey/test/TestFileUtils.java @@ -109,7 +109,7 @@ public static String getFileContents(Path path) { try { - return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); + return Files.readString(path); } catch (IOException fail) { @@ -306,7 +306,7 @@ public static Set getSampleDataDirs() if (sampledataDirsFile.exists()) { String path = getFileContents(sampledataDirsFile); - _sampledataDirs.addAll(Arrays.stream(path.split(";")).map(File::new).collect(Collectors.toList())); + _sampledataDirs.addAll(Arrays.stream(path.split(";")).map(File::new).toList()); } else { @@ -317,7 +317,7 @@ public static Set getSampleDataDirs() // We know where the modules live; no reason to insist that sampledata.dirs exists. Files.walkFileTree(modulesDir, Collections.emptySet(), 2, new SimpleFileVisitor<>(){ @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException + public @NotNull FileVisitResult preVisitDirectory(@NotNull Path dir, @NotNull BasicFileAttributes attrs) { if (dir.equals(modulesDir)) { diff --git a/src/org/labkey/test/pages/admin/ExternalSourcesPage.java b/src/org/labkey/test/pages/admin/ExternalSourcesPage.java index 25d1da4db3..25d3c41075 100644 --- a/src/org/labkey/test/pages/admin/ExternalSourcesPage.java +++ b/src/org/labkey/test/pages/admin/ExternalSourcesPage.java @@ -207,6 +207,7 @@ public enum Directive implements OptionSelect.SelectOption Frame("frame-src"), Image("image-src"), Style("style-src"), + Object("object-src"), ; private final String directiveId; diff --git a/src/org/labkey/test/pages/reports/ScriptReportPage.java b/src/org/labkey/test/pages/reports/ScriptReportPage.java index 2d57bc293d..31b0db491e 100644 --- a/src/org/labkey/test/pages/reports/ScriptReportPage.java +++ b/src/org/labkey/test/pages/reports/ScriptReportPage.java @@ -11,12 +11,14 @@ import org.labkey.test.pages.LabKeyPage; import org.labkey.test.util.CodeMirrorHelper; import org.labkey.test.util.Ext4Helper; +import org.labkey.test.util.PipelineStatusTable; import org.labkey.test.util.TestLogger; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import java.util.Map; +import java.util.Objects; import java.util.Optional; import static org.labkey.test.components.ext4.Checkbox.Ext4Checkbox; @@ -79,6 +81,7 @@ public CodeMirrorHelper getEditor() public String saveReport(String name, boolean isSaveAs, int wait) { + String reportIdBeforeSave = getReportId(); WebElement saveButton = Ext4Helper.Locators.ext4Button(isSaveAs ? "Save As" : "Save").findElement(getDriver()); scrollIntoView(saveButton, true); clickAndWait(saveButton, wait); @@ -86,6 +89,11 @@ public String saveReport(String name, boolean isSaveAs, int wait) { saveReportWithName(name, isSaveAs); } + return Objects.requireNonNullElse(getReportId(), reportIdBeforeSave); + } + + public String getReportId() + { return getUrlParam("reportId", true); } @@ -141,6 +149,7 @@ public void clearOption(ReportOption option) private void _selectOption(ReportOption option, boolean checked) { + clickSourceTab(); ensureFieldSetExpanded(option.getSection()); Checkbox checkbox; if (option.isCheckbox()) @@ -202,6 +211,17 @@ public WebElement findReportElement() return Locator.byClass("reportView").findElement(getDriver()); } + public void startPipelineJobAndWait() + { + clickReportTab(); + + waitAndClick(Locator.lkButton("Start Job")); + waitAndClickAndWait(Locator.linkWithText("click here")); + new PipelineStatusTable(this) + .clickStatusLink(0) + .waitForComplete(); + } + @Override protected ElementCache newElementCache() { diff --git a/src/org/labkey/test/pages/wiki/EditPage.java b/src/org/labkey/test/pages/wiki/EditPage.java index 032f0c2734..9e4d76a535 100644 --- a/src/org/labkey/test/pages/wiki/EditPage.java +++ b/src/org/labkey/test/pages/wiki/EditPage.java @@ -100,10 +100,48 @@ public EditPage setTitle(String title) public EditPage setBody(String body) { + switchWikiToSourceView(); elementCache().bodyTextArea.set(body); return this; } + /** + * Switches the wiki edit page to source view when the format type is HTML. + */ + public void switchWikiToSourceView() + { + String curFormat = executeScript("return LABKEY._wiki.getProps().rendererType;", String.class); + if (curFormat.equalsIgnoreCase("HTML")) + { + if (isElementPresent(Locator.css("#wiki-tab-source.labkey-tab-inactive"))) + { + Locator tab = Locator.css("#wiki-tab-source > a"); + waitForElementToBeVisible(tab); + click(tab); + waitForElement(Locator.css("#wiki-tab-source.labkey-tab-active")); + } + } + } + + public void switchWikiToVisualView() + { + String curFormat = (String) executeScript("return LABKEY._wiki.getProps().rendererType;"); + if (curFormat.equalsIgnoreCase("HTML")) + { + if (isElementPresent(Locator.css("#wiki-tab-visual.labkey-tab-inactive"))) + { + Locator tab = Locator.css("#wiki-tab-visual > a"); + waitForElementToBeVisible(tab); + click(tab); + + Locator yesButton = Locator.tagWithText("span","Yes"); + waitForElementToBeVisible(yesButton); + waitAndClick(yesButton); + waitForElement(Locator.css("#wiki-tab-visual.labkey-tab-active")); + } + } + } + public EditPage setShouldIndex(boolean shouldIndex) { elementCache().shouldIndexCheckbox.set(shouldIndex); diff --git a/src/org/labkey/test/tests/AbstractKnitrReportTest.java b/src/org/labkey/test/tests/AbstractKnitrReportTest.java index d40ece66e7..562b775d94 100644 --- a/src/org/labkey/test/tests/AbstractKnitrReportTest.java +++ b/src/org/labkey/test/tests/AbstractKnitrReportTest.java @@ -17,6 +17,7 @@ import org.junit.Assume; import org.junit.BeforeClass; +import org.junit.Test; import org.labkey.remoteapi.CommandException; import org.labkey.test.BaseWebDriverTest; import org.labkey.test.Locator; @@ -25,12 +26,16 @@ import org.labkey.test.pages.admin.ExternalSourcesPage; import org.labkey.test.pages.core.admin.logger.ManagerPage; import org.labkey.test.pages.reports.ManageViewsPage; +import org.labkey.test.pages.reports.ScriptReportPage; +import org.labkey.test.pages.reports.ScriptReportPage.StandardReportOption; import org.labkey.test.util.CodeMirrorHelper; +import org.labkey.test.util.CspLogUtil; import org.labkey.test.util.Log4jUtils; import org.labkey.test.util.LogMethod; import org.labkey.test.util.LoggedParam; import org.labkey.test.util.PortalHelper; import org.labkey.test.util.RReportHelper; +import org.labkey.test.util.WikiHelper; import org.labkey.test.util.core.admin.CspConfigHelper; import org.openqa.selenium.WebElement; @@ -54,6 +59,10 @@ public abstract class AbstractKnitrReportTest extends BaseWebDriverTest protected static final Path rmdReport_no_scriptpad = TestFileUtils.getSampleData("reports/knitr_no_scriptpad.rmd").toPath(); private static final Path rhtmlReport = scriptpadReports.resolve("script_rhtml.rhtml"); private static final Path rhtmlReport_no_scriptpad = TestFileUtils.getSampleData("reports/knitr_no_scriptpad.rhtml").toPath(); + private static final Path rhtmlNonceCheck = TestFileUtils.getSampleData("reports/nonce_check.rhtml").toPath(); + private static final Locator.XPathLocator nonceCheckLoc = Locator.id("nonce-check-result"); + private static final Locator.XPathLocator nonceCheckSuccessLoc = nonceCheckLoc.withText("SUCCESS"); + protected final RReportHelper _rReportHelper = new RReportHelper(this); private static String readReport(final Path reportFile) @@ -81,6 +90,7 @@ protected void setupProject() try { new CspConfigHelper(this).setAllowedHosts(Map.of( + ExternalSourcesPage.Directive.Object, List.of("'self'"), // Issue 53226: reports-streamFile is blocked by object-src CSP directive ExternalSourcesPage.Directive.Style, List.of("https://cdn.datatables.net"), ExternalSourcesPage.Directive.Font, List.of("https://mathjax.rstudio.com"))); } @@ -166,7 +176,9 @@ protected void htmlFormat() Locator.tag("pre").containing("## \"1\",249318596,\"2008-05-17\",86,36,129,76,64"), Locator.tag("pre").withText("## knitr says hello to HTML!"), Locator.tag("pre").startsWith("## Error").containing(": non-numeric argument to binary operator"), - Locator.tag("p").startsWith("Well, everything seems to be working. Let's ask R what is the value of \u03C0? Of course it is 3.141")}; + Locator.tag("p").startsWith("Well, everything seems to be working. Let's ask R what is the value of \u03C0? Of course it is 3.141"), + nonceCheckSuccessLoc // Inline script should run + }; String[] reportNotContains = {"", // Uninterpreted html "