diff --git a/src/pyrad3/dictionary.py b/src/pyrad3/dictionary.py index 71ec478..115cb15 100644 --- a/src/pyrad3/dictionary.py +++ b/src/pyrad3/dictionary.py @@ -454,7 +454,7 @@ class Dictionary: self.cur_vendor.attrs[attrcode] = attribute if self.cur_vendor != self.rfc_vendor: - codes = [26] + codes + codes = [26, self.cur_vendor.code] + codes attrcode = codes[0] if len(codes) == 1 else tuple(codes) self.attrindex[attrcode] = attribute self.attrindex[name] = attribute diff --git a/tests/test_dictionary.py b/tests/test_dictionary.py index 6271329..98feb83 100644 --- a/tests/test_dictionary.py +++ b/tests/test_dictionary.py @@ -377,3 +377,34 @@ def test_invalid_attribute_flags(invalid_flag): dictionary = StringIO(f"ATTRIBUTE NAME 123 octets {invalid_flag}") with pytest.raises(ParseError): Dictionary("", dictionary) + + +@pytest.mark.parametrize( + "attribute", ["RFC-ATTRIBUTE", "VENDOR-ATTRIBUTE", 7, (26, 5555, 7)] +) +def test_get_attributes_from_dictionaries(attribute): + dictionary = StringIO( + "ATTRIBUTE RFC-ATTRIBUTE 7 integer\n" + "VENDOR TEST-VENDOR 5555\n" + "BEGIN-VENDOR TEST-VENDOR\n" + "ATTRIBUTE VENDOR-ATTRIBUTE 7 integer\n" + "END-VENDOR TEST-VENDOR" + ) + dd = Dictionary("", dictionary) + _ = dd[attribute] + + +@pytest.mark.parametrize( + "attribute", ["RFC-ATTRIBUTE1", 8, (26, 5556, 7), (26, 5555, 8)] +) +def test_get_nonexisting_attributes_from_dictionaries(attribute): + dictionary = StringIO( + "ATTRIBUTE RFC-ATTRIBUTE 7 integer\n" + "VENDOR TEST-VENDOR 5555\n" + "BEGIN-VENDOR TEST-VENDOR\n" + "ATTRIBUTE VENDOR-ATTRIBUTE 7 integer\n" + "END-VENDOR TEST-VENDOR" + ) + dd = Dictionary("", dictionary) + with pytest.raises(KeyError): + _ = dd[attribute]