示例#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, ))
示例#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)
示例#3
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)
示例#4
0
 def test_perm_str(self):
     assert isinstance(Node(0, 0, 0)._perm_str(), str)
示例#5
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)
示例#6
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"))
示例#7
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)
示例#8
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)
示例#9
0
 def test_instantiation(self):
     parent = Node(0, 0, 0)
     Node(0, 0, 0, parent=parent)