Skip to content

Commit e5a67cd

Browse files
new: FilterAttributeValues: add tests for new filter notation
Test regexp filter via new notation, test invalid filter type.
1 parent a749150 commit e5a67cd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/satosa/micro_services/test_attribute_modifications.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
from satosa.exception import SATOSAError
13
from satosa.internal import AuthenticationInformation
24
from satosa.internal import InternalData
35
from satosa.micro_services.attribute_modifications import FilterAttributeValues
@@ -116,3 +118,43 @@ def test_filter_one_attribute_for_one_target_provider_for_one_requester(self):
116118
}
117119
filtered = filter_service.process(None, resp)
118120
assert filtered.attributes == {"a1": ["1:foo:bar:2"]}
121+
122+
def test_filter_one_attribute_from_all_target_providers_for_all_requesters_in_extended_notation(self):
123+
attribute_filters = {
124+
"": {
125+
"": {
126+
"a2": {
127+
"regexp": "^foo:bar$"
128+
}
129+
}
130+
}
131+
}
132+
filter_service = self.create_filter_service(attribute_filters)
133+
134+
resp = InternalData(AuthenticationInformation())
135+
resp.attributes = {
136+
"a1": ["abc:xyz"],
137+
"a2": ["foo:bar", "1:foo:bar:2"],
138+
}
139+
filtered = filter_service.process(None, resp)
140+
assert filtered.attributes == {"a1": ["abc:xyz"], "a2": ["foo:bar"]}
141+
142+
def test_invalid_filter_type(self):
143+
attribute_filters = {
144+
"": {
145+
"": {
146+
"a2": {
147+
"invalid_filter": None
148+
}
149+
}
150+
}
151+
}
152+
filter_service = self.create_filter_service(attribute_filters)
153+
154+
resp = InternalData(AuthenticationInformation())
155+
resp.attributes = {
156+
"a1": ["abc:xyz"],
157+
"a2": ["foo:bar", "1:foo:bar:2"],
158+
}
159+
with pytest.raises(SATOSAError):
160+
filtered = filter_service.process(None, resp)

0 commit comments

Comments
 (0)