aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_nsjail.py
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-06-22 13:27:47 -0700
committerGravatar MarkKoz <[email protected]>2019-06-22 13:36:39 -0700
commit81e2a92019a184b2a558658777ceded99b360731 (patch)
tree5cbb4c14bd6db7ab0832862c1ee3ee2fb62ea458 /tests/test_nsjail.py
parentRewrite NsJail tests (diff)
Add a NsJail log parser test
* Add support for debug level to log regex * Change type annotation of log_parse to Iterable
Diffstat (limited to 'tests/test_nsjail.py')
-rw-r--r--tests/test_nsjail.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py
index 1184b87..e3b8eb3 100644
--- a/tests/test_nsjail.py
+++ b/tests/test_nsjail.py
@@ -10,6 +10,7 @@ class NsJailTests(unittest.TestCase):
super().setUp()
self.nsjail = NsJail()
+ self.nsjail.DEBUG = False
self.logger = logging.getLogger("snekbox.nsjail")
def test_print_returns_0(self):
@@ -75,3 +76,32 @@ class NsJailTests(unittest.TestCase):
self.assertEqual(result.returncode, None)
self.assertEqual(result.stdout, "ValueError: embedded null byte")
self.assertEqual(result.stderr, None)
+
+ def test_log_parser(self):
+ log_lines = (
+ "[D][2019-06-22T20:07:00+0000][16] void foo::bar()():100 This is a debug message.",
+ "[I][2019-06-22T20:07:48+0000] pid=20 ([STANDALONE MODE]) "
+ "exited with status: 2, (PIDs left: 0)",
+ "[W][2019-06-22T20:06:04+0000][14] void cmdline::logParams(nsjconf_t*)():250 "
+ "Process will be UID/EUID=0 in the global user namespace, and will have user "
+ "root-level access to files",
+ "[W][2019-06-22T20:07:00+0000][16] void foo::bar()():100 This is a warning!",
+ "[E][2019-06-22T20:07:00+0000][16] bool "
+ "cmdline::setupArgv(nsjconf_t*, int, char**, int)():316 No command-line provided",
+ "[F][2019-06-22T20:07:00+0000][16] int main(int, char**)():204 "
+ "Couldn't parse cmdline options",
+ "Invalid Line"
+ )
+
+ with self.assertLogs(self.logger, logging.DEBUG) as log:
+ self.nsjail._parse_log(log_lines)
+
+ self.assertIn("DEBUG:snekbox.nsjail:This is a debug message.", log.output)
+ self.assertIn("ERROR:snekbox.nsjail:Couldn't parse cmdline options", log.output)
+ self.assertIn("ERROR:snekbox.nsjail:No command-line provided", log.output)
+ self.assertIn("WARNING:snekbox.nsjail:Failed to parse log line 'Invalid Line'", log.output)
+ self.assertIn("WARNING:snekbox.nsjail:This is a warning!", log.output)
+ self.assertIn(
+ "INFO:snekbox.nsjail:pid=20 ([STANDALONE MODE]) exited with status: 2, (PIDs left: 0)",
+ log.output
+ )