Merge pull request #6468 from ryanpetrello/fix-6464

add a boolean `authorize` field for the Network Credential Type
This commit is contained in:
Ryan Petrello 2017-06-09 09:47:39 -04:00 committed by GitHub
commit a04f666319
3 changed files with 23 additions and 1 deletions

View File

@ -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',

View File

@ -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
#

View File

@ -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