Skip to content

Commit 9784ae4

Browse files
committed
fix: add public type property to AuthenticationMethod base class
The _type class attribute was private, causing AttributeError when examples or user code accessed auth.type. Add a @Property that exposes it as a read-only public attribute.
1 parent ddcc6f6 commit 9784ae4

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/didww/resources/authentication_method.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class AuthenticationMethod:
66
def __init__(self, **kwargs):
77
self._attributes = kwargs
88

9+
@property
10+
def type(self):
11+
return self._type
12+
913
def _attr(self, key):
1014
return self._attributes.get(key)
1115

tests/resources/test_voice_out_trunk.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,18 @@ def test_to_jsonapi_roundtrip(self):
165165
auth = IpOnlyAuthenticationMethod(allowed_sip_ips=["10.0.0.0/8"], tech_prefix="")
166166
serialized = auth.to_jsonapi()
167167
assert serialized == {"type": "ip_only", "attributes": {"allowed_sip_ips": ["10.0.0.0/8"], "tech_prefix": ""}}
168+
169+
def test_type_property_on_known_subclass(self):
170+
auth = IpOnlyAuthenticationMethod(allowed_sip_ips=["203.0.113.0/24"])
171+
assert auth.type == "ip_only"
172+
173+
def test_type_property_on_credentials_and_ip(self):
174+
auth = CredentialsAndIpAuthenticationMethod(
175+
allowed_sip_ips=["203.0.113.0/24"], username="u", password="p",
176+
)
177+
assert auth.type == "credentials_and_ip"
178+
179+
def test_type_property_on_generic(self):
180+
data = {"type": "future_auth", "attributes": {"key": "val"}}
181+
auth = AuthenticationMethod.from_jsonapi(data)
182+
assert auth.type == "future_auth"

0 commit comments

Comments
 (0)