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 May 24, 2024
1 parent f93f936 commit 50efb0b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
6 changes: 6 additions & 0 deletions fastapi_auth_api_key/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down
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
2 changes: 1 addition & 1 deletion fastapi_auth_api_key/dependencies.py
Original file line number Diff line number Diff line change
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 50efb0b

Please sign in to comment.