Example #1
0
    def test_get_source_perm(self):
        parents = (None, DirectoryNode(0, 0,
                                       0o000), DirectoryNode(0, 0, 0o755))
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)

        for p, u, g in itertools.product(parents, uids, gids):
            if p is None or p.may_execute(u, (g, )):
                FileNode(u, g, 0o644, parent=p).get_source(u, (g, ))
            else:
                with pytest.raises(RootspacePermissionError):
                    FileNode(u, g, 0o644, parent=p).get_source(u, (g, ))
Example #2
0
    def test_remove_node_perm(self):
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)

        for u, g in itertools.product(uids, gids):
            node = DirectoryNode(0, 1, 0o750)
            child = DirectoryNode(0, 1, 0o750)
            node.insert_node(0, (0, ), "child", child)

            if node.may_write(u, (g, )):
                node.remove_node(u, (g, ), "child")
            else:
                with pytest.raises(RootspacePermissionError):
                    node.remove_node(u, (g, ), "child")
Example #3
0
 def test_from_dict(self):
     s = {
         "uid": 0,
         "gid": 0,
         "perm": 0o755,
         "accessed": 0.0,
         "modified": 0.0,
         "changed": 0.0,
         "contents": {}
     }
     assert isinstance(DirectoryNode.from_dict(s), Node)
Example #4
0
    def test_serialisation(self):
        s = {
            "uid": 0,
            "gid": 0,
            "perm": 0o755,
            "accessed": 0.0,
            "modified": 0.0,
            "changed": 0.0,
            "contents": {}
        }
        n = DirectoryNode.from_dict(s)

        assert s == n.to_dict(0, (0, ))
Example #5
0
    def test_list_perm(self):
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)

        for u, g in itertools.product(uids, gids):
            node = DirectoryNode(0, 1, 0o750)

            if node.may_read(u, (g, )):
                node.list(u, (g, ))
            else:
                with pytest.raises(RootspacePermissionError):
                    node.list(u, (g, ))
Example #6
0
    def test_list_value(self):
        parent = DirectoryNode(0, 0, 0o755)
        child = DirectoryNode(0, 0, 0o755, parent=parent)

        value = parent.list(0, (0, ))
        assert isinstance(value, dict)
        assert "." in value and ".." not in value
        assert isinstance(value["."], dict)
        assert value["."] == parent.stat(0, (0, ))

        value2 = child.list(0, (0, ))
        assert isinstance(value2, dict)
        assert "." in value2 and ".." in value2
Example #7
0
    def test_move_node_calls(self, mocker):
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)

        mocker.patch("rootspace.filesystem.DirectoryNode.insert_node")
        mocker.patch("rootspace.filesystem.DirectoryNode.remove_node")

        for u, g in itertools.product(uids, gids):
            parent_a = DirectoryNode(0, 1, 0o750)
            parent_b = DirectoryNode(0, 1, 0o750)
            child = DirectoryNode(0, 1, 0o750, parent=parent_a)
            parent_a._contents["child"] = child

            parent_a.move_node(u, (g, ), "child", parent_b, "new_child")

            assert parent_b.insert_node.call_count == 1
            assert parent_a.remove_node.call_count == 1

            mocker.resetall()
Example #8
0
 def test_move_node_input(self):
     for pp in (None, int(), float(), str(), dict(), list(), tuple(), set(),
                object()):
         with pytest.raises(TypeError):
             DirectoryNode(0, 0, 0).move_node(0, (0, ), "some", pp, "other")
Example #9
0
 def test_remove_node_badfile(self):
     with pytest.raises(RootspaceFileNotFoundError):
         DirectoryNode(0, 0, 0o755).remove_node(0, (0, ), "child")
Example #10
0
 def test_insert_node_input(self):
     for pp in (None, int(), float(), str(), dict(), list(), tuple(), set(),
                object()):
         with pytest.raises(TypeError):
             DirectoryNode(0, 0, 0).insert_node(0, (0, ), "child", pp)
Example #11
0
 def test_to_dict(self):
     value = DirectoryNode(0, 0, 0o755).to_dict(0, (0, ))
     assert isinstance(value, dict)
     assert isinstance(json.dumps(value), str)