Skip to content

Commit 0ba6bcc

Browse files
committed
Fix unite tests
1 parent 1103a73 commit 0ba6bcc

20 files changed

Lines changed: 186 additions & 182 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import datetime
33
import os
44
import re
5-
from typing import Tuple, Optional, List, Any
5+
from typing import Tuple, Optional, List, Any, Dict
66

77
from keepersdk import crypto, utils, errors
88
from keepersdk.authentication import keeper_auth
@@ -394,7 +394,7 @@ def _get_current_salt(self, auth: keeper_auth.KeeperAuth, is_sso_user: bool):
394394
else:
395395
raise kae
396396

397-
def _handle_sso_deletion(self, kwargs: dict, auth: keeper_auth.KeeperAuth, is_sso_user: bool, current_salt) -> bool:
397+
def _handle_sso_deletion(self, kwargs: Dict, auth: keeper_auth.KeeperAuth, is_sso_user: bool, current_salt) -> bool:
398398
"""Handle SSO password deletion request."""
399399
if not kwargs.get('delete_sso'):
400400
return False

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def __init__(self):
3030
class AuditSettingMixin:
3131
LAST_USERNAME = ""
3232
LAST_ENTERPRISE_ID = 0
33-
SETTINGS = None # type: Optional[dict]
34-
EVENT_TYPES = None # type: Optional[List[Tuple[int, str]]]
33+
SETTINGS: Optional[Dict] = None
34+
EVENT_TYPES: Optional[List[Tuple[int, str]]] = None
3535

3636
@staticmethod
3737
def load_settings(auth: keeper_auth.KeeperAuth, reload: bool=False) -> Optional[Dict[str, Any]]:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
import shlex
66
import sys
7-
from typing import Optional, Any, Dict, Iterable, Tuple
7+
from typing import Optional, Any, Dict, Iterable, Tuple, Set, List
88

99
from keepersdk import errors
1010

@@ -146,15 +146,15 @@ def __init__(self, parser: argparse.ArgumentParser):
146146
def execute(self, context: KeeperParams, **kwargs):
147147
pass
148148

149-
def _get_all_option_strings(self, parser: argparse.ArgumentParser) -> set:
149+
def _get_all_option_strings(self, parser: argparse.ArgumentParser) -> Set:
150150
"""Get all valid option strings from the parser and its parents."""
151151
options = set()
152152
for action in parser._actions:
153153
for opt in action.option_strings:
154154
options.add(opt)
155155
return options
156156

157-
def _validate_strict_options(self, arg_list: list, valid_options: set) -> None:
157+
def _validate_strict_options(self, arg_list: List, valid_options: Set) -> None:
158158
"""Validate that all option-like arguments are recognized.
159159
160160
Raises ParseError if:

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

Lines changed: 15 additions & 15 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):
@@ -505,7 +505,7 @@ def _is_valid_scan_result(self, result) -> bool:
505505
"""Validate scan result structure."""
506506
return result and len(result) == 2
507507

508-
def _display_results(self, scan_results: list, echo_passwords: bool) -> None:
508+
def _display_results(self, scan_results: List, echo_passwords: bool) -> None:
509509
"""Display scan results in a formatted way."""
510510
for result in scan_results:
511511
password, scan_result = result
@@ -523,7 +523,7 @@ def _get_status_text(self, scan_result) -> str:
523523
status_code = client_pb2.BWStatus.BREACHED if is_breached else client_pb2.BWStatus.GOOD
524524
return STATUS_TO_TEXT.get(status_code, "Unknown")
525525

526-
def _cleanup_scan_data(self, breach_watch, scan_results: list) -> None:
526+
def _cleanup_scan_data(self, breach_watch, scan_results: List) -> None:
527527
"""Clean up scan data by deleting EUIDs."""
528528
euids = self._extract_euids(scan_results)
529529
if euids:
@@ -532,7 +532,7 @@ def _cleanup_scan_data(self, breach_watch, scan_results: list) -> None:
532532
except Exception as e:
533533
logger.warning(f"Failed to cleanup scan data: {e}")
534534

535-
def _extract_euids(self, scan_results: list) -> list:
535+
def _extract_euids(self, scan_results: List) -> List:
536536
"""Extract EUIDs from scan results for cleanup."""
537537
euids = []
538538
for result in scan_results:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def execute(self, context: KeeperParams, **kwargs):
137137
teams[queued_team.node_id] = []
138138
queued_teams[queued_team.node_id].append(queued_team)
139139

140-
def tree_node(node: enterprise_types.Node) -> Tuple[str, Dict[str, dict]]:
140+
def tree_node(node: enterprise_types.Node) -> Tuple[str, Dict[str, Dict]]:
141141
node_name = node.name
142142
if not node_name:
143143
node_name = enterprise_data.enterprise_info.enterprise_name

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/enterprise_team.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22
import json
3-
from typing import Dict, List, Optional, Any, Tuple
3+
from typing import Dict, List, Optional, Any, Tuple, Set
44

55
from keepersdk import utils, crypto
66
from keepersdk.enterprise import enterprise_types, batch_management, enterprise_management
@@ -573,7 +573,7 @@ def _build_user_approval_requests(
573573
def _collect_team_keys_and_users(
574574
self, queued_team_users, teams: Dict[str, Any],
575575
added_teams: Dict[str, Any], active_users: Dict[int, str]
576-
) -> Tuple[Dict[str, Any], set]:
576+
) -> Tuple[Dict[str, Any], Set]:
577577
"""Collect team UIDs that need keys loaded and all user emails."""
578578
team_keys = {}
579579
all_users = set()
@@ -595,7 +595,7 @@ def _collect_team_keys_and_users(
595595

596596
def _load_team_and_user_keys(
597597
self, vault, team_keys: Dict[str, Any],
598-
added_team_keys: Dict[str, bytes], all_users: set
598+
added_team_keys: Dict[str, bytes], all_users: Set
599599
) -> None:
600600
"""Load team keys and user public keys from the vault."""
601601
vault.keeper_auth.load_team_keys(list(team_keys.keys()))

0 commit comments

Comments
 (0)