Exemple #1
0
    def test_conf_sshd_with_match_multiple(self):
        new_file = "\
Port 22\n\
Match host 192.168.1.1\n\
  ChallengeResponseAuthentication yes\n\
Match host 192.168.1.2\n\
  ChallengeResponseAuthentication yes\n\
Match all\n\
#Other config\n\
"
        expected_output = "\
Port 22\n\
Match host 192.168.1.1\n\
  ChallengeResponseAuthentication yes\n\
Match host 192.168.1.2\n\
  ChallengeResponseAuthentication yes\n\
Match all\n\
#Other config\n\
PasswordAuthentication no\n\
ChallengeResponseAuthentication no\n\
ClientAliveInterval 180\n\
"

        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=new_file):
                osutil.DefaultOSUtil().conf_sshd(disable_password=True)
                patch_write.assert_called_once_with(
                    conf.get_sshd_conf_file_path(),
                    expected_output)
Exemple #2
0
 def conf_sshd(self, disable_password):
     option = "no" if disable_password else "yes"
     conf_file_path = conf.get_sshd_conf_file_path()
     conf_file = fileutil.read_file(conf_file_path).split("\n")
     textutil.set_ssh_config(conf_file, "PasswordAuthentication", option)
     textutil.set_ssh_config(conf_file, "ChallengeResponseAuthentication", option)
     textutil.set_ssh_config(conf_file, "ClientAliveInterval", str(conf.get_ssh_client_alive_interval()))
     fileutil.write_file(conf_file_path, "\n".join(conf_file))
     logger.info("{0} SSH password-based authentication methods."
                 .format("Disabled" if disable_password else "Enabled"))
     logger.info("Configured SSH client probing to keep connections alive.")
Exemple #3
0
 def conf_sshd(self, disable_password):
     option = "no" if disable_password else "yes"
     conf_file_path = conf.get_sshd_conf_file_path()
     conf_file = fileutil.read_file(conf_file_path).split("\n")
     textutil.set_ssh_config(conf_file, "PasswordAuthentication", option)
     textutil.set_ssh_config(conf_file, "ChallengeResponseAuthentication", option)
     textutil.set_ssh_config(conf_file, "ClientAliveInterval", "180")
     fileutil.write_file(conf_file_path, "\n".join(conf_file))
     logger.info("{0} SSH password-based authentication methods."
                 .format("Disabled" if disable_password else "Enabled"))
     logger.info("Configured SSH client probing to keep connections alive.")
Exemple #4
0
 def test_get_sshd_conf_file_path(self):
     self.assertTrue(
         conf.get_sshd_conf_file_path(
             self.conf).startswith("/notareal/path"))