mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
raise url string parsing error as validation error
This commit is contained in:
@@ -492,7 +492,11 @@ def format_ssh_private_key(value):
|
|||||||
|
|
||||||
@JSONSchemaField.format_checker.checks('url')
|
@JSONSchemaField.format_checker.checks('url')
|
||||||
def format_url(value):
|
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(
|
raise jsonschema.exceptions.FormatError(
|
||||||
'Invalid URL: Missing url scheme (http, https, etc.)'
|
'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
|
@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(
|
credential_type = CredentialType(
|
||||||
kind='test',
|
kind='test',
|
||||||
name='MyTestCredentialType',
|
name='MyTestCredentialType',
|
||||||
@@ -1961,7 +1961,7 @@ def test_create_credential_with_missing_url_schema_xfail(post, organization, adm
|
|||||||
credential_type.save()
|
credential_type.save()
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'name': 'Second Best credential ever',
|
'name': 'Second Best Credential Ever',
|
||||||
'organization': organization.pk,
|
'organization': organization.pk,
|
||||||
'credential_type': credential_type.pk,
|
'credential_type': credential_type.pk,
|
||||||
'inputs': {'server_url': 'foo.com'}
|
'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'})
|
endpoint = reverse('api:credential_list', kwargs={'version': 'v2'})
|
||||||
response = post(endpoint, params, admin)
|
response = post(endpoint, params, admin)
|
||||||
assert response.status_code == 400
|
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)
|
response = post(endpoint, params, admin)
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
|
|||||||
Reference in New Issue
Block a user