diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 806c681cff..660c00b75f 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -701,6 +701,10 @@ def net(cls): 'label': 'Private Key Passphrase', 'type': 'string', 'secret': True, + }, { + 'id': 'authorize', + 'label': 'Authorize', + 'type': 'boolean', }, { 'id': 'authorize_password', 'label': 'Authorize Password', diff --git a/awx/main/tests/functional/api/test_credential.py b/awx/main/tests/functional/api/test_credential.py index 684517ea99..1b9b2ec610 100644 --- a/awx/main/tests/functional/api/test_credential.py +++ b/awx/main/tests/functional/api/test_credential.py @@ -798,6 +798,7 @@ def test_vault_create_ok(post, organization, admin, version, params): 'password': 'some_password', 'ssh_key_data': 'some_key_data', 'ssh_key_unlock': 'some_key_unlock', + 'authorize': True, 'authorize_password': 'some_authorize_password', }], ['v2', { @@ -808,6 +809,7 @@ def test_vault_create_ok(post, organization, admin, version, params): 'password': 'some_password', 'ssh_key_data': 'some_key_data', 'ssh_key_unlock': 'some_key_unlock', + 'authorize': True, 'authorize_password': 'some_authorize_password', } }] @@ -830,6 +832,7 @@ def test_net_create_ok(post, organization, admin, version, params): assert decrypt_field(cred, 'ssh_key_data') == 'some_key_data' assert decrypt_field(cred, 'ssh_key_unlock') == 'some_key_unlock' assert decrypt_field(cred, 'authorize_password') == 'some_authorize_password' + assert cred.inputs['authorize'] is True # diff --git a/awx/main/tests/functional/test_credential.py b/awx/main/tests/functional/test_credential.py index 7d76e3d377..16d80e6a3c 100644 --- a/awx/main/tests/functional/test_credential.py +++ b/awx/main/tests/functional/test_credential.py @@ -171,6 +171,16 @@ def test_credential_creation(organization_factory): @pytest.mark.parametrize('inputs', [ ['must-be-a-dict'], {'user': 'wrong-key'}, + {'username': 1}, + {'username': 1.5}, + {'username': ['a', 'b', 'c']}, + {'username': {'a': 'b'}}, + {'username': False}, + {'flag': 1}, + {'flag': 1.5}, + {'flag': ['a', 'b', 'c']}, + {'flag': {'a': 'b'}}, + {'flag': 'some-string'}, ]) def test_credential_creation_validation_failure(organization_factory, inputs): org = organization_factory('test').organization @@ -183,16 +193,21 @@ def test_credential_creation_validation_failure(organization_factory, inputs): 'id': 'username', 'label': 'Username for SomeCloud', 'type': 'string' + },{ + 'id': 'flag', + 'label': 'Some Boolean Flag', + 'type': 'boolean' }] } ) type_.save() - with pytest.raises(ValidationError): + with pytest.raises(Exception) as e: cred = Credential(credential_type=type_, name="Bob's Credential", inputs=inputs, organization=org) cred.save() cred.full_clean() + assert e.type in (ValidationError, serializers.ValidationError) @pytest.mark.django_db