2626os .environ [test_v1_env_var_name ] = test_encoded_v1_token .decode ("utf-8" )
2727
2828# For v2 API key tests
29- test_v2_key_message = {"t" : "g" , "id " : "some-id" }
29+ test_v2_key_message = {"t" : "g" , "jti " : "some-id" }
3030test_v2_api_key = jwt .encode (test_v2_key_message , "secret" , algorithm = "HS512" )
31- test_v2_key_env_var_name = uuid_str ()
31+ test_v2_key_env_var_name = "MOMENTO_API_KEY"
3232test_v2_endpoint = "testEndpoint"
33- test_v2_endpoint_env_var_name = uuid_str ()
33+ test_v2_endpoint_env_var_name = "MOMENTO_ENDPOINT"
3434os .environ [test_v2_key_env_var_name ] = test_v2_api_key
3535os .environ [test_v2_endpoint_env_var_name ] = test_v2_endpoint
3636
@@ -113,7 +113,6 @@ def test_env_token_raises_if_not_exists() -> None:
113113@pytest .mark .parametrize (
114114 "provider, expected_api_key, expected_control_endpoint, expected_cache_endpoint, expected_token_endpoint" ,
115115 [
116- # v2_key_from_string - basic usage
117116 (
118117 CredentialProvider .from_api_key_v2 (
119118 api_key = test_v2_api_key ,
@@ -124,9 +123,8 @@ def test_env_token_raises_if_not_exists() -> None:
124123 f"cache.{ test_v2_endpoint } " ,
125124 f"token.{ test_v2_endpoint } " ,
126125 ),
127- # v2_key_from_environment_variable - basic usage
128126 (
129- CredentialProvider .from_env_var_v2 (
127+ CredentialProvider .from_environment_variables_v2 (
130128 api_key_env_var = test_v2_key_env_var_name ,
131129 endpoint_env_var = test_v2_endpoint_env_var_name ,
132130 ),
@@ -135,6 +133,13 @@ def test_env_token_raises_if_not_exists() -> None:
135133 f"cache.{ test_v2_endpoint } " ,
136134 f"token.{ test_v2_endpoint } " ,
137135 ),
136+ (
137+ CredentialProvider .from_environment_variables_v2 (),
138+ test_v2_api_key ,
139+ f"control.{ test_v2_endpoint } " ,
140+ f"cache.{ test_v2_endpoint } " ,
141+ f"token.{ test_v2_endpoint } " ,
142+ ),
138143 ],
139144)
140145def test_v2_api_key_endpoints (
@@ -162,24 +167,28 @@ def test_v2_key_from_string_raises_if_endpoint_empty() -> None:
162167
163168def test_v2_key_from_env_raises_if_env_var_name_empty () -> None :
164169 with pytest .raises (InvalidArgumentException , match = "API key environment variable name cannot be empty" ):
165- CredentialProvider .from_env_var_v2 (api_key_env_var = "" , endpoint_env_var = test_v2_endpoint_env_var_name )
170+ CredentialProvider .from_environment_variables_v2 (
171+ api_key_env_var = "" , endpoint_env_var = test_v2_endpoint_env_var_name
172+ )
166173
167174
168175def test_v2_key_from_env_raises_if_env_var_missing () -> None :
169176 with pytest .raises (RuntimeError , match = "Missing required environment variable" ):
170- CredentialProvider .from_env_var_v2 (api_key_env_var = uuid_str (), endpoint_env_var = test_v2_endpoint_env_var_name )
177+ CredentialProvider .from_environment_variables_v2 (
178+ api_key_env_var = uuid_str (), endpoint_env_var = test_v2_endpoint_env_var_name
179+ )
171180
172181
173182def test_v2_key_from_env_raises_if_endpoint_empty () -> None :
174183 with pytest .raises (InvalidArgumentException , match = "Endpoint environment variable name cannot be empty" ):
175- CredentialProvider .from_env_var_v2 (api_key_env_var = test_v2_key_env_var_name , endpoint_env_var = "" )
184+ CredentialProvider .from_environment_variables_v2 (api_key_env_var = test_v2_key_env_var_name , endpoint_env_var = "" )
176185
177186
178187def test_v2_key_from_env_raises_if_api_key_empty_string () -> None :
179188 empty_api_key_env_var = uuid_str ()
180189 os .environ [empty_api_key_env_var ] = ""
181190 with pytest .raises (RuntimeError , match = "Missing required environment variable" ):
182- CredentialProvider .from_env_var_v2 (
191+ CredentialProvider .from_environment_variables_v2 (
183192 api_key_env_var = empty_api_key_env_var , endpoint_env_var = test_v2_endpoint_env_var_name
184193 )
185194
@@ -203,7 +212,7 @@ def test_v2_key_from_env_raises_if_base64_api_key() -> None:
203212 "Received an invalid v2 API key. Are you using the correct key? Or did you mean to use `from_environment_variable()` with a legacy key instead?"
204213 ),
205214 ):
206- CredentialProvider .from_env_var_v2 (
215+ CredentialProvider .from_environment_variables_v2 (
207216 api_key_env_var = test_v1_env_var_name , endpoint_env_var = test_v2_endpoint_env_var_name
208217 )
209218
@@ -225,7 +234,7 @@ def test_v2_key_from_env_raises_if_pre_v1_token() -> None:
225234 "Received an invalid v2 API key. Are you using the correct key? Or did you mean to use `from_environment_variable()` with a legacy key instead?"
226235 ),
227236 ):
228- CredentialProvider .from_env_var_v2 (
237+ CredentialProvider .from_environment_variables_v2 (
229238 api_key_env_var = test_env_var_name , endpoint_env_var = test_v2_endpoint_env_var_name
230239 )
231240
@@ -234,7 +243,7 @@ def test_v2_key_provided_to_from_string() -> None:
234243 with pytest .raises (
235244 InvalidArgumentException ,
236245 match = re .escape (
237- "Received a v2 API key. Are you using the correct key? Or did you mean to use `from_api_key_v2()` or `from_env_var_v2 ()` instead?"
246+ "Received a v2 API key. Are you using the correct key? Or did you mean to use `from_api_key_v2()` or `from_environment_variables_v2 ()` instead?"
238247 ),
239248 ):
240249 CredentialProvider .from_string (auth_token = test_v2_api_key )
@@ -244,7 +253,7 @@ def test_v2_key_provided_to_from_disposable_token() -> None:
244253 with pytest .raises (
245254 InvalidArgumentException ,
246255 match = re .escape (
247- "Received a v2 API key. Are you using the correct key? Or did you mean to use `from_api_key_v2()` or `from_env_var_v2 ()` instead?"
256+ "Received a v2 API key. Are you using the correct key? Or did you mean to use `from_api_key_v2()` or `from_environment_variables_v2 ()` instead?"
248257 ),
249258 ):
250259 CredentialProvider .from_disposable_token (auth_token = test_v2_api_key )
0 commit comments