diff --git a/libs/common/spec/importers/keepass2-xml-importer-testdata.ts b/libs/common/spec/importers/keepass2-xml-importer-testdata.ts
new file mode 100644
index 0000000000..e06ca2cf65
--- /dev/null
+++ b/libs/common/spec/importers/keepass2-xml-importer-testdata.ts
@@ -0,0 +1,533 @@
+export const TestData = `
+
+
+ KeePass
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+ 365
+
+ 2016-12-31T21:33:59Z
+ -1
+ -1
+
+ False
+ False
+ True
+ False
+ False
+
+ True
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ 10
+ 6291456
+ AAAAAAAAAAAAAAAAAAAAAA==
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+
+
+
+
+ KvS57lVwl13AfGFLwkvq4Q==
+ Root
+
+ 48
+
+ 2016-12-31T21:33:52Z
+ 2016-12-31T21:33:52Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:33:52Z
+ False
+ 1
+ 2016-12-31T21:33:52Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ P0ParXgGMBW6caOL2YrhqQ==
+ Folder2
+ a note about the folder
+ 48
+
+ 2016-12-31T21:43:30Z
+ 2016-12-31T21:43:43Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:43:30Z
+ False
+ 1
+ 2016-12-31T21:43:43Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ fAa543oYlgnJKkhKag5HLw==
+ 1
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:43:48Z
+
+
+ att2
+ att2value
+
+
+ attr1
+ att1value
+
+line1
+line2
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+ fAa543oYlgnJKkhKag5HLw==
+ 0
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:34:40Z
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+
+
+
+
+
+`;
+export const TestData1 = `
+
+
+ KeePass
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+ 365
+
+ 2016-12-31T21:33:59Z
+ -1
+ -1
+
+ False
+ False
+ True
+ False
+ False
+
+ True
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ 10
+ 6291456
+ AAAAAAAAAAAAAAAAAAAAAA==
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+
+
+
+ KvS57lVwl13AfGFLwkvq4Q==
+ Root
+
+ 48
+
+ 2016-12-31T21:33:52Z
+ 2016-12-31T21:33:52Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:33:52Z
+ False
+ 1
+ 2016-12-31T21:33:52Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ P0ParXgGMBW6caOL2YrhqQ==
+ Folder2
+ a note about the folder
+ 48
+
+ 2016-12-31T21:43:30Z
+ 2016-12-31T21:43:43Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:43:30Z
+ False
+ 1
+ 2016-12-31T21:43:43Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ fAa543oYlgnJKkhKag5HLw==
+ 1
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:43:48Z
+
+
+ att2
+ att2value
+
+
+ attr1
+ att1value
+
+line1
+line2
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+ fAa543oYlgnJKkhKag5HLw==
+ 0
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:34:40Z
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+
+
+
+
+`;
+export const TestData2 = `
+
+ KeePass
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+
+ 2016-12-31T21:33:52Z
+ 365
+
+ 2016-12-31T21:33:59Z
+ -1
+ -1
+
+ False
+ False
+ True
+ False
+ False
+
+ True
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ AAAAAAAAAAAAAAAAAAAAAA==
+ 2016-12-31T21:33:52Z
+ 10
+ 6291456
+ AAAAAAAAAAAAAAAAAAAAAA==
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+
+
+
+
+ KvS57lVwl13AfGFLwkvq4Q==
+ Root
+
+ 48
+
+ 2016-12-31T21:33:52Z
+ 2016-12-31T21:33:52Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:33:52Z
+ False
+ 1
+ 2016-12-31T21:33:52Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ P0ParXgGMBW6caOL2YrhqQ==
+ Folder2
+ a note about the folder
+ 48
+
+ 2016-12-31T21:43:30Z
+ 2016-12-31T21:43:43Z
+ 2017-01-01T22:58:00Z
+ 2016-12-31T21:43:30Z
+ False
+ 1
+ 2016-12-31T21:43:43Z
+
+ True
+
+ null
+ null
+ AAAAAAAAAAAAAAAAAAAAAA==
+
+ fAa543oYlgnJKkhKag5HLw==
+ 1
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:40:23Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:43:48Z
+
+
+ att2
+ att2value
+
+
+ attr1
+ att1value
+
+line1
+line2
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+ fAa543oYlgnJKkhKag5HLw==
+ 0
+
+
+
+
+
+ 2016-12-31T21:34:13Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:40Z
+ 2016-12-31T21:34:13Z
+ False
+ 0
+ 2016-12-31T21:34:40Z
+
+
+ Notes
+ This is a note!!!
+
+line1
+line2
+
+
+ Password
+ googpass
+
+
+ Title
+ Google
+
+
+ URL
+ google.com
+
+
+ UserName
+ googleuser
+
+
+ True
+ 0
+
+
+
+
+
+
+
+ `;
diff --git a/libs/common/spec/importers/keepass2-xml-importer.spec.ts b/libs/common/spec/importers/keepass2-xml-importer.spec.ts
index e6f22ed850..285a1563ba 100644
--- a/libs/common/spec/importers/keepass2-xml-importer.spec.ts
+++ b/libs/common/spec/importers/keepass2-xml-importer.spec.ts
@@ -1,184 +1,7 @@
import { KeePass2XmlImporter as Importer } from "@bitwarden/common/importers/keepass2-xml-importer";
+import { FolderView } from "@bitwarden/common/models/view/folder.view";
-const TestData = `
-
-
- KeePass
-
- 2016-12-31T21:33:52Z
-
- 2016-12-31T21:33:52Z
-
- 2016-12-31T21:33:52Z
- 365
-
- 2016-12-31T21:33:59Z
- -1
- -1
-
- False
- False
- True
- False
- False
-
- True
- AAAAAAAAAAAAAAAAAAAAAA==
- 2016-12-31T21:33:52Z
- AAAAAAAAAAAAAAAAAAAAAA==
- 2016-12-31T21:33:52Z
- 10
- 6291456
- AAAAAAAAAAAAAAAAAAAAAA==
- AAAAAAAAAAAAAAAAAAAAAA==
-
-
-
-
-
- KvS57lVwl13AfGFLwkvq4Q==
- Root
-
- 48
-
- 2016-12-31T21:33:52Z
- 2016-12-31T21:33:52Z
- 2017-01-01T22:58:00Z
- 2016-12-31T21:33:52Z
- False
- 1
- 2016-12-31T21:33:52Z
-
- True
-
- null
- null
- AAAAAAAAAAAAAAAAAAAAAA==
-
- P0ParXgGMBW6caOL2YrhqQ==
- Folder2
- a note about the folder
- 48
-
- 2016-12-31T21:43:30Z
- 2016-12-31T21:43:43Z
- 2017-01-01T22:58:00Z
- 2016-12-31T21:43:30Z
- False
- 1
- 2016-12-31T21:43:43Z
-
- True
-
- null
- null
- AAAAAAAAAAAAAAAAAAAAAA==
-
- fAa543oYlgnJKkhKag5HLw==
- 1
-
-
-
-
-
- 2016-12-31T21:34:13Z
- 2016-12-31T21:40:23Z
- 2016-12-31T21:40:23Z
- 2016-12-31T21:34:13Z
- False
- 0
- 2016-12-31T21:43:48Z
-
-
- att2
- att2value
-
-
- attr1
- att1value
-
-line1
-line2
-
-
- Notes
- This is a note!!!
-
-line1
-line2
-
-
- Password
- googpass
-
-
- Title
- Google
-
-
- URL
- google.com
-
-
- UserName
- googleuser
-
-
- True
- 0
-
-
-
- fAa543oYlgnJKkhKag5HLw==
- 0
-
-
-
-
-
- 2016-12-31T21:34:13Z
- 2016-12-31T21:34:40Z
- 2016-12-31T21:34:40Z
- 2016-12-31T21:34:13Z
- False
- 0
- 2016-12-31T21:34:40Z
-
-
- Notes
- This is a note!!!
-
-line1
-line2
-
-
- Password
- googpass
-
-
- Title
- Google
-
-
- URL
- google.com
-
-
- UserName
- googleuser
-
-
- True
- 0
-
-
-
-
-
-
-
-
-`;
+import { TestData, TestData1, TestData2 } from "./keepass2-xml-importer-testdata";
describe("KeePass2 Xml Importer", () => {
it("should parse XML data", async () => {
@@ -186,4 +9,34 @@ describe("KeePass2 Xml Importer", () => {
const result = await importer.parse(TestData);
expect(result != null).toBe(true);
});
+
+ it("parse XML should contains folders", async () => {
+ const importer = new Importer();
+ const folder = new FolderView();
+ folder.name = "Folder2";
+ const actual = [folder];
+
+ const result = await importer.parse(TestData);
+ expect(result.folders).toEqual(actual);
+ });
+
+ it("parse XML should contains login details", async () => {
+ const importer = new Importer();
+ const result = await importer.parse(TestData);
+ expect(result.ciphers[0].login.uri != null).toBe(true);
+ expect(result.ciphers[0].login.username != null).toBe(true);
+ expect(result.ciphers[0].login.password != null).toBe(true);
+ });
+
+ it("should return error with missing root tag", async () => {
+ const importer = new Importer();
+ const result = await importer.parse(TestData1);
+ expect(result.errorMessage).toBe("Missing `KeePassFile > Root` node.");
+ });
+
+ it("should return error with missing KeePassFile tag", async () => {
+ const importer = new Importer();
+ const result = await importer.parse(TestData2);
+ expect(result.success).toBe(false);
+ });
});
diff --git a/libs/common/src/importers/keepass2-xml-importer.ts b/libs/common/src/importers/keepass2-xml-importer.ts
index 2da304a3ba..2bb169c4d1 100644
--- a/libs/common/src/importers/keepass2-xml-importer.ts
+++ b/libs/common/src/importers/keepass2-xml-importer.ts
@@ -15,7 +15,23 @@ export class KeePass2XmlImporter extends BaseImporter implements Importer {
return Promise.resolve(this.result);
}
- const rootGroup = doc.querySelector("KeePassFile > Root > Group");
+ //Note: The doc.querySelector("KeePassFile > Root > Group") no longers works on node and we have to breakdown the query by nodes
+ const KeePassFileNode = doc.querySelector("KeePassFile");
+
+ if (KeePassFileNode == null) {
+ this.result.errorMessage = "Missing `KeePassFile` node.";
+ this.result.success = false;
+ return Promise.resolve(this.result);
+ }
+
+ const RootNode = KeePassFileNode.querySelector("Root");
+ if (RootNode == null) {
+ this.result.errorMessage = "Missing `KeePassFile > Root` node.";
+ this.result.success = false;
+ return Promise.resolve(this.result);
+ }
+
+ const rootGroup = RootNode.querySelector("Group");
if (rootGroup == null) {
this.result.errorMessage = "Missing `KeePassFile > Root > Group` node.";
this.result.success = false;