示例#1
0
def test_is_update_fail():
    s = SampleACL(u('u'), dt(1))

    _is_update_fail(s, None, ValueError('update cannot be a value that evaluates to false'))
    _is_update_fail(
        s, SampleACLDelta([u('a'), u('u')], [u('v')]),
        UnauthorizedError('ACLs for the sample owner u may not be modified by a delta update.'))
    _is_update_fail(
        s, SampleACLDelta([u('a')], write=[u('v'), u('u')]),
        UnauthorizedError('ACLs for the sample owner u may not be modified by a delta update.'))
    _is_update_fail(
        s, SampleACLDelta([u('a')], read=[u('v'), u('u')]),
        UnauthorizedError('ACLs for the sample owner u may not be modified by a delta update.'))
    _is_update_fail(
        s, SampleACLDelta([u('a')], remove=[u('v'), u('u')]),
        UnauthorizedError('ACLs for the sample owner u may not be modified by a delta update.'))
    _is_update_fail(
        s, SampleACLDelta([u('a')], remove=[u('v'), u('u')], at_least=True),
        UnauthorizedError('ACLs for the sample owner u may not be modified by a delta update.'))
示例#2
0
def test_delta_build():
    a = SampleACLDelta()
    assert a.admin == ()
    assert a.write == ()
    assert a.read == ()
    assert a.remove == ()
    assert a.public_read is None
    assert a.at_least is False

    a = SampleACLDelta(
        [u('baz'), u('bat'), u('baz')],
        read=[u('wheee'), u('wheee')],
        write=[u('wugga'), u('a'), u('b'), u('wugga')],
        remove=[u('bleah'), u('ffs'), u('c')],
        public_read=True,
        at_least=True)
    assert a.admin == (u('bat'), u('baz'))
    assert a.write == (u('a'), u('b'), u('wugga'))
    assert a.read == (u('wheee'),)
    assert a.remove == (u('bleah'), u('c'), u('ffs'))
    assert a.public_read is True
    assert a.at_least is True

    a = SampleACLDelta(public_read=False, at_least=None)
    assert a.admin == ()
    assert a.write == ()
    assert a.read == ()
    assert a.remove == ()
    assert a.public_read is False
    assert a.at_least is False

    a = SampleACLDelta(public_read=None)
    assert a.admin == ()
    assert a.write == ()
    assert a.read == ()
    assert a.remove == ()
    assert a.public_read is None
    assert a.at_least is False
示例#3
0
def acl_delta_from_dict(d: Dict[str, Any]) -> SampleACLDelta:
    '''
    Given a dict, create a SampleACLDelta object from the contents of the dict.

    :param params: The dict containing the ACL delta.
    :returns: the ACL delta.
    :raises IllegalParameterError: if any of the arguments are illegal.
    '''
    # since we're translating from SDK server data structures, we assume this is a dict
    incpub = d.get('public_read')
    if incpub is None or incpub == 0:
        pub = None
    elif type(incpub) != int:
        raise _IllegalParameterError(
            'public_read must be an integer if present')
    else:
        pub = incpub > 0

    return SampleACLDelta(_get_acl(d, 'admin'), _get_acl(d, 'write'),
                          _get_acl(d, 'read'), _get_acl(d, 'remove'), pub,
                          bool(d.get('at_least')))
示例#4
0
def test_delta_hash():
    # hashes will change from instance to instance of the python interpreter, and therefore
    # tests can't be written that directly test the hash value. See
    # https://docs.python.org/3/reference/datamodel.html#object.__hash__

    assert hash(SampleACLDelta()) == hash(SampleACLDelta())

    assert hash(SampleACLDelta([u('bar')])) == hash(SampleACLDelta([u('bar')]))
    assert hash(SampleACLDelta([u('bar')])) != hash(SampleACLDelta([u('baz')]))

    assert hash(SampleACLDelta(write=[u('bar')])) == hash(SampleACLDelta(write=[u('bar')]))
    assert hash(SampleACLDelta(write=[u('bar')])) != hash(SampleACLDelta(write=[u('baz')]))

    assert hash(SampleACLDelta(read=[u('bar')])) == hash(SampleACLDelta(read=[u('bar')]))
    assert hash(SampleACLDelta(read=[u('bar')])) != hash(SampleACLDelta(read=[u('baz')]))

    assert hash(SampleACLDelta(remove=[u('bar')])) == hash(SampleACLDelta(remove=[u('bar')]))
    assert hash(SampleACLDelta(remove=[u('bar')])) != hash(SampleACLDelta(remove=[u('baz')]))

    assert hash(SampleACLDelta(public_read=True)) == hash(SampleACLDelta(public_read=True))
    assert hash(SampleACLDelta(public_read=True)) != hash(SampleACLDelta(public_read=False))

    assert hash(SampleACLDelta(at_least=True)) == hash(SampleACLDelta(at_least=True))
    assert hash(SampleACLDelta(at_least=True)) != hash(SampleACLDelta(at_least=False))
示例#5
0
def test_delta_eq():
    assert SampleACLDelta() == SampleACLDelta()

    assert SampleACLDelta([u('bar')]) == SampleACLDelta([u('bar')])
    assert SampleACLDelta([u('bar')]) != SampleACLDelta([u('baz')])

    assert SampleACLDelta(write=[u('bar')]) == SampleACLDelta(write=[u('bar')])
    assert SampleACLDelta(write=[u('bar')]) != SampleACLDelta(write=[u('baz')])

    assert SampleACLDelta(read=[u('bar')]) == SampleACLDelta(read=[u('bar')])
    assert SampleACLDelta(read=[u('bar')]) != SampleACLDelta(read=[u('baz')])

    assert SampleACLDelta(remove=[u('bar')]) == SampleACLDelta(remove=[u('bar')])
    assert SampleACLDelta(remove=[u('bar')]) != SampleACLDelta(remove=[u('baz')])

    assert SampleACLDelta(public_read=True) == SampleACLDelta(public_read=True)
    assert SampleACLDelta(public_read=True) != SampleACLDelta(public_read=False)

    assert SampleACLDelta(at_least=True) == SampleACLDelta(at_least=True)
    assert SampleACLDelta(at_least=True) != SampleACLDelta(at_least=False)

    assert SampleACLDelta() != 1
    assert [] != SampleACLDelta()
示例#6
0
def _build_delta_fail(admin, write, read, remove, expected):
    with raises(Exception) as got:
        SampleACLDelta(admin, write, read, remove)
    assert_exception_correct(got.value, expected)
示例#7
0
def test_is_update():
    s = SampleACL(
        u('o'),
        dt(1),
        [u('a1'), u('a2')],
        [u('w1'), u('w2')],
        [u('r1'), u('r2')],
        True)

    assert s.is_update(SampleACLDelta()) is False

    assert s.is_update(SampleACLDelta([u('a1')])) is False
    assert s.is_update(SampleACLDelta([u('a1')], at_least=True)) is False
    assert s.is_update(SampleACLDelta([u('o')], at_least=True)) is False
    assert s.is_update(SampleACLDelta([u('a3')])) is True

    assert s.is_update(SampleACLDelta(write=[u('w2')])) is False
    assert s.is_update(SampleACLDelta(write=[u('w2')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(write=[u('o')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(write=[u('a1')])) is True
    assert s.is_update(SampleACLDelta(write=[u('a1')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(write=[u('w4')])) is True

    assert s.is_update(SampleACLDelta(read=[u('r1')])) is False
    assert s.is_update(SampleACLDelta(read=[u('r1')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(read=[u('o')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(read=[u('a1')])) is True
    assert s.is_update(SampleACLDelta(read=[u('a1')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(read=[u('w1')])) is True
    assert s.is_update(SampleACLDelta(read=[u('w1')], at_least=True)) is False
    assert s.is_update(SampleACLDelta(read=[u('r3')])) is True

    assert s.is_update(SampleACLDelta(remove=[u('a1')])) is True
    assert s.is_update(SampleACLDelta(remove=[u('a1')], at_least=True)) is True
    assert s.is_update(SampleACLDelta(remove=[u('a3')])) is False

    assert s.is_update(SampleACLDelta(remove=[u('w2')])) is True
    assert s.is_update(SampleACLDelta(remove=[u('w2')], at_least=True)) is True
    assert s.is_update(SampleACLDelta(remove=[u('w4')])) is False

    assert s.is_update(SampleACLDelta(remove=[u('r1')])) is True
    assert s.is_update(SampleACLDelta(remove=[u('r1')], at_least=True)) is True
    assert s.is_update(SampleACLDelta(remove=[u('r3')])) is False

    assert s.is_update(SampleACLDelta(public_read=False)) is True
    assert s.is_update(SampleACLDelta(public_read=None)) is False
    assert s.is_update(SampleACLDelta(public_read=True)) is False