Skip to content

Commit

Permalink
(KC-687) security-audit-report fix: username and email resolution b…
Browse files Browse the repository at this point in the history
…ug w/in multiple MSP/MC contexts
  • Loading branch information
aaunario-keeper authored and sk-keeper committed Oct 18, 2023
1 parent 1f50493 commit db559b4
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions keepercommander/commands/security_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(self):
class SecurityAuditReportCommand(EnterpriseCommand):
def __init__(self):
super(SecurityAuditReportCommand, self).__init__()
self.tree_key = None
self.user_lookup = None
self.enterprise_private_rsa_key = None
self.score_data_keys = (
Expand All @@ -118,26 +119,23 @@ def get_strong_by_total(self, total, strong):
return 0 if (total == 0) else (strong / total)

def resolve_user_info(self, params, enterprise_user_id):
if self.user_lookup is None:
if self.user_lookup is None or params.enterprise.get('unencrypted_tree_key') != self.tree_key:
self.tree_key = params.enterprise.get('unencrypted_tree_key')
self.user_lookup = {}
if params.enterprise:
if 'users' in params.enterprise:
for user in params.enterprise['users']:
if 'enterprise_user_id' in user and 'username' in user:
email = user['username']
username = user['data']['displayname'] if 'data' in user and 'displayname' in user[
'data'] else None
if (
username is None or not username.strip()) and 'encrypted_data' in user and 'key_type' in user:
username = user['encrypted_data'] if user['key_type'] == 'no_key' else None
username = email if username is None or not username.strip() else username
node_id = user.get('node_id', 0)
self.user_lookup[user['enterprise_user_id']] = \
{
'username': username,
'email': email,
'node_id': node_id
}
for user in params.enterprise.get('users'):
if 'enterprise_user_id' in user and 'username' in user:
email = user['username']
username = user['data']['displayname'] if 'data' in user and 'displayname' in user['data'] \
else None
if (username is None or not username.strip()) and 'encrypted_data' in user and 'key_type' in user:
username = user['encrypted_data'] if user['key_type'] == 'no_key' else None
username = email if username is None or not username.strip() else username
node_id = user.get('node_id', 0)
self.user_lookup[user['enterprise_user_id']] = {
'username': username,
'email': email,
'node_id': node_id
}

info = {
'username': enterprise_user_id,
Expand Down

0 comments on commit db559b4

Please sign in to comment.