@@ -186,15 +186,31 @@ def test_validate_credentials_with_invalid_dict_context_key(self):
186186 SkyflowMessages .Error .INVALID_CTX_MAP_KEY .value .format ("invalid key" )
187187 )
188188
189- def test_validate_credentials_with_invalid_context_type (self ):
190- for invalid_context in [123 , ["user_12345" ], True ]:
191- credentials = {
192- "api_key" : "sky-abc12-1234567890abcdef1234567890abcdef" ,
193- "context" : invalid_context
194- }
195- with self .assertRaises (SkyflowError ) as context :
189+ def test_validate_credentials_with_scalar_context (self ):
190+ """Numbers and booleans are valid ctx claims, so they must not be rejected here.
191+
192+ The token engine and the auth service both accept them; rejecting them would make the
193+ client stricter than generate_bearer_token for no reason. Falsy scalars are included
194+ because nothing on this path may test truthiness.
195+ """
196+ for scalar_context in [123 , 0 , 1.5 , 0.0 , True , False ]:
197+ with self .subTest (context = scalar_context ):
198+ credentials = {
199+ "api_key" : "sky-abc12-1234567890abcdef1234567890abcdef" ,
200+ "context" : scalar_context
201+ }
196202 validate_credentials (self .logger , credentials )
197- self .assertEqual (context .exception .message , SkyflowMessages .Error .INVALID_CONTEXT .value )
203+
204+ def test_validate_credentials_with_invalid_context_type (self ):
205+ for invalid_context in [["user_12345" ], ("user_12345" ,), None , object ()]:
206+ with self .subTest (context = invalid_context ):
207+ credentials = {
208+ "api_key" : "sky-abc12-1234567890abcdef1234567890abcdef" ,
209+ "context" : invalid_context
210+ }
211+ with self .assertRaises (SkyflowError ) as context :
212+ validate_credentials (self .logger , credentials )
213+ self .assertEqual (context .exception .message , SkyflowMessages .Error .INVALID_CONTEXT .value )
198214
199215 def test_validate_credentials_with_dict_context_in_config (self ):
200216 """Config-scoped messages are used when a config id is available."""
0 commit comments