Skip to content

Commit

Permalink
https://github.com/andgineer/bitwarden-import-msecure/issues/1
Browse files Browse the repository at this point in the history
URI not exported for login records
  • Loading branch information
andgineer committed Apr 25, 2024
1 parent e76539f commit 597f4da
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/bitwarden_import_msecure/bitwarden_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def write_record(self, data: Dict[str, Any]) -> None:
if data["type"] == "login":
item["login"] = {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": data["login_uri"],
}
],
"username": data["login_username"],
"password": data["login_password"],
"totp": None,
Expand Down
28 changes: 24 additions & 4 deletions tests/resources/bitwarden_export.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "https://www.openstreetmap.org"
}
],
"username": "andrey@sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand All @@ -46,7 +51,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "vk.com"
}
],
"username": "+1 555 555 5555",
"password": "",
"totp": null
Expand All @@ -69,7 +79,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "https://airtable.com/"
}
],
"username": "andrey@sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand Down Expand Up @@ -123,7 +138,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "hub.docker.com"
}
],
"username": "sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand Down
28 changes: 24 additions & 4 deletions tests/resources/bitwarden_notes_export.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "https://www.openstreetmap.org"
}
],
"username": "andrey@sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand All @@ -46,7 +51,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "vk.com"
}
],
"username": "+1 555 555 5555",
"password": "",
"totp": null
Expand All @@ -69,7 +79,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "https://airtable.com/"
}
],
"username": "andrey@sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand Down Expand Up @@ -123,7 +138,12 @@
"collectionIds": null,
"login": {
"fido2Credentials": [],
"uris": [],
"uris": [
{
"match": "null",
"uri": "hub.docker.com"
}
],
"username": "sorokin.engineer",
"password": "my-cool-password",
"totp": null
Expand Down
18 changes: 13 additions & 5 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from bitwarden_import_msecure.main import bitwarden_import_msecure


UPDATE_EXPECTED_OUTPUT = False # (!) Regenerate expected output files, but be sure to check the changes


def assert_files_context_is_equal(file_path1, file_path2):
"""Compare the content of two files, abstracting away platform differences in newline characters."""
with open(file_path1, 'r', newline=None, encoding='utf-8') as f1, open(file_path2, 'r', newline=None,
Expand All @@ -25,7 +28,8 @@ def test_bitwarden_import_msecure_default_output(tmpdir, msecure_export, bitward

output_file = tmpdir.join("bitwarden.json")

# bitwarden_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
if UPDATE_EXPECTED_OUTPUT:
bitwarden_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert_files_context_is_equal(output_file, bitwarden_file)


Expand All @@ -39,7 +43,8 @@ def test_bitwarden_import_msecure_note_mode_default_output(tmpdir, msecure_expor

output_file = tmpdir.join("bitwarden.json")

# bitwarden_notes_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
if UPDATE_EXPECTED_OUTPUT:
bitwarden_notes_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert_files_context_is_equal(output_file, bitwarden_notes_file)


Expand Down Expand Up @@ -70,7 +75,8 @@ def test_bitwarden_import_msecure_to_output_file(tmpdir, msecure_export, bitward
result = runner.invoke(bitwarden_import_msecure, [str(input_file), str(output_file), "--force"])
assert result.exit_code == 0

# bitwarden_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
if UPDATE_EXPECTED_OUTPUT:
bitwarden_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert_files_context_is_equal(output_file, bitwarden_file)
assert input_file.read() == msecure_export # Ensure input file remains unchanged

Expand All @@ -85,7 +91,8 @@ def test_bitwarden_import_msecure_default_csv_output(tmpdir, msecure_export, bit

output_file = tmpdir.join("bitwarden.csv")

# bitwarden_csv_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
if UPDATE_EXPECTED_OUTPUT:
bitwarden_csv_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert_files_context_is_equal(output_file, bitwarden_csv_file)


Expand All @@ -99,5 +106,6 @@ def test_bitwarden_import_msecure_note_mode_default_csv_output(tmpdir, msecure_e

output_file = tmpdir.join("bitwarden.csv")

# bitwarden_notes_csv_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
if UPDATE_EXPECTED_OUTPUT:
bitwarden_notes_csv_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert_files_context_is_equal(output_file, bitwarden_notes_csv_file)

0 comments on commit 597f4da

Please sign in to comment.