11# Copyright 2026 Camptocamp SA
22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
4- import os
54from unittest import mock
65
76from odoo import exceptions
87
8+ from odoo .addons .server_environment .tests .common import ServerEnvironmentCase
99from odoo .addons .webservice .tests .common import CommonWebService
1010
1111
@@ -15,14 +15,6 @@ def _setup_records(cls):
1515 res = super ()._setup_records ()
1616 cls .url = "https://localhost.demo.odoo/"
1717 # Certificate and private key configuration
18- os .environ ["SERVER_ENV_CONFIG" ] = "\n " .join (
19- [
20- "[webservice_backend.test_client_certificate_and_key]" ,
21- "auth_type = client_certificate" ,
22- "client_certificate_path = /path/client.cert" ,
23- "client_private_key_path = /path/client.key" ,
24- ]
25- )
2618 cls .backend_certificate_and_key = cls .env ["webservice.backend" ].create (
2719 {
2820 "name" : "Webservice Client Certificate & Key" ,
@@ -35,13 +27,6 @@ def _setup_records(cls):
3527 }
3628 )
3729 # Certificate only configuration (no private key)
38- os .environ ["SERVER_ENV_CONFIG" ] = "\n " .join (
39- [
40- "[webservice_backend.test_client_certificate_only]" ,
41- "auth_type = client_certificate" ,
42- "client_certificate_path = /path/client.pem" ,
43- ]
44- )
4530 cls .backend_certificate_only = cls .env ["webservice.backend" ].create (
4631 {
4732 "name" : "Webservice Client Certificate Only" ,
@@ -94,3 +79,33 @@ def test_auth_type_validation(self):
9479 "auth_type" : "client_certificate" ,
9580 }
9681 )
82+
83+
84+ class TestClientCertAuthServerEnv (ServerEnvironmentCase ):
85+ def test_client_certificate_server_env (self ):
86+ client_certificate_config = """
87+ [webservice_backend.test_server_env]
88+ auth_type = client_certificate
89+ client_certificate_path = /path/client.cert
90+ client_private_key_path = /path/client.key
91+ """
92+ with self .load_config (public = client_certificate_config ):
93+ backend = self .env ["webservice.backend" ].create (
94+ {
95+ "name" : "Test Server Env" ,
96+ "tech_name" : "test_server_env" ,
97+ "protocol" : "http" ,
98+ "url" : "https://localhost" ,
99+ "auth_type" : "none" ,
100+ }
101+ )
102+ backend .invalidate_recordset ()
103+ self .assertEqual (backend .auth_type , "client_certificate" )
104+ self .assertEqual (
105+ backend .client_certificate_path ,
106+ "/path/client.cert" ,
107+ )
108+ self .assertEqual (
109+ backend .client_private_key_path ,
110+ "/path/client.key" ,
111+ )
0 commit comments