Bug 1692481 Fix Import Error error modal after importing with multiple column headers r=tgiles

Differential Revision: https://phabricator.services.mozilla.com/D105099
This commit is contained in:
Andrei Cristian Petcu 2021-02-16 18:36:57 +00:00
Родитель 622de84aae
Коммит 99c5b52ccc
2 изменённых файлов: 28 добавлений и 4 удалений

Просмотреть файл

@ -153,15 +153,18 @@ class LoginCSVImport {
); );
} }
let parsedLines; let parsedLines;
let headerLine;
if (filePath.endsWith(".csv")) { if (filePath.endsWith(".csv")) {
headerLine = d3.csv.parseRows(csvString)[0];
parsedLines = d3.csv.parse(csvString); parsedLines = d3.csv.parse(csvString);
} else if (filePath.endsWith(".tsv")) { } else if (filePath.endsWith(".tsv")) {
headerLine = d3.tsv.parseRows(csvString)[0];
parsedLines = d3.tsv.parse(csvString); parsedLines = d3.tsv.parse(csvString);
} }
let fieldsInFile = new Set(); let fieldsInFile = new Set();
if (parsedLines && parsedLines[0]) { if (parsedLines && headerLine) {
for (const columnName in parsedLines[0]) { for (const columnName of headerLine) {
const fieldName = csvColumnToFieldMap.get( const fieldName = csvColumnToFieldMap.get(
columnName.toLocaleLowerCase() columnName.toLocaleLowerCase()
); );

Просмотреть файл

@ -153,9 +153,9 @@ add_task(async function test_import_lacking_username_column() {
}); });
/** /**
* Ensure that an import fails if there are two headings that map to one login field. * Ensure that an import fails if there are two columns that map to one login field.
*/ */
add_task(async function test_import_with_duplicate_columns() { add_task(async function test_import_with_duplicate_fields() {
// Two origin columns (url & login_uri). // Two origin columns (url & login_uri).
// One row has different values and the other has the same. // One row has different values and the other has the same.
let csvFilePath = await setupCsv([ let csvFilePath = await setupCsv([
@ -176,6 +176,27 @@ add_task(async function test_import_with_duplicate_columns() {
); );
}); });
/**
* Ensure that an import fails if there are two identical columns.
*/
add_task(async function test_import_with_duplicate_columns() {
let csvFilePath = await setupCsv([
"url,username,password,password",
"https://example.com/path,john@example.com,azerty,12345",
]);
await Assert.rejects(
LoginCSVImport.importFromCSV(csvFilePath),
/CONFLICTING_VALUES_ERROR/,
"Check that the errorType is file format error"
);
LoginTestUtils.checkLogins(
[],
"Check that no login was added from a file with duplicated columns"
);
});
/** /**
* Ensure that import is allowed with only origin, username, password and that * Ensure that import is allowed with only origin, username, password and that
* one can mix and match column naming between conventions from different * one can mix and match column naming between conventions from different