From ad9fda9a066749b9e3769d85e3ba92228f387aae Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 6 Jun 2017 09:58:25 -0400 Subject: [PATCH] add a boolean `authorize` field for the Network Credential Type see: #6464 --- awx/main/models/credential.py | 4 ++++ .../tests/functional/api/test_credential.py | 3 +++ awx/main/tests/functional/test_credential.py | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index ccded60c38..a9ba6eaeed 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 c1b8027a99..4868011a3a 100644 --- a/awx/main/tests/functional/api/test_credential.py +++ b/awx/main/tests/functional/api/test_credential.py @@ -743,6 +743,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', { @@ -753,6 +754,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', } }] @@ -775,6 +777,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