mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 11:41:08 -03:30
Merge pull request #1666 from wwitzel3/issue-1652
do not allow requests with empty values in __in values
This commit is contained in:
@@ -132,6 +132,8 @@ class FieldLookupBackend(BaseFilterBackend):
|
|||||||
elif new_lookup.endswith('__in'):
|
elif new_lookup.endswith('__in'):
|
||||||
items = []
|
items = []
|
||||||
for item in value.split(','):
|
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))
|
items.append(self.value_to_python_for_field(field, item))
|
||||||
value = items
|
value = items
|
||||||
elif new_lookup.endswith('__regex') or new_lookup.endswith('__iregex'):
|
elif new_lookup.endswith('__regex') or new_lookup.endswith('__iregex'):
|
||||||
|
|||||||
12
awx/main/tests/unit/api/test_filters.py
Normal file
12
awx/main/tests/unit/api/test_filters.py
Normal 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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user