mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-21 11:35:34 +01:00
[PM 1672] SecureSafe Import Url Header Fix (#6623)
* Get the url field name ignoring the case format * Adding test cases for the SecureSafe importer * Updating test cases and the way the url field is selected * updating the variable name from url to urlField
This commit is contained in:
parent
b9cf29ff0c
commit
db221dee05
74
libs/importer/spec/securesafe-csv-importer.spec.ts
Normal file
74
libs/importer/spec/securesafe-csv-importer.spec.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
||||
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
|
||||
|
||||
import { SecureSafeCsvImporter } from "../src/importers";
|
||||
|
||||
import { data_upperUrl, data_lowerUrl } from "./test-data/securesafe-csv/securesafe-example.csv";
|
||||
|
||||
const CipherData = [
|
||||
{
|
||||
title: "should parse upper case url",
|
||||
csv: data_upperUrl,
|
||||
expected: Object.assign(new CipherView(), {
|
||||
id: null,
|
||||
organizationId: null,
|
||||
folderId: null,
|
||||
name: "Gmail",
|
||||
login: Object.assign(new LoginView(), {
|
||||
username: "test@gmail.com",
|
||||
password: "test",
|
||||
uris: [
|
||||
Object.assign(new LoginUriView(), {
|
||||
uri: "https://gmail.com",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
notes: null,
|
||||
type: 1,
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: "should parse lower case url",
|
||||
csv: data_lowerUrl,
|
||||
expected: Object.assign(new CipherView(), {
|
||||
id: null,
|
||||
organizationId: null,
|
||||
folderId: null,
|
||||
name: "Gmail",
|
||||
login: Object.assign(new LoginView(), {
|
||||
username: "test@gmail.com",
|
||||
password: "test",
|
||||
uris: [
|
||||
Object.assign(new LoginUriView(), {
|
||||
uri: "https://gmail.com",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
notes: null,
|
||||
type: 1,
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
describe("SecureSafe CSV Importer", () => {
|
||||
CipherData.forEach((data) => {
|
||||
it(data.title, async () => {
|
||||
const importer = new SecureSafeCsvImporter();
|
||||
const result = await importer.parse(data.csv);
|
||||
expect(result != null).toBe(true);
|
||||
expect(result.ciphers.length).toBeGreaterThan(0);
|
||||
|
||||
const cipher = result.ciphers.shift();
|
||||
expect(cipher.name).toEqual(data.expected.name);
|
||||
expect(cipher.login).toEqual(
|
||||
expect.objectContaining({
|
||||
username: data.expected.login.username,
|
||||
password: data.expected.login.password,
|
||||
})
|
||||
);
|
||||
expect(cipher.login.uris.length).toEqual(1);
|
||||
expect(cipher.login.uris[0].uri).toEqual(data.expected.login.uris[0].uri);
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
export const data_upperUrl = `"Title","Username","Password","URL","Comment"
|
||||
"Gmail","test@gmail.com","test","https://gmail.com"`;
|
||||
|
||||
export const data_lowerUrl = `"Title","Username","Password","url","Comment"
|
||||
"Gmail","test@gmail.com","test","https://gmail.com"`;
|
@ -12,11 +12,13 @@ export class SecureSafeCsvImporter extends BaseImporter implements Importer {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
// The url field can be in different case formats.
|
||||
const urlField = Object.keys(results[0]).find((k) => /url/i.test(k));
|
||||
results.forEach((value) => {
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(value.Title);
|
||||
cipher.notes = this.getValueOrDefault(value.Comment);
|
||||
cipher.login.uris = this.makeUriArray(value.Url);
|
||||
cipher.login.uris = this.makeUriArray(value[urlField]);
|
||||
cipher.login.password = this.getValueOrDefault(value.Password);
|
||||
cipher.login.username = this.getValueOrDefault(value.Username);
|
||||
this.cleanupCipher(cipher);
|
||||
|
Loading…
Reference in New Issue
Block a user