Skip to content

Commit 82cf0d2

Browse files
authored
Fix file path validation with non root contextPath, update error msg for saveBatch invalid file, etc (#7002)
1 parent dcab251 commit 82cf0d2

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

api/src/org/labkey/api/assay/DefaultAssayRunCreator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,11 +1223,17 @@ else if (!missing)
12231223
}
12241224
catch (ConversionException e)
12251225
{
1226-
String message = ConvertHelper.getStandardConversionErrorMessage(value, label, type);
1227-
if (e.getCause() instanceof ArithmeticException)
1228-
message += ": " + e.getCause().getLocalizedMessage();
1226+
String message;
1227+
if (e instanceof ConvertHelper.FileConversionException fce)
1228+
message = fce.getMessage();
12291229
else
1230-
message += ".";
1230+
{
1231+
message = ConvertHelper.getStandardConversionErrorMessage(value, label, type);
1232+
if (e.getCause() instanceof ArithmeticException)
1233+
message += ": " + e.getCause().getLocalizedMessage();
1234+
else
1235+
message += ".";
1236+
}
12311237

12321238
// Attempt to resolve lookups by display value
12331239
boolean skipError = false;

api/src/org/labkey/api/data/ExpDataFileConverter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,16 @@ public static File convertToFile(Object value, @NotNull Container container, @No
364364

365365
// toss in here an additional check, if starts with HTTP then try to use _webdav to resolve it
366366
// MAKE sure that the security is in place - figure out what container it is in
367-
String webdav = value.toString();
368-
if (null != StringUtils.trimToNull(webdav))
367+
String rootSubstitutedPath = getFileRootSubstitutedFilePath(value.toString(), fileRootPath);;
368+
if (null != StringUtils.trimToNull(rootSubstitutedPath))
369369
{
370370
if (assayResultFileRoot != null)
371371
{
372372
try
373373
{
374374
for (int i = 0; i < 5; i++) // try up to 5 times to find a case-sensitive match
375375
{
376-
String resultsFileName = FileUtil.getAppendedFileName(webdav, i);
376+
String resultsFileName = FileUtil.getAppendedFileName(rootSubstitutedPath, i);
377377
FileLike assayResultFile = assayResultFileRoot.resolveChild(resultsFileName);
378378

379379
if (!assayResultFile.isFile())
@@ -390,7 +390,9 @@ public static File convertToFile(Object value, @NotNull Container container, @No
390390

391391
}
392392

393-
webdav = getFileRootSubstitutedFilePath(webdav, fileRootPath);
393+
String webdav = rootSubstitutedPath;
394+
if (webdav.startsWith(AppProps.getInstance().getContextPath()))
395+
webdav = webdav.substring(AppProps.getInstance().getContextPath().length());
394396
Path path = Path.decode(FileUtil.encodeForURL(webdav, true /*Issue 51207*/).replace(AppProps.getInstance().getBaseServerUrl() + AppProps.getInstance().getContextPath(), ""));
395397
WebdavResource resource = WebdavService.get().getResolver().lookup(path);
396398
if (resource != null && resource.isFile())
@@ -440,7 +442,7 @@ public static File convertToFile(Object value, @NotNull Container container, @No
440442
}
441443

442444
// Otherwise, treat it as a plain path (processed by getFileRootSubstitutedFilePath)
443-
return FILE_CONVERTER.convert(File.class, webdav);
445+
return FILE_CONVERTER.convert(File.class, rootSubstitutedPath);
444446
}
445447

446448
// if two files were uploaded with the same name but different casing, then the file system will uniquify the names

study/test/src/org/labkey/test/tests/study/AssayTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import org.junit.Test;
2020
import org.junit.experimental.categories.Category;
21+
import org.labkey.remoteapi.CommandException;
2122
import org.labkey.remoteapi.assay.AssayListCommand;
2223
import org.labkey.remoteapi.assay.AssayListResponse;
2324
import org.labkey.test.Locator;
2425
import org.labkey.test.TestFileUtils;
2526
import org.labkey.test.TestTimeoutException;
27+
import org.labkey.test.WebTestHelper;
2628
import org.labkey.test.categories.Assays;
2729
import org.labkey.test.categories.Daily;
2830
import org.labkey.test.components.CustomizeView;
@@ -35,12 +37,14 @@
3537
import org.labkey.test.params.experiment.SampleTypeDefinition;
3638
import org.labkey.test.tests.AbstractAssayTest;
3739
import org.labkey.test.tests.AuditLogTest;
40+
import org.labkey.test.util.AuditLogHelper;
3841
import org.labkey.test.util.DataRegionTable;
3942
import org.labkey.test.util.LogMethod;
4043
import org.labkey.test.util.SampleTypeHelper;
4144
import org.labkey.test.util.StudyHelper;
4245

4346
import java.io.File;
47+
import java.io.IOException;
4448
import java.util.ArrayList;
4549
import java.util.List;
4650

@@ -267,7 +271,7 @@ private void verifyWebdavTree()
267271
}
268272

269273
@LogMethod
270-
private void editResults()
274+
private void editResults() throws IOException, CommandException
271275
{
272276
// Verify that the results aren't editable by default
273277
navigateToFolder(getProjectName(), TEST_ASSAY_FLDR_LAB1);
@@ -310,15 +314,13 @@ private void editResults()
310314
});
311315

312316
// Verify that the edit was audited
317+
AuditLogHelper auditLogHelper = new AuditLogHelper(this, () -> WebTestHelper.getRemoteApiConnection(false));
318+
auditLogHelper.checkAuditEventDiffCount(getProjectName(), AuditLogHelper.AuditEvent.QUERY_UPDATE_AUDIT_EVENT, List.of(0/*delete*/, 4/*edit*/));
319+
313320
goToSchemaBrowser();
314321
viewQueryData("auditLog", "ExperimentAuditEvent");
315-
assertTextPresent(
316-
"Data row, id ",
317-
", edited in " + TEST_ASSAY + ".",
318-
"Specimen ID changed from 'AAA07XK5-05' to 'EditedSpecimenID'",
319-
"Visit ID changed from '601.0' to '601.5",
320-
"testAssayDataProp5 changed from blank to '514801'",
321-
"Deleted data row, id ");
322+
assertTextPresent("1 data row has been edited in " + TEST_ASSAY + ".");
323+
322324
}
323325

324326
/**

study/test/src/org/labkey/test/tests/study/StudyDatasetFileFieldTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void testFileField() throws IOException, CommandException
130130
File downloadedFile = doAndWaitForDownload(() -> waitAndClick(WAIT_FOR_JAVASCRIPT, Locator.tagWithAttribute("a", "title", "Download attached file"), 0));
131131
checker().verifyTrue("Incorrect file name ", FileUtils.contentEquals(downloadedFile, inputFile));
132132

133-
FileBrowserHelper.FileDetailInfo fileInfoOriginalFile = _fileBrowserHelper.getFileDetailInfo(getProjectName(), "sample.txt");
133+
FileBrowserHelper.FileDetailInfo fileInfoOriginalFile = FileBrowserHelper.getFileDetailInfo(getProjectName(), "sample.txt");
134134

135135
goToFolderManagement().goToExportTab();
136136
new Checkbox(Locator.tagWithText("label", "Files").precedingSibling("input").findElement(getDriver())).check();

0 commit comments

Comments
 (0)