Skip to content

Commit 2db8008

Browse files
author
Roland Hedberg
committed
More user friendly error message.
1 parent 692aaac commit 2db8008

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/saml2/assertion.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,33 @@ def filter_on_attributes(ava, required=None, optional=None, acs=None):
9393
if required is None:
9494
required = []
9595

96+
nform = "friendly_name"
9697
for attr in required:
97-
found = False
98-
nform = ""
99-
for nform in ["friendly_name", "name"]:
100-
try:
101-
_name = attr[nform]
102-
except KeyError:
103-
if nform == "friendly_name":
104-
_name = get_local_name(acs, attr["name"],
105-
attr["name_format"])
106-
else:
107-
continue
98+
try:
99+
_name = attr[nform]
100+
except KeyError:
101+
if nform == "friendly_name":
102+
_name = get_local_name(acs, attr["name"],
103+
attr["name_format"])
104+
else:
105+
continue
108106

109-
_fn = _match(_name, ava)
110-
if _fn:
111-
try:
112-
values = [av["text"] for av in attr["attribute_value"]]
113-
except KeyError:
114-
values = []
115-
res[_fn] = _filter_values(ava[_fn], values, True)
116-
found = True
117-
break
107+
_fn = _match(_name, ava)
108+
if not _fn: # In the unlikely case that someone has provided us
109+
# with URIs as attribute names
110+
_fn = _match(attr["name"], ava)
118111

119-
if not found:
120-
raise MissingValue("Required attribute missing: '%s'" % (
121-
attr[nform],))
112+
if _fn:
113+
try:
114+
values = [av["text"] for av in attr["attribute_value"]]
115+
except KeyError:
116+
values = []
117+
res[_fn] = _filter_values(ava[_fn], values, True)
118+
continue
119+
else:
120+
desc = "Required attribute missing: '%s' (%s)" % (attr["name"],
121+
_name)
122+
raise MissingValue(desc)
122123

123124
if optional is None:
124125
optional = []

0 commit comments

Comments
 (0)