diff --git a/tests/unit/test_route.py b/tests/unit/test_route.py index 645698b..839f897 100644 --- a/tests/unit/test_route.py +++ b/tests/unit/test_route.py @@ -62,6 +62,54 @@ CONFIG_WITH_TLS = { } } +CONFIG_MIDDLEWARE = { + "http": { + "middlewares": { + "custom-headers-http": { + "headers": { + "customRequestHeaders": { + "X-Forwarded-Proto": "http" + } + } + }, + "custom-headers-https": { + "headers": { + "customRequestHeaders": { + "X-Forwarded-Proto": "https" + } + } + }, + }, + "routers": { + "juju-foo-router": { + "entryPoints": ["web"], + "middlewares": ["custom-headers-http"], + "rule": "PathPrefix(`/path`)", + "service": "juju-foo-service", + }, + "juju-foo-router-tls": { + "entryPoints": ["websecure"], + "middlewares": ["custom-headers-https"], + "rule": "PathPrefix(`/path`)", + "service": "juju-foo-service", + "tls": { + "domains": [ + { + "main": "testhostname", + "sans": ["*.testhostname"], + }, + ], + }, + }, + }, + "services": { + "juju-foo-service": { + "loadBalancer": {"servers": [{"url": "http://foo.testmodel-endpoints.local:8080"}]} + } + }, + } +} + @pytest.fixture(scope="function") def harness() -> Harness[TraefikIngressCharm]: @@ -280,3 +328,15 @@ def test_static_config_partially_broken(harness: Harness[TraefikIngressCharm]): assert generated_config["barbaras"] == {"rhabarber": "bar"} assert generated_config["entryPoints"]["shondaland"]["address"] == ":6767" assert generated_config["foo"] == {"bar": "baz"} + +def test_middleware(harness: Harness[TraefikIngressCharm]): + tr_relation_id, relation = initialize_and_setup_tr_relation(harness) + charm = harness.charm + config = yaml.dump(CONFIG_MIDDLEWARE) + harness.update_relation_data(tr_relation_id, REMOTE_APP_NAME, {"config": config}) + + assert charm.traefik_route.is_ready(relation) + assert charm.traefik_route.get_config(relation) == config + file = f"/opt/traefik/juju/juju_ingress_{relation.name}_{relation.id}_{relation.app.name}.yaml" + conf = yaml.safe_load(charm.container.pull(file).read()) + assert conf == CONFIG_MIDDLEWARE diff --git a/tox.ini b/tox.ini index 596356a..2e9d47b 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,8 @@ all_path = {[vars]src_path} {[vars]tst_path} {[vars]lib_path} [testenv] setenv = - JUJU_VERSION=3.0.3 # fix ops borkiness + # fix ops borkiness + JUJU_VERSION=3.0.3 PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path} PYTHONBREAKPOINT=ipdb.set_trace PY_COLORS=1