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:
parent
8f9fe93de5
commit
4ef291b00b
@ -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'):
|
||||
|
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)
|
||||
|
Loading…
Reference in New Issue
Block a user