Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Skip the SAML tests if xmlsec1 isn't available. #8905

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8905.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip the SAML tests if the requirements (pysaml2 and xmlsec1) aren't available.
23 changes: 23 additions & 0 deletions tests/handlers/test_saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@

from tests.unittest import HomeserverTestCase, override_config

# Check if we have the tests.
try:
import saml2.config
from saml2.sigver import SigverError

has_saml2 = True

# pysaml2 can be installed and imported, but might not be able to find xmlsec1.
config = saml2.config.SPConfig()
try:
config.load({"metadata": {}})
has_xmlsec1 = True
except SigverError:
has_xmlsec1 = False
Comment on lines +29 to +35
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could call get_xmlsec_binary manually if we wanted, but since this is the code-path we use (in saml_config it seemed nicer to do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this covers all exception cases, it looks quite nice to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice anything else that could cause an issue, but no promises. 😄

except ImportError:
has_saml2 = False
has_xmlsec1 = None

# These are a few constants that are used as config parameters in the tests.
BASE_URL = "https://synapse/"

Expand Down Expand Up @@ -86,6 +104,11 @@ def make_homeserver(self, reactor, clock):

return hs

if not has_saml2:
skip = "Requires pysaml2"
elif not has_xmlsec1:
skip = "Requires xmlsec1"

def test_map_saml_response_to_user(self):
"""Ensure that mapping the SAML response returned from a provider to an MXID works properly."""
saml_response = FakeAuthnResponse({"uid": "test_user", "username": "test_user"})
Expand Down