Skip to content

Commit

Permalink
[MIG] fastapi_auth_api_key: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 committed Jun 4, 2024
1 parent f93f936 commit ae3d34c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
16 changes: 11 additions & 5 deletions fastapi_auth_api_key/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Fastapi Auth Api Key
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_api_key
:target: https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_auth_api_key
:target: https://translation.odoo-community.org/projects/rest-framework-17-0/rest-framework-17-0-fastapi_auth_api_key
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -78,7 +78,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_api_key%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_api_key%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand All @@ -94,6 +94,12 @@ Contributors
~~~~~~~~~~~~

* Matthieu Méquignon <[email protected]>
* Son Ho <[email protected]>

Other credits
~~~~~~~~~~~~~

The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp

Maintainers
~~~~~~~~~~~
Expand All @@ -116,6 +122,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-mmequignon|

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/16.0/fastapi_auth_api_key>`_ project on GitHub.
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion fastapi_auth_api_key/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Fastapi Auth Api Key",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Others",
"website": "https://github.com/OCA/rest-framework",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
4 changes: 2 additions & 2 deletions fastapi_auth_api_key/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from typing_extensions import Annotated
from typing import Annotated

from odoo import SUPERUSER_ID
from odoo.api import Environment
Expand Down Expand Up @@ -34,7 +34,7 @@ def authenticated_auth_api_key(
except ValidationError as error:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=error.name,
detail=error.args,
headers={"WWW-Authenticate": "HTTP-API-KEY"},
) from error
# Ensure the api key is authorized for the current endpoint.
Expand Down
1 change: 1 addition & 0 deletions fastapi_auth_api_key/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Matthieu Méquignon <[email protected]>
* Son Ho <[email protected]>
1 change: 1 addition & 0 deletions fastapi_auth_api_key/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp
22 changes: 17 additions & 5 deletions fastapi_auth_api_key/tests/test_fastapi_api_key_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
# Is it valid? We need an env without superpowers
demo_user = cls.env.ref("base.partner_demo")
demo_user = cls.env.ref("base.user_demo")
cls.demo_env = demo_user.with_user(demo_user).env
cls.demo_endpoint = cls.env["fastapi.endpoint"].create(
{
"name": "Test Enpoint",
"app": "demo",
"root_path": "/path_demo",
"demo_auth_method": "api_key",
"user_id": demo_user.id,
}
)
cls.setUpClassApiKey()

@classmethod
Expand Down Expand Up @@ -63,19 +72,22 @@ def setUpClassApiKey(cls):
def test_authenticated_auth_api_key(self):
# An exception is raised when no api key is used
with self.assertRaises(HTTPException) as error:
authenticated_auth_api_key(False, self.demo_env)
authenticated_auth_api_key(False, self.demo_env, self.demo_endpoint)
self.assertEqual(error.exception.detail, "No HTTP-API-KEY provided")
# An exception is raised when no api key record is found
with self.assertRaises(HTTPException) as error:
authenticated_auth_api_key("404", self.demo_env)
self.assertEqual(error.exception.detail, "The key 404 is not allowed")
authenticated_auth_api_key("404", self.demo_env, self.demo_endpoint)
self.assertEqual(error.exception.detail, ("The key 404 is not allowed",))
# TODO enable this when we know how to filter keys based
# on endpoint's api key group.
# An exception is raised when unauthorized api key record is found
# with self.assertRaises(HTTPException) as error:
# authenticated_auth_api_key("not_authorized", self.demo_env)
self.demo_endpoint.auth_api_key_group_id = (
self.authorized_api_key.auth_api_key_group_ids[0]
)
result_key = authenticated_auth_api_key(
self.authorized_api_key.key, self.demo_env
self.authorized_api_key.key, self.demo_env, self.demo_endpoint
)
self.assertEqual(result_key, self.authorized_api_key)

Expand Down
2 changes: 1 addition & 1 deletion fastapi_auth_api_key/views/fastapi_endpoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<field name="model">fastapi.endpoint</field>
<field name="inherit_id" ref="fastapi.fastapi_endpoint_form_view" />
<field name="arch" type="xml">
<group name="resources" position="inside">
<group name="resoures" position="inside">
<field name="auth_api_key_group_id" />
</group>
</field>
Expand Down

0 comments on commit ae3d34c

Please sign in to comment.