|
47 | 47 | _TaskResult, |
48 | 48 | ) |
49 | 49 | from openeo.rest._testing import OPENEO_BACKEND, DummyBackend, build_capabilities |
| 50 | +from openeo.rest.auth.testing import OidcMock |
50 | 51 | from openeo.util import rfc3339 |
51 | 52 | from openeo.utils.version import ComparableVersion |
52 | 53 |
|
@@ -269,7 +270,7 @@ def test_create_job_db(self, tmp_path, job_manager, job_manager_root_dir, sleep_ |
269 | 270 | assert set(result.status) == {"finished"} |
270 | 271 | assert set(result.backend_name) == {"foo", "bar"} |
271 | 272 |
|
272 | | - def test_basic_threading(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock): |
| 273 | + def test_start_job_thread_basic(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock): |
273 | 274 | df = pd.DataFrame( |
274 | 275 | { |
275 | 276 | "year": [2018, 2019, 2020, 2021, 2022], |
@@ -868,6 +869,52 @@ def execute(self): |
868 | 869 | assert any("Skipping invalid db_update" in msg for msg in caplog.messages) |
869 | 870 | assert any("Skipping invalid stats_update" in msg for msg in caplog.messages) |
870 | 871 |
|
| 872 | + def test_refresh_bearer_token_before_start( |
| 873 | + self, |
| 874 | + tmp_path, |
| 875 | + job_manager, |
| 876 | + dummy_backend_foo, |
| 877 | + dummy_backend_bar, |
| 878 | + job_manager_root_dir, |
| 879 | + sleep_mock, |
| 880 | + requests_mock, |
| 881 | + ): |
| 882 | + |
| 883 | + client_id = "client123" |
| 884 | + client_secret = "$3cr3t" |
| 885 | + oidc_issuer = "https://oidc.test/" |
| 886 | + oidc_mock = OidcMock( |
| 887 | + requests_mock=requests_mock, |
| 888 | + expected_grant_type="client_credentials", |
| 889 | + expected_client_id=client_id, |
| 890 | + expected_fields={"client_secret": client_secret, "scope": "openid"}, |
| 891 | + oidc_issuer=oidc_issuer, |
| 892 | + ) |
| 893 | + dummy_backend_foo.setup_credentials_oidc(issuer=oidc_issuer) |
| 894 | + dummy_backend_bar.setup_credentials_oidc(issuer=oidc_issuer) |
| 895 | + dummy_backend_foo.connection.authenticate_oidc_client_credentials(client_id="client123", client_secret="$3cr3t") |
| 896 | + dummy_backend_bar.connection.authenticate_oidc_client_credentials(client_id="client123", client_secret="$3cr3t") |
| 897 | + |
| 898 | + # After this setup, we have 2 client credential token requests (one for each backend) |
| 899 | + assert len(oidc_mock.grant_request_history) == 2 |
| 900 | + |
| 901 | + df = pd.DataFrame({"year": [2020, 2021, 2022, 2023, 2024]}) |
| 902 | + job_db_path = tmp_path / "jobs.csv" |
| 903 | + job_db = CsvJobDatabase(job_db_path).initialize_from_df(df) |
| 904 | + run_stats = job_manager.run_jobs(job_db=job_db, start_job=self._create_year_job) |
| 905 | + |
| 906 | + assert run_stats == dirty_equals.IsPartialDict( |
| 907 | + { |
| 908 | + "job_queued_for_start": 5, |
| 909 | + "job started running": 5, |
| 910 | + "job finished": 5, |
| 911 | + } |
| 912 | + ) |
| 913 | + |
| 914 | + # Because of proactive+throttled token refreshing, |
| 915 | + # we should have 2 additional token requests now |
| 916 | + assert len(oidc_mock.grant_request_history) == 4 |
| 917 | + |
871 | 918 |
|
872 | 919 | JOB_DB_DF_BASICS = pd.DataFrame( |
873 | 920 | { |
|
0 commit comments