1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[PS-1805] BEEEP: Renamed importers based on agreed naming-convention (#3978)

* Rename all importer related files

Renamed all files based on our naming convention which we decided on with https://github.com/bitwarden/adr/blob/master/decisions/0012-angular-filename-convention.md

* Removed entries from whitelist-capital-letters.txt

* Rename missing safeInCloud test data

* Fix broken import

* Renamed folders (removed capital letters)

* Fix filename of BitwardenCsvImporter

* Fix imports of onepassword mac/win importer tests

* Remove already renamed folders from whitelist

* Rename dashlaneImporters to dashlane

Rename the folder
Fix all the imports
Remove dashlaneImporters from white-list

* Rename keeperImporters to keeper

Rename the folder
Fix all the imports
Remove keeperImporters from white-list

* Rename onepasswordImporters to onepassword

Rename the folder
Fix all the imports
Remove onepasswordImporters from white-list

* Rename safeinCloud test data folder

* Fix onepassword importer type imports
This commit is contained in:
Daniel James Smith
2022-11-11 16:20:03 +01:00
committed by GitHub
parent 235fb8f6ee
commit 0e78910582
141 changed files with 217 additions and 354 deletions

View File

@@ -0,0 +1,101 @@
import { FieldType } from "../enums/fieldType";
import { ImportResult } from "../models/domain/import-result";
import { FolderView } from "../models/view/folder.view";
import { BaseImporter } from "./base-importer";
import { Importer } from "./importer";
export class KeePass2XmlImporter extends BaseImporter implements Importer {
result = new ImportResult();
parse(data: string): Promise<ImportResult> {
const doc = this.parseXml(data);
if (doc == null) {
this.result.success = false;
return Promise.resolve(this.result);
}
const rootGroup = doc.querySelector("KeePassFile > Root > Group");
if (rootGroup == null) {
this.result.errorMessage = "Missing `KeePassFile > Root > Group` node.";
this.result.success = false;
return Promise.resolve(this.result);
}
this.traverse(rootGroup, true, "");
if (this.organization) {
this.moveFoldersToCollections(this.result);
}
this.result.success = true;
return Promise.resolve(this.result);
}
traverse(node: Element, isRootNode: boolean, groupPrefixName: string) {
const folderIndex = this.result.folders.length;
let groupName = groupPrefixName;
if (!isRootNode) {
if (groupName !== "") {
groupName += "/";
}
const nameEl = this.querySelectorDirectChild(node, "Name");
groupName += nameEl == null ? "-" : nameEl.textContent;
const folder = new FolderView();
folder.name = groupName;
this.result.folders.push(folder);
}
this.querySelectorAllDirectChild(node, "Entry").forEach((entry) => {
const cipherIndex = this.result.ciphers.length;
const cipher = this.initLoginCipher();
this.querySelectorAllDirectChild(entry, "String").forEach((entryString) => {
const valueEl = this.querySelectorDirectChild(entryString, "Value");
const value = valueEl != null ? valueEl.textContent : null;
if (this.isNullOrWhitespace(value)) {
return;
}
const keyEl = this.querySelectorDirectChild(entryString, "Key");
const key = keyEl != null ? keyEl.textContent : null;
if (key === "URL") {
cipher.login.uris = this.makeUriArray(value);
} else if (key === "UserName") {
cipher.login.username = value;
} else if (key === "Password") {
cipher.login.password = value;
} else if (key === "otp") {
cipher.login.totp = value.replace("key=", "");
} else if (key === "Title") {
cipher.name = value;
} else if (key === "Notes") {
cipher.notes += value + "\n";
} else {
let type = FieldType.Text;
const attrs = valueEl.attributes as any;
if (
attrs.length > 0 &&
attrs.ProtectInMemory != null &&
attrs.ProtectInMemory.value === "True"
) {
type = FieldType.Hidden;
}
this.processKvp(cipher, key, value, type);
}
});
this.cleanupCipher(cipher);
this.result.ciphers.push(cipher);
if (!isRootNode) {
this.result.folderRelationships.push([cipherIndex, folderIndex]);
}
});
this.querySelectorAllDirectChild(node, "Group").forEach((group) => {
this.traverse(group, false, groupName);
});
}
}