diff --git a/README.md b/README.md index 85e8621..6a7e5af 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,15 @@ Controls if the ssl enforce test should follow redirects. Use together with `conga_aemdst_ssl_enforce_lazy` because following redirects may result in a lazy match. + conga_aemdst_response_test_expected_url_overrides: [] + # example: + # - pattern: http:\/\/company1\.tld\/ + # expected_url: https:\/\/sso.company1\.tld\/ + +Allows overriding of expected urls by matching the `pattern` against the +automatic calculated expected url and overwriting it with the provided +`expected_url`. + conga_aemdst_curl_expected_http_code: 301 Default response code of the curl task. diff --git a/action_plugins/conga_aemdst_facts.py b/action_plugins/conga_aemdst_facts.py index 6d428fe..900c1af 100644 --- a/action_plugins/conga_aemdst_facts.py +++ b/action_plugins/conga_aemdst_facts.py @@ -8,6 +8,8 @@ from ansible.plugins.action import ActionBase from ansible.errors import AnsibleOptionsError +import re + try: from __main__ import display except ImportError: @@ -34,6 +36,7 @@ def run(self, tmp=None, task_vars=None): try: # Get conga_facts based config (whole or tenant config) config = self._get_arg_or_var('conga_config') + expected_url_overrides = self._get_arg_or_var('conga_aemdst_response_test_expected_url_overrides',[]) except AnsibleOptionsError as err: return self._fail_result(result, err.message) @@ -87,6 +90,18 @@ def run(self, tmp=None, task_vars=None): # when ssl is not offloaded we are expecting an ssl upgrade response_test_expected_url = ssl_enforce_expected_url + # override expected url if configured + for expected_url_override in expected_url_overrides: + pattern = expected_url_override.get("pattern", None) + expected_url = expected_url_override.get("expected_url", None) + if pattern and expected_url: + re_pattern = re.compile(pattern) + re_pattern_match = re_pattern.match(response_test_expected_url) + if re_pattern_match: + display.v("pattern matched, replacing %s with %s" % (response_test_expected_url, expected_url)) + response_test_expected_url = expected_url + break + results = { # "config": config, "server_listen_address": server_listen_address, diff --git a/defaults/main.yml b/defaults/main.yml index 49a0657..767b268 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,14 @@ conga_aemdst_ssl_enforce_lazy: false # Controls if the ssl enforce test should follow redirects. Use together with `conga_aemdst_ssl_enforce_lazy` because following redirects may result in a lazy match. conga_aemdst_ssl_enforce_follow_redirects: false +# Allows overriding of expected urls by matching the `pattern` against the automatic calculated expected url +# and overwriting it with the provided expected_url +conga_aemdst_response_test_expected_url_overrides: [] +# example: +# - pattern: http:\/\/company1\.tld\/ +# expected_url: https:\/\/sso.company1\.tld\/ + + # Default response code of the curl task conga_aemdst_curl_expected_http_code: 301 # Default test behavior of the curl task