-
Notifications
You must be signed in to change notification settings - Fork 14
fix: Presigned resource urls shouldn't follow base url #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
bb5a260
1db6008
6fb6f03
d7163b8
77c5f20
a28026c
116621b
2d31a37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import impit | ||
|
||
from integration.conftest import parametrized_api_urls | ||
janbuchar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
from integration.integration_test_utils import random_resource_name | ||
|
||
if TYPE_CHECKING: | ||
from apify_client import ApifyClient, ApifyClientAsync | ||
from apify_client import ApifyClient, ApifyClientAsync | ||
from apify_client.client import DEFAULT_API_URL | ||
|
||
|
||
class TestKeyValueStoreSync: | ||
|
@@ -47,6 +46,28 @@ def test_key_value_store_should_create_public_keys_non_expiring_url(self, apify_ | |
store.delete() | ||
assert apify_client.key_value_store(created_store['id']).get() is None | ||
|
||
@parametrized_api_urls | ||
def test_public_url(self, api_token: str, api_url: str, api_public_url: str) -> None: | ||
apify_client = ApifyClient(token=api_token, api_url=api_url, api_public_url=api_public_url) | ||
created_store = apify_client.key_value_stores().get_or_create(name=random_resource_name('key-value-store')) | ||
kvs = apify_client.key_value_store(created_store['id']) | ||
try: | ||
public_url = kvs.create_keys_public_url() | ||
assert public_url == ( | ||
f'{(api_public_url or DEFAULT_API_URL).strip("/")}/v2/key-value-stores/' | ||
f'{created_store["id"]}/keys?signature={public_url.split("signature=")[1]}' | ||
) | ||
finally: | ||
kvs.delete() | ||
|
||
def test_public_url_nonexistent_host(self, api_token: str) -> None: | ||
kvs_name = 'whatever' | ||
non_existent_url = 'http://10.0.88.214:8010' | ||
apify_client = ApifyClient(token=api_token, api_url=non_existent_url) | ||
kvs_client = apify_client.key_value_store(key_value_store_id=kvs_name) | ||
assert kvs_client._url() == f'{non_existent_url}/v2/key-value-stores/{kvs_name}' | ||
assert kvs_client._url(public=True) == f'{DEFAULT_API_URL}/v2/key-value-stores/{kvs_name}' | ||
|
||
|
||
|
||
class TestKeyValueStoreAsync: | ||
async def test_key_value_store_should_create_expiring_keys_public_url_with_params( | ||
|
@@ -90,3 +111,27 @@ async def test_key_value_store_should_create_public_keys_non_expiring_url( | |
|
||
await store.delete() | ||
assert await apify_client_async.key_value_store(created_store['id']).get() is None | ||
|
||
@parametrized_api_urls | ||
async def test_public_url(self, api_token: str, api_url: str, api_public_url: str) -> None: | ||
apify_client = ApifyClientAsync(token=api_token, api_url=api_url, api_public_url=api_public_url) | ||
created_store = await apify_client.key_value_stores().get_or_create( | ||
name=random_resource_name('key-value-store') | ||
) | ||
kvs = apify_client.key_value_store(created_store['id']) | ||
try: | ||
public_url = await kvs.create_keys_public_url() | ||
assert public_url == ( | ||
f'{(api_public_url or DEFAULT_API_URL).strip("/")}/v2/key-value-stores/' | ||
f'{created_store["id"]}/keys?signature={public_url.split("signature=")[1]}' | ||
) | ||
finally: | ||
await kvs.delete() | ||
|
||
async def test_public_url_nonexistent_host(self, api_token: str) -> None: | ||
kvs_name = 'whatever' | ||
non_existent_url = 'http://10.0.88.214:8010' | ||
apify_client = ApifyClientAsync(token=api_token, api_url=non_existent_url) | ||
kvs_client = apify_client.key_value_store(key_value_store_id=kvs_name) | ||
assert kvs_client._url() == f'{non_existent_url}/v2/key-value-stores/{kvs_name}' | ||
assert kvs_client._url(public=True) == f'{DEFAULT_API_URL}/v2/key-value-stores/{kvs_name}' |
Uh oh!
There was an error while loading. Please reload this page.