Skip to content

Commit

Permalink
Add restrictions on names of domains - automated tests (#2189)
Browse files Browse the repository at this point in the history
  • Loading branch information
XingY authored Dec 16, 2024
1 parent 48eb487 commit 9ddd6d0
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 63 deletions.
Binary file modified data/samples/ParentSamples.xlsx
Binary file not shown.
7 changes: 4 additions & 3 deletions src/org/labkey/test/AssayAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

@Category({Daily.class, Assays.class})
@BaseWebDriverTest.ClassTimeout(minutes = 6)
Expand Down Expand Up @@ -159,7 +160,7 @@ public void testImportRun_serverFilePath() throws Exception
{
goToProjectHome();

String assayName = "GPAT-ImportRunApi" + TRICKY_CHARACTERS;
String assayName = "GPAT-ImportRunApi" + DOMAIN_TRICKY_CHARACTERS;
APIAssayHelper assayHelper = new APIAssayHelper(this);
int assayId = assayHelper.getIdFromAssayName(assayName, getProjectName(), false);
if (assayId == 0)
Expand Down Expand Up @@ -248,7 +249,7 @@ public void testImportRun_dataRows() throws Exception
goToProjectHome();

log("create GPAT assay");
String assayName = "GPAT-ImportRunApi-dataRows" + TRICKY_CHARACTERS;
String assayName = "GPAT-ImportRunApi-dataRows" + DOMAIN_TRICKY_CHARACTERS;
createAssayWithFileFields(assayName);

File fileRoot = TestFileUtils.getDefaultFileRoot(getProjectName());
Expand Down Expand Up @@ -297,7 +298,7 @@ public void testGpatSaveBatch() throws Exception
goToProjectHome();

log("create GPAT assay");
String assayName = "GPAT-SaveBatch" + TRICKY_CHARACTERS;
String assayName = "GPAT-SaveBatch" + DOMAIN_TRICKY_CHARACTERS;
createAssayWithFileFields(assayName);

log("create run via saveBatch");
Expand Down
16 changes: 12 additions & 4 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2173,12 +2173,14 @@ public void searchFor(final String projectName, String searchFor, final Integer
assertTextPresent(searchFor);
}
}

// Helper methods for interacting with the query schema browser
public void selectSchema(String schemaName)
{
String[] schemaParts = schemaName.split("\\.");

selectSchema(schemaParts);
}
// Helper methods for interacting with the query schema browser
public void selectSchema(String[] schemaParts)
{
StringBuilder schemaWithParents = new StringBuilder();
String separator = "";
for (String schemaPart : schemaParts)
Expand Down Expand Up @@ -2227,8 +2229,14 @@ public void selectSchema(String schemaName)

public void selectQuery(String schemaName, String queryName)
{
selectQuery(schemaName.split("\\."), queryName);
}

public void selectQuery(String[] schemaPart, String queryName)
{
String schemaName = StringUtils.join(schemaPart, ".");
log("Selecting query " + schemaName + "." + queryName + " in the schema browser...");
selectSchema(schemaName);
selectSchema(schemaPart);
mouseOver(Locator.byClass(".x4-tab-button")); // Move away from schema tree to dismiss tooltip
waitAndClick(Ext4Helper.Locators.tab(schemaName)); // Click schema tab to make sure query list is visible
WebElement queryLink = Locator.tagWithClass("table", "lk-qd-coltable").append(Locator.tagWithClass("span", "labkey-link")).withText(queryName).notHidden().waitForElement(getDriver(), WAIT_FOR_JAVASCRIPT);
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/test/Locator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ public XPathLocator withAttributeContaining(String attrName, String partialAttrV
public XPathLocator withAttributeIgnoreCase(String attrName, String attrVal)
{
return this.withPredicate(
String.format("translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')=%s",
String.format("translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZÅ', 'abcdefghijklmnopqrstuvwxyzå')=%s",
attrName, xq(attrVal.toLowerCase())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.labkey.test.components.UpdatingComponent;
import org.labkey.test.components.bootstrap.ModalDialog;
import org.labkey.test.components.html.Checkbox;
import org.labkey.test.util.EscapeUtil;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -162,7 +163,9 @@ private String expandAvailableFields(String... fields)

while(iterator.hasNext())
{
fieldKey.append(iterator.next().replace(" ", ""));
String field = iterator.next().trim();
String fieldEncoded = field.contains("$D") ? field : EscapeUtil.fieldKeyEncodePart(field);
fieldKey.append(fieldEncoded);

// If this isn't the last item in the collection keep expanding and building the expected data-fieldkey value.
if(iterator.hasNext())
Expand Down
5 changes: 4 additions & 1 deletion src/org/labkey/test/params/FieldDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
import java.util.List;
import java.util.Map;

import static org.labkey.test.util.TestDataGenerator.DOMAIN_SPECIAL_STRING;

public class FieldDefinition extends PropertyDescriptor
{
private static final String SNOWMAN = "\u2603";
private static final String ANGSTROM = "\u00C5";
public static final String ANGSTROM = "\u00C5";
private static final String A_UMLAUT = "\u00E4";
// Non-alphanumeric characters supported for field names
public static final String TRICKY_CHARACTERS = "><&$,/%\\'}{][ \";:" + SNOWMAN + ANGSTROM + A_UMLAUT;
public static final String DOMAIN_TRICKY_CHARACTERS = DOMAIN_SPECIAL_STRING + SNOWMAN + ANGSTROM + A_UMLAUT;

// for UI helpers
private ColumnType _type;
Expand Down
4 changes: 3 additions & 1 deletion src/org/labkey/test/tests/AbstractAssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.Arrays;
import java.util.List;

import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

/**
* @deprecated TODO: Move shared functionality to a Helper class
*/
Expand All @@ -59,7 +61,7 @@ public abstract class AbstractAssayTest extends BaseWebDriverTest
protected final static String TEST_ASSAY_FLDR_STUDY3 = "Study 3"; //another sub of Studies
protected final static String TEST_ASSAY_PERMS_STUDY_READALL = "READ";

protected static final String TEST_ASSAY = "Test" + TRICKY_CHARACTERS + "Assay1";
protected static final String TEST_ASSAY = "Test" + DOMAIN_TRICKY_CHARACTERS + "Assay1";
protected static final String TEST_ASSAY_DESC = "Description for assay 1";
protected static final String TEST_ASSAY_SET_PROP_NAME = "testAssaySetProp";
protected static final int TEST_ASSAY_SET_PREDEFINED_PROP_COUNT = 2;
Expand Down
5 changes: 3 additions & 2 deletions src/org/labkey/test/tests/ClientAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.WebTestHelper.getHttpResponse;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

@Category({BVT.class})
@BaseWebDriverTest.ClassTimeout(minutes = 14)
Expand All @@ -106,7 +107,7 @@ public class ClientAPITest extends BaseWebDriverTest
private static final String OTHER_PROJECT_LIST = "otherProjectList"; // for cross-project query test
// Add tricky characters to assay name to check for regressions
// Issue 36077: SelectRows: SchemaKey decoding of public schema name causes request failure
protected static final String TEST_ASSAY = "TestAssay1" + TRICKY_CHARACTERS;
protected static final String TEST_ASSAY = "TestAssay1" + DOMAIN_TRICKY_CHARACTERS;
protected static final String TEST_ASSAY_DESC = "Description for assay 1";
private static final List<FieldDefinition> LIST_COLUMNS = List.of(
new FieldDefinition("FirstName", FieldDefinition.ColumnType.String).setLabel("First Name").setDescription("The first name").setRequired(true),
Expand Down Expand Up @@ -626,7 +627,7 @@ public void validateDatasetNameIsNotBlank()
"});\n";

Map<String, Object> error = (Map<String,Object>)executeAsyncScript(create);
assertEquals("Unexpected error message", "Dataset name cannot be empty.", error.get("exception"));
assertEquals("Unexpected error message", "StudyDatasetVisit name must not be blank.", error.get("exception"));
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion src/org/labkey/test/tests/CustomizeViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

@Category({Daily.class})
@BaseWebDriverTest.ClassTimeout(minutes = 8)
public class CustomizeViewTest extends BaseWebDriverTest
{
public static final String PROJECT_NAME = "CustomizeViewTest";
public static final String LIST_NAME = "People" + INJECT_CHARS_1;
public static final String LIST_NAME = "People" + DOMAIN_TRICKY_CHARACTERS;
private final static String LIST_KEY_COLUMN = "Key";
private final static String LAST_NAME_COLUMN = "LastName" + INJECT_CHARS_2;
private final static String FIRST_NAME_COLUMN = "FirstName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testExportImportSimpleDataClass() throws Exception
{
String subfolder = "simpleDataClassExportFolder";
String subfolderPath = getProjectName() + "/" + subfolder;
String testDataClass = "testData?<>*/Class"; // having the dataClass with non-file-legal chars in it is intentional,
String testDataClass = "testData_/Class"; // having the dataClass with non-file-legal chars in it is intentional,
// the import/export processes will write temp-files with names derived from
// the dataClass name. This ensures that the sanitized name on export can
// be successfully matched up with the intended dataClass on import
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testExportImportMissingValueDataClass() throws Exception

String subfolder = "missingValueDataClassExportFolder";
String subfolderPath = getProjectName() + "/" + subfolder;
String testDataClass = "missing?Value*Data//Class"; // having the dataClass with non-file-legal chars in it is intentional,
String testDataClass = "missing_Value+Data//Class"; // having the dataClass with non-file-legal chars in it is intentional,
// the import/export processes will write temp-files with names derived from
// the dataClass name. This ensures that the sanitized name on export can
// be successfully matched up with the intended dataClass on import
Expand Down
3 changes: 2 additions & 1 deletion src/org/labkey/test/tests/DataRegionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

@Category({Daily.class, Data.class})
@BaseWebDriverTest.ClassTimeout(minutes = 6)
public class DataRegionTest extends AbstractQWPTest
{
private static final String LIST_NAME = "WebColors" + INJECT_CHARS_1;
private static final String LIST_NAME = "WebColors" + DOMAIN_TRICKY_CHARACTERS;
private static final FieldDefinition.ColumnType LIST_KEY_TYPE = FieldDefinition.ColumnType.Integer;
private static final String LIST_KEY_NAME = "Key";

Expand Down
3 changes: 2 additions & 1 deletion src/org/labkey/test/tests/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static org.junit.Assert.assertEquals;
import static org.labkey.test.params.FieldDefinition.ColumnType;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;
import static org.labkey.test.params.FieldDefinition.LookupInfo;
import static org.labkey.test.util.PermissionsHelper.MemberType;

Expand All @@ -59,7 +60,7 @@ public class FilterTest extends BaseWebDriverTest
protected final static String R_VIEW = TRICKY_CHARACTERS + "R report";
protected final static String FACET_TEST_LIST = "FacetList";

protected final static String LIST_NAME_COLORS = TRICKY_CHARACTERS_NO_QUOTES + "Colors";
protected final static String LIST_NAME_COLORS = "Colors" + DOMAIN_TRICKY_CHARACTERS;
protected final static String LIST_KEY_NAME2 = "Color";

protected final FieldDefinition _listColKey = new FieldDefinition("Color", ColumnType.String);
Expand Down
27 changes: 20 additions & 7 deletions src/org/labkey/test/tests/GpatAssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.labkey.test.tests;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -37,8 +38,10 @@
import org.labkey.test.pages.core.admin.BaseSettingsPage;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.EscapeUtil;
import org.labkey.test.util.LogMethod;
import org.labkey.test.util.LoggedParam;
import org.labkey.test.util.TestDataGenerator;
import org.labkey.test.util.core.webdav.WebDavUploadHelper;
import org.openqa.selenium.WebElement;

Expand All @@ -53,6 +56,7 @@
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.labkey.test.params.FieldDefinition.DOMAIN_TRICKY_CHARACTERS;

@Category({Assays.class, BVT.class})
@BaseWebDriverTest.ClassTimeout(minutes = 7)
Expand All @@ -62,7 +66,7 @@ public class GpatAssayTest extends BaseWebDriverTest
private static final File GPAT_ASSAY_XLSX = TestFileUtils.getSampleData("GPAT/trial01a.xlsx");
private static final File GPAT_ASSAY_TSV = TestFileUtils.getSampleData("GPAT/trial02.tsv");
private static final File GPAT_ASSAY_FNA_1 = TestFileUtils.getSampleData("GPAT/trial03.fna");
private static final String ASSAY_NAME_XLS = "XLS Assay " + TRICKY_CHARACTERS;
private static final String ASSAY_NAME_XLS = "XLS Assay " + DOMAIN_TRICKY_CHARACTERS;
private static final String ASSAY_NAME_XLSX = "XLSX Assay";
private static final String ASSAY_NAME_TSV = "TSV Assay";
private static final String ASSAY_NAME_FNA = "FASTA Assay";
Expand Down Expand Up @@ -118,7 +122,7 @@ public void testSteps()
{
// Issue 36077: SelectRows: SchemaKey decoding of public schema name causes request failure
Connection cn = createDefaultConnection();
SelectRowsCommand selectCmd = new SelectRowsCommand("assay.General." + ASSAY_NAME_XLS, "Runs");
SelectRowsCommand selectCmd = new SelectRowsCommand("assay.General." + EscapeUtil.fieldKeyEncodePart(ASSAY_NAME_XLS), "Runs");
selectCmd.setRequiredVersion(17.1);
SelectRowsResponse selectResp = selectCmd.execute(cn, getProjectName());
assertEquals(1, selectResp.getRowCount().intValue());
Expand Down Expand Up @@ -333,15 +337,20 @@ public void testMultipleFileUploadSingleRowInAssayRun()
@Test
public void testUpdateAssayDesign() throws IOException, CommandException
{
File trialData = TestFileUtils.getSampleData("GPAT/renameAssayTrial.xls");

String invalidAssayName = TestDataGenerator.randomInvalidDomainName(10);
ReactAssayDesignerPage assayDesignerPage = startCreateGpatAssay(trialData, invalidAssayName);
List<String> errors = assayDesignerPage.clickSaveExpectingErrors();
assayDesignerPage.clickCancel();
Assert.assertTrue("Error msg not as expected during assay creation", errors.contains("Invalid Assay Design name \"" + invalidAssayName + "\". Assay Design name must start with a letter or a number."));

BaseSettingsPage.resetSettings(createDefaultConnection(), "/");
BaseSettingsPage.resetSettings(createDefaultConnection(), getProjectName());

File trialData = TestFileUtils.getSampleData("GPAT/renameAssayTrial.xls");

String originalAssayName = "A Assay Name";
String originalAssayName = TestDataGenerator.randomDomainName();
log(String.format("Create an assay named '%s'.", originalAssayName));
ReactAssayDesignerPage assayDesignerPage = startCreateGpatAssay(trialData, originalAssayName);
assayDesignerPage = startCreateGpatAssay(trialData, originalAssayName);

DomainFormPanel runProperties = assayDesignerPage.goToRunFields();

Expand Down Expand Up @@ -389,14 +398,18 @@ public void testUpdateAssayDesign() throws IOException, CommandException
checker().verifyEquals(String.format("Value in column '%s' is not as expected.", runDateTime02),
defaultDateTimeFormat.format(date), rowMap.get(runDateTime02));

String newAssayName = "Updated Assay Name";
String newAssayName = TestDataGenerator.randomDomainName();
log(String.format("Edit the assay design and rename it to '%s'.", newAssayName));

assayDesignerPage = _assayHelper.clickEditAssayDesign(false);
checker().fatal()
.verifyTrue("The 'Name' field should be enabled and editable. Fatal error.",
assayDesignerPage.isNameEnabled());

assayDesignerPage.setName(invalidAssayName);
errors = assayDesignerPage.clickSaveExpectingErrors();
Assert.assertTrue("Error msg not as expected during assay update", errors.contains("Invalid Assay Design name \"" + invalidAssayName + "\". Assay Design name must start with a letter or a number."));

assayDesignerPage.setName(newAssayName);

log("Convert the date, time and dateTime run fields to different (compatible) types.");
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/test/tests/JavaClientApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
public class JavaClientApiTest extends BaseWebDriverTest
{
public static final String PROJECT_NAME = JavaClientApiTest.class.getSimpleName() + " Project " + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
public static final String LIST_NAME = "People" + FieldDefinition.TRICKY_CHARACTERS;
public static final String LIST_NAME = "People" + FieldDefinition.DOMAIN_TRICKY_CHARACTERS;
public static final String LAST_NAME = "LastName" + FieldDefinition.TRICKY_CHARACTERS;
public static final String USER_NAME = "user1@javaclientapi.test";
public static final String USER2_NAME = "user2@javaclientapi.test";
Expand Down
Loading

0 comments on commit 9ddd6d0

Please sign in to comment.