Example #1
0
 def setUp(self):
     self.fout = []
     self.task = []
     self.secret = b"Magic World!"
     # 0: EACCES
     self.fout.append(config.touch("file_write_0.out", self.secret, 0o600))
     self.task.append(config.build("file_write_0", config.TMPL_FILE_WRITE.replace(
         b"@FN@", ("\"%s\"" % self.fout[-1]).encode())))
     # allow everyone to read from jail
     self.prefix = os.path.abspath(os.path.normpath(os.path.dirname(self.task[-1])))
     os.chmod(self.prefix, 0o755)
     self.addCleanup(os.chmod, self.prefix, 0o700)
     # 1: EACCES
     fn_rel = "../file_write_1.out"
     fn_full = config.touch(fn_rel, self.secret, 0o666)
     self.assertTrue(fn_full is not None)
     self.addCleanup(os.unlink, fn_full)
     self.fout.append(fn_rel)
     self.task.append(config.build("file_write_1", config.TMPL_FILE_WRITE.replace(
         b"@FN@", ("\"%s\"" % self.fout[-1]).encode())))
     # 2: OK
     fn_rel = "./file_write_2.out"
     fn_full = config.touch(fn_rel, self.secret, 0o666)
     self.assertTrue(fn_full is not None)
     self.fout.append(fn_rel)
     self.task.append(config.build("file_write_2", config.TMPL_FILE_WRITE.replace(
         b"@FN@", ("\"%s\"" % self.fout[-1]).encode())))
     for f in self.fout + self.task:
         self.assertTrue(f is not None)
     pass
Example #2
0
 def setUp(self):
     self.fout = []
     self.task = []
     self.fout.append(config.touch("file_write.out"))
     self.task.append(config.build("file_write", config.TMPL_FILE_WRITE.replace(
         b"@FN@", ("\"%s\"" % self.fout[-1]).encode())))
     self.fout.append(config.touch("loop_print.out"))
     self.task.append(config.build("loop_print", config.CODE_LOOP_PRINT))
     for fn in self.fout + self.task:
         self.assertTrue(fn is not None)
     pass
Example #3
0
 def test_rlimit_fsz(self):
     s_wr = open(config.touch("rlimit_fsz.out"), "wb")
     s = Sandbox(self.task[5], stdout=s_wr)
     s.policy = AllowResLimitPolicy(s)
     s.run()
     s_wr.close()
     self.assertEqual(s.status, Sandbox.S_STATUS_FIN)
     self.assertEqual(s.result, Sandbox.S_RESULT_OL)
     d = s.probe(False)
     self.assertEqual(d['signal_info'], (SIGXFSZ, SI_USER))
     pass