def test_settings_get_full_string(): assert settings_get("example.string", True) == { "type": "string", "value": "yolo swag", "default": "yolo swag", "description": "Dummy string setting", }
def test_settings_get_full_int(): assert settings_get("example.int", True) == { "type": "int", "value": 42, "default": 42, "description": "Dummy int setting", }
def test_settings_get_full_bool(): assert settings_get("example.bool", True) == { "type": "bool", "value": True, "default": True, "description": "Dummy bool setting", }
def test_settings_get_full_enum(): assert settings_get("example.enum", True) == { "type": "enum", "value": "a", "default": "a", "description": "Dummy enum setting", "choices": ["a", "b", "c"], }
def run(self): regenconf_modified_files = list(self.manually_modified_files()) if not regenconf_modified_files: yield dict( meta={"test": "regenconf"}, status="SUCCESS", summary="diagnosis_regenconf_allgood", ) else: for f in regenconf_modified_files: yield dict( meta={ "test": "regenconf", "category": f["category"], "file": f["path"], }, status="WARNING", summary="diagnosis_regenconf_manually_modified", details=["diagnosis_regenconf_manually_modified_details"], ) if ( any(f["path"] == "/etc/ssh/sshd_config" for f in regenconf_modified_files) and os.system( "grep -q '^ *AllowGroups\\|^ *AllowUsers' /etc/ssh/sshd_config" ) != 0 ): yield dict( meta={"test": "sshd_config_insecure"}, status="ERROR", summary="diagnosis_sshd_config_insecure", ) # Check consistency between actual ssh port in sshd_config vs. setting ssh_port_setting = settings_get("security.ssh.port") ssh_port_line = re.findall( r"\bPort *([0-9]{2,5})\b", read_file("/etc/ssh/sshd_config") ) if len(ssh_port_line) == 1 and int(ssh_port_line[0]) != ssh_port_setting: yield dict( meta={"test": "sshd_config_port_inconsistency"}, status="WARNING", summary="diagnosis_sshd_config_inconsistent", details=["diagnosis_sshd_config_inconsistent_details"], )
def get_ips_checked(self): outgoing_ipversions = [] outgoing_ips = [] ipv4 = Diagnoser.get_cached_report("ip", {"test": "ipv4"}) or {} if ipv4.get("status") == "SUCCESS": outgoing_ipversions.append(4) global_ipv4 = ipv4.get("data", {}).get("global", {}) if global_ipv4: outgoing_ips.append(global_ipv4) if settings_get("smtp.allow_ipv6"): ipv6 = Diagnoser.get_cached_report("ip", {"test": "ipv6"}) or {} if ipv6.get("status") == "SUCCESS": outgoing_ipversions.append(6) global_ipv6 = ipv6.get("data", {}).get("global", {}) if global_ipv6: outgoing_ips.append(global_ipv6) return (outgoing_ipversions, outgoing_ips)
def test_settings_get_doesnt_exists(): with pytest.raises(YunohostError): settings_get("doesnt.exists")
def test_settings_get_enum(): assert settings_get("example.enum") == "a"
def test_settings_get_string(): assert settings_get("example.string") == "yolo swag"
def test_settings_get_int(): assert settings_get("example.int") == 42
def test_settings_get_bool(): assert settings_get("example.bool")
def test_reset(): settings_set("example.int", 21) assert settings_get("example.int") == 21 settings_reset("example.int") assert settings_get("example.int") == settings_get("example.int", True)["default"]
def test_settings_set_enum(): settings_set("example.enum", "c") assert settings_get("example.enum") == "c"
def test_settings_set_int(): settings_set("example.int", 21) assert settings_get("example.int") == 21
def test_settings_set(): settings_set("example.bool", False) assert settings_get("example.bool") is False settings_set("example.bool", "on") assert settings_get("example.bool") is True