Beispiel #1
0
def test_admin_permissions():
    conf = test_config()
    loop = pyuv.Loop.default_loop()

    with KeyManager(loop, conf) as h:
        h.create_key({"admin": True}, key="test", label="admin")
        key = Key.load(h.get_key("test"))
        assert key.api_key == "test"
        assert key.label == "admin"
        assert key.permissions == {"admin": True}
        assert key.is_admin() == True
        assert key.can_create_key() == True
        assert key.can_create_user() == True
        assert key.can_manage_all() == True
        assert key.can_read_all() == True
        assert key.can_write_all() == True
        assert key.can_read("test") == True
        assert key.can_read("test.test") == True
        assert key.can_read("test1") == True
        assert key.can_read("test1.test") == True
        assert key.can_write("test") == True
        assert key.can_write("test.test") == True
        assert key.can_write("test1") == True
        assert key.can_write("test1.test") == True
        assert key.can_manage("test") == True
        assert key.can_manage("test.test") == True
        assert key.can_manage("test1") == True
        assert key.can_manage("test1.test") == True
Beispiel #2
0
def test_write_session1():
    conf = test_config()
    loop = pyuv.Loop.default_loop()

    with KeyManager(loop, conf) as h:
        h.create_key({"write": ["test", "test1"]}, key="test")
        key = Key.load(h.get_key("test"))
        assert key.api_key == "test"
        assert key.is_admin() == False
        assert key.can_create_key() == False
        assert key.can_create_user() == False
        assert key.can_manage_all() == False
        assert key.can_read_all() == False
        assert key.can_write_all() == False
        assert key.can_read("test") == True
        assert key.can_read("test.test") == True
        assert key.can_read("test1") == True
        assert key.can_read("test1.test") == True
        assert key.can_write("test") == True
        assert key.can_write("test.test") == True
        assert key.can_write("test1") == True
        assert key.can_write("test1.test") == True
        assert key.can_manage("test") == False
        assert key.can_manage("test.test") == False
        assert key.can_manage("test1") == False
        assert key.can_manage("test1.test") == False
Beispiel #3
0
def test_key_manager():
    conf = test_config()
    loop = pyuv.Loop.default_loop()

    with KeyManager(loop, conf) as h:
        h.set_key("test", {"permission": {}})

        with pytest.raises(KeyConflict):
            h.set_key("test", {"permission": {}})

        assert h.has_key("test") == True

        key = h.get_key("test")
        assert key == {"key": "test", "permission": {}}
        assert len(h._cache) == 1
        assert "test" in h._cache
        assert len(h._entries) == 1
        assert list(h._entries) == ["test"]

        key = h.delete_key("test")
        with pytest.raises(KeyNotFound):
            key = h.get_key("test")

        h.set_key("test", {"permission": {}})
        h.set_key("test1", {"permission": {}}, "test")

        assert h.has_key("test1") == True
        assert h.all_subkeys("test") == [{"key": "test1", "permission": {}}]
        assert len(h.all_keys()) == 2
        assert h.all_keys() == ["test", "test1"]
        assert h.all_keys(include_key=True) == [{
            "key": "test",
            "permission": {}
        }, {
            "key": "test1",
            "permission": {}
        }]

        h.get_key("test")
        h.get_key("test1")
        assert len(h._cache) == 2
        assert "test" in h._cache
        assert "test1" in h._cache
        assert len(h._entries) == 2
        assert list(h._entries) == ["test", "test1"]

        # make sure keys are deleted from the cache
        h.delete_key("test")
        assert len(h._cache) == 0
        assert len(h._entries) == 0

        with pytest.raises(KeyNotFound):
            key = h.get_key("test")

        with pytest.raises(KeyNotFound):
            key = h.get_key("test1")
Beispiel #4
0
def test_create_key():
    conf = test_config()
    loop = pyuv.Loop.default_loop()

    with KeyManager(loop, conf) as h:
        h.create_key({"admin": True}, label="some key", key="test")
        key = h.get_key("test")

        assert key == {
            "key": "test",
            "label": "some key",
            "permissions": {
                "admin": True
            }
        }
Beispiel #5
0
def test_write_job3():
    conf = test_config()
    loop = pyuv.Loop.default_loop()

    with KeyManager(loop, conf) as h:
        h.create_key({"write": ["test.test", "test1.test"]}, key="test1")
        key = Key.load(h.get_key("test1"))
        assert key.can_read("test") == False
        assert key.can_read("test.test") == True
        assert key.can_read("test1") == False
        assert key.can_read("test1.test") == True
        assert key.can_write("test") == False
        assert key.can_write("test.test") == True
        assert key.can_write("test1") == False
        assert key.can_write("test1.test") == True
        assert key.can_manage("test") == False
        assert key.can_manage("test.test") == False
        assert key.can_manage("test1") == False
        assert key.can_manage("test1.test") == False