Ejemplo n.º 1
0
 def test_no_accesses(self):
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(),
             action_tracer.AccessConstraints()),
         action_tracer.FSAccessSet(),
     )
Ejemplo n.º 2
0
 def test_ok_read(self):
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(reads={"readable.txt"}),
             action_tracer.AccessConstraints(
                 allowed_reads={"readable.txt"})),
         action_tracer.FSAccessSet(),
     )
Ejemplo n.º 3
0
 def test_forbidden_read(self):
     read = "unreadable.txt"
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(reads={read}),
             action_tracer.AccessConstraints()),
         action_tracer.FSAccessSet(reads={read}),
     )
Ejemplo n.º 4
0
 def test_ok_write(self):
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(writes={"writeable.txt"}),
             action_tracer.AccessConstraints(
                 allowed_writes={"writeable.txt"})),
         action_tracer.FSAccessSet(),
     )
Ejemplo n.º 5
0
 def test_forbidden_writes(self):
     # make sure multiple violations accumulate
     bad_writes = {
         "unwriteable.txt",
         "you-shall-not-pass.txt",
     }
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(writes=bad_writes),
             action_tracer.AccessConstraints()),
         action_tracer.FSAccessSet(writes=bad_writes),
     )
Ejemplo n.º 6
0
 def test_read_from_temporary_writes_ok(self):
     temp_file = "__file.tmp"
     reads = {temp_file}
     writes = {
         "unwriteable.txt",
         temp_file,
     }
     self.assertEqual(
         action_tracer.check_access_permissions(
             action_tracer.FSAccessSet(reads=reads, writes=writes),
             action_tracer.AccessConstraints()),
         action_tracer.FSAccessSet(reads=set(), writes=writes),
     )
Ejemplo n.º 7
0
 def test_reads(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses(
             [
                 action_tracer.Read("r1.txt"),
                 action_tracer.Read("r2.txt"),
             ]), action_tracer.FSAccessSet(reads={"r1.txt", "r2.txt"}))
Ejemplo n.º 8
0
 def test_delete(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses(
             [
                 action_tracer.Delete("d1.txt"),
                 action_tracer.Delete("d2.txt"),
             ]), action_tracer.FSAccessSet(deletes={"d1.txt", "d2.txt"}))
Ejemplo n.º 9
0
 def test_write_after_delete(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses(
             [
                 action_tracer.Delete("temp.txt"),
                 action_tracer.Write("temp.txt"),
             ]), action_tracer.FSAccessSet(writes={"temp.txt"}))
Ejemplo n.º 10
0
 def test_read_after_write(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses(
             [
                 action_tracer.Write("temp.txt"),
                 action_tracer.Read("temp.txt"),
             ]), action_tracer.FSAccessSet(reads=set(), writes={"temp.txt"}))
Ejemplo n.º 11
0
 def test_writes(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses(
             [
                 action_tracer.Write("wb.txt"),
                 action_tracer.Write("wa.txt"),
             ]), action_tracer.FSAccessSet(writes={"wa.txt", "wb.txt"}))
Ejemplo n.º 12
0
 def test_reads(self):
     self.assertEqual(
         str(action_tracer.FSAccessSet(reads={"c", "a", "b"})),
         textwrap.dedent("""\
              Reads:
                a
                b
                c"""))
Ejemplo n.º 13
0
 def test_deletes(self):
     self.assertEqual(
         str(action_tracer.FSAccessSet(deletes={"r", "q", "p"})),
         textwrap.dedent("""\
              Deletes:
                p
                q
                r"""))
Ejemplo n.º 14
0
 def test_writes(self):
     self.assertEqual(
         str(action_tracer.FSAccessSet(writes={"e", "f", "d"})),
         textwrap.dedent("""\
              Writes:
                d
                e
                f"""))
Ejemplo n.º 15
0
 def test_reads_writes_no_deletes(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses([
             action_tracer.Read("r2.txt"),
             action_tracer.Write("wb.txt"),
             action_tracer.Write("wa.txt"),
             action_tracer.Read("r1.txt"),
         ]),
         action_tracer.FSAccessSet(reads={"r1.txt", "r2.txt"},
                                   writes={"wa.txt", "wb.txt"}))
Ejemplo n.º 16
0
 def test_reads_writes(self):
     files = {"c", "a", "b"}
     self.assertEqual(
         str(action_tracer.FSAccessSet(reads=files, writes=files)),
         textwrap.dedent("""\
              Reads:
                a
                b
                c
              Writes:
                a
                b
                c"""))
Ejemplo n.º 17
0
 def test_writes_deletes(self):
     files = {"c", "a", "b"}
     self.assertEqual(
         str(action_tracer.FSAccessSet(writes=files, deletes=files)),
         textwrap.dedent("""\
              Writes:
                a
                b
                c
              Deletes:
                a
                b
                c"""))
Ejemplo n.º 18
0
 def test_no_accesses(self):
     self.assertEqual(
         action_tracer.finalize_filesystem_accesses([]),
         action_tracer.FSAccessSet())
Ejemplo n.º 19
0
 def test_empty(self):
     self.assertEqual(str(action_tracer.FSAccessSet()), "[empty accesses]")