예제 #1
0
async def test_block_create_and_read(alice_backend_sock, realm):
    await block_create(alice_backend_sock, BLOCK_ID, realm, BLOCK_DATA)

    rep = await block_read(alice_backend_sock, BLOCK_ID)
    assert rep == {"status": "ok", "block": BLOCK_DATA}

    # Test not found as well

    dummy_id = BlockID.from_hex("00000000000000000000000000000002")
    rep = await block_read(alice_backend_sock, dummy_id)
    assert rep == {"status": "not_found"}
예제 #2
0
async def test_s3_read(caplog):
    org_id = OrganizationID("org42")
    block_id = BlockID.from_hex("0694a21176354e8295e28a543e5887f9")

    def _assert_log():
        log = caplog.assert_occured_once("[warning  ] Block read error")
        assert f"organization_id={org_id}" in log
        assert f"block_id={block_id}" in log
        assert len(caplog.messages) == 1
        caplog.clear()

    with mock.patch("boto3.client") as client_mock:
        client_mock.return_value = Mock()
        client_mock().head_bucket.return_value = True
        blockstore = S3BlockStoreComponent("europe", "parsec", "john",
                                           "secret")

        # Ok
        response_mock = Mock()
        response_mock.read.return_value = "content"
        client_mock().get_object.return_value = {"Body": response_mock}
        assert await blockstore.read(org_id, block_id) == "content"
        client_mock().get_object.assert_called_once_with(
            Bucket="parsec", Key="org42/0694a211-7635-4e82-95e2-8a543e5887f9")
        client_mock().get_object.reset_mock()
        assert not caplog.messages

        # Not found
        client_mock().get_object.side_effect = S3ClientError(
            error_response={"Error": {
                "Code": "404"
            }}, operation_name="GET")
        with pytest.raises(BlockStoreError):
            assert await blockstore.read(org_id, block_id)
        _assert_log()

        # Connection error
        client_mock().get_object.side_effect = S3EndpointConnectionError(
            endpoint_url="url")
        with pytest.raises(BlockStoreError):
            assert await blockstore.read(org_id, block_id)
        _assert_log()

        # Unknown exception
        client_mock().get_object.side_effect = S3ClientError(
            error_response={"Error": {
                "Code": "401"
            }}, operation_name="GET")
        with pytest.raises(BlockStoreError):
            assert await blockstore.read(org_id, block_id)
        _assert_log()
예제 #3
0
async def test_swift_create(caplog):
    org_id = OrganizationID("org42")
    block_id = BlockID.from_hex("0694a21176354e8295e28a543e5887f9")

    def _assert_log():
        log = caplog.assert_occured_once("[warning  ] Block create error")
        assert f"organization_id={org_id}" in log
        assert f"block_id={block_id}" in log
        assert len(caplog.messages) == 1
        caplog.clear()

    with mock.patch("swiftclient.Connection") as connection_mock:
        connection_mock.return_value = Mock()
        connection_mock().head_container.return_value = True
        blockstore = SwiftBlockStoreComponent("http://url", "scille", "parsec",
                                              "john", "secret")

        # Ok
        connection_mock().get_object.side_effect = ClientException(
            http_status=404, msg="")
        await blockstore.create(org_id, block_id, "content")
        connection_mock().put_object.assert_called_with(
            "parsec", "org42/0694a211-7635-4e82-95e2-8a543e5887f9", "content")
        connection_mock().put_object.reset_mock()
        assert not caplog.messages

        # Connection error at PUT
        connection_mock().get_object.side_effect = ClientException(
            msg="Connection error")
        connection_mock().put_object.side_effect = ClientException(
            msg="Connection error")
        with pytest.raises(BlockStoreError):
            await blockstore.create(org_id, block_id, "content")
        _assert_log()

        # Unknown exception at PUT
        connection_mock().put_object.side_effect = ClientException(
            http_status=500, msg="")
        with pytest.raises(BlockStoreError):
            await blockstore.create(org_id, block_id, "content")
        _assert_log()
예제 #4
0
async def block(backend, alice, realm):
    block_id = BlockID.from_hex("0000000000000000000000000000000C")

    await backend.block.create(alice.organization_id, alice.device_id,
                               block_id, realm, BLOCK_DATA)
    return block_id
예제 #5
0
    generate_checksum_chunk,
    rebuild_block_from_chunks,
)
from parsec.api.protocol import (
    BlockID,
    VlobID,
    block_create_serializer,
    block_read_serializer,
    packb,
    RealmRole,
)

from tests.common import customize_fixtures
from tests.backend.common import block_create, block_read

BLOCK_ID = BlockID.from_hex("00000000000000000000000000000001")
VLOB_ID = VlobID.from_hex("00000000000000000000000000000002")
BLOCK_DATA = b"Hodi ho !"


@pytest.fixture
async def block(backend, alice, realm):
    block_id = BlockID.from_hex("0000000000000000000000000000000C")

    await backend.block.create(alice.organization_id, alice.device_id,
                               block_id, realm, BLOCK_DATA)
    return block_id


@pytest.mark.trio
async def test_block_read_check_access_rights(backend, alice, bob,