示例#1
0
    async def test_upload_fail(self, nginx_proxy, memory_file):
        """Test failed upload to a TLS server."""

        # Make sure we actually use encryption, access via plain
        # HTTP shall fail.
        async with aiohttp.ClientSession() as session:
            with pytest.raises(aiotus.ProtocolError) as excinfo:
                http_url = nginx_proxy.url.with_scheme("http")
                await aiotus.creation.create(session, http_url, memory_file,
                                             {})
            assert "Wrong status code" in str(excinfo.value)

        # As we use a self-signed certificate, the connection will fail.
        async with aiohttp.ClientSession() as session:
            with pytest.raises(
                    aiohttp.ClientConnectorCertificateError) as excinfo:
                await aiotus.creation.create(session, nginx_proxy.url,
                                             memory_file, {})
            assert "certificate verify failed: self signed certificate" in str(
                excinfo.value)

        # The retrying upload function returns 'None', as the upload fails.
        config = aiotus.RetryConfiguration(max_retry_period_seconds=0.001)
        location = await aiotus.upload(nginx_proxy.url,
                                       memory_file,
                                       config=config)
        assert location is None

        # Uploading with TLS verification disabled shall work.
        async with aiohttp.ClientSession() as session:
            async with aiohttp.ClientSession() as session:
                await aiotus.creation.create(session,
                                             nginx_proxy.url,
                                             memory_file, {},
                                             ssl=False)

        # With TLS verification disabled the creation works.
        config = aiotus.RetryConfiguration(ssl=False)
        location = await aiotus.upload(nginx_proxy.url,
                                       memory_file,
                                       config=config)
        assert location is not None

        # Fetching the metadata over HTTP fails.
        async with aiohttp.ClientSession() as session:
            with pytest.raises(aiohttp.ClientResponseError) as excinfo:
                http_location = location.with_scheme("http")
                await aiotus.core.metadata(session, http_location)
            assert "Bad Request" in str(excinfo.value)
示例#2
0
    async def test_retry(self, tus_server, memory_file):
        """Test the retry functionality."""

        # Make the server fail a few times to test the retry logic.
        tus_server["retries_head"] = 3
        tus_server["retries_upload"] = 3

        config = aiotus.RetryConfiguration(max_retry_period_seconds=0.001)
        md1 = {"key1": "value1".encode(), "key2": "value2".encode()}

        location = await aiotus.upload(tus_server["create_endpoint"],
                                       memory_file,
                                       md1,
                                       config=config)

        assert location is not None
        assert tus_server["data"] is not None
        assert tus_server["data"] == memory_file.getbuffer()

        tus_server["retries_head"] = 3
        md2 = await aiotus.metadata(location, config=config)

        assert md1 == md2

        tus_server["retries_head"] = 11
        md = await aiotus.metadata(location, config=config)

        assert md is None
示例#3
0
    async def test_timeout(self, tus_server, memory_file):
        """Test handling of the retry exception."""

        tus_server["retries_options"] = 20

        config = aiotus.RetryConfiguration(max_retry_period_seconds=0.001)
        location = await aiotus.upload_multiple(
            tus_server["create_endpoint"], [memory_file], config=config
        )

        assert location is None
示例#4
0
    async def test_upload_functional(self, nginx_proxy, memory_file):
        """Test creation on a TLS server."""

        ssl_ctx = ssl.create_default_context(cafile=nginx_proxy.certificate)
        async with aiohttp.ClientSession() as session:
            await aiotus.creation.create(
                session, nginx_proxy.url, memory_file, {}, ssl=ssl_ctx
            )

        config = aiotus.RetryConfiguration(max_retry_period_seconds=0.001, ssl=ssl_ctx)
        location = await aiotus.upload(nginx_proxy.url, memory_file, config=config)
        assert location is not None
示例#5
0
    async def test_upload_upload_retries_exceeded(self, tus_server, memory_file):
        """Not enough retries to do the upload."""

        tus_server["retries_upload"] = 11

        config = aiotus.RetryConfiguration(max_retry_period_seconds=0.001)

        location = await aiotus.upload(
            tus_server["create_endpoint"], memory_file, config=config
        )

        assert location is None
        assert tus_server["data"] is not None  # Upload could be created.