Beispiel #1
0
    def test_stat_perm(self):
        parents = (None, Node(0, 0, 0o755))
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)
        perms = range(512)

        for pa, nu, ng, np, u, g in itertools.product(parents, uids, gids,
                                                      perms, uids, gids):
            if pa is None or pa.may_read(u, (g, )):
                Node(nu, ng, np, parent=pa).stat(u, (g, ))
            else:
                with pytest.raises(RootspacePermissionError):
                    Node(pa, nu, ng, np, parent=pa).stat(u, (g, ))
Beispiel #2
0
    def test_modify_perm_perm(self):
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)
        perms = range(512)
        new_perms = (0, )

        for nu, ng, np, u, g, pp in itertools.product(uids, gids, perms, uids,
                                                      gids, new_perms):
            if u == 0 or u == nu:
                Node(nu, ng, np).modify_perm(u, (g, ), pp)
            else:
                with pytest.raises(RootspacePermissionError):
                    Node(nu, ng, np).modify_perm(u, (g, ), pp)
Beispiel #3
0
 def test_from_dict(self):
     s = {
         "uid": 0,
         "gid": 0,
         "perm": 0o755,
         "accessed": 0.0,
         "modified": 0.0,
         "changed": 0.0
     }
     assert isinstance(Node.from_dict(s), Node)
Beispiel #4
0
    def test_serialisation(self):
        s = {
            "uid": 0,
            "gid": 0,
            "perm": 0o755,
            "accessed": 0.0,
            "modified": 0.0,
            "changed": 0.0
        }
        n = Node.from_dict(s)

        assert s == n.to_dict(0, (0, ))
Beispiel #5
0
    def test_may_execute(self):
        uids = (0, 1, 1000)
        gids = (0, 1, 1000)
        perms = range(512)

        def exp_exec(nuid, ngid, nperm, uid, gid):
            perm_bits = (((nperm // 64) % 2) > 0,
                         (((nperm % 64) // 8) % 2) > 0, ((nperm % 8) % 2) > 0)
            privileged = (uid == 0 and any(perm_bits))
            user_perm = (uid == nuid and perm_bits[0])
            group_perm = (gid == ngid and perm_bits[1])
            other_perm = perm_bits[2]

            return privileged or user_perm or group_perm or other_perm

        for nu, ng, np, u, g in itertools.product(uids, gids, perms, uids,
                                                  gids):
            assert Node(nu, ng,
                        np).may_execute(u,
                                        (g, )) == exp_exec(nu, ng, np, u, g)
Beispiel #6
0
 def test_perm_str(self):
     assert isinstance(Node(0, 0, 0)._perm_str(), str)
Beispiel #7
0
 def test_to_dict(self):
     value = Node(0, 0, 0o755).to_dict(0, (0, ))
     assert isinstance(value, dict)
     assert isinstance(json.dumps(value), str)
Beispiel #8
0
 def test_stat_value(self):
     value = Node(0, 0, 0o755).stat(0, (0, ))
     assert isinstance(value, dict)
     assert all(k in value for k in ("uid", "gid", "perm", "accessed",
                                     "modified", "changed"))
Beispiel #9
0
 def test_modify_perm_input(self):
     for pp in (None, float(), str(), dict(), list(), tuple(), set(),
                object()):
         with pytest.raises(TypeError):
             Node(0, 0, 0).modify_perm(0, (0, ), pp)
Beispiel #10
0
 def test_modify_parent_input(self):
     for npa in (None, int(), float(), str(), dict(), list(), tuple(),
                 set(), object()):
         with pytest.raises(TypeError):
             Node(0, 0, 0).modify_parent(0, (0, ), npa)
Beispiel #11
0
 def test_instantiation(self):
     parent = Node(0, 0, 0)
     Node(0, 0, 0, parent=parent)