Skip to content

Commit d9516b0

Browse files
committed
[FIX] auth_api_key: Read API key from headers
1 parent 6c7d03e commit d9516b0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

auth_api_key/models/ir_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)

auth_api_key/tests/test_auth_api_key.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from odoo.exceptions import AccessError, ValidationError
44
from odoo.tests.common import TransactionCase
55

6+
from odoo.addons.website.tools import MockRequest
7+
68

79
class 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())

0 commit comments

Comments
 (0)