@@ -326,6 +326,27 @@ def test_get_tenant_instance_from_headers(auth_value, tenant_id):
326326 # -> the get function is called with the tenant ID
327327 c8y_factory ._get_tenant_instance .assert_called_once_with (tenant_id )
328328
329+ @mock .patch .dict (os .environ , env_multi_tenant , clear = True )
330+ def test_get_tenant_instance_missing_auth_info ():
331+ """Verify that missing auth information from headers or cookies is
332+ reported correctly."""
333+ c8y_factory = MultiTenantCumulocityApp ()
334+
335+ # missing auth information in headers
336+ with pytest .raises (KeyError ) as e :
337+ c8y_factory .get_tenant_instance (headers = {'random' : 'header' })
338+ assert 'random' in str (e )
339+
340+ # missing auth information in cookies
341+ with pytest .raises (KeyError ) as e :
342+ c8y_factory .get_tenant_instance (cookies = {'random' : 'cookie' })
343+ assert 'random' in str (e )
344+
345+ # missing auth information in headers and cookies
346+ with pytest .raises (KeyError ) as e :
347+ c8y_factory .get_tenant_instance (headers = {'header' : '1' }, cookies = {'cookie' : '2' })
348+ assert 'header' in str (e ) and 'cookie' in str (e )
349+
329350
330351@pytest .mark .parametrize ('auth_value, username' , [
331352 (b64encode ('t12345/some@domain.com:password' ), 't12345/some@domain.com' ),
0 commit comments