Skip to content
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

Update session caching according to core auth changes #509

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [Version 3.10.0] - 2023-12-07

- Adjust session caching to mirror changes to the core services. Older version might no longer correctly cache sessions.

## [Version 3.9.5] - 2023-12-07

- The `SentinelHubDownloadClient` class now has a `default_retry_time` parameter, which allows control over the waiting time when a request gets a 429 TOO_MANY_REQUESTS response without a specific retry time in the headers. The default value for this behavior has been changed from 0s to 30s to avoid edge-cases where SH services were bombarded with requests.
Expand Down
2 changes: 1 addition & 1 deletion sentinelhub/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version of the sentinelhub package."""

__version__ = "3.9.5"
__version__ = "3.10.0"
2 changes: 1 addition & 1 deletion sentinelhub/download/sentinelhub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_cache_key(config_or_session: SentinelHubSession | SHConfig) -> tuple[st
base_url = config_or_session.config.sh_base_url

# If session was generated from token then config_or_session.config.sh_client_id could have wrong client id.
sh_client_id = config_or_session.info().get("aud", "")
sh_client_id = config_or_session.info().get("azp", "")
if not sh_client_id:
warnings.warn(
"Failed to read client ID from OAuth token. Session caching might not work correctly.",
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Any

import pytest
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
from oauthlib.oauth2.rfc6749.errors import InvalidClientError
from shapely.geometry import Polygon

from sentinelhub import (
Expand Down Expand Up @@ -483,7 +483,7 @@ def test_bad_credentials() -> None:
bad_credentials_config.sh_client_id = "test"

request = SentinelHubRequest(**request_params, config=bad_credentials_config)
with pytest.raises(CustomOAuth2Error):
with pytest.raises(InvalidClientError):
request.get_data()

missing_credentials_config = SHConfig()
Expand Down
9 changes: 3 additions & 6 deletions tests/download/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

import pytest
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error
from oauthlib.oauth2.rfc6749.errors import CustomOAuth2Error, InvalidClientError
from requests_mock import Mocker

from sentinelhub import SentinelHubSession, SHConfig, __version__
Expand Down Expand Up @@ -48,10 +48,7 @@ def test_session(session: SentinelHubSession) -> None:

@pytest.mark.sh_integration()
def test_token_info(session: SentinelHubSession) -> None:
info = session.info()

for key in ["sub", "aud", "jti", "exp", "name", "email", "sid", "org", "did", "aid", "d"]:
assert key in info
assert "azp" in session.info()


def test_session_content_and_headers(fake_config: SHConfig, fake_token: dict[str, Any], requests_mock: Mocker) -> None:
Expand Down Expand Up @@ -108,7 +105,7 @@ def test_refreshing_procedure(fake_token: JsonDict, fake_config: SHConfig) -> No
assert session.token == fake_token

session = SentinelHubSession(config=fake_config, refresh_before_expiry=500, _token=fake_token)
with pytest.raises(CustomOAuth2Error):
with pytest.raises(InvalidClientError):
_ = session.token


Expand Down