mirror of
https://github.com/ansible/awx.git
synced 2026-01-25 00:11:23 -03:30
raise url string parsing error as validation error
This commit is contained in:
parent
9737ab620c
commit
84b21620b2
@ -492,7 +492,11 @@ def format_ssh_private_key(value):
|
||||
|
||||
@JSONSchemaField.format_checker.checks('url')
|
||||
def format_url(value):
|
||||
if urllib.parse.urlparse(value).scheme == '':
|
||||
try:
|
||||
scheme = urllib.parse.urlparse(value).scheme
|
||||
except Exception as e:
|
||||
raise jsonschema.exceptions.FormatError(str(e))
|
||||
if scheme == '':
|
||||
raise jsonschema.exceptions.FormatError(
|
||||
'Invalid URL: Missing url scheme (http, https, etc.)'
|
||||
)
|
||||
|
||||
@ -1945,7 +1945,7 @@ def test_create_credential_missing_user_team_org_xfail(post, admin, credentialty
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create_credential_with_missing_url_schema_xfail(post, organization, admin):
|
||||
def test_create_credential_with_invalid_url_xfail(post, organization, admin):
|
||||
credential_type = CredentialType(
|
||||
kind='test',
|
||||
name='MyTestCredentialType',
|
||||
@ -1961,7 +1961,7 @@ def test_create_credential_with_missing_url_schema_xfail(post, organization, adm
|
||||
credential_type.save()
|
||||
|
||||
params = {
|
||||
'name': 'Second Best credential ever',
|
||||
'name': 'Second Best Credential Ever',
|
||||
'organization': organization.pk,
|
||||
'credential_type': credential_type.pk,
|
||||
'inputs': {'server_url': 'foo.com'}
|
||||
@ -1969,7 +1969,13 @@ def test_create_credential_with_missing_url_schema_xfail(post, organization, adm
|
||||
endpoint = reverse('api:credential_list', kwargs={'version': 'v2'})
|
||||
response = post(endpoint, params, admin)
|
||||
assert response.status_code == 400
|
||||
assert response.data['inputs']['server_url'] == ['Invalid URL: Missing url scheme (http, https, etc.)']
|
||||
|
||||
params['inputs'] = {'server_url': 'http://foo.com'}
|
||||
params['inputs']['server_url'] = 'https://[dead:beef'
|
||||
response = post(endpoint, params, admin)
|
||||
assert response.status_code == 400
|
||||
assert response.data['inputs']['server_url'] == ['Invalid IPv6 URL']
|
||||
|
||||
params['inputs']['server_url'] = 'http://foo.com'
|
||||
response = post(endpoint, params, admin)
|
||||
assert response.status_code == 201
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user