コード例 #1
0
def test_settings_get_full_string():
    assert settings_get("example.string", True) == {
        "type": "string",
        "value": "yolo swag",
        "default": "yolo swag",
        "description": "Dummy string setting",
    }
コード例 #2
0
def test_settings_get_full_int():
    assert settings_get("example.int", True) == {
        "type": "int",
        "value": 42,
        "default": 42,
        "description": "Dummy int setting",
    }
コード例 #3
0
def test_settings_get_full_bool():
    assert settings_get("example.bool", True) == {
        "type": "bool",
        "value": True,
        "default": True,
        "description": "Dummy bool setting",
    }
コード例 #4
0
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"],
    }
コード例 #5
0
    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"],
            )
コード例 #6
0
ファイル: 24-mail.py プロジェクト: grenagit/yunohost
    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)
コード例 #7
0
def test_settings_get_doesnt_exists():
    with pytest.raises(YunohostError):
        settings_get("doesnt.exists")
コード例 #8
0
def test_settings_get_enum():
    assert settings_get("example.enum") == "a"
コード例 #9
0
def test_settings_get_string():
    assert settings_get("example.string") == "yolo swag"
コード例 #10
0
def test_settings_get_int():
    assert settings_get("example.int") == 42
コード例 #11
0
def test_settings_get_bool():
    assert settings_get("example.bool")
コード例 #12
0
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"]
コード例 #13
0
def test_settings_set_enum():
    settings_set("example.enum", "c")
    assert settings_get("example.enum") == "c"
コード例 #14
0
def test_settings_set_int():
    settings_set("example.int", 21)
    assert settings_get("example.int") == 21
コード例 #15
0
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