Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Nov 14, 2023
1 parent 05a234c commit c4b8df5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class VideoGrants:
@dataclasses.dataclass
class Claims:
exp: int = 0
iss: str = "" # api key
iss: str = "" # api key
nbf: int = 0
sub: str = "" # identity
sub: str = "" # identity

name: str = ""
video: VideoGrants = dataclasses.field(default_factory=VideoGrants)
Expand Down Expand Up @@ -165,7 +165,8 @@ def verify(self, token: str) -> Claims:


def camel_to_snake(str):
return re.sub(r'(?<!^)(?=[A-Z])', '_', str).lower()
return re.sub(r"(?<!^)(?=[A-Z])", "_", str).lower()


def snake_to_camel(str):
return ''.join(word.title() for word in name.split('_'))
return "".join(word.title() for word in name.split("_"))

Check failure on line 172 in livekit-api/livekit/api/access_token.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F821)

livekit-api/livekit/api/access_token.py:172:45: F821 Undefined name `name`
11 changes: 9 additions & 2 deletions livekit-api/tests/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_verify_token():

token_verifier = TokenVerifier(TEST_API_KEY, TEST_API_SECRET)
claims = token_verifier.verify(token)

assert claims.sub == "test_identity"
assert claims.metadata == "test_metadata"
assert claims.video == grants
Expand All @@ -36,6 +36,11 @@ def test_verify_token_invalid():
with pytest.raises(Exception):
token_verifier.verify(token)

token_verifier = TokenVerifier("invalid_key", TEST_API_SECRET)
with pytest.raises(Exception):
token_verifier.verify(token)


def test_verify_token_expired():
token = (
AccessToken(TEST_API_KEY, TEST_API_SECRET)
Expand All @@ -44,6 +49,8 @@ def test_verify_token_expired():
.to_jwt()
)

token_verifier = TokenVerifier(TEST_API_KEY, TEST_API_SECRET, leeway=datetime.timedelta(seconds=0))
token_verifier = TokenVerifier(
TEST_API_KEY, TEST_API_SECRET, leeway=datetime.timedelta(seconds=0)
)
with pytest.raises(Exception):
token_verifier.verify(token)

0 comments on commit c4b8df5

Please sign in to comment.