Skip to content

Commit

Permalink
Fix bug in name
Browse files Browse the repository at this point in the history
  • Loading branch information
ajermaky committed Jul 3, 2024
1 parent 76eb6ae commit 765ea8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/py/reddit_edgecontext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ def name(self) -> str:
service.
"""
subject = self.authentication_token.subject
if subject is None or subject == "":
if not self.is_service():
raise NoAuthenticationError
subject = self.authentication_token.subject
name = subject[len("service/") :]
return name

Expand Down
8 changes: 8 additions & 0 deletions lib/py/tests/edge_context_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def test_logged_out_user(self):
"device_id": self.DEVICE_ID,
},
)
with self.assertRaises(NoAuthenticationError):
request_context.service.name

def test_logged_in_user(self):
request_context = self.factory.from_upstream(SERIALIZED_EDGECONTEXT_WITH_VALID_AUTH)
Expand Down Expand Up @@ -285,6 +287,8 @@ def test_logged_in_user(self):
"device_id": self.DEVICE_ID,
},
)
with self.assertRaises(NoAuthenticationError):
request_context.service.name

def test_expired_token(self):
request_context = self.factory.from_upstream(SERIALIZED_EDGECONTEXT_WITH_EXPIRED_AUTH)
Expand Down Expand Up @@ -349,6 +353,8 @@ def test_service_auth(self):
self.assertEqual(request_context.service.on_behalf_of_id, None)
self.assertEqual(request_context.service.on_behalf_of_roles, None)
self.assertEqual(request_context.service.requests_elevated_access, None)
with self.assertRaises(NoAuthenticationError):
request_context.user.id

def test_service_auth_with_additional_options(self):
request_context = self.factory.from_upstream(
Expand All @@ -359,3 +365,5 @@ def test_service_auth_with_additional_options(self):
self.assertEqual(request_context.service.on_behalf_of_id, "t2_deadbeef")
self.assertEqual(request_context.service.on_behalf_of_roles, ["admin"])
self.assertEqual(request_context.service.requests_elevated_access, True)
with self.assertRaises(NoAuthenticationError):
request_context.user.id

0 comments on commit 765ea8c

Please sign in to comment.