Skip to content

Commit 1890abe

Browse files
committed
Actually return token_str from sign() + tests
1 parent aaefa7b commit 1890abe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/swt/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SWT_RSA_SHA256(SWT):
169169
def algorithm(self):
170170
return SWT.ALGORITHM_RSA_SHA256
171171

172-
def sign(self):
172+
def sign(self) -> str:
173173
self._token_claims[self.__class__.exp_claim] = int(time.time()) + self._ttl
174174
self._token_claims_str = urlencode(self._token_claims)
175175
key = RSA.importKey(self.get_private_key())
@@ -179,6 +179,8 @@ def sign(self):
179179
self._token_signature_str = quote(b64encode(self._token_signature))
180180
self._token_str = self._token_claims_str + f'&{self.algorithm}=' + self._token_signature_str
181181

182+
return self.token_str
183+
182184

183185
@property
184186
def is_signed(self) -> bool:

tests/test_swt_rsa_sha256.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ def test_expired_swt_rsa_sha256():
5555
token.ttl = 1
5656
token.set_claim('sub', 42)
5757
token.set_claim('foo', 'bar')
58-
token.sign()
58+
token_str = token.sign()
5959
time.sleep(2)
6060

6161
assert token.is_expired == True, "Token is expired"
6262
assert token.is_signed, "Token is signed"
6363
assert token.is_valid == False, "Token is invalid (signed but expired)"
64+
assert type(token.token_str) == str, "Token serialization is a string (from object)"
65+
assert type(token_str) == str, "Token serialization is a string (from sign method)"
66+
6467

6568
def test_valid_swt_from_string_without_key_locators():
6669
token = SWT_RSA_SHA256(pytest.test_token_str)

0 commit comments

Comments
 (0)