Skip to content

Commit 8fe3fe2

Browse files
committed
[MIG] endpoint_auth_api_key: Migration to 19.0
1 parent d84f641 commit 8fe3fe2

9 files changed

Lines changed: 131 additions & 84 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: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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.tests import tagged
7+
from odoo.tools import DotDict
8+
9+
from odoo.addons.base.tests.common import TransactionCaseWithUserDemo
10+
from odoo.addons.http_routing.tests.common import MockRequest
11+
12+
13+
def _setup_demo_api_keys(env, demo_user):
14+
"""Create demo API keys for tests."""
15+
api_key_model = env["auth.api.key"]
16+
17+
api_key_1 = api_key_model.create(
18+
{
19+
"name": "Endpoint API key demo",
20+
"key": "cZ6dF2UQwNcm",
21+
"user_id": demo_user.id,
22+
}
23+
)
24+
api_key_2 = api_key_model.create(
25+
{
26+
"name": "Endpoint API key demo 2",
27+
"key": "kV47QyOTC5mS",
28+
"user_id": demo_user.id,
29+
}
30+
)
31+
return api_key_1, api_key_2
32+
33+
34+
def _setup_demo_api_key_group(env, api_key_1):
35+
"""Create demo API key group for tests."""
36+
return env["auth.api.key.group"].create(
37+
{
38+
"name": "Demo Group 1",
39+
"code": "demo_group1",
40+
"auth_api_key_ids": [Command.set(api_key_1.ids)],
41+
}
42+
)
43+
44+
45+
def _setup_demo_endpoint(env, api_key_group):
46+
"""Create demo endpoint for tests."""
47+
return env["endpoint.endpoint"].create(
48+
{
49+
"name": "Demo Endpoint - auth api key",
50+
"route": "/demo/api/key",
51+
"request_method": "GET",
52+
"auth_type": "api_key",
53+
"auth_api_key_group_ids": [Command.set(api_key_group.ids)],
54+
"exec_mode": "code",
55+
"code_snippet": 'result = {"response": Response("ok")}',
56+
}
57+
)
58+
59+
60+
@tagged("-at_install", "post_install")
61+
class CommonEndpointAuthAPIKey(TransactionCaseWithUserDemo):
62+
@classmethod
63+
def setUpClass(cls):
64+
super().setUpClass()
65+
cls._setup_env()
66+
cls._setup_records()
67+
68+
@classmethod
69+
def _setup_env(cls):
70+
cls.env = cls.env(context=cls._setup_context())
71+
72+
@classmethod
73+
def _setup_context(cls):
74+
return dict(
75+
cls.env.context,
76+
tracking_disable=True,
77+
)
78+
79+
@classmethod
80+
def _setup_records(cls):
81+
cls.api_key, cls.api_key2 = _setup_demo_api_keys(
82+
cls.env,
83+
cls.user_demo,
84+
)
85+
cls.key_group = _setup_demo_api_key_group(
86+
cls.env,
87+
cls.api_key,
88+
)
89+
cls.endpoint = _setup_demo_endpoint(
90+
cls.env,
91+
cls.key_group,
92+
)
93+
94+
@contextlib.contextmanager
95+
def _get_mocked_request(
96+
self, httprequest=None, extra_headers=None, request_attrs=None
97+
):
98+
with MockRequest(self.env) as mocked_request:
99+
mocked_request.httprequest = (
100+
DotDict(httprequest) if httprequest else mocked_request.httprequest
101+
)
102+
headers = {}
103+
headers.update(extra_headers or {})
104+
mocked_request.httprequest.headers = headers
105+
request_attrs = request_attrs or {}
106+
for k, v in request_attrs.items():
107+
setattr(mocked_request, k, v)
108+
mocked_request.make_response = lambda data, **kw: data
109+
yield mocked_request

endpoint_auth_api_key/tests/test_endpoint.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@
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):
14-
@classmethod
15-
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
22-
13+
class TestEndpoint(CommonEndpointAuthAPIKey):
2314
@mute_logger("endpoint.endpoint")
2415
def test_endpoint_validate_request_no_key(self):
2516
endpoint = self.endpoint.copy(

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)