Skip to content

Commit

Permalink
Adapt to enable_basic_auth config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
soxofaan committed Nov 8, 2023
1 parent 1768862 commit c7a323a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 22 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 3 additions & 12 deletions conf/backend_config.py
Original file line number Diff line number Diff line change
@@ -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,
)
2 changes: 1 addition & 1 deletion src/openeo_aggregator/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 19 additions & 3 deletions src/openeo_aggregator/config.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"],
)
8 changes: 8 additions & 0 deletions tests/backend_config.py
Original file line number Diff line number Diff line change
@@ -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,
)
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
from pathlib import Path
from typing import List

import flask
Expand All @@ -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",
Expand Down
35 changes: 31 additions & 4 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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"""
Expand All @@ -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="/")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c7a323a

Please sign in to comment.