|
21 | 21 | import org.junit.BeforeClass; |
22 | 22 | import org.junit.Test; |
23 | 23 | 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; |
24 | 28 | import org.labkey.test.BaseWebDriverTest; |
25 | 29 | import org.labkey.test.Locator; |
26 | 30 | import org.labkey.test.SortDirection; |
27 | 31 | import org.labkey.test.TestFileUtils; |
28 | 32 | import org.labkey.test.TestTimeoutException; |
| 33 | +import org.labkey.test.WebTestHelper; |
29 | 34 | import org.labkey.test.categories.Assays; |
30 | 35 | import org.labkey.test.categories.Daily; |
31 | 36 | import org.labkey.test.components.CrosstabDataRegion; |
|
39 | 44 | import org.labkey.test.util.PipelineStatusTable; |
40 | 45 | import org.labkey.test.util.PortalHelper; |
41 | 46 | import org.labkey.test.util.QCAssayScriptHelper; |
| 47 | +import org.labkey.test.util.SimpleHttpRequest; |
| 48 | +import org.labkey.test.util.SimpleHttpResponse; |
42 | 49 | import org.openqa.selenium.NoSuchElementException; |
43 | 50 |
|
44 | 51 | import java.io.File; |
| 52 | +import java.io.IOException; |
45 | 53 | import java.util.Arrays; |
46 | 54 | import java.util.HashMap; |
47 | 55 | import java.util.List; |
48 | 56 | import java.util.Map; |
49 | 57 |
|
50 | 58 | import static org.junit.Assert.assertEquals; |
| 59 | +import static org.junit.Assert.assertTrue; |
51 | 60 | import static org.labkey.test.components.PlateSummary.Row.A; |
52 | 61 | import static org.labkey.test.components.PlateSummary.Row.C; |
53 | 62 | import static org.labkey.test.components.PlateSummary.Row.E; |
@@ -519,10 +528,61 @@ protected void runTransformTest() |
519 | 528 | protected void doBackgroundSubtractionTest() |
520 | 529 | { |
521 | 530 | removeTransformScript(); |
| 531 | + verifyCrossContainerBackgroundSubtractionDenied(); |
522 | 532 | verifyBackgroundSubtractionOnExistingRun(); |
523 | 533 | verifyBackgroundSubtractionOnNewRun(); |
524 | 534 | } |
525 | 535 |
|
| 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 | + |
526 | 586 | // Unable to apply background substitution to runs imported with a transform script. |
527 | 587 | protected void removeTransformScript() |
528 | 588 | { |
|
0 commit comments