66
77from fastapi_cloud_cli .utils .auth import (
88 AuthConfig ,
9- is_logged_in ,
10- is_token_expired ,
9+ Identity ,
10+ _is_token_expired ,
1111 write_auth_config ,
1212)
1313
@@ -19,21 +19,21 @@ def test_is_token_expired_with_valid_token() -> None:
1919
2020 token = create_jwt_token ({"exp" : future_exp , "sub" : "test_user" })
2121
22- assert not is_token_expired (token )
22+ assert not _is_token_expired (token )
2323
2424
2525def test_is_token_expired_with_expired_token () -> None :
2626 past_exp = int (time .time ()) - 3600
2727 token = create_jwt_token ({"exp" : past_exp , "sub" : "test_user" })
2828
29- assert is_token_expired (token )
29+ assert _is_token_expired (token )
3030
3131
3232def test_is_token_expired_with_no_exp_claim () -> None :
3333 token = create_jwt_token ({"sub" : "test_user" })
3434
3535 # Tokens without exp claim should be considered valid
36- assert not is_token_expired (token )
36+ assert not _is_token_expired (token )
3737
3838
3939@pytest .mark .parametrize (
@@ -47,12 +47,12 @@ def test_is_token_expired_with_no_exp_claim() -> None:
4747 ],
4848)
4949def test_is_token_expired_with_malformed_token (token : str ) -> None :
50- assert is_token_expired (token )
50+ assert _is_token_expired (token )
5151
5252
5353def test_is_token_expired_with_invalid_base64 () -> None :
5454 token = "header.!!!invalid_signature!!!.signature"
55- assert is_token_expired (token )
55+ assert _is_token_expired (token )
5656
5757
5858def test_is_token_expired_with_invalid_json () -> None :
@@ -61,12 +61,26 @@ def test_is_token_expired_with_invalid_json() -> None:
6161 signature = base64 .urlsafe_b64encode (b"signature" ).decode ().rstrip ("=" )
6262 token = f"{ header_encoded } .{ payload_encoded } .{ signature } "
6363
64- assert is_token_expired (token )
64+ assert _is_token_expired (token )
65+
66+
67+ def test_is_token_expired_edge_case_exact_expiration () -> None :
68+ current_time = int (time .time ())
69+ token = create_jwt_token ({"exp" : current_time , "sub" : "test_user" })
70+
71+ assert _is_token_expired (token )
72+
73+
74+ def test_is_token_expired_edge_case_one_second_before () -> None :
75+ current_time = int (time .time ())
76+ token = create_jwt_token ({"exp" : current_time + 1 , "sub" : "test_user" })
77+
78+ assert not _is_token_expired (token )
6579
6680
6781def test_is_logged_in_with_no_token (temp_auth_config : Path ) -> None :
6882 assert not temp_auth_config .exists ()
69- assert not is_logged_in ()
83+ assert not Identity (). is_logged_in ()
7084
7185
7286def test_is_logged_in_with_valid_token (temp_auth_config : Path ) -> None :
@@ -75,7 +89,7 @@ def test_is_logged_in_with_valid_token(temp_auth_config: Path) -> None:
7589
7690 write_auth_config (AuthConfig (access_token = token ))
7791
78- assert is_logged_in ()
92+ assert Identity (). is_logged_in ()
7993
8094
8195def test_is_logged_in_with_expired_token (temp_auth_config : Path ) -> None :
@@ -84,24 +98,10 @@ def test_is_logged_in_with_expired_token(temp_auth_config: Path) -> None:
8498
8599 write_auth_config (AuthConfig (access_token = token ))
86100
87- assert not is_logged_in ()
101+ assert not Identity (). is_logged_in ()
88102
89103
90104def test_is_logged_in_with_malformed_token (temp_auth_config : Path ) -> None :
91105 write_auth_config (AuthConfig (access_token = "not.a.valid.token" ))
92106
93- assert not is_logged_in ()
94-
95-
96- def test_is_token_expired_edge_case_exact_expiration () -> None :
97- current_time = int (time .time ())
98- token = create_jwt_token ({"exp" : current_time , "sub" : "test_user" })
99-
100- assert is_token_expired (token )
101-
102-
103- def test_is_token_expired_edge_case_one_second_before () -> None :
104- current_time = int (time .time ())
105- token = create_jwt_token ({"exp" : current_time + 1 , "sub" : "test_user" })
106-
107- assert not is_token_expired (token )
107+ assert not Identity ().is_logged_in ()
0 commit comments