Skip to content

Commit

Permalink
Merge pull request #15 from wcm-io-devops/feature/overwrite-expected-…
Browse files Browse the repository at this point in the history
…support

Add support for overriding expected urls for response test
  • Loading branch information
tobias-richter authored Dec 18, 2019
2 parents 5c38cd3 + 7b56380 commit 69f3169
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions action_plugins/conga_aemdst_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from ansible.plugins.action import ActionBase
from ansible.errors import AnsibleOptionsError

import re

try:
from __main__ import display
except ImportError:
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69f3169

Please sign in to comment.