mirror of
https://github.com/VinylDNS/vinyldns
synced 2025-08-31 14:25:30 +00:00
Properly reject requests sent to non-existent routes (#739)
* Refactor routing
This commit is contained in:
@@ -3,6 +3,7 @@ from hamcrest import *
|
||||
from vinyldns_python import VinylDNSClient
|
||||
from dns.resolver import *
|
||||
from vinyldns_context import VinylDNSTestContext
|
||||
from requests.compat import urljoin
|
||||
|
||||
|
||||
def test_request_fails_when_user_account_is_locked():
|
||||
@@ -27,3 +28,23 @@ def test_request_succeeds_when_user_is_found_and_not_locked():
|
||||
client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, 'okAccessKey', 'okSecretKey')
|
||||
|
||||
client.list_batch_change_summaries(status=200)
|
||||
|
||||
def test_request_fails_when_accessing_non_existent_route():
|
||||
"""
|
||||
Test request fails with NotFound (404) when route cannot be resolved, regardless of authentication
|
||||
"""
|
||||
client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, 'unknownAccessKey', 'anyAccessSecretKey')
|
||||
url = urljoin(VinylDNSTestContext.vinyldns_url, u'/no-existo')
|
||||
_, data = client.make_request(url, u'GET', client.headers, status=404)
|
||||
|
||||
assert_that(data, is_("The requested path [/no-existo] does not exist."))
|
||||
|
||||
def test_request_fails_with_unsupported_http_method_for_route():
|
||||
"""
|
||||
Test request fails with MethodNotAllowed (405) when HTTP Method is not supported for specified route
|
||||
"""
|
||||
client = VinylDNSClient(VinylDNSTestContext.vinyldns_url, 'unknownAccessKey', 'anyAccessSecretKey')
|
||||
url = urljoin(VinylDNSTestContext.vinyldns_url, u'/zones')
|
||||
_, data = client.make_request(url, u'PUT', client.headers, status=405)
|
||||
|
||||
assert_that(data, is_("HTTP method not allowed, supported methods: GET, POST"))
|
||||
|
@@ -219,3 +219,26 @@ def test_create_group_no_members(shared_zone_test_context):
|
||||
finally:
|
||||
if result:
|
||||
client.delete_group(result['id'], status=(200,404))
|
||||
|
||||
def test_create_group_adds_admins_to_member_list(shared_zone_test_context):
|
||||
"""
|
||||
Tests that creating a group adds admins to member list
|
||||
"""
|
||||
client = shared_zone_test_context.ok_vinyldns_client
|
||||
result = None
|
||||
|
||||
try:
|
||||
new_group = {
|
||||
'name': 'test-create-group-add-admins-to-members',
|
||||
'email': 'test@test.com',
|
||||
'description': 'this is a description',
|
||||
'members': [ {'id': 'ok'} ],
|
||||
'admins': [ {'id': 'dummy'} ]
|
||||
}
|
||||
|
||||
result = client.create_group(new_group, status=200)
|
||||
assert_that(map(lambda x: x['id'], result['members']), contains('ok', 'dummy'))
|
||||
assert_that(result['admins'][0]['id'], is_('dummy'))
|
||||
finally:
|
||||
if result:
|
||||
client.delete_group(result['id'], status=(200,404))
|
||||
|
@@ -614,3 +614,31 @@ def test_update_group_not_authorized(shared_zone_test_context):
|
||||
finally:
|
||||
if saved_group:
|
||||
ok_client.delete_group(saved_group['id'], status=(200,404))
|
||||
|
||||
def test_update_group_adds_admins_to_member_list(shared_zone_test_context):
|
||||
"""
|
||||
Tests that updating a group adds admins to member list
|
||||
"""
|
||||
ok_client = shared_zone_test_context.ok_vinyldns_client
|
||||
dummy_client = shared_zone_test_context.dummy_vinyldns_client
|
||||
result = None
|
||||
|
||||
try:
|
||||
new_group = {
|
||||
'name': 'test-update-group-add-admins-to-members',
|
||||
'email': 'test@test.com',
|
||||
'description': 'this is a description',
|
||||
'members': [ {'id': 'ok'} ],
|
||||
'admins': [ {'id': 'ok'} ]
|
||||
}
|
||||
|
||||
saved_group = ok_client.create_group(new_group, status=200)
|
||||
|
||||
saved_group['admins'] = [ { 'id': 'dummy' }]
|
||||
result = ok_client.update_group(saved_group['id'], saved_group, status=200)
|
||||
|
||||
assert_that(map(lambda x: x['id'], result['members']), contains('ok', 'dummy'))
|
||||
assert_that(result['admins'][0]['id'], is_('dummy'))
|
||||
finally:
|
||||
if result:
|
||||
dummy_client.delete_group(result['id'], status=(200,404))
|
||||
|
Reference in New Issue
Block a user