Skip to content

Commit 0d41102

Browse files
committed
Fix unit tests
1 parent 1103a73 commit 0d41102

11 files changed

Lines changed: 88 additions & 84 deletions

File tree

keepercli-package/src/keepercli/commands/breachwatch.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import base64
33
import getpass
44
import json
5-
from typing import Any, List, Optional, Set
5+
from typing import Any, List, Optional, Set, Dict
66

77
from keepersdk.enterprise import breachwatch_report
88
from keepersdk.proto import breachwatch_pb2, client_pb2
@@ -16,7 +16,7 @@
1616

1717
logger = api.get_logger()
1818

19-
STATUS_TO_TEXT: dict[int, str] = {
19+
STATUS_TO_TEXT: Dict[int, str] = {
2020
client_pb2.BWStatus.GOOD: "GOOD",
2121
client_pb2.BWStatus.WEAK: "WEAK",
2222
client_pb2.BWStatus.BREACHED: "BREACHED"
@@ -176,7 +176,7 @@ def execute(self, context: KeeperParams, **kwargs) -> Any:
176176
else:
177177
logger.info("No breach watch requests to process")
178178

179-
def _get_record_names(self, kwargs: dict) -> list[str]:
179+
def _get_record_names(self, kwargs: dict) -> List[str]:
180180
"""Extract record names from kwargs."""
181181
records = kwargs.get('records')
182182
if not records:
@@ -187,14 +187,14 @@ def _get_record_names(self, kwargs: dict) -> list[str]:
187187

188188
return records
189189

190-
def _resolve_record_uids(self, record_names: list[str], context: KeeperParams) -> Set[str]:
190+
def _resolve_record_uids(self, record_names: List[str], context: KeeperParams) -> Set[str]:
191191
"""Resolve record names to UIDs using the context."""
192192
record_uids: Set[str] = set()
193193
for record_name in record_names:
194194
record_uids.update(record_utils.resolve_records(record_name, context))
195195
return record_uids
196196

197-
def _get_breached_records(self, vault: vault_online.VaultOnline) -> dict[str, str]:
197+
def _get_breached_records(self, vault: vault_online.VaultOnline) -> Dict[str, str]:
198198
"""Get breached records and their passwords."""
199199
record_passwords = {}
200200

@@ -219,7 +219,7 @@ def _extract_record_password(self, vault: vault_online.VaultOnline, record_uid:
219219

220220
return None
221221

222-
def _create_breach_watch_requests(self, vault: vault_online.VaultOnline, record_passwords: dict[str, str], record_uids: Set[str]) -> list[breachwatch_pb2.BreachWatchRecordRequest]:
222+
def _create_breach_watch_requests(self, vault: vault_online.VaultOnline, record_passwords: Dict[str, str], record_uids: Set[str]) -> List[breachwatch_pb2.BreachWatchRecordRequest]:
223223
"""Create breach watch record requests for the given records."""
224224
bw_requests = []
225225

@@ -296,7 +296,7 @@ def _get_existing_breach_watch_euid(self, vault: vault_online.VaultOnline, recor
296296

297297
return None
298298

299-
def _process_breach_watch_requests(self, vault: vault_online.VaultOnline, bw_requests: list[breachwatch_pb2.BreachWatchRecordRequest]) -> None:
299+
def _process_breach_watch_requests(self, vault: vault_online.VaultOnline, bw_requests: List[breachwatch_pb2.BreachWatchRecordRequest]) -> None:
300300
"""Process the breach watch requests."""
301301
# Queue audit event
302302
self._queue_audit_event(vault)
@@ -309,7 +309,7 @@ def _queue_audit_event(self, vault: vault_online.VaultOnline) -> None:
309309
if audit_plugin:
310310
audit_plugin.schedule_audit_event('bw_record_ignored')
311311

312-
def _send_breach_watch_requests(self, vault: vault_online.VaultOnline, bw_requests: list[breachwatch_pb2.BreachWatchRecordRequest]) -> None:
312+
def _send_breach_watch_requests(self, vault: vault_online.VaultOnline, bw_requests: List[breachwatch_pb2.BreachWatchRecordRequest]) -> None:
313313
"""Send breach watch requests in chunks."""
314314
while bw_requests:
315315
chunk = bw_requests[0:999]
@@ -321,7 +321,7 @@ def _send_breach_watch_requests(self, vault: vault_online.VaultOnline, bw_reques
321321
except Exception as e:
322322
logger.error(f'Error sending breach watch chunk: {e}')
323323

324-
def _send_breach_watch_chunk(self, vault: vault_online.VaultOnline, chunk: list[breachwatch_pb2.BreachWatchRecordRequest]) -> breachwatch_pb2.BreachWatchUpdateResponse:
324+
def _send_breach_watch_chunk(self, vault: vault_online.VaultOnline, chunk: List[breachwatch_pb2.BreachWatchRecordRequest]) -> breachwatch_pb2.BreachWatchUpdateResponse:
325325
"""Send a chunk of breach watch requests."""
326326
rq = breachwatch_pb2.BreachWatchUpdateRequest()
327327
rq.breachWatchRecordRequest.extend(chunk)
@@ -368,7 +368,7 @@ def _validate_context(self, context: KeeperParams) -> None:
368368
if not context.auth.auth_context.license.get('breachWatchEnabled'):
369369
raise ValueError("Breach watch is not enabled. Please contact your administrator to enable this feature.")
370370

371-
def _get_and_validate_record_uids(self, kwargs: dict) -> list[str]:
371+
def _get_and_validate_record_uids(self, kwargs: Dict) -> List[str]:
372372
"""Extract and validate record UIDs from kwargs."""
373373
record_uids = kwargs.get('records')
374374
if not record_uids:
@@ -479,7 +479,7 @@ def _is_vault_ready(self, context: KeeperParams) -> bool:
479479
raise base.CommandError('Breach watch is not enabled. Please contact your administrator to enable this feature.')
480480
return True
481481

482-
def _get_passwords_to_scan(self, kwargs: dict) -> list[str]:
482+
def _get_passwords_to_scan(self, kwargs: dict) -> List[str]:
483483
"""Get passwords from command line arguments or prompt user."""
484484
passwords = kwargs.get('passwords', [])
485485
if passwords:
@@ -493,7 +493,7 @@ def _get_passwords_to_scan(self, kwargs: dict) -> list[str]:
493493
logger.info('')
494494
return []
495495

496-
def _scan_passwords(self, breach_watch, passwords: list[str]) -> list:
496+
def _scan_passwords(self, breach_watch, passwords: List[str]) -> list:
497497
"""Scan passwords and return results with EUIDs for cleanup."""
498498
scan_results = []
499499
for result in breach_watch.scan_passwords(passwords):

keepercli-package/src/keepercli/commands/enterprise_push.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import copy
55
import re
6-
from typing import Any
6+
from typing import Any, List, Set, Dict, Optional
77

88
from . import base
99
from .. import api
@@ -100,7 +100,7 @@ def load_template_records_from_file(file_path: str) -> list:
100100
TRANSFER_RECORD_SUCCESS = "transfer_record_success"
101101

102102

103-
def _substitute_value(value: str, values: dict[str, str]) -> str:
103+
def _substitute_value(value: str, values: Dict[str, str]) -> str:
104104
"""Replace all ${key} placeholders in a string with values from the given dict."""
105105
result = value
106106
while True:
@@ -113,7 +113,7 @@ def _substitute_value(value: str, values: dict[str, str]) -> str:
113113
return result
114114

115115

116-
def _substitute_in_dict(container: dict, values: dict[str, str]) -> None:
116+
def _substitute_in_dict(container: Dict, values: Dict[str, str]) -> None:
117117
"""Recursively substitute placeholders in dict (and nested dicts/lists) in place."""
118118
for key, val in list(container.items()):
119119
if isinstance(val, str):
@@ -126,7 +126,7 @@ def _substitute_in_dict(container: dict, values: dict[str, str]) -> None:
126126
container[key] = _substitute_in_list(val, values)
127127

128128

129-
def _substitute_in_list(container: list, values: dict[str, str]) -> list:
129+
def _substitute_in_list(container: list, values: Dict[str, str]) -> List:
130130
"""Return a new list with placeholders substituted."""
131131
result = []
132132
for item in container:
@@ -142,7 +142,7 @@ def _substitute_in_list(container: list, values: dict[str, str]) -> list:
142142
return result
143143

144144

145-
def _get_substitution_values(enterprise: enterprise_types.IEnterpriseData, email: str) -> dict[str, str]:
145+
def _get_substitution_values(enterprise: enterprise_types.IEnterpriseData, email: str) -> Dict[str, str]:
146146
"""Build substitution map for a user: user_email, user_name, generate_password."""
147147
values = {
148148
"user_email": email,
@@ -156,14 +156,14 @@ def _get_substitution_values(enterprise: enterprise_types.IEnterpriseData, email
156156

157157

158158
def _substitute_record_params(
159-
enterprise: enterprise_types.IEnterpriseData, email: str, record_data: dict
159+
enterprise: enterprise_types.IEnterpriseData, email: str, record_data: Dict
160160
) -> None:
161161
"""Fill template parameters in record_data for the given user (in place)."""
162162
values = _get_substitution_values(enterprise, email)
163163
_substitute_in_dict(record_data, values)
164164

165165

166-
def _resolve_user_to_email(enterprise: enterprise_types.IEnterpriseData, user_id: str) -> str | None:
166+
def _resolve_user_to_email(enterprise: enterprise_types.IEnterpriseData, user_id: str) -> Optional[str]:
167167
"""Resolve user identifier (email, name, or enterprise_user_id) to username (email)."""
168168
user_id_lower = user_id.lower()
169169
for u in enterprise.users.get_all_entities():
@@ -176,7 +176,7 @@ def _resolve_user_to_email(enterprise: enterprise_types.IEnterpriseData, user_id
176176
return None
177177

178178

179-
def _resolve_team_to_uid(enterprise: enterprise_types.IEnterpriseData, team_id: str) -> str | None:
179+
def _resolve_team_to_uid(enterprise: enterprise_types.IEnterpriseData, team_id: str) -> Optional[str]:
180180
"""Resolve team identifier (name or team_uid) to team_uid."""
181181
for t in enterprise.teams.get_all_entities() or []:
182182
if team_id == t.team_uid or team_id.lower() == t.name.lower():
@@ -187,9 +187,9 @@ def _resolve_team_to_uid(enterprise: enterprise_types.IEnterpriseData, team_id:
187187
def _collect_recipient_emails(
188188
enterprise: enterprise_types.IEnterpriseData,
189189
current_username: str,
190-
user_ids: list[str],
191-
team_ids: list[str],
192-
) -> set[str]:
190+
user_ids: List[str],
191+
team_ids: List[str],
192+
) -> Set[str]:
193193
"""Resolve user_ids and team_ids to a set of recipient emails. Excludes current user."""
194194
emails = set()
195195

@@ -231,8 +231,8 @@ def _collect_recipient_emails(
231231
def _build_typed_records_for_user(
232232
enterprise: enterprise_types.IEnterpriseData,
233233
email: str,
234-
record_data: list[dict[str, Any]],
235-
) -> list[TypedRecord]:
234+
record_data: List[Dict[str, Any]],
235+
) -> List[TypedRecord]:
236236
"""Substitute template params and convert JSON templates to typed records."""
237237
user_records = []
238238
for template in record_data:
@@ -247,10 +247,10 @@ def _build_typed_records_for_user(
247247
def _build_records_add_request(
248248
auth: keeper_auth.KeeperAuth,
249249
vault: vault_online.VaultOnline,
250-
typed_records: list[TypedRecord],
250+
typed_records: List[TypedRecord],
251251
user_ec_key: Any,
252252
user_rsa_key: Any,
253-
record_keys_out: dict[str, bytes],
253+
record_keys_out: Dict[str, bytes],
254254
) -> record_pb2.RecordsAddRequest:
255255
"""Build RecordsAddRequest and fill record_keys_out with uid -> encrypted_key for transfer."""
256256
rq = record_pb2.RecordsAddRequest()
@@ -303,7 +303,7 @@ def _add_transfer_and_cleanup(
303303
auth: keeper_auth.KeeperAuth,
304304
email: str,
305305
add_request: record_pb2.RecordsAddRequest,
306-
record_keys_for_user: dict[str, Any],
306+
record_keys_for_user: Dict[str, Any],
307307
) -> None:
308308
"""Execute records_add, transfer ownership to user, then unlink from admin (pre_delete + delete)."""
309309
rs = auth.execute_auth_rest(
@@ -378,7 +378,7 @@ def _process_one_recipient(
378378
auth: keeper_auth.KeeperAuth,
379379
vault: vault_online.VaultOnline,
380380
email: str,
381-
record_data: list[dict[str, Any]],
381+
record_data: List[Dict[str, Any]],
382382
) -> None:
383383
"""Load user key, build records, add to vault, transfer ownership to user."""
384384
user_key = auth.get_user_keys(email)
@@ -428,9 +428,9 @@ def push_enterprise_records(
428428
enterprise: enterprise_types.IEnterpriseData,
429429
auth: keeper_auth.KeeperAuth,
430430
vault: vault_online.VaultOnline,
431-
user_ids: list[str],
432-
team_ids: list[str],
433-
record_data: list[dict[str, Any]],
431+
user_ids: List[str],
432+
team_ids: List[str],
433+
record_data: List[Dict[str, Any]],
434434
) -> None:
435435
"""Resolve recipients, then for each user substitute template params and add/transfer records."""
436436
emails = list(

keepercli-package/src/keepercli/commands/record_type_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from typing import List
23

34
from .. import api
45

@@ -99,7 +100,7 @@ def get_record_type_example(vault: vault_online.VaultOnline, record_type_name: s
99100
raise ValueError(f'No record type found with name {record_type_name}. Use "record-type-info" to list all record types')
100101

101102

102-
def get_record_types(vault:vault_online.VaultOnline) -> list[vault_types.RecordType]:
103+
def get_record_types(vault:vault_online.VaultOnline) -> List[vault_types.RecordType]:
103104
records = [] # (recordTypeId, name, scope)
104105
record_types = vault.vault_data.get_record_types()
105106

keepercli-package/src/keepercli/commands/secrets_manager.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
from enum import Enum
33
import time
4-
from typing import Optional
4+
from typing import Optional, List, Set, Tuple
55

66
from keepersdk import utils
77
from keepersdk.proto.enterprise_pb2 import GENERAL
@@ -454,7 +454,7 @@ def _confirm_remove_all_clients(clients_count: int) -> bool:
454454
return user_choice.lower() == USER_CHOICE_YES
455455

456456
@staticmethod
457-
def remove_client(vault: vault_online.VaultOnline, uid: str, client_names_and_ids: list[str], force: bool = False):
457+
def remove_client(vault: vault_online.VaultOnline, uid: str, client_names_and_ids: List[str], force: bool = False):
458458
"""Remove client devices from a KSM application."""
459459
ksm_management.KSMClientManagement.remove_clients_from_ksm_app(
460460
vault=vault,
@@ -539,7 +539,7 @@ def _get_app_uid_from_kwargs(self, vault, app_uid_or_name: Optional[str]) -> str
539539

540540
return ksm_app.record_uid
541541

542-
def _parse_secret_uids(self, secret_uids_str: Optional[str]) -> list[str]:
542+
def _parse_secret_uids(self, secret_uids_str: Optional[str]) -> List[str]:
543543
"""Parse secret UIDs from string."""
544544
if not secret_uids_str:
545545
return []
@@ -552,7 +552,7 @@ def _find_ksm_application(self, vault: vault_online.VaultOnline, app_uid_or_name
552552
None
553553
)
554554

555-
def _handle_add_share(self, context: KeeperParams, app_uid: str, secret_uids: list[str], is_editable: bool) -> None:
555+
def _handle_add_share(self, context: KeeperParams, app_uid: str, secret_uids: List[str], is_editable: bool) -> None:
556556
"""Handle adding shares to a KSM application."""
557557
if not context.vault:
558558
raise ValueError("Vault is not initialized.")
@@ -600,7 +600,7 @@ def _handle_share_error(kae: base.errors.KeeperApiError) -> bool:
600600
raise ValueError(f"Failed to share secrets: {kae}")
601601

602602
@staticmethod
603-
def remove_share(vault: vault_online.VaultOnline, app_uid: str, secret_uids: list[str]) -> None:
603+
def remove_share(vault: vault_online.VaultOnline, app_uid: str, secret_uids: List[str]) -> None:
604604
"""Remove shares from a KSM application."""
605605
if not secret_uids:
606606
logger.warning("No secret UIDs provided for removal.")
@@ -623,7 +623,7 @@ def remove_share(vault: vault_online.VaultOnline, app_uid: str, secret_uids: lis
623623
logger.info("Shared secrets were successfully removed from the application\n")
624624

625625
@staticmethod
626-
def _get_current_shared_uids(vault: vault_online.VaultOnline, app_uid: str) -> set:
626+
def _get_current_shared_uids(vault: vault_online.VaultOnline, app_uid: str) -> Set:
627627
"""Get currently shared UIDs for the application."""
628628
app_infos = ksm_management.get_app_info(vault=vault, app_uid=app_uid)
629629
if not app_infos:
@@ -636,14 +636,14 @@ def _get_current_shared_uids(vault: vault_online.VaultOnline, app_uid: str) -> s
636636
}
637637

638638
@staticmethod
639-
def _validate_share_uids(secret_uids: list[str], current_shared_uids: set) -> tuple[list, list]:
639+
def _validate_share_uids(secret_uids: List[str], current_shared_uids: Set) -> Tuple[List, List]:
640640
"""Validate secret UIDs against currently shared UIDs."""
641641
valid_uids = [uid for uid in secret_uids if uid in current_shared_uids]
642642
invalid_uids = [uid for uid in secret_uids if uid not in current_shared_uids]
643643
return valid_uids, invalid_uids
644644

645645
@staticmethod
646-
def _log_invalid_uids(invalid_uids: list[str]) -> None:
646+
def _log_invalid_uids(invalid_uids: List[str]) -> None:
647647
"""Log warnings for invalid UIDs."""
648648
for uid in invalid_uids:
649649
logger.warning(f"Secret UID '{uid}' is not shared with this application. Skipping.")

keepercli-package/src/keepercli/commands/shares.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import math
44
import re
55
from enum import Enum
6-
from typing import Optional
6+
from typing import Optional, List, Set
77

88
from keepersdk import utils
99
from keepersdk.authentication import keeper_auth
@@ -132,7 +132,7 @@ def execute(self, context: KeeperParams, **kwargs) -> None:
132132
if not context.vault:
133133
raise ValueError("Vault is not initialized.")
134134
vault = context.vault
135-
135+
136136
uid_or_name = kwargs.get('record')
137137
if not uid_or_name:
138138
return self.get_parser().print_help()
@@ -154,7 +154,7 @@ def execute(self, context: KeeperParams, **kwargs) -> None:
154154
share_expiration = share_management_utils.get_share_expiration(
155155
kwargs.get('expire_at'), kwargs.get('expire_in')
156156
)
157-
157+
158158
request = RecordShares.prep_request(
159159
vault=vault,
160160
enterprise=context.enterprise_data,
@@ -403,7 +403,7 @@ def _get_share_admin_obj_uids(self, vault: vault_online.VaultOnline,
403403
except (ValueError, AttributeError) as e:
404404
raise ValueError(f'get_share_admin: msg = {e}') from e
405405

406-
def _get_record_uids(self, vault: vault_online.VaultOnline, name: str) -> set[str]:
406+
def _get_record_uids(self, vault: vault_online.VaultOnline, name: str) -> Set[str]:
407407
"""Get record UIDs by name or UID."""
408408
record_uids = set()
409409
if not vault or not vault.vault_data:
@@ -1042,7 +1042,7 @@ def _find_client_id(self, applications, share_name: str) -> Optional[bytes]:
10421042

10431043
return self._resolve_partial_matches(partial_matches, share_name)
10441044

1045-
def _resolve_partial_matches(self, partial_matches: list[bytes], original_name: str) -> Optional[bytes]:
1045+
def _resolve_partial_matches(self, partial_matches: List[bytes], original_name: str) -> Optional[bytes]:
10461046
"""
10471047
Resolve partial matches to a single client ID.
10481048

0 commit comments

Comments
 (0)