Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/vaultwarden/clients/bitwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(
timeout: int = 30,
):
# if one of the parameters is None, raise an exception
if not all(
[url, email, password, client_id, client_secret, device_id]
):
if not all([url, password, client_id, client_secret, device_id]):
raise BitwardenError("All parameters are required")
self.email = email
self.password = password
Expand Down Expand Up @@ -96,6 +94,18 @@ def _set_connect_token(self):
"identity/connect/token", headers=headers, data=payload
)
self._connect_token = ConnectToken.model_validate_json(resp.text)

if self.email is None:
headers = {
"Authorization": f"Bearer {self._connect_token.access_token}",
"content-type": "application/json; charset=utf-8",
"Accept": "*/*",
}
resp = self._http_client.get(
"api/accounts/profile", headers=headers
)
self.email = resp.json()["email"]

import vaultwarden.models.bitwarden

self._connect_token.master_key = make_master_key(
Expand Down
39 changes: 33 additions & 6 deletions tests/e2e/test_bitwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@
client_id = os.environ.get("BITWARDEN_CLIENT_ID", None)
client_secret = os.environ.get("BITWARDEN_CLIENT_SECRET", None)
device_id = os.environ.get("BITWARDEN_DEVICE_ID", None)
bitwarden = BitwardenAPIClient(
url, email, password, client_id, client_secret, device_id
)

# Get test organization id from environment variables
test_organization = os.environ.get("BITWARDEN_TEST_ORGANIZATION", None)

client_with_mail = BitwardenAPIClient(
url,
email,
password,
client_id,
client_secret,
device_id,
)

client_without_mail = BitwardenAPIClient(
url,
None,
password,
client_id,
client_secret,
device_id,
)


class BitwardenBasic(unittest.TestCase):
def setUp(self) -> None:
self.organization = get_organization(bitwarden, test_organization)
class BitwardenBaseTests:
def setup_base(self):
self.organization = get_organization(self.bitwarden, test_organization)
self.test_colls_names = self.organization.collections(as_dict=True)
self.test_colls_ids = self.organization.collections()
self.test_users = self.organization.users()
Expand Down Expand Up @@ -128,5 +143,17 @@ def test_deduplicate(self):
return


class BitwardenWithEmailTests(unittest.TestCase, BitwardenBaseTests):
def setUp(self):
self.bitwarden = client_with_mail
self.setup_base()


class BitwardenWithoutEmailTests(unittest.TestCase, BitwardenBaseTests):
def setUp(self):
self.bitwarden = client_without_mail
self.setup_base()


if __name__ == "__main__":
unittest.main()
Loading