-
-
Notifications
You must be signed in to change notification settings - Fork 110
[19.0][IMP] webservice, webservice_server_env: neutralize webservice backend credentials #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yankinmax
wants to merge
3
commits into
OCA:19.0
Choose a base branch
from
camptocamp:imp-webservice-add-neutralize
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−20
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| odoo-addon-webservice @ git+https://github.com/OCA/web-api.git@refs/pull/143/head#subdirectory=webservice | ||
| odoo-addon-webservice_server_env @ git+https://github.com/OCA/web-api.git@refs/pull/143/head#subdirectory=webservice_server_env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- remove webservice backend credentials | ||
| UPDATE webservice_backend | ||
| SET username = NULL, | ||
| password = NULL, | ||
| api_key = NULL, | ||
| oauth2_clientid = NULL, | ||
| oauth2_client_secret = NULL, | ||
| oauth2_client_auth_value = NULL, | ||
| oauth2_token = NULL; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| When a database is neutralized, stored webservice backend credentials | ||
| (username, password, API key, OAuth2 client id/secret/token, custom | ||
| OAuth2 auth header value) are cleared. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from . import test_oauth2 | ||
| from . import test_webservice | ||
| from . import test_utils | ||
| from . import test_neutralize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo.modules import neutralize | ||
| from odoo.tests import tagged | ||
|
|
||
| from .common import CommonWebService | ||
|
|
||
|
|
||
| @tagged("neutralize") | ||
| class TestWebserviceNeutralize(CommonWebService): | ||
| @classmethod | ||
| def _setup_records(cls): | ||
| res = super()._setup_records() | ||
| # `auth_type="none"` skips the `_check_auth_type` constraint so all | ||
| # credential fields can be populated at once regardless of which | ||
| # auth method would normally require them. | ||
| cls.backend = cls.env["webservice.backend"].create( | ||
| { | ||
| "name": "Neutralize WebService", | ||
| "protocol": "http", | ||
| "url": "https://localhost.demo.odoo/", | ||
| "tech_name": "neutralize_ws", | ||
| "auth_type": "none", | ||
| "username": "secret-user", | ||
| "password": "secret-password", | ||
| "api_key": "secret-api-key", | ||
| "oauth2_clientid": "secret-client-id", | ||
| "oauth2_client_secret": "secret-client-secret", | ||
| "oauth2_client_auth_value": "secret-header-value", | ||
| "oauth2_token": '{"access_token": "secret-token"}', | ||
| } | ||
| ) | ||
| return res | ||
|
|
||
| def test_neutralize_removes_webservice_credentials(self): | ||
| """Test database neutralization clears stored webservice backend credentials.""" | ||
| installed_modules = neutralize.get_installed_modules(self.cr) | ||
| queries = neutralize.get_neutralization_queries(installed_modules) | ||
| for query in queries: | ||
| self.cr.execute(query) | ||
| self.backend.invalidate_recordset() | ||
| self.assertFalse(self.backend.username) | ||
| self.assertFalse(self.backend.password) | ||
| self.assertFalse(self.backend.api_key) | ||
| self.assertFalse(self.backend.oauth2_clientid) | ||
| self.assertFalse(self.backend.oauth2_client_secret) | ||
| self.assertFalse(self.backend.oauth2_client_auth_value) | ||
| self.assertFalse(self.backend.oauth2_token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| -- remove webservice backend credentials stored as server environment defaults | ||
| -- (this module turns username/password/api_key/oauth2_clientid/oauth2_client_secret | ||
| -- into non-stored fields backed by the server_env_defaults JSON column | ||
| -- this neutralization is needed if both webservice and server_environment are installed, | ||
| -- so the plain columns nulled by webservice/data/neutralize.sql can be properly cleared) | ||
| UPDATE webservice_backend | ||
|
yankinmax marked this conversation as resolved.
|
||
| SET server_env_defaults = ( | ||
| server_env_defaults::jsonb | ||
| - 'x_username_env_default' | ||
| - 'x_password_env_default' | ||
| - 'x_api_key_env_default' | ||
| - 'x_oauth2_clientid_env_default' | ||
| - 'x_oauth2_client_secret_env_default' | ||
| - 'x_oauth2_client_auth_value_env_default' | ||
| )::text | ||
| WHERE server_env_defaults IS NOT NULL; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| When a database is neutralized, webservice backend credentials (username, | ||
| password, API key, OAuth2 client id/secret, custom OAuth2 auth header | ||
| value) stored as server environment defaults are cleared as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from . import test_oauth2 | ||
| from . import test_neutralize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo.modules import neutralize | ||
| from odoo.tests import tagged | ||
|
|
||
| from odoo.addons.webservice.tests.common import CommonWebService | ||
|
|
||
|
|
||
| @tagged("neutralize") | ||
| class TestWebserviceServerEnvNeutralize(CommonWebService): | ||
| @classmethod | ||
| def _setup_records(cls): | ||
| res = super()._setup_records() | ||
| # No `SERVER_ENV_CONFIG` section is defined for this tech_name, so | ||
| # these credentials are stored as env-default values inside | ||
| # `server_env_defaults` instead of the (now unused) plain columns. | ||
| cls.backend = cls.env["webservice.backend"].create( | ||
| { | ||
| "name": "Neutralize WebService Server Env", | ||
| "protocol": "http", | ||
| "url": "https://localhost.demo.odoo/", | ||
| "tech_name": "neutralize_server_env_ws", | ||
| "auth_type": "none", | ||
| "username": "secret-user", | ||
| "password": "secret-password", | ||
| "api_key": "secret-api-key", | ||
| "oauth2_clientid": "secret-client-id", | ||
| "oauth2_client_secret": "secret-client-secret", | ||
| "oauth2_client_auth_value": "secret-header-value", | ||
| } | ||
| ) | ||
| return res | ||
|
|
||
| def test_neutralize_removes_server_env_default_credentials(self): | ||
| """Test neutralization clears credentials stored as server-env defaults.""" | ||
| installed_modules = neutralize.get_installed_modules(self.cr) | ||
| queries = neutralize.get_neutralization_queries(installed_modules) | ||
| for query in queries: | ||
| self.cr.execute(query) | ||
| self.backend.invalidate_recordset() | ||
| self.assertFalse(self.backend.username) | ||
| self.assertFalse(self.backend.password) | ||
| self.assertFalse(self.backend.api_key) | ||
| self.assertFalse(self.backend.oauth2_clientid) | ||
| self.assertFalse(self.backend.oauth2_client_secret) | ||
| self.assertFalse(self.backend.oauth2_client_auth_value) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.