mirror of
https://github.com/ansible/awx.git
synced 2026-02-21 05:00:07 -03:30
Merge pull request #7174 from chrismeyersfsu/fix-7083
disallow insights creds on smart inventory
This commit is contained in:
@@ -370,6 +370,8 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
|
|||||||
return self.groups.exclude(parents__pk__in=group_pks).distinct()
|
return self.groups.exclude(parents__pk__in=group_pks).distinct()
|
||||||
|
|
||||||
def clean_insights_credential(self):
|
def clean_insights_credential(self):
|
||||||
|
if self.kind == 'smart':
|
||||||
|
raise ValidationError(_("Assignment not allowed for Smart Inventory"))
|
||||||
if self.insights_credential and self.insights_credential.credential_type.kind != 'insights':
|
if self.insights_credential and self.insights_credential.credential_type.kind != 'insights':
|
||||||
raise ValidationError(_("Credential kind must be 'insights'."))
|
raise ValidationError(_("Credential kind must be 'insights'."))
|
||||||
return self.insights_credential
|
return self.insights_credential
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import mock
|
import mock
|
||||||
|
import json
|
||||||
|
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
UnifiedJob,
|
UnifiedJob,
|
||||||
InventoryUpdate,
|
InventoryUpdate,
|
||||||
Job,
|
Job,
|
||||||
|
Inventory,
|
||||||
|
Credential,
|
||||||
|
CredentialType,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -36,3 +43,33 @@ def test__build_job_explanation():
|
|||||||
|
|
||||||
assert job_explanation == 'Previous Task Canceled: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \
|
assert job_explanation == 'Previous Task Canceled: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \
|
||||||
('inventory_update', 'I_am_an_Inventory_Update', 3)
|
('inventory_update', 'I_am_an_Inventory_Update', 3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_clean_insights_credential():
|
||||||
|
cred_type = CredentialType.defaults['insights']()
|
||||||
|
insights_cred = Credential(credential_type=cred_type)
|
||||||
|
inv = Inventory(insights_credential=insights_cred)
|
||||||
|
|
||||||
|
inv.clean_insights_credential()
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_clean_insights_credential():
|
||||||
|
cred_type = CredentialType.defaults['scm']()
|
||||||
|
cred = Credential(credential_type=cred_type)
|
||||||
|
inv = Inventory(insights_credential=cred)
|
||||||
|
|
||||||
|
with pytest.raises(ValidationError) as e:
|
||||||
|
inv.clean_insights_credential()
|
||||||
|
|
||||||
|
assert json.dumps(str(e.value)) == json.dumps(str([u"Credential kind must be 'insights'."]))
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_kind_clean_insights_credential():
|
||||||
|
cred_type = CredentialType.defaults['insights']()
|
||||||
|
insights_cred = Credential(credential_type=cred_type)
|
||||||
|
inv = Inventory(kind='smart', insights_credential=insights_cred)
|
||||||
|
|
||||||
|
with pytest.raises(ValidationError) as e:
|
||||||
|
inv.clean_insights_credential()
|
||||||
|
|
||||||
|
assert json.dumps(str(e.value)) == json.dumps(str([u'Assignment not allowed for Smart Inventory']))
|
||||||
|
|||||||
Reference in New Issue
Block a user