|
1 | 1 | # ruff: noqa: PGH003
|
2 | 2 |
|
3 | 3 | import pickle
|
| 4 | +from datetime import UTC, datetime |
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 |
|
7 | 8 | import obstore as obs
|
8 |
| -from obstore.exceptions import BaseError |
| 9 | +from obstore.exceptions import BaseError, UnauthenticatedError |
9 | 10 | from obstore.store import S3Store, from_url
|
10 | 11 |
|
11 | 12 |
|
@@ -97,3 +98,27 @@ def test_config_round_trip():
|
97 | 98 | assert store.prefix == new_store.prefix
|
98 | 99 | assert store.client_options == new_store.client_options
|
99 | 100 | assert store.retry_config == new_store.retry_config
|
| 101 | + |
| 102 | + |
| 103 | +def test_invalid_credential_provider(): |
| 104 | + """Test that passing an invalid synchronous credential provider raises an error. |
| 105 | +
|
| 106 | + instead of trying to await the value. |
| 107 | + """ |
| 108 | + |
| 109 | + def credential_provider(): |
| 110 | + return {"access_key_id": "str", "expires_at": datetime.now(UTC)} |
| 111 | + |
| 112 | + store = S3Store("bucket", credential_provider=credential_provider) # type: ignore |
| 113 | + with pytest.raises(UnauthenticatedError): |
| 114 | + obs.list(store).collect() |
| 115 | + |
| 116 | + |
| 117 | +@pytest.mark.asyncio |
| 118 | +async def test_invalid_credential_provider_async(): |
| 119 | + async def credential_provider(): |
| 120 | + return {"access_key_id": "str", "expires_at": datetime.now(UTC)} |
| 121 | + |
| 122 | + store = S3Store("bucket", credential_provider=credential_provider) # type: ignore |
| 123 | + with pytest.raises(UnauthenticatedError): |
| 124 | + await obs.list(store).collect_async() |
0 commit comments