mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24:21 +01:00
fix unit tests + add graph method
* fix unit tests on roles (adding mandatory description) * adding a method to get roles graph in json
This commit is contained in:
parent
9b803008bc
commit
a62c5a64ac
@ -10,6 +10,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
@ -463,14 +464,26 @@ class LdapCherry(object):
|
|||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def delete(self, **params):
|
def delete(self, **params):
|
||||||
""" remove user page """
|
""" remove user page """
|
||||||
self._check_auth(must_admin=True, is_admin=is_admin)
|
self._check_auth(must_admin=True)
|
||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def graph(self, **params):
|
||||||
|
""" remove user page """
|
||||||
|
self._check_auth(must_admin=True)
|
||||||
|
is_admin = self._check_admin()
|
||||||
|
graph={}
|
||||||
|
for r in self.roles.graph:
|
||||||
|
s = list(self.roles.graph[r]['sub_roles'])
|
||||||
|
p = list(self.roles.graph[r]['parent_roles'])
|
||||||
|
graph[r] = { 'sub_roles': s, 'parent_roles': p}
|
||||||
|
return json.dumps(graph, separators=(',',':'))
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def modify(self, **params):
|
def modify(self, **params):
|
||||||
""" modify user page """
|
""" modify user page """
|
||||||
self._check_auth(must_admin=True, is_admin=is_admin)
|
self._check_auth(must_admin=True)
|
||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ users:
|
|||||||
ad: [Domain Users]
|
ad: [Domain Users]
|
||||||
ldap: ['cn=users,ou=group,dc=example,dc=com']
|
ldap: ['cn=users,ou=group,dc=example,dc=com']
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
subroles:
|
subroles:
|
||||||
admin-lv2:
|
admin-lv2:
|
||||||
LC_admins: true
|
LC_admins: true
|
||||||
@ -10,6 +11,7 @@ users:
|
|||||||
ad: [Domain Users]
|
ad: [Domain Users]
|
||||||
ldap: ['cn=nagios admins,ou=group,dc=example,dc=com']
|
ldap: ['cn=nagios admins,ou=group,dc=example,dc=com']
|
||||||
display_name: Administrators Level 2
|
display_name: Administrators Level 2
|
||||||
|
description: description
|
||||||
subroles:
|
subroles:
|
||||||
admin-lv3:
|
admin-lv3:
|
||||||
backends_groups:
|
backends_groups:
|
||||||
@ -17,10 +19,12 @@ users:
|
|||||||
ldap: ['cn=dns admins,ou=group,dc=example,dc=com', 'cn=nagios admins,ou=group,dc=example,dc=com',
|
ldap: ['cn=dns admins,ou=group,dc=example,dc=com', 'cn=nagios admins,ou=group,dc=example,dc=com',
|
||||||
'cn=puppet admins,ou=group,dc=example,dc=com',]
|
'cn=puppet admins,ou=group,dc=example,dc=com',]
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
|
description: description
|
||||||
subroles: {}
|
subroles: {}
|
||||||
developpers:
|
developpers:
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ad: [Domain Users]
|
ad: [Domain Users]
|
||||||
ldap: ['cn=developpers,ou=group,dc=example,dc=com']
|
ldap: ['cn=developpers,ou=group,dc=example,dc=com']
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
subroles: {}
|
subroles: {}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
admin-lv3:
|
admin-lv3:
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=dns admins,ou=group,dc=example,dc=com
|
- cn=dns admins,ou=group,dc=example,dc=com
|
||||||
@ -13,6 +14,7 @@ admin-lv3:
|
|||||||
|
|
||||||
admin-lv2:
|
admin-lv2:
|
||||||
display_name: Administrators Level 2
|
display_name: Administrators Level 2
|
||||||
|
description: description
|
||||||
LC_admins: True
|
LC_admins: True
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
@ -23,6 +25,7 @@ admin-lv2:
|
|||||||
|
|
||||||
developpers:
|
developpers:
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=developpers,ou=group,dc=example,dc=com
|
- cn=developpers,ou=group,dc=example,dc=com
|
||||||
@ -32,6 +35,7 @@ developpers:
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
admin -lv3:
|
admin -lv3:
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
LC_admins: True
|
LC_admins: True
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=dns admins,ou=group,dc=example,dc=com
|
- cn=dns admins,ou=group,dc=example,dc=com
|
||||||
@ -14,6 +15,7 @@ admin -lv3:
|
|||||||
|
|
||||||
admin -lv2:
|
admin -lv2:
|
||||||
display_name: Administrators Level 2
|
display_name: Administrators Level 2
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=nagios admins,ou=group,dc=example,dc=com
|
- cn=nagios admins,ou=group,dc=example,dc=com
|
||||||
@ -23,6 +25,7 @@ admin -lv2:
|
|||||||
|
|
||||||
developpers:
|
developpers:
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=developpers,ou=group,dc=example,dc=com
|
- cn=developpers,ou=group,dc=example,dc=com
|
||||||
@ -32,6 +35,7 @@ developpers:
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
@ -40,6 +44,7 @@ users:
|
|||||||
|
|
||||||
users2:
|
users2:
|
||||||
display_name: Simple Users 2
|
display_name: Simple Users 2
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
admin -lv3:
|
admin -lv3:
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
|
description: description
|
||||||
LC_admins: True
|
LC_admins: True
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
@ -14,6 +15,7 @@ admin -lv3:
|
|||||||
|
|
||||||
admin -lv3:
|
admin -lv3:
|
||||||
display_name: Administrators Level 2
|
display_name: Administrators Level 2
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=nagios admins,ou=group,dc=example,dc=com
|
- cn=nagios admins,ou=group,dc=example,dc=com
|
||||||
@ -23,6 +25,7 @@ admin -lv3:
|
|||||||
|
|
||||||
developpers:
|
developpers:
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=developpers,ou=group,dc=example,dc=com
|
- cn=developpers,ou=group,dc=example,dc=com
|
||||||
@ -32,6 +35,7 @@ developpers:
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
admin-lv3:
|
admin-lv3:
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
|
description: description
|
||||||
LC_admins: True
|
LC_admins: True
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
@ -14,9 +15,11 @@ admin-lv3:
|
|||||||
|
|
||||||
admin-lv2:
|
admin-lv2:
|
||||||
display_name: Administrators Level 2
|
display_name: Administrators Level 2
|
||||||
|
description: description
|
||||||
|
|
||||||
developpers:
|
developpers:
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=developpers,ou=group,dc=example,dc=com
|
- cn=developpers,ou=group,dc=example,dc=com
|
||||||
@ -26,6 +29,7 @@ developpers:
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
admin-lv3:
|
admin-lv3:
|
||||||
display_name: Administrators Level 3
|
display_name: Administrators Level 3
|
||||||
LC_admins: True
|
LC_admins: True
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=dns admins,ou=group,dc=example,dc=com
|
- cn=dns admins,ou=group,dc=example,dc=com
|
||||||
@ -13,6 +14,7 @@ admin-lv3:
|
|||||||
- Domain Controllers
|
- Domain Controllers
|
||||||
|
|
||||||
admin-lv2:
|
admin-lv2:
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=nagios admins,ou=group,dc=example,dc=com
|
- cn=nagios admins,ou=group,dc=example,dc=com
|
||||||
@ -22,6 +24,7 @@ admin-lv2:
|
|||||||
|
|
||||||
developpers:
|
developpers:
|
||||||
display_name: Developpers
|
display_name: Developpers
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=developpers,ou=group,dc=example,dc=com
|
- cn=developpers,ou=group,dc=example,dc=com
|
||||||
@ -31,6 +34,7 @@ developpers:
|
|||||||
|
|
||||||
users:
|
users:
|
||||||
display_name: Simple Users
|
display_name: Simple Users
|
||||||
|
description: description
|
||||||
backends_groups:
|
backends_groups:
|
||||||
ldap:
|
ldap:
|
||||||
- cn=users,ou=group,dc=example,dc=com
|
- cn=users,ou=group,dc=example,dc=com
|
||||||
|
@ -78,7 +78,7 @@ class TestError(object):
|
|||||||
|
|
||||||
def testNested(self):
|
def testNested(self):
|
||||||
inv = Roles('./tests/cfg/nested.yml')
|
inv = Roles('./tests/cfg/nested.yml')
|
||||||
expected = {'developpers': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=developpers,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Developpers'}, 'admin-lv3': {'backends_groups': {'ad': ['Domain Users', 'Administrators', 'Domain Controllers'], 'ldap': ['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com', 'cn=puppet admins,ou=group,dc=example,dc=com', 'cn=dns admins,ou=group,dc=example,dc=com']}, 'display_name': 'Administrators Level 3'}, 'admin-lv2': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Administrators Level 2', 'LC_admins': True}, 'users': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Simple Users'}}
|
expected = {'developpers': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=developpers,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Developpers', 'description': 'description'}, 'admin-lv3': {'backends_groups': {'ad': ['Domain Users', 'Administrators', 'Domain Controllers'], 'ldap': ['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com', 'cn=puppet admins,ou=group,dc=example,dc=com', 'cn=dns admins,ou=group,dc=example,dc=com']}, 'display_name': 'Administrators Level 3', 'description': 'description'}, 'admin-lv2': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=nagios admins,ou=group,dc=example,dc=com', 'cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Administrators Level 2', 'description': 'description', 'LC_admins': True}, 'users': {'backends_groups': {'ad': ['Domain Users'], 'ldap': ['cn=users,ou=group,dc=example,dc=com']}, 'display_name': 'Simple Users', 'description': 'description'}}
|
||||||
assert expected == inv.flatten
|
assert expected == inv.flatten
|
||||||
|
|
||||||
def testGetGroupMissingRole(self):
|
def testGetGroupMissingRole(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user