示例#1
0
    def test_conf_text_var(self, session_env_config_setup):
        """ Validate configuration settings are overwritten
        by TLOG_REC_SESSION_CONF_TEXT variable
        """
        logfile = mklogfile(self.tempdir)
        msg = inspect.stack()[0][3]
        tmp_notice_msg = "temp"
        tmp_conf_file = TMP_TLOG_REC_SESSION_CONF

        # system wide configuration file
        sessionclass_system = TlogRecSessionConfig(writer="journal")
        sessionclass_system.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)

        # temporary configuration file
        sessionclass_tmp = TlogRecSessionConfig(writer="file",
                                                file_writer_path=logfile,
                                                notice=tmp_notice_msg)
        sessionclass_tmp.generate_config(tmp_conf_file)

        # validate the notice override
        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell.sendline(f'export TLOG_REC_SESSION_CONF_FILE={tmp_conf_file}')
        shell.sendline('export TLOG_REC_SESSION_CONF_TEXT='
                       '\'{"notice":"TEXT Notice"}\'')
        shell.sendline(TLOG_REC_SESSION_PROG)
        shell.expect("TEXT Notice")
        shell.sendline(f'echo {msg}')
        shell.expect(msg)
        shell.sendline('exit')
        shell.close()
示例#2
0
    def test_conf_file_var(self, session_env_config_setup):
        """ Validate configuration settings are overwritten
        by TLOG_REC_SESSION_CONF_FILE variable
        """
        logfile = mklogfile(self.tempdir)
        msg = inspect.stack()[0][3]
        input_notice = "Test NOTICE"
        tmp_conf_file = TMP_TLOG_REC_SESSION_CONF

        # system wide journal configuration file
        sessionclass_system = TlogRecSessionConfig(writer="journal")
        sessionclass_system.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)

        # temporary configuration file to override with
        sessionclass_tmp = TlogRecSessionConfig(writer="file",
                                                file_writer_path=logfile,
                                                notice=input_notice)
        sessionclass_tmp.generate_config(tmp_conf_file)

        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell.sendline(f'export TLOG_REC_SESSION_CONF_FILE={tmp_conf_file}')
        shell.sendline(TLOG_REC_SESSION_PROG)
        # validate the notice override
        shell.expect(input_notice)
        shell.sendline(f'echo {msg}')
        shell.expect(msg)
        shell.sendline('exit')
        check_recording(shell, msg, logfile)
        shell.close()
示例#3
0
 def test_session_record_to_syslog(self):
     """
     Check tlog-rec-session preserves session via syslog
     """
     myname = inspect.stack()[0][3]
     sessionclass = TlogRecSessionConfig(writer="syslog")
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     shell.sendline('echo {}'.format(myname))
     shell.sendline('exit')
     check_recording(shell, myname)
     shell.close()
示例#4
0
 def test_session_record_with_different_shell(self):
     """
     Check tlog-rec-session can specify different shell
     """
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(shell="/usr/bin/tcsh",
                                         writer="file",
                                         file_writer_path=logfile)
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     shell.sendline('echo $SHELL')
     check_recording(shell, '/usr/bin/tcsh', logfile)
     shell.sendline('exit')
示例#5
0
 def test_session_record_to_file(self):
     """
     Check tlog-rec-session preserves session in a file
     """
     myname = inspect.stack()[0][3]
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(writer="file",
                                         file_writer_path=logfile)
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     shell.sendline('echo {}'.format(myname))
     shell.sendline('exit')
     check_recording(shell, myname, logfile)
     shell.close()
示例#6
0
 def test_session_record_fast_input_with_payload(self):
     """
     Check tlog-rec limits output payload size
     """
     myname = inspect.stack()[0][3]
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(writer="file",
                                         file_writer_path=logfile,
                                         payload=128)
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     for num in range(0, 200):
         shell.sendline('echo {}_{}'.format(myname, num))
     shell.sendline('exit')
     check_recording(shell, '{}_199'.format(myname), logfile)
     shell.close()
示例#7
0
 def test_session_record_fast_input_with_limit_action_delay(self):
     """
     Check tlog-rec-session delays recording when logging limit reached
     """
     myname = inspect.stack()[0][3]
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(writer="file",
                                         file_writer_path=logfile,
                                         limit_rate=500,
                                         limit_action="delay")
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     for num in range(0, 200):
         shell.sendline('echo {}_{}'.format(myname, num))
     shell.sendline('exit')
     check_recording(shell, '{}_199'.format(myname), logfile)
     shell.close()
示例#8
0
 def test_session_record_fast_input_with_limit_action_drop(self):
     """
     Check tlog-rec-session drops output when logging limit reached
     """
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(writer="file",
                                         file_writer_path=logfile,
                                         limit_rate=10,
                                         limit_action="drop")
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     shell.sendline('cat /usr/share/dict/linux.words')
     time.sleep(1)
     shell.sendline('exit')
     shell.close()
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     check_recording_missing(shell, 'Byronite', logfile)
     check_recording_missing(shell, 'zygote', logfile)
示例#9
0
 def test_session_record_user_in_utmp(self, utempter_enabled):
     """
     Check tlog-rec-session preserves session in a file
     """
     if not utempter_enabled:
         pytest.skip('utempter not enabled, skipping test')
     myname = inspect.stack()[0][3]
     whoami = '{} pts'.format(self.user)
     logfile = mklogfile(self.tempdir)
     sessionclass = TlogRecSessionConfig(writer="file",
                                         file_writer_path=logfile)
     sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)
     shell = ssh_pexpect(self.user, 'Secret123', 'localhost')
     shell.sendline('echo {}'.format(myname))
     shell.sendline('who am i')
     shell.sendline('exit')
     check_recording(shell, myname, logfile)
     check_recording(shell, whoami, logfile)
     shell.close()
示例#10
0
    def test_conf_text_var(self, rec_env_config_setup):
        """ Validate configuration settings are overwritten
        by TLOG_REC_CONF_TEXT variable
        """
        logfile = mklogfile(self.tempdir)
        msg = inspect.stack()[0][3]
        tmp_conf_file = TMP_TLOG_REC_CONF

        # system wide configuration file
        recclass_system = TlogRecConfig(writer="journal")
        recclass_system.generate_config(SYSTEM_TLOG_REC_CONF)

        # temporary configuration file
        recclass_tmp = TlogRecSessionConfig(writer="syslog")
        recclass_tmp.generate_config(tmp_conf_file)

        # validate the file writer override
        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell.sendline(f'export TLOG_REC_CONF_FILE={tmp_conf_file}')
        shell.sendline('export TLOG_REC_CONF_TEXT=\'{"writer":"file"}\'')
        shell.sendline(TLOG_REC_PROG + f"-c echo {msg}")
        check_recording(shell, msg, logfile)
        shell.close()
示例#11
0
    def test_conf_shell_var(self, session_env_config_setup):
        """ Validate the TLOG_REC_SESSION_SHELL variable
        is honored
        """
        msg = inspect.stack()[0][3]
        input_shell = "/bin/tcsh"

        sessionclass = TlogRecSessionConfig(writer="journal",
                                            shell='/bin/bash')
        sessionclass.generate_config(SYSTEM_TLOG_REC_SESSION_CONF)

        shell = ssh_pexpect(self.user1, 'Secret123', 'localhost')
        shell.sendline('export TLOG_REC_SESSION_CONF_TEXT='
                       '\'{"shell":"/bin/zsh"}\'')
        shell.sendline(f'export TLOG_REC_SESSION_SHELL={input_shell}')
        shell.sendline(TLOG_REC_SESSION_PROG)
        shell.expect("ATTENTION")
        shell.sendline("echo $SHELL")
        shell.expect(input_shell)
        shell.sendline(f'echo {msg}')
        shell.expect(msg)
        shell.sendline('exit')
        shell.close()