require url scheme for credential type url inputs

This adds a url formatting type for credential input string fields
The validator for this formatting type will throw an error if the
provided url string doesn't have a url schema.
This commit is contained in:
Jake McDermott
2019-04-30 13:17:15 -04:00
parent 52276ebbab
commit 9737ab620c
6 changed files with 45 additions and 1 deletions

View File

@@ -1942,3 +1942,34 @@ def test_create_credential_missing_user_team_org_xfail(post, admin, credentialty
admin
)
assert response.status_code == 400
@pytest.mark.django_db
def test_create_credential_with_missing_url_schema_xfail(post, organization, admin):
credential_type = CredentialType(
kind='test',
name='MyTestCredentialType',
inputs = {
'fields': [{
'id': 'server_url',
'label': 'Server Url',
'type': 'string',
'format': 'url'
}]
}
)
credential_type.save()
params = {
'name': 'Second Best credential ever',
'organization': organization.pk,
'credential_type': credential_type.pk,
'inputs': {'server_url': 'foo.com'}
}
endpoint = reverse('api:credential_list', kwargs={'version': 'v2'})
response = post(endpoint, params, admin)
assert response.status_code == 400
params['inputs'] = {'server_url': 'http://foo.com'}
response = post(endpoint, params, admin)
assert response.status_code == 201