Exemple #1
0
    def test_root_ssh_password_config_task_enabled(self):
        """Test the root password SSH login configuration task - enabled (write config file)."""
        # the config file should be written out when the override is enabled
        with tempfile.TemporaryDirectory() as sysroot:
            config_path = os.path.join(sysroot, self.SSHD_OVERRIDE_PATH)
            os.makedirs(os.path.dirname(config_path))

            # no config should exist before we run the task
            assert not os.path.exists(config_path)

            task = ConfigureRootPasswordSSHLoginTask(sysroot=sysroot, password_allowed=True)
            task.run()

            # correct override config should exist after we run the task
            assert os.path.exists(config_path)

            expected_content = dedent("""
            # This file has been generated by the Anaconda Installer.
            # Allow root to log in using ssh. Remove this file to opt-out.
            PermitRootLogin yes
            """)

            with open(config_path, "rt") as f:
                config_content = f.read()

            assert config_content.strip() == expected_content.strip()
Exemple #2
0
    def test_root_ssh_password_config_task_disabled(self):
        """Test the root password SSH login configuration task - disabled (no config file)."""
        # the config file should not be written out when the override is disabled
        with tempfile.TemporaryDirectory() as sysroot:
            config_path = os.path.join(sysroot, self.SSHD_OVERRIDE_PATH)
            os.makedirs(os.path.dirname(config_path))

            # no config should exist before we run the task
            assert not os.path.exists(config_path)

            task = ConfigureRootPasswordSSHLoginTask(sysroot=sysroot, password_allowed=False)
            task.run()

            # correct override config should exist after we run the task
            assert not os.path.exists(config_path)