File tree Expand file tree Collapse file tree 6 files changed +19
-17
lines changed
Expand file tree Collapse file tree 6 files changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,7 @@ def __init__(
5252 http_client : HTTPClient ,
5353 ):
5454 self .lock_public_keys = Lock ()
55- # validate project id
56- project_id = project_id or os .getenv ("DESCOPE_PROJECT_ID" , "" )
55+
5756 if not project_id :
5857 raise AuthException (
5958 400 ,
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ def __init__(
3535 auth_management_key : Optional [str ] = None ,
3636 fga_cache_url : Optional [str ] = None ,
3737 ):
38+ # validate project id
39+ project_id = project_id or os .getenv ("DESCOPE_PROJECT_ID" , "" )
40+ if not project_id :
41+ raise AuthException (
42+ 400 ,
43+ ERROR_TYPE_INVALID_ARGUMENT ,
44+ (
45+ "Unable to init DescopeClient because project_id cannot be empty. "
46+ "Set environment variable DESCOPE_PROJECT_ID or pass your Project ID to the init function."
47+ ),
48+ )
49+
3850 # Auth Initialization
3951 auth_http_client = HTTPClient (
4052 project_id = project_id ,
Original file line number Diff line number Diff line change @@ -53,8 +53,6 @@ def __init__(
5353 secure : bool = True ,
5454 management_key : Optional [str ] = None ,
5555 ) -> None :
56- # validate project id
57- project_id = project_id or os .getenv ("DESCOPE_PROJECT_ID" , "" )
5856 if not project_id :
5957 raise AuthException (
6058 400 ,
Original file line number Diff line number Diff line change 11import json
2- import os
32import unittest
43from enum import Enum
54from http import HTTPStatus
@@ -134,12 +133,7 @@ def test_fetch_public_key(self):
134133 mock_get .return_value .text = valid_keys_response
135134 self .assertIsNone (auth ._fetch_public_keys ())
136135
137- def test_project_id_from_env (self ):
138- os .environ ["DESCOPE_PROJECT_ID" ] = self .dummy_project_id
139- Auth (http_client = self .make_http_client ())
140-
141- def test_project_id_from_env_without_env (self ):
142- os .environ ["DESCOPE_PROJECT_ID" ] = ""
136+ def test_empty_project_id (self ):
143137 self .assertRaises (AuthException , Auth , http_client = self .make_http_client ())
144138
145139 def test_base_url_for_project_id (self ):
Original file line number Diff line number Diff line change 11import json
2+ import os
23import sys
34import unittest
45from copy import deepcopy
@@ -69,6 +70,10 @@ def test_descope_client(self):
6970 DescopeClient (project_id = "dummy" , public_key = self .public_key_str )
7071 )
7172
73+ def test_project_id_from_env_without_env (self ):
74+ os .environ ["DESCOPE_PROJECT_ID" ] = ""
75+ self .assertRaises (AuthException , DescopeClient , "" )
76+
7277 def test_mgmt (self ):
7378 client = DescopeClient (self .dummy_project_id , self .public_key_dict )
7479
Original file line number Diff line number Diff line change 11import importlib
22import importlib .util
3- import os
43import sys
54import types
65import unittest
76
8- from descope import AuthException
97from descope .http_client import HTTPClient
108
119
@@ -17,10 +15,6 @@ def test_base_url_for_project_id(self):
1715 pid = "Puse12aAc4T2V93bddihGEx2Ryhc8e5Z"
1816 assert HTTPClient .base_url_for_project_id (pid ) == "https://api.use1.descope.com"
1917
20- def test_project_id_from_env_without_env (self ):
21- os .environ ["DESCOPE_PROJECT_ID" ] = ""
22- self .assertRaises (AuthException , HTTPClient , "" )
23-
2418 @unittest .skipIf (
2519 importlib .util .find_spec ("importlib.metadata" ) is not None ,
2620 "Stdlib metadata available; skip fallback path test" ,
You can’t perform that action at this time.
0 commit comments