1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-23 16:38:45 +01:00

[PM-3100] Fixes imports of "reduced" psono data (#5859)

* Fixes imports of "reduced" psono data

* Fix typo in file name

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
KuhnChris 2023-08-25 21:16:53 +02:00 committed by GitHub
parent 708eb21a49
commit f2df456516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import { EnvVariablesData } from "./test-data/psono-json/environment-variables";
import { FoldersTestData } from "./test-data/psono-json/folders"; import { FoldersTestData } from "./test-data/psono-json/folders";
import { GPGData } from "./test-data/psono-json/gpg"; import { GPGData } from "./test-data/psono-json/gpg";
import { NotesData } from "./test-data/psono-json/notes"; import { NotesData } from "./test-data/psono-json/notes";
import { ReducedWebsiteLoginsData } from "./test-data/psono-json/reduced-website-logins";
import { TOTPData } from "./test-data/psono-json/totp"; import { TOTPData } from "./test-data/psono-json/totp";
import { WebsiteLoginsData } from "./test-data/psono-json/website-logins"; import { WebsiteLoginsData } from "./test-data/psono-json/website-logins";
@ -23,6 +24,7 @@ function validateCustomField(
expect(fields).not.toBeUndefined(); expect(fields).not.toBeUndefined();
const customField = fields.find((f) => f.name === fieldName); const customField = fields.find((f) => f.name === fieldName);
expect(customField).not.toBeNull(); expect(customField).not.toBeNull();
expect(customField).not.toBeUndefined();
expect(customField.value).toEqual(expectedValue); expect(customField.value).toEqual(expectedValue);
expect(customField.type).toEqual(fieldType); expect(customField.type).toEqual(fieldType);
@ -38,6 +40,7 @@ describe("PSONO JSON Importer", () => {
const FoldersTestDataJson = JSON.stringify(FoldersTestData); const FoldersTestDataJson = JSON.stringify(FoldersTestData);
const GPGDataJson = JSON.stringify(GPGData); const GPGDataJson = JSON.stringify(GPGData);
const EnvVariablesDataJson = JSON.stringify(EnvVariablesData); const EnvVariablesDataJson = JSON.stringify(EnvVariablesData);
const ReducedWebsiteLoginsDataJson = JSON.stringify(ReducedWebsiteLoginsData);
it("should parse Website/Password data", async () => { it("should parse Website/Password data", async () => {
const importer = new PsonoJsonImporter(); const importer = new PsonoJsonImporter();
@ -64,6 +67,23 @@ describe("PSONO JSON Importer", () => {
validateCustomField(cipher.fields, "callback_user", "callbackUser"); validateCustomField(cipher.fields, "callback_user", "callbackUser");
validateCustomField(cipher.fields, "callback_pass", "callbackPassword"); validateCustomField(cipher.fields, "callback_pass", "callbackPassword");
}); });
it("should parse Website/Password data with missing fields", async () => {
const importer = new PsonoJsonImporter();
const result = await importer.parse(ReducedWebsiteLoginsDataJson);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.type).toEqual(CipherType.Login);
expect(cipher.name).toEqual("export_website_1");
expect(cipher.login.username).toEqual("username123");
expect(cipher.login.password).toEqual("password123");
expect(cipher.login.uris).toEqual(null);
expect(cipher.fields.length).toBe(2);
validateCustomField(cipher.fields, "create_date", "2022-09-10T23:05:02.351417Z");
validateCustomField(cipher.fields, "write_date", "2022-09-10T23:05:02.351583Z");
});
it("should parse Application Password data", async () => { it("should parse Application Password data", async () => {
const importer = new PsonoJsonImporter(); const importer = new PsonoJsonImporter();

View File

@ -0,0 +1,21 @@
import { PsonoJsonExport } from "../../../src/importers/psono/psono-json-types";
export const ReducedWebsiteLoginsData: PsonoJsonExport = {
folders: [],
items: [
{
type: "website_password",
name: "export_website_name",
website_password_password: "password123",
website_password_username: "username123",
website_password_notes: "",
website_password_url: "",
website_password_title: "export_website_1",
create_date: "2022-09-10T23:05:02.351417Z",
write_date: "2022-09-10T23:05:02.351583Z",
callback_url: "",
callback_user: "",
callback_pass: "",
},
],
};

View File

@ -131,7 +131,7 @@ export class PsonoJsonImporter extends BaseImporter implements Importer {
this.processKvp( this.processKvp(
cipher, cipher,
"website_password_auto_submit", "website_password_auto_submit",
entry.website_password_auto_submit.toString(), entry.website_password_auto_submit?.toString(),
FieldType.Boolean FieldType.Boolean
); );

View File

@ -38,15 +38,15 @@ export type PsonoEntryTypes =
export interface WebsitePasswordEntry extends RecordBase { export interface WebsitePasswordEntry extends RecordBase {
type: "website_password"; type: "website_password";
autosubmit: boolean; autosubmit?: boolean;
urlfilter: string; urlfilter?: string;
website_password_title: string; website_password_title: string;
website_password_url: string; website_password_url: string;
website_password_username: string; website_password_username: string;
website_password_password: string; website_password_password: string;
website_password_notes: string; website_password_notes: string;
website_password_auto_submit: boolean; website_password_auto_submit?: boolean;
website_password_url_filter: string; website_password_url_filter?: string;
} }
export interface PsonoEntry { export interface PsonoEntry {