mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
commit
8b98360fd2
44 changed files with 243 additions and 242 deletions
|
@ -15,6 +15,7 @@ THIS_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
ACTIONSMAP_FILE = THIS_SCRIPT_DIR + '/yunohost.yml'
|
ACTIONSMAP_FILE = THIS_SCRIPT_DIR + '/yunohost.yml'
|
||||||
BASH_COMPLETION_FILE = THIS_SCRIPT_DIR + '/../bash-completion.d/yunohost'
|
BASH_COMPLETION_FILE = THIS_SCRIPT_DIR + '/../bash-completion.d/yunohost'
|
||||||
|
|
||||||
|
|
||||||
def get_dict_actions(OPTION_SUBTREE, category):
|
def get_dict_actions(OPTION_SUBTREE, category):
|
||||||
ACTIONS = [action for action in OPTION_SUBTREE[category]["actions"].keys()
|
ACTIONS = [action for action in OPTION_SUBTREE[category]["actions"].keys()
|
||||||
if not action.startswith('_')]
|
if not action.startswith('_')]
|
||||||
|
@ -24,6 +25,7 @@ def get_dict_actions(OPTION_SUBTREE, category):
|
||||||
|
|
||||||
return DICT
|
return DICT
|
||||||
|
|
||||||
|
|
||||||
with open(ACTIONSMAP_FILE, 'r') as stream:
|
with open(ACTIONSMAP_FILE, 'r') as stream:
|
||||||
|
|
||||||
# Getting the dictionary containning what actions are possible per category
|
# Getting the dictionary containning what actions are possible per category
|
||||||
|
|
|
@ -75,7 +75,6 @@ class BaseSystemDiagnoser(Diagnoser):
|
||||||
summary="diagnosis_basesystem_ynh_main_version" if consistent_versions else "diagnosis_basesystem_ynh_inconsistent_versions",
|
summary="diagnosis_basesystem_ynh_main_version" if consistent_versions else "diagnosis_basesystem_ynh_inconsistent_versions",
|
||||||
details=ynh_version_details)
|
details=ynh_version_details)
|
||||||
|
|
||||||
|
|
||||||
if self.is_vulnerable_to_meltdown():
|
if self.is_vulnerable_to_meltdown():
|
||||||
yield dict(meta={"test": "meltdown"},
|
yield dict(meta={"test": "meltdown"},
|
||||||
status="ERROR",
|
status="ERROR",
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from yunohost.diagnosis import Diagnoser
|
from yunohost.diagnosis import Diagnoser
|
||||||
from yunohost.utils.error import YunohostError
|
|
||||||
from yunohost.service import _get_services
|
from yunohost.service import _get_services
|
||||||
|
|
||||||
|
|
||||||
class PortsDiagnoser(Diagnoser):
|
class PortsDiagnoser(Diagnoser):
|
||||||
|
|
||||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||||
|
|
|
@ -8,7 +8,6 @@ from moulinette.utils.filesystem import read_file
|
||||||
|
|
||||||
from yunohost.diagnosis import Diagnoser
|
from yunohost.diagnosis import Diagnoser
|
||||||
from yunohost.domain import domain_list
|
from yunohost.domain import domain_list
|
||||||
from yunohost.utils.error import YunohostError
|
|
||||||
|
|
||||||
DIAGNOSIS_SERVER = "diagnosis.yunohost.org"
|
DIAGNOSIS_SERVER = "diagnosis.yunohost.org"
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
status="SUCCESS",
|
status="SUCCESS",
|
||||||
summary="diagnosis_mail_" + name + "_ok")
|
summary="diagnosis_mail_" + name + "_ok")
|
||||||
|
|
||||||
|
|
||||||
def check_outgoing_port_25(self):
|
def check_outgoing_port_25(self):
|
||||||
"""
|
"""
|
||||||
Check outgoing port 25 is open and not blocked by router
|
Check outgoing port 25 is open and not blocked by router
|
||||||
|
@ -64,7 +63,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
details=["diagnosis_mail_outgoing_port_25_blocked_details",
|
details=["diagnosis_mail_outgoing_port_25_blocked_details",
|
||||||
"diagnosis_mail_outgoing_port_25_blocked_relay_vpn"])
|
"diagnosis_mail_outgoing_port_25_blocked_relay_vpn"])
|
||||||
|
|
||||||
|
|
||||||
def check_ehlo(self):
|
def check_ehlo(self):
|
||||||
"""
|
"""
|
||||||
Check the server is reachable from outside and it's the good one
|
Check the server is reachable from outside and it's the good one
|
||||||
|
@ -99,7 +97,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
summary="diagnosis_mail_ehlo_wrong",
|
summary="diagnosis_mail_ehlo_wrong",
|
||||||
details=["diagnosis_mail_ehlo_wrong_details"])
|
details=["diagnosis_mail_ehlo_wrong_details"])
|
||||||
|
|
||||||
|
|
||||||
def check_fcrdns(self):
|
def check_fcrdns(self):
|
||||||
"""
|
"""
|
||||||
Check the reverse DNS is well defined by doing a Forward-confirmed
|
Check the reverse DNS is well defined by doing a Forward-confirmed
|
||||||
|
@ -148,7 +145,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
summary="diagnosis_mail_fcrdns_different_from_ehlo_domain",
|
summary="diagnosis_mail_fcrdns_different_from_ehlo_domain",
|
||||||
details=details)
|
details=details)
|
||||||
|
|
||||||
|
|
||||||
def check_blacklist(self):
|
def check_blacklist(self):
|
||||||
"""
|
"""
|
||||||
Check with dig onto blacklist DNS server
|
Check with dig onto blacklist DNS server
|
||||||
|
@ -225,7 +221,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
status="SUCCESS",
|
status="SUCCESS",
|
||||||
summary="diagnosis_mail_queue_ok")
|
summary="diagnosis_mail_queue_ok")
|
||||||
|
|
||||||
|
|
||||||
def get_ips_checked(self):
|
def get_ips_checked(self):
|
||||||
outgoing_ipversions = []
|
outgoing_ipversions = []
|
||||||
outgoing_ips = []
|
outgoing_ips = []
|
||||||
|
@ -245,5 +240,6 @@ class MailDiagnoser(Diagnoser):
|
||||||
outgoing_ips.append(global_ipv6)
|
outgoing_ips.append(global_ipv6)
|
||||||
return (outgoing_ipversions, outgoing_ips)
|
return (outgoing_ipversions, outgoing_ips)
|
||||||
|
|
||||||
|
|
||||||
def main(args, env, loggers):
|
def main(args, env, loggers):
|
||||||
return MailDiagnoser(args, env, loggers).diagnose()
|
return MailDiagnoser(args, env, loggers).diagnose()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import os
|
||||||
from yunohost.diagnosis import Diagnoser
|
from yunohost.diagnosis import Diagnoser
|
||||||
from yunohost.service import service_status
|
from yunohost.service import service_status
|
||||||
|
|
||||||
|
|
||||||
class ServicesDiagnoser(Diagnoser):
|
class ServicesDiagnoser(Diagnoser):
|
||||||
|
|
||||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||||
|
@ -36,5 +37,6 @@ class ServicesDiagnoser(Diagnoser):
|
||||||
|
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
||||||
def main(args, env, loggers):
|
def main(args, env, loggers):
|
||||||
return ServicesDiagnoser(args, env, loggers).diagnose()
|
return ServicesDiagnoser(args, env, loggers).diagnose()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import re
|
||||||
|
|
||||||
from yunohost.diagnosis import Diagnoser
|
from yunohost.diagnosis import Diagnoser
|
||||||
|
|
||||||
|
|
||||||
class SystemResourcesDiagnoser(Diagnoser):
|
class SystemResourcesDiagnoser(Diagnoser):
|
||||||
|
|
||||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||||
|
@ -96,7 +97,6 @@ class SystemResourcesDiagnoser(Diagnoser):
|
||||||
item["status"] = "SUCCESS"
|
item["status"] = "SUCCESS"
|
||||||
item["summary"] = "diagnosis_diskusage_ok"
|
item["summary"] = "diagnosis_diskusage_ok"
|
||||||
|
|
||||||
|
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -112,7 +112,6 @@ class SystemResourcesDiagnoser(Diagnoser):
|
||||||
summary="diagnosis_processes_killed_by_oom_reaper",
|
summary="diagnosis_processes_killed_by_oom_reaper",
|
||||||
data={"kills_summary": kills_summary})
|
data={"kills_summary": kills_summary})
|
||||||
|
|
||||||
|
|
||||||
def recent_kills_by_oom_reaper(self):
|
def recent_kills_by_oom_reaper(self):
|
||||||
if not os.path.exists("/var/log/kern.log"):
|
if not os.path.exists("/var/log/kern.log"):
|
||||||
return []
|
return []
|
||||||
|
@ -160,5 +159,6 @@ def round_(n):
|
||||||
n = int(round(n))
|
n = int(round(n))
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
def main(args, env, loggers):
|
def main(args, env, loggers):
|
||||||
return SystemResourcesDiagnoser(args, env, loggers).diagnose()
|
return SystemResourcesDiagnoser(args, env, loggers).diagnose()
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import subprocess
|
|
||||||
from yunohost.diagnosis import Diagnoser
|
from yunohost.diagnosis import Diagnoser
|
||||||
from yunohost.regenconf import _get_regenconf_infos, _calculate_hash
|
from yunohost.regenconf import _get_regenconf_infos, _calculate_hash
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import os
|
||||||
import glob
|
import glob
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
def render(helpers):
|
def render(helpers):
|
||||||
|
|
||||||
data = {"helpers": helpers,
|
data = {"helpers": helpers,
|
||||||
|
@ -29,6 +30,7 @@ def render(helpers):
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
class Parser():
|
class Parser():
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
|
@ -180,13 +182,14 @@ class Parser():
|
||||||
b["usage"] = b["usage"].strip()
|
b["usage"] = b["usage"].strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def is_global_comment(line):
|
def is_global_comment(line):
|
||||||
return line.startswith('#')
|
return line.startswith('#')
|
||||||
|
|
||||||
|
|
||||||
def malformed_error(line_number):
|
def malformed_error(line_number):
|
||||||
return "Malformed file line {} ?".format(line_number)
|
return "Malformed file line {} ?".format(line_number)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
helper_files = sorted(glob.glob("../data/helpers.d/*"))
|
helper_files = sorted(glob.glob("../data/helpers.d/*"))
|
||||||
|
@ -204,5 +207,5 @@ def main():
|
||||||
|
|
||||||
render(helpers)
|
render(helpers)
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
|
@ -91,7 +91,7 @@ def init_logging(interface="cli",
|
||||||
logfile = os.path.join(logdir, "yunohost-%s.log" % interface)
|
logfile = os.path.join(logdir, "yunohost-%s.log" % interface)
|
||||||
|
|
||||||
if not os.path.isdir(logdir):
|
if not os.path.isdir(logdir):
|
||||||
os.makedirs(logdir, 0750)
|
os.makedirs(logdir, 0o750)
|
||||||
|
|
||||||
# ####################################################################### #
|
# ####################################################################### #
|
||||||
# Logging configuration for CLI (or any other interface than api...) #
|
# Logging configuration for CLI (or any other interface than api...) #
|
||||||
|
|
|
@ -681,7 +681,7 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu
|
||||||
|
|
||||||
from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback
|
from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback
|
||||||
from yunohost.log import OperationLogger
|
from yunohost.log import OperationLogger
|
||||||
from yunohost.permission import user_permission_list, permission_create, permission_url, permission_delete, permission_sync_to_user, user_permission_update
|
from yunohost.permission import user_permission_list, permission_create, permission_url, permission_delete, permission_sync_to_user
|
||||||
from yunohost.regenconf import manually_modified_files
|
from yunohost.regenconf import manually_modified_files
|
||||||
|
|
||||||
# Fetch or extract sources
|
# Fetch or extract sources
|
||||||
|
|
|
@ -890,8 +890,6 @@ class RestoreManager():
|
||||||
"""
|
"""
|
||||||
from permission import permission_sync_to_user
|
from permission import permission_sync_to_user
|
||||||
|
|
||||||
successfull_apps = self.targets.list("apps", include=["Success", "Warning"])
|
|
||||||
|
|
||||||
permission_sync_to_user()
|
permission_sync_to_user()
|
||||||
|
|
||||||
if os.path.ismount(self.work_dir):
|
if os.path.ismount(self.work_dir):
|
||||||
|
@ -1156,7 +1154,7 @@ class RestoreManager():
|
||||||
return
|
return
|
||||||
|
|
||||||
from yunohost.user import user_group_list
|
from yunohost.user import user_group_list
|
||||||
from yunohost.permission import permission_create, permission_delete, user_permission_update, user_permission_list, permission_sync_to_user
|
from yunohost.permission import permission_create, permission_delete, user_permission_list, permission_sync_to_user
|
||||||
|
|
||||||
# Backup old permission for apps
|
# Backup old permission for apps
|
||||||
# We need to do that because in case of an app is installed we can't remove the permission for this app
|
# We need to do that because in case of an app is installed we can't remove the permission for this app
|
||||||
|
@ -1253,7 +1251,7 @@ class RestoreManager():
|
||||||
name should be already install)
|
name should be already install)
|
||||||
"""
|
"""
|
||||||
from yunohost.user import user_group_list
|
from yunohost.user import user_group_list
|
||||||
from yunohost.permission import permission_create, permission_delete, user_permission_list, user_permission_update, permission_sync_to_user
|
from yunohost.permission import permission_create, permission_delete, user_permission_list, permission_sync_to_user
|
||||||
|
|
||||||
def copytree(src, dst, symlinks=False, ignore=None):
|
def copytree(src, dst, symlinks=False, ignore=None):
|
||||||
for item in os.listdir(src):
|
for item in os.listdir(src):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from shutil import copy2
|
||||||
|
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
|
|
||||||
from yunohost.app import _is_installed, _get_app_settings, _set_app_settings, _patch_legacy_php_versions_in_settings
|
from yunohost.app import _is_installed, _patch_legacy_php_versions_in_settings
|
||||||
from yunohost.tools import Migration
|
from yunohost.tools import Migration
|
||||||
from yunohost.service import _run_service_command
|
from yunohost.service import _run_service_command
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MyMigration(Migration):
|
||||||
# Make sure there's a 9.6 cluster
|
# Make sure there's a 9.6 cluster
|
||||||
try:
|
try:
|
||||||
self.runcmd("pg_lsclusters | grep -q '^9.6 '")
|
self.runcmd("pg_lsclusters | grep -q '^9.6 '")
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logger.warning("It looks like there's not active 9.6 cluster, so probably don't need to run this migration")
|
logger.warning("It looks like there's not active 9.6 cluster, so probably don't need to run this migration")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -63,4 +63,3 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
out = out.strip().split("\n")
|
out = out.strip().split("\n")
|
||||||
return (returncode, out, err)
|
return (returncode, out, err)
|
||||||
|
|
||||||
|
|
|
@ -106,4 +106,3 @@ class MyMigration(Migration):
|
||||||
|
|
||||||
out = out.strip().split("\n")
|
out = out.strip().split("\n")
|
||||||
return (returncode, out, err)
|
return (returncode, out, err)
|
||||||
|
|
||||||
|
|
|
@ -477,6 +477,7 @@ class Diagnoser():
|
||||||
meta_data.update(item.get("data", {}))
|
meta_data.update(item.get("data", {}))
|
||||||
|
|
||||||
html_tags = re.compile(r'<[^>]+>')
|
html_tags = re.compile(r'<[^>]+>')
|
||||||
|
|
||||||
def m18n_(info):
|
def m18n_(info):
|
||||||
if not isinstance(info, tuple) and not isinstance(info, list):
|
if not isinstance(info, tuple) and not isinstance(info, list):
|
||||||
info = (info, {})
|
info = (info, {})
|
||||||
|
|
|
@ -615,15 +615,15 @@ def _get_DKIM(domain):
|
||||||
dkim = re.match((
|
dkim = re.match((
|
||||||
r'^(?P<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
r'^(?P<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
||||||
'[^"]*"v=(?P<v>[^";]+);'
|
'[^"]*"v=(?P<v>[^";]+);'
|
||||||
'[\s"]*k=(?P<k>[^";]+);'
|
r'[\s"]*k=(?P<k>[^";]+);'
|
||||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
dkim = re.match((
|
dkim = re.match((
|
||||||
r'^(?P<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
r'^(?P<host>[a-z_\-\.]+)[\s]+([0-9]+[\s]+)?IN[\s]+TXT[\s]+'
|
||||||
'[^"]*"v=(?P<v>[^";]+);'
|
'[^"]*"v=(?P<v>[^";]+);'
|
||||||
'[\s"]*h=(?P<h>[^";]+);'
|
r'[\s"]*h=(?P<h>[^";]+);'
|
||||||
'[\s"]*k=(?P<k>[^";]+);'
|
r'[\s"]*k=(?P<k>[^";]+);'
|
||||||
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
'[\s"]*p=(?P<p>[^";]+)'), dkim_content, re.M | re.S
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
Manage firewall rules
|
Manage firewall rules
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import yaml
|
import yaml
|
||||||
import miniupnpc
|
import miniupnpc
|
||||||
|
|
||||||
|
|
|
@ -268,9 +268,9 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
|
|
||||||
# Validate callbacks
|
# Validate callbacks
|
||||||
if not callable(pre_callback):
|
if not callable(pre_callback):
|
||||||
pre_callback = lambda name, priority, path, args: args
|
def pre_callback(name, priority, path, args): return args
|
||||||
if not callable(post_callback):
|
if not callable(post_callback):
|
||||||
post_callback = lambda name, priority, path, succeed: None
|
def post_callback(name, priority, path, succeed): return None
|
||||||
|
|
||||||
# Iterate over hooks and execute them
|
# Iterate over hooks and execute them
|
||||||
for priority in sorted(hooks_dict):
|
for priority in sorted(hooks_dict):
|
||||||
|
@ -291,7 +291,7 @@ def hook_callback(action, hooks=[], args=None, no_trace=False, chdir=None,
|
||||||
else:
|
else:
|
||||||
post_callback(name=name, priority=priority, path=path,
|
post_callback(name=name, priority=priority, path=path,
|
||||||
succeed=True)
|
succeed=True)
|
||||||
if not name in result:
|
if name not in result:
|
||||||
result[name] = {}
|
result[name] = {}
|
||||||
result[name][path] = {'state': state, 'stdreturn': hook_return}
|
result[name][path] = {'state': state, 'stdreturn': hook_return}
|
||||||
return result
|
return result
|
||||||
|
@ -444,7 +444,7 @@ def _hook_exec_python(path, args, env, loggers):
|
||||||
dir_ = os.path.dirname(path)
|
dir_ = os.path.dirname(path)
|
||||||
name = os.path.splitext(os.path.basename(path))[0]
|
name = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|
||||||
if not dir_ in sys.path:
|
if dir_ not in sys.path:
|
||||||
sys.path = [dir_] + sys.path
|
sys.path = [dir_] + sys.path
|
||||||
module = import_module(name)
|
module = import_module(name)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ import random
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.user import user_list
|
|
||||||
from yunohost.log import is_unit_operation
|
from yunohost.log import is_unit_operation
|
||||||
|
|
||||||
logger = getActionLogger('yunohost.user')
|
logger = getActionLogger('yunohost.user')
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -31,7 +30,6 @@ from datetime import datetime
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from moulinette.utils import log, filesystem
|
from moulinette.utils import log, filesystem
|
||||||
from moulinette.utils.filesystem import read_file
|
|
||||||
|
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.log import is_unit_operation
|
from yunohost.log import is_unit_operation
|
||||||
|
|
|
@ -654,7 +654,6 @@ def _tail(file, n):
|
||||||
avg_line_length = 74
|
avg_line_length = 74
|
||||||
to_read = n
|
to_read = n
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if file.endswith(".gz"):
|
if file.endswith(".gz"):
|
||||||
import gzip
|
import gzip
|
||||||
|
|
|
@ -15,6 +15,7 @@ logger = getActionLogger('yunohost.settings')
|
||||||
SETTINGS_PATH = "/etc/yunohost/settings.json"
|
SETTINGS_PATH = "/etc/yunohost/settings.json"
|
||||||
SETTINGS_PATH_OTHER_LOCATION = "/etc/yunohost/settings-%s.json"
|
SETTINGS_PATH_OTHER_LOCATION = "/etc/yunohost/settings-%s.json"
|
||||||
|
|
||||||
|
|
||||||
def is_boolean(value):
|
def is_boolean(value):
|
||||||
"""
|
"""
|
||||||
Ensure a string value is intended as a boolean
|
Ensure a string value is intended as a boolean
|
||||||
|
@ -321,17 +322,20 @@ def reconfigure_nginx(setting_name, old_value, new_value):
|
||||||
if old_value != new_value:
|
if old_value != new_value:
|
||||||
service_regen_conf(names=['nginx'])
|
service_regen_conf(names=['nginx'])
|
||||||
|
|
||||||
|
|
||||||
@post_change_hook("security.ssh.compatibility")
|
@post_change_hook("security.ssh.compatibility")
|
||||||
def reconfigure_ssh(setting_name, old_value, new_value):
|
def reconfigure_ssh(setting_name, old_value, new_value):
|
||||||
if old_value != new_value:
|
if old_value != new_value:
|
||||||
service_regen_conf(names=['ssh'])
|
service_regen_conf(names=['ssh'])
|
||||||
|
|
||||||
|
|
||||||
@post_change_hook("smtp.allow_ipv6")
|
@post_change_hook("smtp.allow_ipv6")
|
||||||
@post_change_hook("security.postfix.compatibility")
|
@post_change_hook("security.postfix.compatibility")
|
||||||
def reconfigure_postfix(setting_name, old_value, new_value):
|
def reconfigure_postfix(setting_name, old_value, new_value):
|
||||||
if old_value != new_value:
|
if old_value != new_value:
|
||||||
service_regen_conf(names=['postfix'])
|
service_regen_conf(names=['postfix'])
|
||||||
|
|
||||||
|
|
||||||
@post_change_hook("pop3.enabled")
|
@post_change_hook("pop3.enabled")
|
||||||
def reconfigure_dovecot(setting_name, old_value, new_value):
|
def reconfigure_dovecot(setting_name, old_value, new_value):
|
||||||
dovecot_package = 'dovecot-pop3d'
|
dovecot_package = 'dovecot-pop3d'
|
||||||
|
|
|
@ -18,10 +18,12 @@ def clone_test_app(request):
|
||||||
else:
|
else:
|
||||||
os.system("cd %s/apps && git pull > /dev/null 2>&1" % cwd)
|
os.system("cd %s/apps && git pull > /dev/null 2>&1" % cwd)
|
||||||
|
|
||||||
|
|
||||||
def get_test_apps_dir():
|
def get_test_apps_dir():
|
||||||
cwd = os.path.split(os.path.realpath(__file__))[0]
|
cwd = os.path.split(os.path.realpath(__file__))[0]
|
||||||
return os.path.join(cwd, "apps")
|
return os.path.join(cwd, "apps")
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def message(mocker, key, **kwargs):
|
def message(mocker, key, **kwargs):
|
||||||
mocker.spy(m18n, "n")
|
mocker.spy(m18n, "n")
|
||||||
|
@ -38,7 +40,6 @@ def raiseYunohostError(mocker, key, **kwargs):
|
||||||
assert e_info._excinfo[1].kwargs == kwargs
|
assert e_info._excinfo[1].kwargs == kwargs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption("--yunodebug", action="store_true", default=False)
|
parser.addoption("--yunodebug", action="store_true", default=False)
|
||||||
|
|
||||||
|
@ -56,12 +57,15 @@ def new_translate(self, key, *args, **kwargs):
|
||||||
raise KeyError("Unable to retrieve key %s for default locale !" % key)
|
raise KeyError("Unable to retrieve key %s for default locale !" % key)
|
||||||
|
|
||||||
return old_translate(self, key, *args, **kwargs)
|
return old_translate(self, key, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
moulinette.core.Translator.translate = new_translate
|
moulinette.core.Translator.translate = new_translate
|
||||||
|
|
||||||
|
|
||||||
def new_m18nn(self, key, *args, **kwargs):
|
def new_m18nn(self, key, *args, **kwargs):
|
||||||
return self._namespaces[self._current_namespace].translate(key, *args, **kwargs)
|
return self._namespaces[self._current_namespace].translate(key, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
moulinette.core.Moulinette18n.n = new_m18nn
|
moulinette.core.Moulinette18n.n = new_m18nn
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -504,36 +504,36 @@ def test_parse_args_in_yunohost_format_boolean_all_yes():
|
||||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||||
expected_result = OrderedDict({"some_boolean": (1, "boolean")})
|
expected_result = OrderedDict({"some_boolean": (1, "boolean")})
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "y"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "y"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "Y"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "Y"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "yes"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "yes"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "YES"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "YES"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "1"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "1"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": 1}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": 1}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": True}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": True}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -541,36 +541,36 @@ def test_parse_args_in_yunohost_format_boolean_all_no():
|
||||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||||
expected_result = OrderedDict({"some_boolean": (0, "boolean")})
|
expected_result = OrderedDict({"some_boolean": (0, "boolean")})
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "n"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "n"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "N"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "N"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "no"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "no"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": "0"}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": "0"}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": 0}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": 0}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
_parse_args_in_yunohost_format({"some_boolean": False}, questions)
|
_parse_args_in_yunohost_format({"some_boolean": False}, questions) ==
|
||||||
== expected_result
|
expected_result
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import glob
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
from moulinette.utils.filesystem import read_json, write_to_json, write_to_yaml, mkdir
|
from moulinette.utils.filesystem import read_json, write_to_json, write_to_yaml
|
||||||
|
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.app import (_initialize_apps_catalog_system,
|
from yunohost.app import (_initialize_apps_catalog_system,
|
||||||
|
@ -37,10 +37,12 @@ DUMMY_APP_CATALOG = """{
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class AnyStringWith(str):
|
class AnyStringWith(str):
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self in other
|
return self in other
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
|
|
||||||
# Clear apps catalog cache
|
# Clear apps catalog cache
|
||||||
|
@ -165,6 +167,7 @@ def test_apps_catalog_update_404(mocker):
|
||||||
_update_apps_catalog()
|
_update_apps_catalog()
|
||||||
m18n.n.assert_any_call("apps_catalog_failed_to_download")
|
m18n.n.assert_any_call("apps_catalog_failed_to_download")
|
||||||
|
|
||||||
|
|
||||||
def test_apps_catalog_update_timeout(mocker):
|
def test_apps_catalog_update_timeout(mocker):
|
||||||
|
|
||||||
# Initialize ...
|
# Initialize ...
|
||||||
|
@ -237,7 +240,6 @@ def test_apps_catalog_load_with_empty_cache(mocker):
|
||||||
m18n.n.assert_any_call("apps_catalog_obsolete_cache")
|
m18n.n.assert_any_call("apps_catalog_obsolete_cache")
|
||||||
m18n.n.assert_any_call("apps_catalog_update_success")
|
m18n.n.assert_any_call("apps_catalog_update_success")
|
||||||
|
|
||||||
|
|
||||||
# Cache shouldn't be empty anymore empty
|
# Cache shouldn't be empty anymore empty
|
||||||
assert glob.glob(APPS_CATALOG_CACHE + "/*")
|
assert glob.glob(APPS_CATALOG_CACHE + "/*")
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ from yunohost.hook import CUSTOM_HOOK_FOLDER
|
||||||
# Get main domain
|
# Get main domain
|
||||||
maindomain = ""
|
maindomain = ""
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
|
|
||||||
global maindomain
|
global maindomain
|
||||||
|
@ -90,6 +91,7 @@ def check_LDAP_db_integrity_call():
|
||||||
yield
|
yield
|
||||||
check_LDAP_db_integrity()
|
check_LDAP_db_integrity()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def check_permission_for_apps_call():
|
def check_permission_for_apps_call():
|
||||||
check_permission_for_apps()
|
check_permission_for_apps()
|
||||||
|
@ -100,6 +102,7 @@ def check_permission_for_apps_call():
|
||||||
# Helpers #
|
# Helpers #
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def app_is_installed(app):
|
def app_is_installed(app):
|
||||||
|
|
||||||
if app == "permissions_app":
|
if app == "permissions_app":
|
||||||
|
@ -184,22 +187,22 @@ def add_archive_wordpress_from_2p4():
|
||||||
|
|
||||||
os.system("mkdir -p /home/yunohost.backup/archives")
|
os.system("mkdir -p /home/yunohost.backup/archives")
|
||||||
|
|
||||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.info.json") + \
|
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.info.json")
|
||||||
" /home/yunohost.backup/archives/backup_wordpress_from_2p4.info.json")
|
+ " /home/yunohost.backup/archives/backup_wordpress_from_2p4.info.json")
|
||||||
|
|
||||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.tar.gz") + \
|
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.tar.gz")
|
||||||
" /home/yunohost.backup/archives/backup_wordpress_from_2p4.tar.gz")
|
+ " /home/yunohost.backup/archives/backup_wordpress_from_2p4.tar.gz")
|
||||||
|
|
||||||
|
|
||||||
def add_archive_system_from_2p4():
|
def add_archive_system_from_2p4():
|
||||||
|
|
||||||
os.system("mkdir -p /home/yunohost.backup/archives")
|
os.system("mkdir -p /home/yunohost.backup/archives")
|
||||||
|
|
||||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.info.json") + \
|
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.info.json")
|
||||||
" /home/yunohost.backup/archives/backup_system_from_2p4.info.json")
|
+ " /home/yunohost.backup/archives/backup_system_from_2p4.info.json")
|
||||||
|
|
||||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.tar.gz") + \
|
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.tar.gz")
|
||||||
" /home/yunohost.backup/archives/backup_system_from_2p4.tar.gz")
|
+ " /home/yunohost.backup/archives/backup_system_from_2p4.tar.gz")
|
||||||
|
|
||||||
#
|
#
|
||||||
# System backup #
|
# System backup #
|
||||||
|
@ -499,6 +502,7 @@ def test_backup_and_restore_with_ynh_restore(mocker):
|
||||||
|
|
||||||
_test_backup_and_restore_app(mocker, "backup_recommended_app")
|
_test_backup_and_restore_app(mocker, "backup_recommended_app")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_permission_app_installed
|
@pytest.mark.with_permission_app_installed
|
||||||
def test_backup_and_restore_permission_app(mocker):
|
def test_backup_and_restore_permission_app(mocker):
|
||||||
|
|
||||||
|
@ -577,6 +581,7 @@ def test_restore_archive_with_no_json(mocker):
|
||||||
with raiseYunohostError(mocker, 'backup_archive_cant_retrieve_info_json'):
|
with raiseYunohostError(mocker, 'backup_archive_cant_retrieve_info_json'):
|
||||||
backup_restore(name="badbackup", force=True)
|
backup_restore(name="badbackup", force=True)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.with_wordpress_archive_from_2p4
|
@pytest.mark.with_wordpress_archive_from_2p4
|
||||||
def test_restore_archive_with_bad_archive(mocker):
|
def test_restore_archive_with_bad_archive(mocker):
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from yunohost.utils.error import YunohostError
|
||||||
# Get main domain
|
# Get main domain
|
||||||
maindomain = ""
|
maindomain = ""
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
global maindomain
|
global maindomain
|
||||||
maindomain = _get_maindomain()
|
maindomain = _get_maindomain()
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
import socket
|
||||||
import requests
|
import requests
|
||||||
import pytest
|
import pytest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from conftest import message, raiseYunohostError, get_test_apps_dir
|
from conftest import message, raiseYunohostError, get_test_apps_dir
|
||||||
|
|
||||||
from yunohost.app import app_install, app_remove, app_change_url, app_list, app_map, _installed_apps
|
from yunohost.app import app_install, app_remove, app_change_url, app_map, _installed_apps
|
||||||
from yunohost.user import user_list, user_create, user_delete, \
|
from yunohost.user import user_list, user_create, user_delete, \
|
||||||
user_group_list, user_group_delete
|
user_group_list, user_group_delete
|
||||||
from yunohost.permission import user_permission_update, user_permission_list, user_permission_reset, \
|
from yunohost.permission import user_permission_update, user_permission_list, user_permission_reset, \
|
||||||
|
@ -17,10 +18,10 @@ dummy_password = "test123Ynh"
|
||||||
|
|
||||||
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
||||||
# Mainly used for 'can_access_webpage' function
|
# Mainly used for 'can_access_webpage' function
|
||||||
import socket
|
|
||||||
|
|
||||||
prv_getaddrinfo = socket.getaddrinfo
|
prv_getaddrinfo = socket.getaddrinfo
|
||||||
|
|
||||||
|
|
||||||
def clean_user_groups_permission():
|
def clean_user_groups_permission():
|
||||||
for u in user_list()['users']:
|
for u in user_list()['users']:
|
||||||
user_delete(u)
|
user_delete(u)
|
||||||
|
@ -44,6 +45,7 @@ def setup_function(function):
|
||||||
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
||||||
# Mainly used for 'can_access_webpage' function
|
# Mainly used for 'can_access_webpage' function
|
||||||
dns_cache = {(maindomain, 443, 0, 1): [(2, 1, 6, '', ('127.0.0.1', 443))]}
|
dns_cache = {(maindomain, 443, 0, 1): [(2, 1, 6, '', ('127.0.0.1', 443))]}
|
||||||
|
|
||||||
def new_getaddrinfo(*args):
|
def new_getaddrinfo(*args):
|
||||||
try:
|
try:
|
||||||
return dns_cache[args]
|
return dns_cache[args]
|
||||||
|
@ -370,16 +372,6 @@ def test_permission_reset_idempotency():
|
||||||
assert set(res['blog.main']['corresponding_users']) == set(["alice", "bob"])
|
assert set(res['blog.main']['corresponding_users']) == set(["alice", "bob"])
|
||||||
|
|
||||||
|
|
||||||
def test_permission_reset_idempotency():
|
|
||||||
# Reset permission
|
|
||||||
user_permission_reset("blog.main")
|
|
||||||
user_permission_reset("blog.main")
|
|
||||||
|
|
||||||
res = user_permission_list(full=True)['permissions']
|
|
||||||
assert res['blog.main']['allowed'] == ["all_users"]
|
|
||||||
assert set(res['blog.main']['corresponding_users']) == set(["alice", "bob"])
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Error on update function
|
# Error on update function
|
||||||
#
|
#
|
||||||
|
@ -407,6 +399,7 @@ def test_permission_redefine_url():
|
||||||
res = user_permission_list(full=True)['permissions']
|
res = user_permission_list(full=True)['permissions']
|
||||||
assert res["blog.main"]["url"] == "/pwet"
|
assert res["blog.main"]["url"] == "/pwet"
|
||||||
|
|
||||||
|
|
||||||
def test_permission_remove_url():
|
def test_permission_remove_url():
|
||||||
permission_url("blog.main", url=None)
|
permission_url("blog.main", url=None)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ TEST_DOMAIN_NGINX_CONFIG = "/etc/nginx/conf.d/%s.conf" % TEST_DOMAIN
|
||||||
TEST_DOMAIN_DNSMASQ_CONFIG = "/etc/dnsmasq.d/%s" % TEST_DOMAIN
|
TEST_DOMAIN_DNSMASQ_CONFIG = "/etc/dnsmasq.d/%s" % TEST_DOMAIN
|
||||||
SSHD_CONFIG = "/etc/ssh/sshd_config"
|
SSHD_CONFIG = "/etc/ssh/sshd_config"
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
|
|
||||||
_force_clear_hashes([TEST_DOMAIN_NGINX_CONFIG])
|
_force_clear_hashes([TEST_DOMAIN_NGINX_CONFIG])
|
||||||
|
|
|
@ -64,11 +64,13 @@ def test_service_add():
|
||||||
service_add("dummyservice", description="A dummy service to run tests")
|
service_add("dummyservice", description="A dummy service to run tests")
|
||||||
assert "dummyservice" in service_status().keys()
|
assert "dummyservice" in service_status().keys()
|
||||||
|
|
||||||
|
|
||||||
def test_service_add_real_service():
|
def test_service_add_real_service():
|
||||||
|
|
||||||
service_add("networking")
|
service_add("networking")
|
||||||
assert "networking" in service_status().keys()
|
assert "networking" in service_status().keys()
|
||||||
|
|
||||||
|
|
||||||
def test_service_remove():
|
def test_service_remove():
|
||||||
|
|
||||||
service_add("dummyservice", description="A dummy service to run tests")
|
service_add("dummyservice", description="A dummy service to run tests")
|
||||||
|
|
|
@ -13,6 +13,7 @@ DEFAULTS["example.int"] = {"type": "int", "default": 42}
|
||||||
DEFAULTS["example.string"] = {"type": "string", "default": "yolo swag"}
|
DEFAULTS["example.string"] = {"type": "string", "default": "yolo swag"}
|
||||||
DEFAULTS["example.enum"] = {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}
|
DEFAULTS["example.enum"] = {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}
|
||||||
|
|
||||||
|
|
||||||
def setup_function(function):
|
def setup_function(function):
|
||||||
os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved")
|
os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved")
|
||||||
|
|
||||||
|
@ -64,10 +65,11 @@ def test_settings_list():
|
||||||
|
|
||||||
def test_settings_set():
|
def test_settings_set():
|
||||||
settings_set("example.bool", False)
|
settings_set("example.bool", False)
|
||||||
assert settings_get("example.bool") == False
|
assert settings_get("example.bool") is False
|
||||||
|
|
||||||
settings_set("example.bool", "on")
|
settings_set("example.bool", "on")
|
||||||
assert settings_get("example.bool") == True
|
assert settings_get("example.bool") is True
|
||||||
|
|
||||||
|
|
||||||
def test_settings_set_int():
|
def test_settings_set_int():
|
||||||
settings_set("example.int", 21)
|
settings_set("example.int", 21)
|
||||||
|
|
|
@ -26,10 +26,8 @@
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import pwd
|
import pwd
|
||||||
import socket
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
from moulinette import msignals, m18n
|
from moulinette import msignals, m18n
|
||||||
|
@ -37,8 +35,8 @@ from moulinette.utils.log import getActionLogger
|
||||||
from moulinette.utils.process import check_output, call_async_output
|
from moulinette.utils.process import check_output, call_async_output
|
||||||
from moulinette.utils.filesystem import read_json, write_to_json, read_yaml, write_to_yaml
|
from moulinette.utils.filesystem import read_json, write_to_json, read_yaml, write_to_yaml
|
||||||
|
|
||||||
from yunohost.app import _update_apps_catalog, app_info, app_upgrade, app_ssowatconf, app_list, _initialize_apps_catalog_system
|
from yunohost.app import _update_apps_catalog, app_info, app_upgrade, _initialize_apps_catalog_system
|
||||||
from yunohost.domain import domain_add, domain_list
|
from yunohost.domain import domain_add
|
||||||
from yunohost.dyndns import _dyndns_available, _dyndns_provides
|
from yunohost.dyndns import _dyndns_available, _dyndns_provides
|
||||||
from yunohost.firewall import firewall_upnp
|
from yunohost.firewall import firewall_upnp
|
||||||
from yunohost.service import service_start, service_enable
|
from yunohost.service import service_start, service_enable
|
||||||
|
@ -53,9 +51,11 @@ MIGRATIONS_STATE_PATH = "/etc/yunohost/migrations.yaml"
|
||||||
|
|
||||||
logger = getActionLogger('yunohost.tools')
|
logger = getActionLogger('yunohost.tools')
|
||||||
|
|
||||||
|
|
||||||
def tools_versions():
|
def tools_versions():
|
||||||
return ynh_packages_version()
|
return ynh_packages_version()
|
||||||
|
|
||||||
|
|
||||||
def tools_ldapinit():
|
def tools_ldapinit():
|
||||||
"""
|
"""
|
||||||
YunoHost LDAP initialization
|
YunoHost LDAP initialization
|
||||||
|
@ -601,7 +601,6 @@ def tools_upgrade(operation_logger, apps=None, system=False, allow_yunohost_upgr
|
||||||
|
|
||||||
logger.debug("Running apt command :\n{}".format(dist_upgrade))
|
logger.debug("Running apt command :\n{}".format(dist_upgrade))
|
||||||
|
|
||||||
|
|
||||||
def is_relevant(l):
|
def is_relevant(l):
|
||||||
irrelevants = [
|
irrelevants = [
|
||||||
"service sudo-ldap already provided",
|
"service sudo-ldap already provided",
|
||||||
|
@ -938,7 +937,7 @@ def _migrate_legacy_migration_json():
|
||||||
# Extract the list of migration ids
|
# Extract the list of migration ids
|
||||||
from . import data_migrations
|
from . import data_migrations
|
||||||
migrations_path = data_migrations.__path__[0]
|
migrations_path = data_migrations.__path__[0]
|
||||||
migration_files = filter(lambda x: re.match("^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path))
|
migration_files = filter(lambda x: re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path))
|
||||||
# (here we remove the .py extension and make sure the ids are sorted)
|
# (here we remove the .py extension and make sure the ids are sorted)
|
||||||
migration_ids = sorted([f.rsplit(".", 1)[0] for f in migration_files])
|
migration_ids = sorted([f.rsplit(".", 1)[0] for f in migration_files])
|
||||||
|
|
||||||
|
@ -987,7 +986,7 @@ def _get_migrations_list():
|
||||||
# (in particular, pending migrations / not already ran are not listed
|
# (in particular, pending migrations / not already ran are not listed
|
||||||
states = tools_migrations_state()["migrations"]
|
states = tools_migrations_state()["migrations"]
|
||||||
|
|
||||||
for migration_file in filter(lambda x: re.match("^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)):
|
for migration_file in filter(lambda x: re.match(r"^\d+_[a-zA-Z0-9_]+\.py$", x), os.listdir(migrations_path)):
|
||||||
m = _load_migration(migration_file)
|
m = _load_migration(migration_file)
|
||||||
m.state = states.get(m.id, "pending")
|
m.state = states.get(m.id, "pending")
|
||||||
migrations.append(m)
|
migrations.append(m)
|
||||||
|
@ -1006,7 +1005,7 @@ def _get_migration_by_name(migration_name):
|
||||||
raise AssertionError("Unable to find migration with name %s" % migration_name)
|
raise AssertionError("Unable to find migration with name %s" % migration_name)
|
||||||
|
|
||||||
migrations_path = data_migrations.__path__[0]
|
migrations_path = data_migrations.__path__[0]
|
||||||
migrations_found = filter(lambda x: re.match("^\d+_%s\.py$" % migration_name, x), os.listdir(migrations_path))
|
migrations_found = filter(lambda x: re.match(r"^\d+_%s\.py$" % migration_name, x), os.listdir(migrations_path))
|
||||||
|
|
||||||
assert len(migrations_found) == 1, "Unable to find migration with name %s" % migration_name
|
assert len(migrations_found) == 1, "Unable to find migration with name %s" % migration_name
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import os
|
||||||
import re
|
import re
|
||||||
import pwd
|
import pwd
|
||||||
import grp
|
import grp
|
||||||
import json
|
|
||||||
import crypt
|
import crypt
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
@ -36,7 +35,6 @@ import copy
|
||||||
|
|
||||||
from moulinette import msignals, msettings, m18n
|
from moulinette import msignals, msettings, m18n
|
||||||
from moulinette.utils.log import getActionLogger
|
from moulinette.utils.log import getActionLogger
|
||||||
from moulinette.utils.filesystem import read_json, write_to_json, read_yaml, write_to_yaml
|
|
||||||
|
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.service import service_status
|
from yunohost.service import service_status
|
||||||
|
@ -240,7 +238,6 @@ def user_delete(operation_logger, username, purge=False):
|
||||||
"""
|
"""
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
from yunohost.utils.ldap import _get_ldap_interface
|
from yunohost.utils.ldap import _get_ldap_interface
|
||||||
from yunohost.permission import permission_sync_to_user
|
|
||||||
|
|
||||||
if username not in user_list()["users"]:
|
if username not in user_list()["users"]:
|
||||||
raise YunohostError('user_unknown', user=username)
|
raise YunohostError('user_unknown', user=username)
|
||||||
|
|
|
@ -29,6 +29,7 @@ from yunohost.utils.error import YunohostError
|
||||||
# to avoid re-authenticating in case we call _get_ldap_authenticator multiple times
|
# to avoid re-authenticating in case we call _get_ldap_authenticator multiple times
|
||||||
_ldap_interface = None
|
_ldap_interface = None
|
||||||
|
|
||||||
|
|
||||||
def _get_ldap_interface():
|
def _get_ldap_interface():
|
||||||
|
|
||||||
global _ldap_interface
|
global _ldap_interface
|
||||||
|
@ -82,4 +83,5 @@ def _destroy_ldap_interface():
|
||||||
if _ldap_interface is not None:
|
if _ldap_interface is not None:
|
||||||
del _ldap_interface
|
del _ldap_interface
|
||||||
|
|
||||||
|
|
||||||
atexit.register(_destroy_ldap_interface)
|
atexit.register(_destroy_ldap_interface)
|
||||||
|
|
|
@ -58,6 +58,7 @@ def get_public_ip_from_remote_server(protocol=4):
|
||||||
|
|
||||||
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
||||||
routes = check_output("ip -%s route show table all" % protocol).split("\n")
|
routes = check_output("ip -%s route show table all" % protocol).split("\n")
|
||||||
|
|
||||||
def is_default_route(r):
|
def is_default_route(r):
|
||||||
# Typically the default route starts with "default"
|
# Typically the default route starts with "default"
|
||||||
# But of course IPv6 is more complex ... e.g. on internet cube there's
|
# But of course IPv6 is more complex ... e.g. on internet cube there's
|
||||||
|
|
|
@ -63,7 +63,7 @@ class PasswordValidator(object):
|
||||||
settings = json.load(open('/etc/yunohost/settings.json', "r"))
|
settings = json.load(open('/etc/yunohost/settings.json', "r"))
|
||||||
setting_key = "security.password." + profile + ".strength"
|
setting_key = "security.password." + profile + ".strength"
|
||||||
self.validation_strength = int(settings[setting_key]["value"])
|
self.validation_strength = int(settings[setting_key]["value"])
|
||||||
except Exception as e:
|
except Exception:
|
||||||
# Fallback to default value if we can't fetch settings for some reason
|
# Fallback to default value if we can't fetch settings for some reason
|
||||||
self.validation_strength = 1
|
self.validation_strength = 1
|
||||||
|
|
||||||
|
@ -83,11 +83,7 @@ class PasswordValidator(object):
|
||||||
# on top (at least not the moulinette ones)
|
# on top (at least not the moulinette ones)
|
||||||
# because the moulinette needs to be correctly initialized
|
# because the moulinette needs to be correctly initialized
|
||||||
# as well as modules available in python's path.
|
# as well as modules available in python's path.
|
||||||
import logging
|
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from moulinette.utils.log import getActionLogger
|
|
||||||
|
|
||||||
logger = logging.getLogger('yunohost.utils.password')
|
|
||||||
|
|
||||||
status, msg = self.validation_summary(password)
|
status, msg = self.validation_summary(password)
|
||||||
if status == "error":
|
if status == "error":
|
||||||
|
|
|
@ -10,6 +10,7 @@ from yunohost.utils.error import YunohostError
|
||||||
|
|
||||||
logger = logging.getLogger('yunohost.utils.yunopaste')
|
logger = logging.getLogger('yunohost.utils.yunopaste')
|
||||||
|
|
||||||
|
|
||||||
def yunopaste(data):
|
def yunopaste(data):
|
||||||
|
|
||||||
paste_server = "https://paste.yunohost.org"
|
paste_server = "https://paste.yunohost.org"
|
||||||
|
@ -44,7 +45,6 @@ def anonymize(data):
|
||||||
data = data.replace(domain.replace(".", "%2e"), redact.replace(".", "%2e"))
|
data = data.replace(domain.replace(".", "%2e"), redact.replace(".", "%2e"))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
# First, let's replace every occurence of the main domain by "domain.tld"
|
# First, let's replace every occurence of the main domain by "domain.tld"
|
||||||
# This should cover a good fraction of the info leaked
|
# This should cover a good fraction of the info leaked
|
||||||
main_domain = _get_maindomain()
|
main_domain = _get_maindomain()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import re
|
|
||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
def test_yaml_syntax():
|
def test_yaml_syntax():
|
||||||
yaml.load(open("data/actionsmap/yunohost.yml"))
|
yaml.load(open("data/actionsmap/yunohost.yml"))
|
||||||
|
|
4
tox.ini
4
tox.ini
|
@ -7,6 +7,6 @@ deps =
|
||||||
py{27,37}-{lint,invalidcode}: flake8
|
py{27,37}-{lint,invalidcode}: flake8
|
||||||
py37-black: black
|
py37-black: black
|
||||||
commands =
|
commands =
|
||||||
py{27,37}-lint: flake8 src doc data tests
|
py{27,37}-lint: flake8 src doc data tests --ignore E402,E501 --exclude src/yunohost/vendor
|
||||||
py{27,37}-invalidcode: flake8 src data --exclude src/yunohost/tests --select F --ignore F401,F841
|
py{27,37}-invalidcode: flake8 src data --exclude src/yunohost/tests,src/yunohost/vendor --select F
|
||||||
py37-black: black --check --diff src doc data tests
|
py37-black: black --check --diff src doc data tests
|
Loading…
Add table
Reference in a new issue