Skip to content

Commit

Permalink
fix: users, improve list_databases
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Dec 12, 2023
1 parent 99a43ad commit c0c8d59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/nethsec/users/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,18 @@ def list_databases(uci):
Returns:
- A list of database objects, each one containing:
- id: database identifier
- name: database identifier
- type: database type (local or ldap)
- description: database description
'''
ret = []
for db in uci.get_all('users'):
if uci.get('users', db, default='') == "local":
ret.append({"id": db, "type": "local", "description": uci.get('users', db, 'description', default='')})
ret.append({"name": db, "type": "local", "description": uci.get('users', db, 'description', default='')})
elif uci.get('users', db, default='') == "ldap":
ret.append({"id": db, "type": "ldap", "description": uci.get('users', db, 'description', default=''), "schema": uci.get('users', db, 'schema', default='')})
ret.append({"name": db, "type": "ldap", "description": uci.get('users', db, 'description', default=''),
"schema": uci.get('users', db, 'schema', default=''),
"uri": uci.get('users', db, 'uri', default='')})
return ret

def add_local_user(uci, name, password="", description="", database="main", extra_fields={}):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ def test_get_group_by_name(tmp_path):

def test_list_databases(tmp_path):
db_list = users.list_databases(_setup_db(tmp_path))
assert {"id": "main", "description": "Main local database", "type": "local"} in db_list
assert {"id": "second", "description": "Secondary local database", "type": "local"} in db_list
assert {"id": "ldap1", "description": "Remote OpenLDAP server", "type": "ldap", "schema": "rfc2307"} in db_list
assert {"id": "ad1", "description": "Remote AD server", "type": "ldap", "schema": "ad"} in db_list
assert {"name": "main", "description": "Main local database", "type": "local"} in db_list
assert {"name": "second", "description": "Secondary local database", "type": "local"} in db_list
assert {"name": "ldap1", "description": "Remote OpenLDAP server", "type": "ldap", "schema": "rfc2307", "uri": "ldaps://192.168.100.234"} in db_list
assert {"name": "ad1", "description": "Remote AD server", "type": "ldap", "schema": "ad", "uri": "ldaps://ad.nethserver.org"} in db_list

def test_add_local_database(tmp_path):
u = _setup_db(tmp_path)
Expand Down

0 comments on commit c0c8d59

Please sign in to comment.