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,8 +18,8 @@ class IrHttp(models.AbstractModel):
1818
1919 @classmethod
2020 def _auth_method_api_key (cls ):
21- headers = request .httprequest .environ
22- api_key = headers .get ("HTTP_API_KEY " )
21+ headers = request .httprequest .headers
22+ api_key = headers .get ("API_KEY " )
2323 if api_key :
2424 request .update_env (user = 1 )
2525 auth_api_key = request .env ["auth.api.key" ]._retrieve_api_key (api_key )
Original file line number Diff line number Diff line change 11# Copyright 2018 ACSONE SA/NV
22# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
4+ from werkzeug .datastructures import EnvironHeaders
5+
36from odoo .exceptions import AccessError , ValidationError
47from odoo .tests .common import TransactionCase
58
9+ from odoo .addons .website .tools import MockRequest
10+
611
712class TestAuthApiKey (TransactionCase ):
813 @classmethod
@@ -68,3 +73,12 @@ def test_user_archived_unarchived_with_option_off(self):
6873 self .assertEqual (
6974 self .env ["auth.api.key" ]._retrieve_uid_from_api_key ("api_key" ), demo_user .id
7075 )
76+
77+ def test_api_key_headers (self ):
78+ """The API key in the headers is read."""
79+ with MockRequest (self .env ) as mocked_request :
80+ mocked_request .httprequest .environ ["HTTP_API_KEY" ] = self .api_key_good .key
81+ mocked_request .httprequest .headers = EnvironHeaders (
82+ mocked_request .httprequest .environ
83+ )
84+ self .assertTrue (self .env ["ir.http" ]._auth_method_api_key ())
You can’t perform that action at this time.
0 commit comments