Skip to content

Commit ccaea80

Browse files
[MIG] auth_jwt_demo: Migration to 19.0
1 parent 2583a98 commit ccaea80

7 files changed

Lines changed: 93 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude: |
1818
/build/|/dist/|
1919
# Ignore test files in addons
2020
/tests/samples/.*|
21+
^auth_jwt_demo/tests/spa.*|
2122
# You don't usually want a bot to modify your legal texts
2223
(LICENSE.*|COPYING.*)
2324
default_language_version:

auth_jwt_demo/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Contributors
9696
------------
9797

9898
- Stéphane Bidoul <stephane.bidoul@acsone.eu>
99+
- `Studio73 <https://www.studio73.es>`__:
100+
101+
- Pablo Cortés
99102

100103
Maintainers
101104
-----------

auth_jwt_demo/__manifest__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
"name": "Auth JWT Test",
66
"summary": """
77
Test/demo module for auth_jwt.""",
8-
"version": "18.0.1.0.0",
8+
"version": "19.0.1.0.0",
99
"license": "LGPL-3",
1010
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1111
"maintainers": ["sbidoul"],
1212
"website": "https://github.com/OCA/server-auth",
1313
"depends": ["auth_jwt"],
1414
"data": [],
1515
"demo": ["demo/auth_jwt_validator.xml"],
16+
"installable": True,
17+
"application": False,
1618
}

auth_jwt_demo/demo/auth_jwt_validator.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<field name="issuer">theissuer</field>
66
<field name="signature_type">secret</field>
77
<field name="secret_algorithm">HS256</field>
8-
<field name="secret_key">thesecret</field>
8+
<field name="secret_key">oca_auth_jwt_test_secret_key_minimum_32_bytes</field>
99
<field name="user_id_strategy">static</field>
1010
<field name="static_user_id" ref="base.user_demo" />
1111
<field name="partner_id_strategy">email</field>
@@ -17,7 +17,7 @@
1717
<field name="issuer">theissuer</field>
1818
<field name="signature_type">secret</field>
1919
<field name="secret_algorithm">HS256</field>
20-
<field name="secret_key">thesecret</field>
20+
<field name="secret_key">oca_auth_jwt_test_secret_key_minimum_32_bytes</field>
2121
<field name="user_id_strategy">static</field>
2222
<field name="static_user_id" ref="base.user_demo" />
2323
<field name="partner_id_strategy">email</field>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
- Stéphane Bidoul \<<stephane.bidoul@acsone.eu>\>
2+
- [Studio73](https://www.studio73.es):
3+
- Pablo Cortés
4+

auth_jwt_demo/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ <h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
441441
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
442442
<ul class="simple">
443443
<li>Stéphane Bidoul &lt;<a class="reference external" href="mailto:stephane.bidoul&#64;acsone.eu">stephane.bidoul&#64;acsone.eu</a>&gt;</li>
444+
<li><a class="reference external" href="https://www.studio73.es">Studio73</a>:<ul>
445+
<li>Pablo Cortés</li>
446+
</ul>
447+
</li>
444448
</ul>
445449
</div>
446450
<div class="section" id="maintainers">

auth_jwt_demo/tests/test_auth_jwt_demo.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,51 @@
77
import jwt
88

99
from odoo import tests
10+
from odoo.tools import convert, file_path
11+
12+
13+
class TestAuthJwtDemo(tests.common.HttpCase):
14+
@classmethod
15+
def setUpClass(cls):
16+
super().setUpClass()
1017

1118

1219
@tests.tagged("post_install", "-at_install")
1320
class TestRegisterHook(tests.HttpCase):
21+
def setUp(self):
22+
super().setUp()
23+
demo_user = self.env.ref("base.user_demo", raise_if_not_found=False)
24+
if not demo_user:
25+
demo_user = self.env["res.users"].create(
26+
{
27+
"name": "Demo User",
28+
"login": "demo",
29+
"email": "demo@example.com",
30+
"group_ids": [(6, 0, [self.env.ref("base.group_user").id])],
31+
}
32+
)
33+
self.env["ir.model.data"].create(
34+
{
35+
"name": "user_demo",
36+
"module": "base",
37+
"model": "res.users",
38+
"res_id": demo_user.id,
39+
"noupdate": True,
40+
}
41+
)
42+
module_name = "auth_jwt_demo"
43+
xml_path_in_module = "demo/auth_jwt_validator.xml"
44+
try:
45+
full_path = file_path(f"{module_name}/{xml_path_in_module}")
46+
except FileNotFoundError:
47+
self.fail(f"No se pudo encontrar el fichero demo: {xml_path_in_module}")
48+
full_path = None
49+
if full_path:
50+
with open(full_path, "rb") as f:
51+
convert.convert_xml_import(
52+
self.env, module_name, f, idref={}, mode="demo", noupdate=False
53+
)
54+
1455
def test_auth_method_exists(self):
1556
validator = self.env["auth.jwt.validator"].search([("name", "=", "demo")])
1657
self.assertEqual(len(validator), 1)
@@ -19,6 +60,40 @@ def test_auth_method_exists(self):
1960

2061
@tests.tagged("post_install", "-at_install")
2162
class TestEndToEnd(tests.HttpCase):
63+
def setUp(self):
64+
super().setUp()
65+
demo_user = self.env.ref("base.user_demo", raise_if_not_found=False)
66+
if not demo_user:
67+
demo_user = self.env["res.users"].create(
68+
{
69+
"name": "Demo User",
70+
"login": "demo",
71+
"email": "demo@example.com",
72+
"group_ids": [(6, 0, [self.env.ref("base.group_user").id])],
73+
}
74+
)
75+
self.env["ir.model.data"].create(
76+
{
77+
"name": "user_demo",
78+
"module": "base",
79+
"model": "res.users",
80+
"res_id": demo_user.id,
81+
"noupdate": True,
82+
}
83+
)
84+
module_name = "auth_jwt_demo"
85+
xml_path_in_module = "demo/auth_jwt_validator.xml"
86+
try:
87+
full_path = file_path(f"{module_name}/{xml_path_in_module}")
88+
except FileNotFoundError:
89+
self.fail(f"No se pudo encontrar el fichero demo: {xml_path_in_module}")
90+
full_path = None
91+
if full_path:
92+
with open(full_path, "rb") as f:
93+
convert.convert_xml_import(
94+
self.env, module_name, f, idref={}, mode="demo", noupdate=False
95+
)
96+
2297
def _get_token(self, aud=None, email=None):
2398
validator = self.env["auth.jwt.validator"].search([("name", "=", "demo")])
2499
payload = {
@@ -74,7 +149,7 @@ def test_whoami_cookie(self):
74149
self.assertTrue(cookie)
75150
# Try again with the cookie.
76151
resp = self.url_open(
77-
"/auth_jwt_demo_cookie/whoami", headers={"Cookie": f"demo_auth={cookie}"}
152+
"/auth_jwt_demo_cookie/whoami", cookies={"demo_auth": cookie}
78153
)
79154
resp.raise_for_status()
80155
whoami = resp.json()
@@ -159,7 +234,7 @@ def test_public_cookie_mode(self):
159234
token = self._get_token(email=partner.email)
160235
resp = self.url_open(
161236
"/auth_jwt_demo_cookie/whoami-public-or-jwt",
162-
headers={"Cookie": f"demo_auth={cookie}"},
237+
cookies={"demo_auth": cookie},
163238
)
164239
resp.raise_for_status()
165240
whoami = resp.json()

0 commit comments

Comments
 (0)