def test_blob_cdn_url(container, binary_blob):
    container.enable_cdn()
    cdn_url = binary_blob.cdn_url

    assert uri_validator(cdn_url)
    assert binary_blob.container.name in cdn_url
    assert binary_blob.name in cdn_url
Example #2
0
def test_blob_generate_download_url_expiration(binary_blob):
    download_url = binary_blob.generate_download_url(expires=1)
    assert uri_validator(download_url)

    sleep(1.1)  # cannot generate a policy with -1 value

    response = requests.get(download_url)
    assert response.status_code == HTTPStatus.FORBIDDEN, response.text
Example #3
0
def test_container_generate_upload_url_expiration(container, text_stream):
    form_post = container.generate_upload_url(blob_name="", expires=-10)
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {"file": text_stream}
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.UNAUTHORIZED, response.text
def test_container_generate_upload_url_expiration(container, text_stream):
    form_post = container.generate_upload_url(blob_name='', expires=-10)
    assert 'url' in form_post and 'fields' in form_post
    assert uri_validator(form_post['url'])

    url = form_post['url']
    fields = form_post['fields']
    multipart_form_data = {'file': text_stream}
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.BAD_REQUEST, response.text
Example #5
0
def test_container_generate_upload_url_expiration(container, text_stream):
    form_post = container.generate_upload_url(settings.TEXT_FORM_FILENAME, expires=-10)
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {"file": text_stream}
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.FORBIDDEN, response.text
def test_container_generate_upload_url(container, binary_stream):
    form_post = container.generate_upload_url(blob_name='prefix_')
    assert 'url' in form_post and 'fields' in form_post
    assert uri_validator(form_post['url'])

    url = form_post['url']
    fields = form_post['fields']
    multipart_form_data = {
        'file': (BINARY_FORM_FILENAME, binary_stream, 'image/png'),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.CREATED, response.text

    blob = container.get_blob('prefix_' + BINARY_FORM_FILENAME)
    # Option meta_data is not supported for rackspace upload url.
    assert blob.content_type == BINARY_OPTIONS['content_type']
Example #7
0
def test_container_generate_upload_url(container, binary_stream):
    form_post = container.generate_upload_url(blob_name="prefix_")
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {
        "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.CREATED, response.text

    blob = container.get_blob("prefix_" + settings.BINARY_FORM_FILENAME)
    # Options not supported: meta_data, content_disposition, and cache_control.
    assert blob.content_type == settings.BINARY_OPTIONS["content_type"]
def test_blob_generate_download_url(binary_blob, temp_file):
    content_disposition = BINARY_OPTIONS.get('content_disposition')
    download_url = binary_blob.generate_download_url(
        content_disposition=content_disposition)
    assert uri_validator(download_url)

    response = requests.get(download_url)
    assert response.status_code == HTTPStatus.OK, response.text
    assert response.headers['content-disposition'] == content_disposition

    with open(temp_file, 'wb') as f:
        for chunk in response.iter_content(chunk_size=128):
            f.write(chunk)

    hash_type = binary_blob.driver.hash_type
    download_hash = file_checksum(temp_file, hash_type=hash_type)
    assert download_hash.hexdigest() == BINARY_MD5_CHECKSUM
Example #9
0
def test_container_generate_upload_url(container, binary_stream, temp_file):
    form_post = container.generate_upload_url(BINARY_FORM_FILENAME,
                                              **BINARY_OPTIONS)
    assert 'url' in form_post and 'fields' in form_post
    assert uri_validator(form_post['url'])

    url = form_post['url']
    fields = form_post['fields']
    multipart_form_data = {
        'file': (BINARY_FORM_FILENAME, binary_stream, 'image/png'),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.NO_CONTENT, response.text

    blob = container.get_blob(BINARY_FORM_FILENAME)
    assert blob.meta_data == BINARY_OPTIONS['meta_data']
    assert blob.content_type == BINARY_OPTIONS['content_type']
Example #10
0
def test_container_generate_upload_url_expiration(container, text_stream):
    form_post = container.generate_upload_url(settings.TEXT_FORM_FILENAME, expires=1)
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    sleep(1.1)  # cannot generate a policy with -1 value

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {"file": text_stream}
    response = requests.post(url, data=fields, files=multipart_form_data)

    if "s3" in container.driver.client._endpoint_url:
        http_code = HTTPStatus.FORBIDDEN
    else:  # minio server
        http_code = HTTPStatus.BAD_REQUEST

    assert response.status_code == http_code, response.text
Example #11
0
def test_container_generate_upload_url(container, binary_stream, temp_file):
    form_post = container.generate_upload_url(
        settings.BINARY_FORM_FILENAME, **settings.BINARY_OPTIONS
    )
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    fields = form_post["fields"]
    multipart_form_data = {
        "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"),
    }
    response = requests.post(url, data=fields, files=multipart_form_data)
    assert response.status_code == HTTPStatus.NO_CONTENT, response.text

    blob = container.get_blob(settings.BINARY_FORM_FILENAME)
    assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"]
    assert blob.content_type == settings.BINARY_OPTIONS["content_type"]
def test_container_generate_upload_url(container, binary_stream):
    form_post = container.generate_upload_url(blob_name='prefix_',
                                              **BINARY_OPTIONS)
    assert 'url' in form_post and 'fields' in form_post
    assert uri_validator(form_post['url'])

    url = form_post['url']
    headers = form_post['headers']
    multipart_form_data = {
        'file': (BINARY_FORM_FILENAME, binary_stream, 'image/png'),
    }

    # https://blogs.msdn.microsoft.com/azureossds/2015/03/30/uploading-files-to-
    # azure-storage-using-sasshared-access-signature/
    response = requests.put(url, headers=headers, files=multipart_form_data)
    assert response.status_code == HTTPStatus.CREATED, response.text

    blob = container.get_blob('prefix_')
    assert blob.meta_data == BINARY_OPTIONS['meta_data']
    assert blob.content_type == BINARY_OPTIONS['content_type']
    assert blob.content_disposition == BINARY_OPTIONS['content_disposition']
    assert blob.cache_control == BINARY_OPTIONS['cache_control']
def test_blob_generate_download_url(binary_blob, temp_file):
    content_disposition = BINARY_OPTIONS.get('content_disposition')
    download_url = binary_blob.generate_download_url(
        content_disposition=content_disposition)
    assert uri_validator(download_url)

    response = requests.get(download_url)
    assert response.status_code == HTTPStatus.OK, response.text
    # Rackspace adds extra garbage to the header
    # 'attachment; filename=avatar-attachment.png;
    #  filename*=UTF-8\\'\\'avatar-attachment.png'
    parsed_disposition = parse_headers(response.headers['content-disposition'])
    response_disposition = '{}; filename={}'.format(
        parsed_disposition.disposition, parsed_disposition.filename_unsafe)
    assert response_disposition == content_disposition

    with open(temp_file, 'wb') as f:
        for chunk in response.iter_content(chunk_size=128):
            f.write(chunk)

    hash_type = binary_blob.driver.hash_type
    download_hash = file_checksum(temp_file, hash_type=hash_type)
    assert download_hash == BINARY_MD5_CHECKSUM
Example #14
0
def test_container_generate_upload_url(container, binary_stream):
    form_post = container.generate_upload_url(blob_name="prefix_",
                                              **settings.BINARY_OPTIONS)
    assert "url" in form_post and "fields" in form_post
    assert uri_validator(form_post["url"])

    url = form_post["url"]
    headers = form_post["headers"]
    multipart_form_data = {
        "file": (settings.BINARY_FORM_FILENAME, binary_stream, "image/png"),
    }

    # https://blogs.msdn.microsoft.com/azureossds/2015/03/30/uploading-files-to-
    # azure-storage-using-sasshared-access-signature/
    response = requests.put(url, headers=headers, files=multipart_form_data)
    assert response.status_code == HTTPStatus.CREATED, response.text

    blob = container.get_blob("prefix_")
    assert blob.meta_data == settings.BINARY_OPTIONS["meta_data"]
    assert blob.content_type == settings.BINARY_OPTIONS["content_type"]
    assert blob.content_disposition == settings.BINARY_OPTIONS[
        "content_disposition"]
    assert blob.cache_control == settings.BINARY_OPTIONS["cache_control"]
Example #15
0
def test_blob_generate_download_url(binary_blob, temp_file):
    content_disposition = settings.BINARY_OPTIONS.get("content_disposition")
    download_url = binary_blob.generate_download_url(
        content_disposition=content_disposition)
    assert uri_validator(download_url)

    response = requests.get(download_url)
    assert response.status_code == HTTPStatus.OK, response.text
    # Rackspace adds extra garbage to the header
    # 'attachment; filename=avatar-attachment.png;
    #  filename*=UTF-8\\'\\'avatar-attachment.png'
    disposition, params = parse_content_disposition(
        response.headers["content-disposition"])
    response_disposition = "{}; filename={}".format(disposition,
                                                    params["filename"])
    assert response_disposition == content_disposition

    with open(temp_file, "wb") as f:
        for chunk in response.iter_content(chunk_size=128):
            f.write(chunk)

    hash_type = binary_blob.driver.hash_type
    download_hash = file_checksum(temp_file, hash_type=hash_type)
    assert download_hash.hexdigest() == settings.BINARY_MD5_CHECKSUM
def test_blob_cdn_url(binary_blob):
    cdn_url = binary_blob.cdn_url
    assert uri_validator(cdn_url)
    # container name not found in url
    assert binary_blob.name in cdn_url
def test_container_cdn_url(container):
    container.enable_cdn()
    cdn_url = container.cdn_url

    assert uri_validator(cdn_url)
    assert container.name in cdn_url
Example #18
0
def test_blob_cdn_url(binary_blob):
    cdn_url = binary_blob.cdn_url
    assert uri_validator(cdn_url)
    assert binary_blob.container.name in cdn_url
    assert binary_blob.name in cdn_url
def test_blob_generate_download_url_expiration(binary_blob):
    download_url = binary_blob.generate_download_url(expires=-10)
    assert uri_validator(download_url)

    response = requests.get(download_url)
    assert response.status_code == HTTPStatus.BAD_REQUEST, response.text
def test_container_cdn_url(container):
    cdn_url = container.cdn_url
    assert uri_validator(cdn_url)