File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class IrHttp(models.AbstractModel):
1818
1919 @classmethod
2020 def _auth_method_api_key (cls ):
21- headers = request .httprequest .environ
21+ headers = request .httprequest .headers
2222 api_key = headers .get ("HTTP_API_KEY" )
2323 if api_key :
2424 request .update_env (user = 1 )
Original file line number Diff line number Diff line change 33from odoo .exceptions import AccessError , ValidationError
44from odoo .tests .common import TransactionCase
55
6+ from odoo .addons .website .tools import MockRequest
7+
68
79class TestAuthApiKey (TransactionCase ):
810 @classmethod
@@ -68,3 +70,11 @@ def test_user_archived_unarchived_with_option_off(self):
6870 self .assertEqual (
6971 self .env ["auth.api.key" ]._retrieve_uid_from_api_key ("api_key" ), demo_user .id
7072 )
73+
74+ def test_api_key_headers (self ):
75+ """The API key in the headers is read."""
76+ with MockRequest (self .env ) as mocked_request :
77+ mocked_request .httprequest .headers = {
78+ "HTTP_API_KEY" : self .api_key_good .key ,
79+ }
80+ self .assertTrue (self .env ["ir.http" ]._auth_method_api_key ())
You can’t perform that action at this time.
0 commit comments