Skip to content
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

[18.0][IMP] server_environment: hide SMTP passwords #210

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server_environment/server_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ def get_view(self, view_id=None, view_type="form", **options):
@api.model
def _is_secret(self, key):
"""
This method is intended to be inherited to defined which keywords
should be secret.
:return: list of secret keywords
This method is intended to be inherited to define which values
should be kept secret.
:return: True if information has to be protected, False otherwise
"""
secret_keys = ["passw", "key", "secret", "token"]
secret_keys = ["_pass", "passw", "key", "secret", "token"]
return any(secret_key in key for secret_key in secret_keys)

@api.model
Expand Down
15 changes: 13 additions & 2 deletions server_environment/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ def set_env_variables(self, public=None, secret=None):
yield

@contextmanager
def load_config(self, public=None, secret=None, serv_config_class=server_env_mixin):
def load_config(
self,
public=None,
secret=None,
config_dir=None,
serv_config_class=server_env_mixin,
):
original_serv_config = serv_config_class.serv_config
try:
with self.set_config_dir(None), self.set_env_variables(public, secret):
with (
self.set_config_dir(config_dir),
self.set_env_variables(public, secret),
):
parser = server_env._load_config()
serv_config_class.serv_config = parser
server_env.serv_config = parser
yield

finally:
serv_config_class.serv_config = original_serv_config
server_env.serv_config = original_serv_config
35 changes: 31 additions & 4 deletions server_environment/tests/test_server_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
from .. import server_env
from . import common

NO_DEFAULT = [
"id",
"create_uid",
"create_date",
"write_uid",
"write_date",
"display_name",
"config",
"__last_update",
]


class TestEnv(common.ServerEnvironmentCase):
def test_view(self):
Expand All @@ -20,17 +31,20 @@ def _test_default(self, hidden_pwd=False):
model = self.env["server.config"]
rec = model.create({})
fields = model.fields_get()
self.assertTrue(fields)
defaults = rec.default_get(list(fields))
self.assertTrue(defaults)
fields_with_default = {fld for fld in fields if fld not in NO_DEFAULT}
self.assertTrue(fields_with_default)
self.assertIsInstance(defaults, dict)
self.assertEqual(fields_with_default, set(defaults))
# Check secrets
pass_checked = False
for default in defaults:
if "passw" in default:
if "_pass" in default:
check = self.assertEqual if hidden_pwd else self.assertNotEqual
check(defaults[default], "**********")
pass_checked = True
self.assertTrue(pass_checked)
return defaults

@patch.dict(odoo_config.options, {"running_env": "dev"})
def test_default_dev(self):
Expand All @@ -54,10 +68,23 @@ def test_odoosh_dev_from_environ(self):
self._test_default()

@patch.dict(odoo_config.options, {"running_env": "testing"})
def test_value_retrival(self):
def test_value_retrieval(self):
with self.set_config_dir("testfiles"):
parser = server_env._load_config()
val = parser.get("external_service.ftp", "user")
self.assertEqual(val, "testing")
val = parser.get("external_service.ftp", "host")
self.assertEqual(val, "sftp.example.com")

@patch.dict(odoo_config.options, {"running_env": "testing"})
def test_default_hidden_password(self):
with self.load_config(config_dir="testfiles"):
model = self.env["server.config"]
model._add_columns()
self.env.registry.setup_models(self.env.cr)
defaults = self._test_default(hidden_pwd=True)

self.assertIn("odoo_I_admin_passwd", defaults)
self.assertIn("odoo_I_db_password", defaults)
self.assertIn("odoo_I_smtp_password", defaults)
self.assertIn("outgoing_mail_provider_promail_I_smtp_pass", defaults)
6 changes: 6 additions & 0 deletions server_environment/tests/testfiles/testing/outmail.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[outgoing_mail.provider_promail]
smtp_encryption = ssl
smtp_host = email.server.invalid
smtp_pass = THISISNOTPUBLIC
smtp_port = 912
smtp_user = user_abc
Loading