Last active
June 19, 2019 14:31
-
-
Save BolaNasr/31397715fd21430d3a6e90078138adf3 to your computer and use it in GitHub Desktop.
acl for users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Jumpscale import j | |
def main(self): | |
""" | |
to run: | |
kosmos 'j.data.bcdb.test(name="dns_manager")' | |
test around acls | |
""" | |
# needs to be done later | |
schema = """ | |
@url = jumpscale.site.url | |
name* = "" | |
""" | |
def do(bcdb): | |
# model has now been added to the DB | |
m = bcdb.model_get_from_schema(schema) | |
self._log_info("POPULATE DATA") | |
for i in range(10): | |
u = bcdb.user.new() | |
u.name = "user_%s" % i | |
u.email = "user%s@me.com" % i | |
u.dm_id = "user%s.dns" % i | |
u.save() | |
for i in range(10): | |
g = bcdb.circle.new() | |
g.name = "gr_%s" % i | |
g.circles = [x for x in range(i + 1)] | |
g.users = [x for x in range(i + 1)] | |
g.save() | |
self._log_info("ALL DATA INSERTED (DONE)") | |
self._log_info("walk over all data") | |
l = bcdb.get_all() | |
self._log_info("walked over all data (DONE)") | |
assert len(l) == 20 | |
assert bcdb.acl.autosave is False | |
a = m.new() | |
a.name = "bola.com" | |
change = a.acl.rights_set(userids=[1], circleids=[2, 3], rights="rw") | |
assert change is True | |
# assert a.acl.readonly is False | |
a.save() | |
# means we have indeed the index for acl == 2 | |
assert len(bcdb.acl.get_all()) == 1 | |
self._log_debug("MODIFY RIGHTS") | |
a = m.new() | |
a.name = "test.com" | |
a.acl.rights_set(userids=[1], rights="r") | |
a.save() | |
assert len(bcdb.acl.get_all()) == 2 # there needs to be a new acl | |
assert a.acl.rights_check(1, "r") is True | |
assert a.acl.rights_check(1, "d") is False | |
a.acl.rights_set([1], [], "rw") | |
assert a.acl.rights_check(1, "r") is True | |
assert a.acl.rights_check(1, "w") is True | |
assert a.acl.rights_check(1, "rw") is True | |
assert a.acl.rights_check(1, "rwd") is False | |
assert a.acl.rights_check(1, "d") is False | |
a.save() | |
# NEED TO DO TESTS WITH GROUPS | |
zdbclient_admin = j.servers.zdb.client_admin_get() | |
zdbclient = zdbclient_admin.namespace_new("test", secret="1234") | |
zdbclient.flush() # empty | |
bcdb = j.data.bcdb.get(name="test", zdbclient=zdbclient, reset=True) | |
do(bcdb) | |
bcdb.reset() | |
bcdb = j.data.bcdb.get(name="test", zdbclient=None, reset=True) | |
do(bcdb) | |
self._log_info("ACL TESTS ALL DONE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment