Fix get-sp-metadata sp-metadata file location

get-sp-metadata action hardcodes the location of an sp metadata file
which is incorrect - it should use the application name to allow custom
application names and usage of multiple keystone-saml-mellon
applications (to have multiple IdPs).

In order to make unit testing easier the global variable for the sp
metadata file in actions.py is moved into a function so that it is
evaluated at the function call time, not module import time.

Change-Id: Ia73cd633f2948080e9a892869074ed2775ecc33c
Closes-Bug: #1833202
This commit is contained in:
Dmitrii Shcherbakov 2019-06-18 13:07:45 +03:00
parent dde20964eb
commit 8a4b2cb7cc
3 changed files with 13 additions and 4 deletions

View File

@ -18,10 +18,9 @@ import sys
import charmhelpers.core.hookenv as hookenv
SP_METADATA_FILE = "/etc/apache2/mellon/sp-meta.keystone-saml-mellon.xml"
def get_sp_metadata(*args):
SP_METADATA_FILE = "/etc/apache2/mellon/sp-meta.{}.xml".format(
hookenv.service_name())
if not os.path.exists(SP_METADATA_FILE):
return hookenv.action_fail(
"The SP metadata file {} does not exist"

View File

@ -36,6 +36,11 @@ basepython = python3.6
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}
[testenv:py37]
basepython = python3.7
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}
[testenv:pep8]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt

View File

@ -28,6 +28,7 @@ class TestKeystoneSAMLMellonActions(test_utils.PatchHelper):
super().setUp()
self.patch_object(actions.hookenv, 'action_set')
self.patch_object(actions.hookenv, 'action_fail')
self.patch_object(actions.hookenv, 'service_name')
self.patch_object(actions, "os")
self.patch(
@ -38,6 +39,9 @@ class TestKeystoneSAMLMellonActions(test_utils.PatchHelper):
self.open.return_value = self.fileobj
def test_get_sp_metadata(self):
service_name = 'keystone-foobar-mellon'
self.service_name.return_value = service_name
# Valid XML
self.sp_metadata_xml = (
"<?xml version='1.0' encoding='UTF-8'?>"
@ -46,7 +50,8 @@ class TestKeystoneSAMLMellonActions(test_utils.PatchHelper):
"</ds:X509Data> </ds:KeyInfo>")
self.file.readlines.return_value = self.sp_metadata_xml
self.metadata_file = ("/etc/apache2/mellon/"
"sp-meta.keystone-saml-mellon.xml")
"sp-meta.{}.xml".format(
service_name))
# File Does not exist
self.os.path.exists.return_value = False