Unknown attribute causes exception
The following lines causes an exception when a unknown attribute is received from server.
"""
Add an item to attributes (by name or id)
"""
try:
code, name = self.__getkeys(key)
except KeyError:
raise ValueError('Invalid radius attribute: %s' % key)
values = self.get(code, [])
values.append(value)
UserDict.__setitem__(self, code, values)
The correct, in my opinion, is log a warning and continue the authentication. That lib does not need to validate the attributes, this is responsibility of the application using py-radius.
try:
code, name = self.__getkeys(key)
values = self.get(code, [])
values.append(value)
UserDict.__setitem__(self, code, values)
except KeyError:
LOGGER.warning('Invalid radius attribute: %s' % key)
Good point, your solution still validates the attributes, disallowing caller from using unknown attributes.
I think if key is a code, we can warn via logger and proceed to add the attribute anyway. When key is a name, it must be known so we can look up the code.
https://github.com/btimby/py-radius/pull/10
Does the PR address your problem?
Thanks @btimby. Your solution looks better.
As soon as possible I will update my code to validate the behavior.
@mqgmaster Thank you sir! Please let me know.