From c7a323aeae836799f96583f9d5e21e5ab76b2ec6 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Tue, 7 Nov 2023 19:02:20 +0100 Subject: [PATCH] Adapt to `enable_basic_auth` config and prepare for being disabled by default (most view tests assume basic auth currently) introduce AggregatorBackendConfig for reuse between real config and test-specific config --- CHANGELOG.md | 9 +++++++-- conf/backend_config.py | 15 +++----------- src/openeo_aggregator/about.py | 2 +- src/openeo_aggregator/config.py | 22 ++++++++++++++++++--- tests/backend_config.py | 8 ++++++++ tests/conftest.py | 11 +++++++++++ tests/test_views.py | 35 +++++++++++++++++++++++++++++---- 7 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 tests/backend_config.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a908d3a..5d900980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,18 @@ All notable changes to this project will be documented in this file. The format is roughly based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [Current: 0.12.x] +## [Current: 0.13.x] +- +- Fix compatibility with `openeo_driver>=0.75.0` (new `enable_basic_auth` config, which is going to be disabled by default) + + +## [0.12.x] - Add (optional) config for collection id whitelisting. Keep union of all "upstream" collections as default. ([#129](https://github.com/Open-EO/openeo-aggregator/issues/129)) - Disable `auto_validation` feature of latest `openeo` python client library release ([#130](https://github.com/Open-EO/openeo-aggregator/issues/130)) -- Fix compatibility with `openeo>=0.25.0` +- Fix compatibility with `openeo>=0.25.0` (introduction of `OpenEoApiPlainError`) ## [0.11.x] diff --git a/conf/backend_config.py b/conf/backend_config.py index 3c1c4189..927c4fe0 100644 --- a/conf/backend_config.py +++ b/conf/backend_config.py @@ -1,18 +1,9 @@ -from openeo_driver.config import OpenEoBackendConfig -from openeo_driver.server import build_backend_deploy_metadata +from openeo_aggregator.config import AggregatorBackendConfig -import openeo_aggregator - -deploy_metadata = build_backend_deploy_metadata( - packages=["openeo", "openeo_driver", "openeo_aggregator"], -) - -# TODO #112 Merge with `AggregatorConfig` -config = OpenEoBackendConfig( +config = AggregatorBackendConfig( + # TODO: eliminate hardcoded openEO Platform references. id="aggregator", capabilities_title="openEO Platform", capabilities_description="openEO Platform, provided through openEO Aggregator Driver", - capabilities_backend_version=openeo_aggregator.about.__version__, - capabilities_deploy_metadata=deploy_metadata, enable_basic_auth=False, ) diff --git a/src/openeo_aggregator/about.py b/src/openeo_aggregator/about.py index ac4bfd8e..3631f21e 100644 --- a/src/openeo_aggregator/about.py +++ b/src/openeo_aggregator/about.py @@ -2,7 +2,7 @@ import sys from typing import Optional -__version__ = "0.12.3a1" +__version__ = "0.13.0a1" def log_version_info(logger: Optional[logging.Logger] = None): diff --git a/src/openeo_aggregator/config.py b/src/openeo_aggregator/config.py index 04c83c90..7ae8fa4c 100644 --- a/src/openeo_aggregator/config.py +++ b/src/openeo_aggregator/config.py @@ -1,12 +1,16 @@ import logging import os -import re from pathlib import Path -from typing import Any, List, Union +from typing import List, Union +import attrs +from openeo_driver.config import OpenEoBackendConfig +from openeo_driver.server import build_backend_deploy_metadata from openeo_driver.users.oidc import OidcProvider from openeo_driver.utils import dict_item +import openeo_aggregator.about + _log = logging.getLogger(__name__) OPENEO_AGGREGATOR_CONFIG = "OPENEO_AGGREGATOR_CONFIG" @@ -27,11 +31,13 @@ class ConfigException(ValueError): pass -# TODO #112 subclass from OpenEoBackendConfig (attrs based instead of dictionary based) class AggregatorConfig(dict): """ Simple dictionary based configuration for aggregator backend """ + + # TODO #112 migrate everything to AggregatorBackendConfig (attrs based instead of dictionary based) + config_source = dict_item() # Dictionary mapping backend id to backend url @@ -114,3 +120,13 @@ def get_config(x: Union[str, Path, AggregatorConfig, None] = None) -> Aggregator return AggregatorConfig.from_py_file(x) raise ValueError(repr(x)) + + +@attrs.frozen(kw_only=True) +class AggregatorBackendConfig(OpenEoBackendConfig): + # TODO #112 migrate everything from AggregatorConfig to this class + + capabilities_backend_version = openeo_aggregator.about.__version__ + capabilities_deploy_metadata = build_backend_deploy_metadata( + packages=["openeo", "openeo_driver", "openeo_aggregator"], + ) diff --git a/tests/backend_config.py b/tests/backend_config.py new file mode 100644 index 00000000..3e4d7687 --- /dev/null +++ b/tests/backend_config.py @@ -0,0 +1,8 @@ +from openeo_aggregator.config import AggregatorBackendConfig + +config = AggregatorBackendConfig( + id="aggregator-dummy", + capabilities_title="openEO Aggregator Test Dummy", + capabilities_description="openEO Aggregator Test Dummy", + enable_basic_auth=True, +) diff --git a/tests/conftest.py b/tests/conftest.py index 087ec698..a1804922 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +import os +from pathlib import Path from typing import List import flask @@ -17,6 +19,15 @@ pytest_plugins = "pytester" +def pytest_configure(config): + """Pytest configuration hook""" + + # Load test specific config + os.environ["OPENEO_BACKEND_CONFIG"] = str(Path(__file__).parent / "backend_config.py") + + + + _DEFAULT_PROCESSES = [ "load_collection", "load_result", diff --git a/tests/test_views.py b/tests/test_views.py index e16ac8a1..33e3b2bb 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -3,6 +3,7 @@ import time from typing import List, Tuple +import openeo_driver.config.load import pytest import requests from openeo.rest import OpenEoApiError, OpenEoRestError @@ -25,7 +26,7 @@ RegexMatcher, ) -from openeo_aggregator.config import AggregatorConfig +from openeo_aggregator.config import AggregatorConfig, get_config_dir from openeo_aggregator.constants import JOB_OPTION_FORCE_BACKEND from openeo_aggregator.metadata import ( STAC_PROPERTY_FEDERATION_BACKENDS, @@ -53,8 +54,8 @@ def test_capabilities(self, api100): def test_title_and_description(self, api100): res = api100.get("/").assert_status_code(200) capabilities = res.json - assert capabilities["title"] == "openEO Platform" - assert capabilities["description"] == "openEO Platform, provided through openEO Aggregator Driver" + assert capabilities["title"] == "openEO Aggregator Test Dummy" + assert capabilities["description"] == "openEO Aggregator Test Dummy" def test_capabilities_validation(self, api100): """https://github.com/Open-EO/openeo-aggregator/issues/42""" @@ -76,7 +77,7 @@ def test_only_oidc_auth(self, api100): res = api100.get("/").assert_status_code(200) capabilities = res.json endpoints = {e["path"] for e in capabilities["endpoints"]} - assert {e for e in endpoints if e.startswith("/credentials")} == {"/credentials/oidc"} + assert {e for e in endpoints if e.startswith("/credentials")} == {"/credentials/basic", "/credentials/oidc"} def test_info(self, flask_app): api100 = ApiTester(api_version="1.0.0", client=flask_app.test_client(), url_root="/") @@ -128,6 +129,32 @@ def test_health_check_invalid_backend(self, api100, requests_mock, backend1, bac } +class TestGeneralRealConfig: + """Some temporary test against real config (that is going to be moved out of this repo at some point)""" + + @pytest.fixture(autouse=True) + def real_config(self, monkeypatch): + openeo_driver.config.load._backend_config_getter.flush() + monkeypatch.setenv( + openeo_driver.config.load.ConfigGetter.OPENEO_BACKEND_CONFIG, + str(get_config_dir() / "backend_config.py"), + ) + yield + openeo_driver.config.load._backend_config_getter.flush() + + def test_title_and_description(self, api100): + res = api100.get("/").assert_status_code(200) + capabilities = res.json + assert capabilities["title"] == "openEO Platform" + assert capabilities["description"] == "openEO Platform, provided through openEO Aggregator Driver" + + def test_only_oidc_auth(self, api100): + res = api100.get("/").assert_status_code(200) + capabilities = res.json + endpoints = {e["path"] for e in capabilities["endpoints"]} + assert {e for e in endpoints if e.startswith("/credentials")} == {"/credentials/oidc"} + + class TestCatalog: def test_collections_basic(self, api100, requests_mock, backend1, backend2):