Skip to content

Commit 9bd95d7

Browse files
committed
moved get_public_key_for_user to bitwarden_client; fix: test when unset env var
1 parent dc9cc40 commit 9bd95d7

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/vaultwarden/clients/bitwarden.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def _api_request(
131131
return self._http_client.request(
132132
method, path, headers=headers, **kwargs
133133
)
134+
135+
def get_public_key_for_user(self, user_id: UUID | None = None) -> str:
136+
resp = self.api_request(
137+
"GET", f"api/users/{self._sync.Profile.Id if not user_id else user_id}/public-key"
138+
)
139+
return resp.json().get("publicKey")
134140

135141
def sync(self, force_refresh: bool = False) -> SyncData:
136142
if self._sync is None or force_refresh:

src/vaultwarden/models/bitwarden.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def confirm(
428428
self,
429429
new_user: OrganizationUserDetails,
430430
):
431-
rsa_public_key_new_user = b64decode(self.get_public_key_for_user(new_user.UserId))
431+
rsa_public_key_new_user = b64decode(self.api_client.get_public_key_for_user(new_user.UserId))
432432
org_key_decrypted = self.key()
433433
key = encrypt_asym(org_key_decrypted, rsa_public_key_new_user)
434434

@@ -440,13 +440,6 @@ def confirm(
440440
)
441441
self._users = self._get_users()
442442
return resp
443-
444-
def get_public_key_for_user(self, user_id: UUID | str):
445-
resp = self.api_client.api_request(
446-
"GET", f"api/users/{user_id}/public-key"
447-
)
448-
resp.raise_for_status()
449-
return resp.json().get("publicKey")
450443

451444
def _get_users(self) -> list[OrganizationUserDetails]:
452445
resp = self.api_client.api_request(

tests/e2e/test_bitwarden.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_invite_user_than_remove(self):
105105
resp = self.organization.invite("[email protected]")
106106
self.assertTrue(resp.is_success)
107107

108-
if not os.environ.get("VAULTWARDEN_INVITATIONS_ALLOWED", True).lower() in ["true", "1", "yes"]:
108+
if not os.environ.get("VAULTWARDEN_INVITATIONS_ALLOWED", "True").lower() in ["true", "1", "yes"]:
109109
user = self.organization.user_search(
110110
"[email protected]", force_refresh=True
111111
)

0 commit comments

Comments
 (0)