From 8dfb4264f5e14318d89122a2823f569befee0620 Mon Sep 17 00:00:00 2001 From: Justin Stephenson Date: Wed, 3 Apr 2019 13:44:07 -0400 Subject: [PATCH 1/3] Intg tests: Add check for TLOG_ journal fields Add test to validate TLOG journal fields are added as expected using the default journal writer configuration. --- lib/tlitest/test_tlog.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/tlitest/test_tlog.py b/lib/tlitest/test_tlog.py index 08211a27..b30c5d56 100644 --- a/lib/tlitest/test_tlog.py +++ b/lib/tlitest/test_tlog.py @@ -147,6 +147,32 @@ def test_record_command_to_journal(self): check_recording(shell, 'test_record_to_journal') shell.close() + def test_record_journal_tlog_fields(self): + """ + Check that documented TLOG fields are added to + journal messages + """ + msgtext = 'test_tlog_fields' + command = f'tlog-rec -w journal echo {msgtext}' + shell = ssh_pexpect(self.user1, 'Secret123', 'localhost') + shell.sendline(command) + # avoid race condition with reading from the journal + time.sleep(5) + + entry = journal_find_last() + message = entry['MESSAGE'] + + # match the message to ensure we found the right message + out_txt = ast.literal_eval(message)['out_txt'] + + assert msgtext in out_txt + tlog_fields = ['TLOG_USER', 'TLOG_SESSION', 'TLOG_REC', 'TLOG_ID'] + for field in tlog_fields: + value = entry[field] + assert value + check_recording(shell, msgtext) + shell.close() + @pytest.mark.tier1 def test_record_command_to_syslog(self): """ From 83f5ec03c5006e46692942612bd84cbb902c61ad Mon Sep 17 00:00:00 2001 From: Justin Stephenson Date: Wed, 3 Apr 2019 14:07:53 -0400 Subject: [PATCH 2/3] Intg tests: Add journal priority test Add test to validate the expected journal priority field is written when the --journal-priority argument is used. --- lib/tlitest/test_tlog.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/tlitest/test_tlog.py b/lib/tlitest/test_tlog.py index b30c5d56..b94f5273 100644 --- a/lib/tlitest/test_tlog.py +++ b/lib/tlitest/test_tlog.py @@ -173,6 +173,35 @@ def test_record_journal_tlog_fields(self): check_recording(shell, msgtext) shell.close() + def test_record_journal_setting_priority(self): + """ + Write and validate a journal message with a + non-default priority + """ + priority = 'err' + expected_priority_num = 3 + msgtext = 'test_journal_priority' + command = f'tlog-rec -w journal --journal-priority={priority} ' \ + f'echo {msgtext}' + + shell = ssh_pexpect(self.user1, 'Secret123', 'localhost') + shell.sendline(command) + # avoid race condition with reading from the journal + time.sleep(5) + + entry = journal_find_last() + message = entry['MESSAGE'] + priority = entry['PRIORITY'] + + # match the message to ensure we found the right message + out_txt = ast.literal_eval(message)['out_txt'] + + assert msgtext in out_txt + priority_entry = entry['PRIORITY'] + assert priority_entry == expected_priority_num + check_recording(shell, msgtext) + shell.close() + @pytest.mark.tier1 def test_record_command_to_syslog(self): """ From 46a325ffa24d6cd76a478db2e717230d6be45265 Mon Sep 17 00:00:00 2001 From: Justin Stephenson Date: Thu, 4 Apr 2019 12:03:59 -0400 Subject: [PATCH 3/3] Intg tests: Add syslog priority-facility test Add test to validate the expected syslog priority and facility fields when the --syslog-priority and --syslog-facility arguments are used. --- lib/tlitest/test_tlog.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/tlitest/test_tlog.py b/lib/tlitest/test_tlog.py index b94f5273..83955e96 100644 --- a/lib/tlitest/test_tlog.py +++ b/lib/tlitest/test_tlog.py @@ -214,6 +214,40 @@ def test_record_command_to_syslog(self): check_recording(shell, 'test_record_to_syslog') shell.close() + def test_record_syslog_setting_priority_facility(self): + """ + Write and validate a journal message with a + non-default priority + """ + priority = 'err' + facility = 'auth' + expected_priority_num = 3 + expected_facility_num = 4 + msgtext = 'test_syslog_priority_facility' + command = f'tlog-rec -w syslog --syslog-priority={priority} ' \ + f'--syslog-facility={facility} echo {msgtext}' + + shell = ssh_pexpect(self.user1, 'Secret123', 'localhost') + print(command) + shell.sendline(command) + # avoid race condition with reading from the journal + time.sleep(5) + + entry = journal_find_last() + message = entry['MESSAGE'] + + # match the message to ensure we found the right message + out_txt = ast.literal_eval(message)['out_txt'] + + priority_entry = entry['PRIORITY'] + facility_entry = entry['SYSLOG_FACILITY'] + + assert msgtext in out_txt + assert priority_entry == expected_priority_num + assert facility_entry == expected_facility_num + check_recording(shell, msgtext) + shell.close() + def test_record_interactive_session(self): """ Check tlog-rec preserves activity during interactive