1
1
from __future__ import absolute_import
2
2
3
3
import unittest
4
+ import unittest .mock
4
5
5
6
from authress .api import token_verifier
6
7
@@ -22,5 +23,27 @@ def test_get_token_for_eddsa(self):
22
23
access_key = 'CLIENT.KEY.ACCOUNT.MC4CAQAwBQYDK2VwBCIEIDVjjrIVCH3dVRq4ixRzBwjVHSoB2QzZ2iJuHq1Wshwp'
23
24
publicKey = { 'alg' : 'EdDSA' , 'kty' : 'OKP' , 'crv' : 'Ed25519' , 'x' : 'JxtSC5tZZJuaW7Aeu5Kh_3tgCpPZRkHaaFyTj5sQ3KU' }
24
25
25
- identity = token_verifier .TokenVerifier ().verify_token (authressCustomDomain = f"https://{ customDomain } " , token = access_key , options = { 'expectedPublicKey' : publicKey })
26
- assert identity ['iss' ] == f'https://{ customDomain } /v1/clients/CLIENT'
26
+ token_verifier_instance = token_verifier .TokenVerifier ()
27
+
28
+ mock_get_key_uncached = unittest .mock .MagicMock (return_value = publicKey )
29
+ token_verifier_instance .get_key_uncached = mock_get_key_uncached
30
+ identity = token_verifier_instance .verify_token (authressCustomDomain = f"https://{ customDomain } " , token = access_key )
31
+
32
+ mock_get_key_uncached .assert_called_once_with (f"https://{ customDomain } /v1/clients/CLIENT/.well-known/openid-configuration/jwks" , "KEY" )
33
+ assert identity ['iss' ] == f'https://{ customDomain } /v1/clients/CLIENT'
34
+ assert identity ['sub' ] == "CLIENT"
35
+
36
+ def test_get_public_key (self ):
37
+ token_verifier_instance = token_verifier .TokenVerifier ()
38
+
39
+ test_key_value = "TestKeyValue"
40
+ mock_get_key_uncached = unittest .mock .MagicMock (return_value = test_key_value )
41
+ token_verifier_instance .get_key_uncached = mock_get_key_uncached
42
+
43
+ public_key_1 = token_verifier_instance .get_public_key (f'https://{ customDomain } /v1/clients/CLIENT' , "Test KID" )
44
+ public_key_2 = token_verifier_instance .get_public_key (f'https://{ customDomain } /v1/clients/CLIENT' , "Test KID" )
45
+
46
+ mock_get_key_uncached .assert_called_once_with (f'https://{ customDomain } /v1/clients/CLIENT' , "Test KID" )
47
+
48
+ assert public_key_1 == public_key_2
49
+ assert public_key_1 == test_key_value
0 commit comments