From 0b4fb0d4274475ffa60924e7916001f38817ded8 Mon Sep 17 00:00:00 2001 From: Trey Chadick Date: Mon, 27 Oct 2025 16:35:44 -0700 Subject: [PATCH] Add test for encryption key upgrade (#7149) --- .../upgrade/EncryptionKeyUpgradeTest.java | 78 +++++++++++++++++++ .../mothership/EditUpgradeMessagePage.java | 16 +++- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 core/test/src/org/labkey/test/tests/upgrade/EncryptionKeyUpgradeTest.java diff --git a/core/test/src/org/labkey/test/tests/upgrade/EncryptionKeyUpgradeTest.java b/core/test/src/org/labkey/test/tests/upgrade/EncryptionKeyUpgradeTest.java new file mode 100644 index 00000000000..65f403d7684 --- /dev/null +++ b/core/test/src/org/labkey/test/tests/upgrade/EncryptionKeyUpgradeTest.java @@ -0,0 +1,78 @@ +package org.labkey.test.tests.upgrade; + +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.labkey.test.Locators; +import org.labkey.test.pages.ConfigureReportsAndScriptsPage; +import org.labkey.test.pages.ConfigureReportsAndScriptsPage.EngineType; +import org.labkey.test.pages.admin.RConfigurationPage; +import org.labkey.test.pages.mothership.EditUpgradeMessagePage; +import org.labkey.test.pages.query.ExecuteQueryPage; +import org.labkey.test.util.RReportHelper; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@Category({}) +public class EncryptionKeyUpgradeTest extends BaseUpgradeTest +{ + private static final String DUMMY_R_SERVE = "Dummy RServe"; + + @Override + protected void doCleanup(boolean afterTest) + { + _containerHelper.deleteProject(getProjectName(), afterTest); + } + + @Override + protected void doSetup() + { + ConfigureReportsAndScriptsPage configureReportsAndScriptsPage = ConfigureReportsAndScriptsPage.beginAt(this); + configureReportsAndScriptsPage.deleteEnginesFromList(List.of(DUMMY_R_SERVE)); + + // Create an R engine with a password (which will be encrypted) + ConfigureReportsAndScriptsPage.EngineConfig config = new ConfigureReportsAndScriptsPage.RServeEngineConfig() + .setPassword("password") + .setName(DUMMY_R_SERVE); + configureReportsAndScriptsPage.addEngine(EngineType.REMOTE_R, config); + + _containerHelper.createProject(getProjectName(), null); + RConfigurationPage.beginAt(this, getProjectName()) + .setEngineOverrides(DUMMY_R_SERVE, DUMMY_R_SERVE) + .save(); + + // Set StatusCake api key + EditUpgradeMessagePage.beginAt(this) + .setStatusCakeApiKey("password") + .save(); + } + + @Test + public void testDummyRemoteREngine() + { + // Trying to contact the R server will trigger an error if there is a problem with password encryption + ExecuteQueryPage.beginAt(this, getProjectName(), "core", "containers").getDataRegion() + .goToReport("Create R Report"); + new RReportHelper(this).clickReportTab(); + + waitForElement(Locators.labkeyError.withText("Error executing command")); + assertTextPresent("Could not connect to: 127.0.0.1:6311"); + + } + + @Test + public void testStatusCakeApiKey() + { + // Just loading this page can trigger an error if there was a problem with the encryption + assertEquals("StatusCake API key input should be present but blank", + "", EditUpgradeMessagePage.beginAt(this).getStatusCakeApiKey()); + } + + @Override + protected String getProjectName() + { + return "EncryptionKeyUpgradeTest Project"; + } + +} diff --git a/mothership/test/src/org/labkey/test/pages/mothership/EditUpgradeMessagePage.java b/mothership/test/src/org/labkey/test/pages/mothership/EditUpgradeMessagePage.java index 899e6471361..41fc9e92806 100644 --- a/mothership/test/src/org/labkey/test/pages/mothership/EditUpgradeMessagePage.java +++ b/mothership/test/src/org/labkey/test/pages/mothership/EditUpgradeMessagePage.java @@ -102,6 +102,17 @@ public EditUpgradeMessagePage setIssuesContainer(String issuesContainerPath) return this; } + public String getStatusCakeApiKey() + { + return elementCache().statusCakeApiKeyInput.get(); + } + + public EditUpgradeMessagePage setStatusCakeApiKey(String apiKey) + { + elementCache().statusCakeApiKeyInput.set(apiKey); + return this; + } + public ShowExceptionsPage save() { sleep(1000); // give time for set or clear actions to process @@ -115,13 +126,14 @@ protected ElementCache newElementCache() return new ElementCache(); } - protected class ElementCache extends BaseMothershipPage.ElementCache + protected class ElementCache extends BaseMothershipPage.ElementCache { Input currentBuildDateInput = new Input(Locator.name("currentBuildDate").findWhenNeeded(this), getDriver()); Input messageTextArea = new Input(Locator.name("message").findWhenNeeded(this), getDriver()); Input createIssueURLInput = new Input(Locator.name("createIssueURL").findWhenNeeded(this), getDriver()); Input issuesContainerInput = new Input(Locator.name("issuesContainer").findWhenNeeded(this), getDriver()); Input marketingMessageTextArea = new Input(Locator.name("marketingMessage").findWhenNeeded(this), getDriver()); - WebElement saveButton = Locator.lkButton("Save").findWhenNeeded( this); + Input statusCakeApiKeyInput = new Input(Locator.name("statusCakeApiKey").findWhenNeeded(this), getDriver()); + WebElement saveButton = Locator.lkButton("Save").findWhenNeeded(this); } }