1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 18:21:12 +03:00

do not allow requests with empty values in __in values

This commit is contained in:
Wayne Witzel III 2016-04-22 15:39:33 -04:00
parent 8f9fe93de5
commit 4ef291b00b
2 changed files with 14 additions and 0 deletions

View File

@ -132,6 +132,8 @@ class FieldLookupBackend(BaseFilterBackend):
elif new_lookup.endswith('__in'):
items = []
for item in value.split(','):
if not item:
raise ValueError('cannot provide empty value for __in')
items.append(self.value_to_python_for_field(field, item))
value = items
elif new_lookup.endswith('__regex') or new_lookup.endswith('__iregex'):

View File

@ -0,0 +1,12 @@
import pytest
from awx.api.filters import FieldLookupBackend
from awx.main.models import JobTemplate
@pytest.mark.parametrize(u"empty_value", [u'', '', u'a,,b'])
def test_empty_in(empty_value):
field_lookup = FieldLookupBackend()
with pytest.raises(ValueError) as excinfo:
field_lookup.value_to_python(JobTemplate, 'project__in', empty_value)
assert 'empty value for __in' in str(excinfo.value)