1- from shopify . utils import *
1+ from shopify import session_token
22from test .test_helper import TestCase
33from datetime import datetime , timedelta
44
@@ -13,7 +13,7 @@ def timestamp(date):
1313 return time .mktime (date .timetuple ()) if sys .version_info [0 ] < 3 else date .timestamp ()
1414
1515
16- class TestSessionTokenUtilityGetDecodedSessionToken (TestCase ):
16+ class TestSessionTokenGetDecodedSessionToken (TestCase ):
1717 @classmethod
1818 def setUpClass (self ):
1919 self .secret = "API Secret"
@@ -42,45 +42,45 @@ def build_auth_header(self):
4242 def test_raises_if_token_authentication_header_is_not_bearer (self ):
4343 authorization_header = "Bad auth header"
4444
45- with self .assertRaises (TokenAuthenticationError ):
46- SessionTokenUtility .get_decoded_session_token (
47- authorization_header , api_key = self . api_key , secret = self . secret
48- )
45+ with self .assertRaises (session_token . TokenAuthenticationError ) as cm :
46+ session_token .get_decoded_session_token (authorization_header , api_key = self . api_key , secret = self . secret )
47+
48+ self . assertEqual ( "The HTTP_AUTHORIZATION_HEADER provided does not contain a Bearer token" , str ( cm . exception ) )
4949
5050 def test_raises_jwt_error_if_session_token_is_expired (self ):
5151 self .payload ["exp" ] = timestamp ((datetime .now () + timedelta (0 , - 10 )))
5252
53- with self .assertRaises (jwt . exceptions . ExpiredSignatureError ) :
54- SessionTokenUtility .get_decoded_session_token (
55- self . build_auth_header (), api_key = self . api_key , secret = self . secret
56- )
53+ with self .assertRaises (session_token . SessionTokenError , msg = "Expird" ) as cm :
54+ session_token .get_decoded_session_token (self . build_auth_header (), api_key = self . api_key , secret = self . secret )
55+
56+ self . assertEqual ( "Signature has expired" , str ( cm . exception ) )
5757
5858 def test_raises_if_aud_doesnt_match_api_key (self ):
5959 self .payload ["aud" ] = "bad audience"
6060
61- with self .assertRaises (jwt . exceptions . InvalidAudienceError ) :
62- SessionTokenUtility .get_decoded_session_token (
63- self . build_auth_header (), api_key = self . api_key , secret = self . secret
64- )
61+ with self .assertRaises (session_token . SessionTokenError ) as cm :
62+ session_token .get_decoded_session_token (self . build_auth_header (), api_key = self . api_key , secret = self . secret )
63+
64+ self . assertEqual ( "Invalid audience" , str ( cm . exception ) )
6565
6666 def test_raises_if_issuer_hostname_is_invalid (self ):
6767 self .payload ["iss" ] = "bad_shop_hostname"
6868
69- with self .assertRaises (InvalidIssuerError ):
70- SessionTokenUtility .get_decoded_session_token (
71- self . build_auth_header (), api_key = self . api_key , secret = self . secret
72- )
69+ with self .assertRaises (session_token . InvalidIssuerError ) as cm :
70+ session_token .get_decoded_session_token (self . build_auth_header (), api_key = self . api_key , secret = self . secret )
71+
72+ self . assertEqual ( "Invalid issuer" , str ( cm . exception ) )
7373
7474 def test_raises_if_iss_and_dest_dont_match (self ):
7575 self .payload ["dest" ] = "bad_shop.myshopify.com"
7676
77- with self .assertRaises (MismatchedHostsError ):
78- SessionTokenUtility .get_decoded_session_token (
79- self . build_auth_header (), api_key = self . api_key , secret = self . secret
80- )
77+ with self .assertRaises (session_token . MismatchedHostsError ) as cm :
78+ session_token .get_decoded_session_token (self . build_auth_header (), api_key = self . api_key , secret = self . secret )
79+
80+ self . assertEqual ( "The issuer and destination do not match" , str ( cm . exception ) )
8181
8282 def test_returns_decoded_payload (self ):
83- decoded_payload = SessionTokenUtility .get_decoded_session_token (
83+ decoded_payload = session_token .get_decoded_session_token (
8484 self .build_auth_header (), api_key = self .api_key , secret = self .secret
8585 )
8686
0 commit comments