Skip to content

Commit 6de4e33

Browse files
committed
Elispot action container scoping
1 parent 127deae commit 6de4e33

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/org/labkey/test/tests/elispotassay/ElispotAssayTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
import org.junit.BeforeClass;
2222
import org.junit.Test;
2323
import org.junit.experimental.categories.Category;
24+
import org.labkey.api.query.QueryKey;
25+
import org.labkey.remoteapi.CommandException;
26+
import org.labkey.remoteapi.query.SelectRowsCommand;
27+
import org.labkey.remoteapi.query.SelectRowsResponse;
2428
import org.labkey.test.BaseWebDriverTest;
2529
import org.labkey.test.Locator;
2630
import org.labkey.test.SortDirection;
2731
import org.labkey.test.TestFileUtils;
2832
import org.labkey.test.TestTimeoutException;
33+
import org.labkey.test.WebTestHelper;
2934
import org.labkey.test.categories.Assays;
3035
import org.labkey.test.categories.Daily;
3136
import org.labkey.test.components.CrosstabDataRegion;
@@ -39,15 +44,19 @@
3944
import org.labkey.test.util.PipelineStatusTable;
4045
import org.labkey.test.util.PortalHelper;
4146
import org.labkey.test.util.QCAssayScriptHelper;
47+
import org.labkey.test.util.SimpleHttpRequest;
48+
import org.labkey.test.util.SimpleHttpResponse;
4249
import org.openqa.selenium.NoSuchElementException;
4350

4451
import java.io.File;
52+
import java.io.IOException;
4553
import java.util.Arrays;
4654
import java.util.HashMap;
4755
import java.util.List;
4856
import java.util.Map;
4957

5058
import static org.junit.Assert.assertEquals;
59+
import static org.junit.Assert.assertTrue;
5160
import static org.labkey.test.components.PlateSummary.Row.A;
5261
import static org.labkey.test.components.PlateSummary.Row.C;
5362
import static org.labkey.test.components.PlateSummary.Row.E;
@@ -519,10 +528,61 @@ protected void runTransformTest()
519528
protected void doBackgroundSubtractionTest()
520529
{
521530
removeTransformScript();
531+
verifyCrossContainerBackgroundSubtractionDenied();
522532
verifyBackgroundSubtractionOnExistingRun();
523533
verifyBackgroundSubtractionOnNewRun();
524534
}
525535

536+
// GitHub Kanban #1892: verify BackgroundSubtractionAction selected run in the current container.
537+
@LogMethod
538+
protected void verifyCrossContainerBackgroundSubtractionDenied()
539+
{
540+
final String crossFolder = "BackgroundSubtractionAuth";
541+
_containerHelper.createSubfolder(getProjectName(), crossFolder, "Assay");
542+
543+
// A run RowId from the assay in the project - "foreign" from the subfolder's perspective.
544+
long foreignRunId = getFirstElispotRunId();
545+
546+
log("POST background subtraction for the project's run (RowId " + foreignRunId + ") from the sibling subfolder - must be denied");
547+
String url = WebTestHelper.buildURL("elispot-assay", getProjectName() + "/" + crossFolder, "backgroundSubtraction",
548+
Map.of(".select", String.valueOf(foreignRunId)));
549+
SimpleHttpRequest request = new SimpleHttpRequest(url, "POST");
550+
request.copySession(getDriver());
551+
SimpleHttpResponse response;
552+
try
553+
{
554+
response = request.getResponse();
555+
}
556+
catch (IOException e)
557+
{
558+
throw new RuntimeException(e);
559+
}
560+
// The run is not in the subfolder, so the action should report it as not found (HTTP 404) rather than queuing the job.
561+
assertEquals("Cross-container background subtraction should be denied for a run in another folder", 404, response.getResponseCode());
562+
assertTrue("Cross-container background subtraction error message not as expected", response.getResponseBody().contains("Run " + foreignRunId + " does not exist"));
563+
564+
log("Verify the project's run was not modified by the cross-container request");
565+
clickProject(TEST_ASSAY_PRJ_ELISPOT);
566+
clickAndWait(Locator.linkWithText(TEST_ASSAY_ELISPOT));
567+
DataRegionTable runTable = new DataRegionTable("Runs", this);
568+
for (String item : runTable.getColumnDataAsText("Background Subtraction"))
569+
assertEquals("Cross-container request must not change background subtraction", "false", item);
570+
}
571+
572+
private long getFirstElispotRunId()
573+
{
574+
SelectRowsCommand select = new SelectRowsCommand("assay.ELISpot." + QueryKey.encodePart(TEST_ASSAY_ELISPOT), "Runs");
575+
try
576+
{
577+
SelectRowsResponse response = select.execute(createDefaultConnection(), getProjectName());
578+
return ((Number) response.getRowset().iterator().next().getValue("RowId")).longValue();
579+
}
580+
catch (IOException | CommandException e)
581+
{
582+
throw new RuntimeException(e);
583+
}
584+
}
585+
526586
// Unable to apply background substitution to runs imported with a transform script.
527587
protected void removeTransformScript()
528588
{

0 commit comments

Comments
 (0)