mirror of
https://github.com/ansible/awx.git
synced 2026-03-29 06:45:09 -02:30
Wrote corresponding tests.
Updated verbiage to be more in line with existing messages.
This commit is contained in:
@@ -2667,7 +2667,7 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
def validate_inputs(self, inputs):
|
def validate_inputs(self, inputs):
|
||||||
if self.instance and self.instance.credential_type.kind == "vault":
|
if self.instance and self.instance.credential_type.kind == "vault":
|
||||||
if 'vault_id' in inputs and inputs['vault_id'] != self.instance.inputs['vault_id']:
|
if 'vault_id' in inputs and inputs['vault_id'] != self.instance.inputs['vault_id']:
|
||||||
raise ValidationError(_('We do not permit Vault IDs to be changed after they have been created.'))
|
raise ValidationError(_('Vault IDs cannot be changed once they have been created.'))
|
||||||
|
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
|
|||||||
@@ -532,6 +532,49 @@ def test_vault_password_required(post, organization, admin):
|
|||||||
assert 'required fields (vault_password)' in j.job_explanation
|
assert 'required fields (vault_password)' in j.job_explanation
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_vault_id_immutable(post, patch, organization, admin):
|
||||||
|
vault = CredentialType.defaults['vault']()
|
||||||
|
vault.save()
|
||||||
|
response = post(
|
||||||
|
reverse('api:credential_list'),
|
||||||
|
{
|
||||||
|
'credential_type': vault.pk,
|
||||||
|
'organization': organization.id,
|
||||||
|
'name': 'Best credential ever',
|
||||||
|
'inputs': {'vault_id': 'password', 'vault_password': 'password'},
|
||||||
|
},
|
||||||
|
admin,
|
||||||
|
)
|
||||||
|
assert response.status_code == 201
|
||||||
|
assert Credential.objects.count() == 1
|
||||||
|
response = patch(
|
||||||
|
reverse('api:credential_detail', kwargs={'pk': response.data['id']}), {'inputs': {'vault_id': 'password2', 'vault_password': 'password'}}, admin
|
||||||
|
)
|
||||||
|
assert response.status_code == 400
|
||||||
|
assert response.data['inputs'][0] == 'Vault IDs cannot be changed once they have been created.'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_patch_without_vault_id_valid(post, patch, organization, admin):
|
||||||
|
vault = CredentialType.defaults['vault']()
|
||||||
|
vault.save()
|
||||||
|
response = post(
|
||||||
|
reverse('api:credential_list'),
|
||||||
|
{
|
||||||
|
'credential_type': vault.pk,
|
||||||
|
'organization': organization.id,
|
||||||
|
'name': 'Best credential ever',
|
||||||
|
'inputs': {'vault_id': 'password', 'vault_password': 'password'},
|
||||||
|
},
|
||||||
|
admin,
|
||||||
|
)
|
||||||
|
assert response.status_code == 201
|
||||||
|
assert Credential.objects.count() == 1
|
||||||
|
response = patch(reverse('api:credential_detail', kwargs={'pk': response.data['id']}), {'name': 'worst_credential_ever'}, admin)
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Net Credentials
|
# Net Credentials
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user