Skip to content

Commit 5591eaa

Browse files
committed
[MIG] endpoint_auth_api_key: Migration to 19.0
1 parent b106e9f commit 5591eaa

9 files changed

Lines changed: 130 additions & 81 deletions

File tree

endpoint_auth_api_key/README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Endpoint Auth API key
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
24-
:target: https://github.com/OCA/web-api/tree/18.0/endpoint_auth_api_key
24+
:target: https://github.com/OCA/web-api/tree/19.0/endpoint_auth_api_key
2525
:alt: OCA/web-api
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-endpoint_auth_api_key
27+
:target: https://translation.odoo-community.org/projects/web-api-19-0/web-api-19-0-endpoint_auth_api_key
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -50,7 +50,7 @@ Bug Tracker
5050
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
5151
In case of trouble, please check there if your issue has already been reported.
5252
If you spotted it first, help us to smash it by providing a detailed and welcomed
53-
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint_auth_api_key%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
53+
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint_auth_api_key%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
5454

5555
Do not contact contributors directly about support or help with technical issues.
5656

@@ -74,8 +74,7 @@ Contributors
7474
Other credits
7575
-------------
7676

77-
The migration of this module from 14.0 to 16.0 was financially supported
78-
by Camptocamp
77+
7978

8079
Maintainers
8180
-----------
@@ -98,6 +97,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
9897

9998
|maintainer-simahawk|
10099

101-
This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/18.0/endpoint_auth_api_key>`_ project on GitHub.
100+
This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/19.0/endpoint_auth_api_key>`_ project on GitHub.
102101

103102
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

endpoint_auth_api_key/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
{
55
"name": "Endpoint Auth API key",
66
"summary": """Provide API key auth for endpoints.""",
7-
"version": "18.0.1.0.1",
7+
"version": "19.0.1.0.0",
88
"license": "LGPL-3",
99
"development_status": "Alpha",
1010
"author": "Camptocamp, Odoo Community Association (OCA)",
1111
"maintainers": ["simahawk"],
1212
"website": "https://github.com/OCA/web-api",
1313
"depends": ["endpoint", "auth_api_key_group"],
14-
"demo": ["demo/api_key_demo.xml", "demo/endpoint_demo.xml"],
1514
"data": ["views/endpoint_view.xml"],
1615
}

endpoint_auth_api_key/demo/api_key_demo.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

endpoint_auth_api_key/demo/endpoint_demo.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
The migration of this module from 14.0 to 16.0 was financially supported
2-
by Camptocamp

endpoint_auth_api_key/static/description/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Endpoint Auth API key</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:cfd515c9f4adfa18204af3865093c9d6d00f92e79b06ce7d7e6ca353a4fc6934
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web-api/tree/18.0/endpoint_auth_api_key"><img alt="OCA/web-api" src="https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-endpoint_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web-api&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web-api/tree/19.0/endpoint_auth_api_key"><img alt="OCA/web-api" src="https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-api-19-0/web-api-19-0-endpoint_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web-api&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>Provide API key auth for endpoints.</p>
379379
<div class="admonition important">
380380
<p class="first admonition-title">Important</p>
@@ -400,7 +400,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h2>
400400
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web-api/issues">GitHub Issues</a>.
401401
In case of trouble, please check there if your issue has already been reported.
402402
If you spotted it first, help us to smash it by providing a detailed and welcomed
403-
<a class="reference external" href="https://github.com/OCA/web-api/issues/new?body=module:%20endpoint_auth_api_key%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
403+
<a class="reference external" href="https://github.com/OCA/web-api/issues/new?body=module:%20endpoint_auth_api_key%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
404404
<p>Do not contact contributors directly about support or help with technical issues.</p>
405405
</div>
406406
<div class="section" id="credits">
@@ -427,8 +427,6 @@ <h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
427427
</div>
428428
<div class="section" id="other-credits">
429429
<h3><a class="toc-backref" href="#toc-entry-5">Other credits</a></h3>
430-
<p>The migration of this module from 14.0 to 16.0 was financially supported
431-
by Camptocamp</p>
432430
</div>
433431
<div class="section" id="maintainers">
434432
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
@@ -441,7 +439,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
441439
promote its widespread use.</p>
442440
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
443441
<p><a class="reference external image-reference" href="https://github.com/simahawk"><img alt="simahawk" src="https://github.com/simahawk.png?size=40px" /></a></p>
444-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web-api/tree/18.0/endpoint_auth_api_key">OCA/web-api</a> project on GitHub.</p>
442+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web-api/tree/19.0/endpoint_auth_api_key">OCA/web-api</a> project on GitHub.</p>
445443
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
446444
</div>
447445
</div>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright 2026 Camptocamp SA
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
import contextlib
4+
5+
from odoo import Command
6+
from odoo.tools import DotDict
7+
8+
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
9+
from odoo.addons.http_routing.tests.common import MockRequest
10+
11+
12+
def _setup_demo_api_keys(env, demo_user):
13+
"""Create demo API keys for tests."""
14+
api_key_model = env["auth.api.key"]
15+
16+
api_key_1 = api_key_model.create(
17+
{
18+
"name": "Endpoint API key demo",
19+
"key": "cZ6dF2UQwNcm",
20+
"user_id": demo_user.id,
21+
}
22+
)
23+
api_key_2 = api_key_model.create(
24+
{
25+
"name": "Endpoint API key demo 2",
26+
"key": "kV47QyOTC5mS",
27+
"user_id": demo_user.id,
28+
}
29+
)
30+
return api_key_1, api_key_2
31+
32+
33+
def _setup_demo_api_key_group(env, api_key_1):
34+
"""Create demo API key group for tests."""
35+
return env["auth.api.key.group"].create(
36+
{
37+
"name": "Demo Group 1",
38+
"code": "demo_group1",
39+
"auth_api_key_ids": [Command.set(api_key_1.ids)],
40+
}
41+
)
42+
43+
44+
def _setup_demo_endpoint(env, api_key_group):
45+
"""Create demo endpoint for tests."""
46+
return env["endpoint.endpoint"].create(
47+
{
48+
"name": "Demo Endpoint - auth api key",
49+
"route": "/demo/api/key",
50+
"request_method": "GET",
51+
"auth_type": "api_key",
52+
"auth_api_key_group_ids": [Command.set(api_key_group.ids)],
53+
"exec_mode": "code",
54+
"code_snippet": 'result = {"response": Response("ok")}',
55+
}
56+
)
57+
58+
59+
class CommonEndpointAuthAPIKey(TransactionCaseWithUserDemo):
60+
@classmethod
61+
def setUpClass(cls):
62+
super().setUpClass()
63+
cls._setup_env()
64+
cls._setup_records()
65+
66+
@classmethod
67+
def _setup_env(cls):
68+
cls.env = cls.env(context=cls._setup_context())
69+
70+
@classmethod
71+
def _setup_context(cls):
72+
return dict(
73+
cls.env.context,
74+
tracking_disable=True,
75+
)
76+
77+
@classmethod
78+
def _setup_records(cls):
79+
cls.api_key, cls.api_key2 = _setup_demo_api_keys(
80+
cls.env,
81+
cls.user_demo,
82+
)
83+
cls.key_group = _setup_demo_api_key_group(
84+
cls.env,
85+
cls.api_key,
86+
)
87+
cls.endpoint = _setup_demo_endpoint(
88+
cls.env,
89+
cls.key_group,
90+
)
91+
92+
@contextlib.contextmanager
93+
def _get_mocked_request(
94+
self, httprequest=None, extra_headers=None, request_attrs=None
95+
):
96+
with MockRequest(self.env) as mocked_request:
97+
mocked_request.httprequest = (
98+
DotDict(httprequest) if httprequest else mocked_request.httprequest
99+
)
100+
headers = {}
101+
headers.update(extra_headers or {})
102+
mocked_request.httprequest.headers = headers
103+
request_attrs = request_attrs or {}
104+
for k, v in request_attrs.items():
105+
setattr(mocked_request, k, v)
106+
mocked_request.make_response = lambda data, **kw: data
107+
yield mocked_request

endpoint_auth_api_key/tests/test_endpoint.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@
77

88
from odoo.tools.misc import mute_logger
99

10-
from odoo.addons.endpoint.tests.common import CommonEndpoint
10+
from .common import CommonEndpointAuthAPIKey
1111

1212

13-
class TestEndpoint(CommonEndpoint):
13+
class TestEndpoint(CommonEndpointAuthAPIKey):
1414
@classmethod
1515
def _setup_records(cls):
16-
super()._setup_records()
17-
cls.endpoint = cls.env.ref("endpoint_auth_api_key.endpoint_demo_1")
18-
cls.key_group = cls.env.ref("endpoint_auth_api_key.auth_api_key_group_demo")
19-
cls.api_key = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo")
20-
cls.api_key2 = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo2")
21-
return
16+
return super()._setup_records()
2217

2318
@mute_logger("endpoint.endpoint")
2419
def test_endpoint_validate_request_no_key(self):

endpoint_auth_api_key/tests/test_endpoint_controller.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
import os
66
import unittest
77

8-
import requests
9-
10-
from odoo import tools
118
from odoo.tests.common import HttpCase
129
from odoo.tools.misc import mute_logger
1310

11+
from .common import CommonEndpointAuthAPIKey
12+
1413

15-
@unittest.skipIf(os.getenv("SKIP_HTTP_CASE"), "EndpoinAuthApikeytHttpCase skipped")
16-
class EndpoinAuthApikeytHttpCase(HttpCase):
14+
@unittest.skipIf(os.getenv("SKIP_HTTP_CASE"), "EndpointAuthApiKeyHttpCase skipped")
15+
class EndpointAuthApiKeyHttpCase(HttpCase, CommonEndpointAuthAPIKey):
1716
@classmethod
1817
def setUpClass(cls):
1918
super().setUpClass()
20-
cls.api_key = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo")
21-
cls.api_key2 = cls.env.ref("endpoint_auth_api_key.auth_api_key_demo2")
2219
# force sync for demo records
2320
cls.env["endpoint.endpoint"].search([])._handle_registry_sync()
2421

@@ -27,30 +24,23 @@ def tearDown(self):
2724
self.env.registry.clear_cache("routing")
2825
super().tearDown()
2926

30-
def _make_url(self, route):
31-
return f"http://127.0.0.1:{tools.config['http_port']}{route}"
32-
3327
def _make_request(self, route, api_key=None, headers=None):
34-
# use requests because you cannot easily manipulate the request w/ `url_open`
35-
headers = headers or {}
28+
headers = dict(headers or {})
3629
if api_key:
37-
headers.update({"API-KEY": api_key.key})
38-
return requests.get(self._make_url(route), headers=headers, timeout=60)
30+
headers["API-KEY"] = api_key.key
31+
return self.url_open(route, headers=headers, timeout=60)
3932

4033
@mute_logger("odoo.addons.auth_api_key.models.ir_http", "odoo.http")
4134
def test_call_no_key(self):
42-
route = "/demo/api/key"
43-
response = self._make_request(route)
35+
response = self._make_request("/demo/api/key")
4436
self.assertEqual(response.status_code, 401)
4537

4638
def test_call_good_key(self):
47-
route = "/demo/api/key"
48-
response = self._make_request(route, api_key=self.api_key)
39+
response = self._make_request("/demo/api/key", api_key=self.api_key)
4940
self.assertEqual(response.status_code, 200)
5041
self.assertEqual(response.content, b"ok")
5142

5243
@mute_logger("endpoint.endpoint")
5344
def test_call_bad_key(self):
54-
route = "/demo/api/key"
55-
response = self._make_request(route, api_key=self.api_key2)
45+
response = self._make_request("/demo/api/key", api_key=self.api_key2)
5646
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)