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
13 changes: 9 additions & 4 deletions keepercommander/commands/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ def register_command_info(aliases, command_info):
SUPPORTED_TEAM_COLUMNS = ['restricts', 'node', 'user_count', 'users', 'queued_user_count', 'queued_users', 'role_count', 'roles']
SUPPORTED_ROLE_COLUMNS = ['visible_below', 'default_role', 'admin', 'node', 'user_count', 'users', 'team_count', 'teams',
'enforcement_count', 'enforcements', 'managed_node_count', 'managed_nodes', 'managed_nodes_permissions']
# Always present in the output row/header, regardless of --columns; not selectable so excluded from validation.
BASE_NODE_COLUMNS = {'node_id', 'name'}
BASE_USER_COLUMNS = {'user_id', 'email'}
BASE_TEAM_COLUMNS = {'team_uid', 'name'}
BASE_ROLE_COLUMNS = {'role_id', 'name'}

enterprise_data_parser = argparse.ArgumentParser(prog='enterprise-down',
description='Download & decrypt enterprise data.')
Expand Down Expand Up @@ -658,7 +663,7 @@ def tree_node(node):
if len(columns) == 0:
columns.update(('parent_node', 'parent_id', 'user_count', 'team_count', 'role_count'))
else:
wc = columns.difference(supported_columns)
wc = columns.difference(supported_columns, BASE_NODE_COLUMNS)
if len(wc) > 0:
logging.warning('\n\nSupported node columns: %s\n', ', '.join(supported_columns))

Expand Down Expand Up @@ -763,7 +768,7 @@ def tree_node(node):
if len(columns) == 0:
columns.update(('name', 'status', 'transfer_status', 'node'))
else:
wc = columns.difference(supported_columns)
wc = columns.difference(supported_columns, BASE_USER_COLUMNS)
if len(wc) > 0:
logging.warning('\n\nSupported user columns: %s\n', ', '.join(supported_columns))

Expand Down Expand Up @@ -875,7 +880,7 @@ def tree_node(node):
if len(params.enterprise['queued_team_users']) > 0:
columns.update(('queued_user_count',))
else:
wc = columns.difference(supported_columns)
wc = columns.difference(supported_columns, BASE_TEAM_COLUMNS)
if len(wc) > 0:
logging.warning('\n\nSupported team columns: %s\n', ', '.join(supported_columns))

Expand Down Expand Up @@ -939,7 +944,7 @@ def tree_node(node):
if len(columns) == 0:
columns.update(('default_role', 'admin', 'node', 'user_count'))
else:
wc = columns.difference(supported_columns)
wc = columns.difference(supported_columns, BASE_ROLE_COLUMNS)
if len(wc) > 0:
logging.warning('\n\nSupported role columns: %s\n', ', '.join(supported_columns))

Expand Down
37 changes: 37 additions & 0 deletions unit-tests/test_command_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,43 @@ def test_enterprise_info_users_verbose_returns_ids(self):
'role_name': ent_env.role1_name,
}])

def test_enterprise_info_columns_base_fields_no_warning(self):
"""Base fields that are always present in the row (user_id/email, team_uid, node_id, role_id, and
name for teams/nodes/roles) should not trigger the "Supported X columns" warning."""
params = get_connected_params()
api.query_enterprise(params)
cmd = enterprise.EnterpriseInfoCommand()

with mock.patch('logging.warning') as warn:
cmd.execute(params, users=True, format='json', columns='user_id,email,name', quiet=True)
warn.assert_not_called()

with mock.patch('logging.warning') as warn:
cmd.execute(params, teams=True, format='json', columns='team_uid,name,users', quiet=True)
warn.assert_not_called()

with mock.patch('logging.warning') as warn:
cmd.execute(params, nodes=True, format='json', columns='node_id,name,users', quiet=True)
warn.assert_not_called()

with mock.patch('logging.warning') as warn:
cmd.execute(params, roles=True, format='json', columns='role_id,name,admin', quiet=True)
warn.assert_not_called()

def test_enterprise_info_columns_invalid_field_still_warns(self):
"""An actually unsupported column should still trigger the "Supported X columns" warning."""
params = get_connected_params()
api.query_enterprise(params)
cmd = enterprise.EnterpriseInfoCommand()

with self.assertLogs(level=logging.WARNING) as log:
cmd.execute(params, users=True, format='json', columns='bogus_column', quiet=True)
self.assertTrue(any('Supported user columns' in m for m in log.output))

with self.assertLogs(level=logging.WARNING) as log:
cmd.execute(params, teams=True, format='json', columns='bogus_column', quiet=True)
self.assertTrue(any('Supported team columns' in m for m in log.output))

def test_enterprise_info_uses_root_displayname(self):
params = get_connected_params()
api.query_enterprise(params)
Expand Down