mirror of
https://github.com/VinylDNS/vinyldns
synced 2025-09-05 00:35:29 +00:00
Open list groups access (#809)
This commit is contained in:
@@ -9,6 +9,7 @@ from vinyldns_context import VinylDNSTestContext
|
||||
class ListGroupsSearchContext(object):
|
||||
def __init__(self):
|
||||
self.client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, access_key='listGroupAccessKey', secret_key='listGroupSecretKey')
|
||||
self.support_user_client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, 'supportUserAccessKey', 'supportUserSecretKey')
|
||||
self.tear_down() # ensures that the environment is clean before starting
|
||||
|
||||
try:
|
||||
@@ -29,6 +30,15 @@ class ListGroupsSearchContext(object):
|
||||
pass
|
||||
raise
|
||||
|
||||
def verify_ignore_access(self, results):
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
|
||||
assert_that(len(results['groups']), greater_than(50))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
assert_that(results, is_not(has_key('startFrom')))
|
||||
assert_that(results, is_not(has_key('nextId')))
|
||||
assert_that(results['maxItems'], is_(100))
|
||||
|
||||
def tear_down(self):
|
||||
clear_zones(self.client)
|
||||
clear_groups(self.client)
|
||||
@@ -51,7 +61,7 @@ def test_list_my_groups_no_parameters(list_my_groups_context):
|
||||
|
||||
results = list_my_groups_context.client.list_my_groups(status=200)
|
||||
|
||||
assert_that(results, has_length(2)) # 2 fields
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
|
||||
assert_that(results['groups'], has_length(50))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
@@ -70,7 +80,7 @@ def test_get_my_groups_using_old_account_auth(list_my_groups_context):
|
||||
Test passing in an account will return an empty set
|
||||
"""
|
||||
results = list_my_groups_context.client.list_my_groups(status=200)
|
||||
assert_that(results, has_length(2))
|
||||
assert_that(results, has_length(3))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
assert_that(results, is_not(has_key('startFrom')))
|
||||
assert_that(results, is_not(has_key('nextId')))
|
||||
@@ -83,7 +93,7 @@ def test_list_my_groups_max_items(list_my_groups_context):
|
||||
"""
|
||||
results = list_my_groups_context.client.list_my_groups(max_items=5, status=200)
|
||||
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
assert_that(results, has_length(4)) # 4 fields
|
||||
|
||||
assert_that(results, has_key('groups'))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
@@ -98,7 +108,7 @@ def test_list_my_groups_paging(list_my_groups_context):
|
||||
"""
|
||||
results=list_my_groups_context.client.list_my_groups(max_items=20, status=200)
|
||||
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
assert_that(results, has_length(4)) # 4 fields
|
||||
assert_that(results, has_key('groups'))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
assert_that(results, is_not(has_key('startFrom')))
|
||||
@@ -110,7 +120,7 @@ def test_list_my_groups_paging(list_my_groups_context):
|
||||
results = list_my_groups_context.client.list_my_groups(max_items=20, start_from=results['nextId'], status=200)
|
||||
|
||||
if 'nextId' in results:
|
||||
assert_that(results, has_length(4)) # 4 fields
|
||||
assert_that(results, has_length(5)) # 5 fields
|
||||
assert_that(results, has_key('groups'))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
assert_that(results['startFrom'], is_(prev['nextId']))
|
||||
@@ -118,7 +128,7 @@ def test_list_my_groups_paging(list_my_groups_context):
|
||||
assert_that(results['maxItems'], is_(20))
|
||||
|
||||
else:
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
assert_that(results, has_length(4)) # 4 fields
|
||||
assert_that(results, has_key('groups'))
|
||||
assert_that(results, is_not(has_key('groupNameFilter')))
|
||||
assert_that(results['startFrom'], is_(prev['nextId']))
|
||||
@@ -132,7 +142,7 @@ def test_list_my_groups_filter_matches(list_my_groups_context):
|
||||
"""
|
||||
results = list_my_groups_context.client.list_my_groups(group_name_filter="test-list-my-groups-01", status=200)
|
||||
|
||||
assert_that(results, has_length(3)) # 3 fields
|
||||
assert_that(results, has_length(4)) # 4 fields
|
||||
|
||||
assert_that(results['groups'], has_length(10))
|
||||
assert_that(results['groupNameFilter'], is_('test-list-my-groups-01'))
|
||||
@@ -163,3 +173,35 @@ def test_list_my_groups_no_deleted(list_my_groups_context):
|
||||
for g in results['groups']:
|
||||
assert_that(g['status'], is_not('Deleted'))
|
||||
|
||||
def test_list_my_groups_with_ignore_access_true(list_my_groups_context):
|
||||
"""
|
||||
Test that we can get all the groups whether a user is a member or not
|
||||
"""
|
||||
|
||||
results = list_my_groups_context.client.list_my_groups(ignore_access=True, status=200)
|
||||
|
||||
list_my_groups_context.verify_ignore_access(results)
|
||||
|
||||
my_results = list_my_groups_context.client.list_my_groups(status=200)
|
||||
my_results['groups'] = sorted(my_results['groups'], key=lambda x: x['name'])
|
||||
|
||||
for i in range(0, 50):
|
||||
assert_that(my_results['groups'][i]['name'], is_("test-list-my-groups-{0:0>3}".format(i)))
|
||||
|
||||
def test_list_my_groups_as_support_user(list_my_groups_context):
|
||||
"""
|
||||
Test that we can get all the groups as a support user, even without ignore_access
|
||||
"""
|
||||
|
||||
results = list_my_groups_context.support_user_client.list_my_groups(status=200)
|
||||
|
||||
list_my_groups_context.verify_ignore_access(results)
|
||||
|
||||
def test_list_my_groups_as_support_user_with_ignore_access_true(list_my_groups_context):
|
||||
"""
|
||||
Test that we can get all the groups as a support user
|
||||
"""
|
||||
|
||||
results = list_my_groups_context.support_user_client.list_my_groups(ignore_access=True, status=200)
|
||||
|
||||
list_my_groups_context.verify_ignore_access(results)
|
||||
|
@@ -226,12 +226,13 @@ class VinylDNSClient(object):
|
||||
|
||||
return data
|
||||
|
||||
def list_my_groups(self, group_name_filter=None, start_from=None, max_items=None, **kwargs):
|
||||
def list_my_groups(self, group_name_filter=None, start_from=None, max_items=None, ignore_access=False, **kwargs):
|
||||
"""
|
||||
Retrieves my groups
|
||||
:param start_from: the start key of the page
|
||||
:param max_items: the page limit
|
||||
:param group_name_filter: only returns groups whose names contain filter string
|
||||
:param ignore_access: determines if groups should be retrieved based on requester's membership
|
||||
:return: the content of the response
|
||||
"""
|
||||
|
||||
@@ -242,6 +243,8 @@ class VinylDNSClient(object):
|
||||
args.append(u'startFrom={0}'.format(start_from))
|
||||
if max_items is not None:
|
||||
args.append(u'maxItems={0}'.format(max_items))
|
||||
if ignore_access is not False:
|
||||
args.append(u'ignoreAccess={0}'.format(ignore_access))
|
||||
|
||||
url = urljoin(self.index_url, u'/groups') + u'?' + u'&'.join(args)
|
||||
response, data = self.make_request(url, u'GET', self.headers, **kwargs)
|
||||
|
Reference in New Issue
Block a user