Compare commits
8 Commits
003b25e9ff
...
6b77f3e865
Author | SHA1 | Date |
---|---|---|
Patrick Cloke | 6b77f3e865 | |
Patrick Cloke | 6b1ac9a396 | |
Patrick Cloke | 837bbf9e23 | |
Patrick Cloke | 1ab9ad13e2 | |
Patrick Cloke | ef2e79f2d1 | |
Patrick Cloke | 6a581821d7 | |
Patrick Cloke | 1de016a9b5 | |
Patrick Cloke | 91792568c4 |
|
@ -1 +1 @@
|
||||||
Add tests for SAML integration.
|
Add additional error checking for OpenID Connect and SAML mapping providers.
|
||||||
|
|
|
@ -23,7 +23,7 @@ import pymacaroons
|
||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
from twisted.web._newclient import ResponseDone
|
from twisted.web._newclient import ResponseDone
|
||||||
|
|
||||||
from synapse.handlers.oidc_handler import OidcError, OidcHandler, OidcMappingProvider
|
from synapse.handlers.oidc_handler import OidcError, OidcMappingProvider
|
||||||
from synapse.handlers.sso import MappingException
|
from synapse.handlers.sso import MappingException
|
||||||
from synapse.types import UserID
|
from synapse.types import UserID
|
||||||
|
|
||||||
|
@ -127,13 +127,8 @@ async def get_json(url):
|
||||||
|
|
||||||
|
|
||||||
class OidcHandlerTestCase(HomeserverTestCase):
|
class OidcHandlerTestCase(HomeserverTestCase):
|
||||||
def make_homeserver(self, reactor, clock):
|
def default_config(self):
|
||||||
|
config = super().default_config()
|
||||||
self.http_client = Mock(spec=["get_json"])
|
|
||||||
self.http_client.get_json.side_effect = get_json
|
|
||||||
self.http_client.user_agent = "Synapse Test"
|
|
||||||
|
|
||||||
config = self.default_config()
|
|
||||||
config["public_baseurl"] = BASE_URL
|
config["public_baseurl"] = BASE_URL
|
||||||
oidc_config = {
|
oidc_config = {
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
|
@ -149,19 +144,24 @@ class OidcHandlerTestCase(HomeserverTestCase):
|
||||||
oidc_config.update(config.get("oidc_config", {}))
|
oidc_config.update(config.get("oidc_config", {}))
|
||||||
config["oidc_config"] = oidc_config
|
config["oidc_config"] = oidc_config
|
||||||
|
|
||||||
hs = self.setup_test_homeserver(
|
return config
|
||||||
http_client=self.http_client,
|
|
||||||
proxied_http_client=self.http_client,
|
|
||||||
config=config,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.handler = OidcHandler(hs)
|
def make_homeserver(self, reactor, clock):
|
||||||
|
|
||||||
|
self.http_client = Mock(spec=["get_json"])
|
||||||
|
self.http_client.get_json.side_effect = get_json
|
||||||
|
self.http_client.user_agent = "Synapse Test"
|
||||||
|
|
||||||
|
hs = self.setup_test_homeserver(proxied_http_client=self.http_client)
|
||||||
|
|
||||||
|
self.handler = hs.get_oidc_handler()
|
||||||
|
sso_handler = hs.get_sso_handler()
|
||||||
# Mock the render error method.
|
# Mock the render error method.
|
||||||
self.render_error = Mock(return_value=None)
|
self.render_error = Mock(return_value=None)
|
||||||
self.handler._sso_handler.render_error = self.render_error
|
sso_handler.render_error = self.render_error
|
||||||
|
|
||||||
# Reduce the number of attempts when generating MXIDs.
|
# Reduce the number of attempts when generating MXIDs.
|
||||||
self.handler._sso_handler._MAP_USERNAME_RETRIES = 3
|
sso_handler._MAP_USERNAME_RETRIES = 3
|
||||||
|
|
||||||
return hs
|
return hs
|
||||||
|
|
||||||
|
@ -832,7 +832,7 @@ class OidcHandlerTestCase(HomeserverTestCase):
|
||||||
# test_user is already taken, so test_user1 gets registered instead.
|
# test_user is already taken, so test_user1 gets registered instead.
|
||||||
self.assertEqual(mxid, "@test_user1:test")
|
self.assertEqual(mxid, "@test_user1:test")
|
||||||
|
|
||||||
# Register all of the potential usernames for a particular username.
|
# Register all of the potential mxids for a particular OIDC username.
|
||||||
self.get_success(
|
self.get_success(
|
||||||
store.register_user(user_id="@tester:test", password_hash=None)
|
store.register_user(user_id="@tester:test", password_hash=None)
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,11 +12,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from mock import Mock
|
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
from synapse.handlers.saml_handler import SamlHandler
|
|
||||||
from synapse.handlers.sso import MappingException
|
from synapse.handlers.sso import MappingException
|
||||||
|
|
||||||
from tests.unittest import HomeserverTestCase
|
from tests.unittest import HomeserverTestCase
|
||||||
|
@ -53,12 +50,8 @@ class TestMappingProvider:
|
||||||
|
|
||||||
|
|
||||||
class SamlHandlerTestCase(HomeserverTestCase):
|
class SamlHandlerTestCase(HomeserverTestCase):
|
||||||
def make_homeserver(self, reactor, clock):
|
def default_config(self):
|
||||||
|
config = super().default_config()
|
||||||
self.http_client = Mock(spec=["get_json"])
|
|
||||||
self.http_client.user_agent = "Synapse Test"
|
|
||||||
|
|
||||||
config = self.default_config()
|
|
||||||
config["public_baseurl"] = BASE_URL
|
config["public_baseurl"] = BASE_URL
|
||||||
saml_config = {
|
saml_config = {
|
||||||
"sp_config": {"metadata": {}},
|
"sp_config": {"metadata": {}},
|
||||||
|
@ -68,16 +61,16 @@ class SamlHandlerTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
config["saml2_config"] = saml_config
|
config["saml2_config"] = saml_config
|
||||||
|
|
||||||
hs = self.setup_test_homeserver(
|
return config
|
||||||
http_client=self.http_client,
|
|
||||||
proxied_http_client=self.http_client,
|
|
||||||
config=config,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.handler = SamlHandler(hs)
|
def make_homeserver(self, reactor, clock):
|
||||||
|
hs = self.setup_test_homeserver()
|
||||||
|
|
||||||
|
self.handler = hs.get_saml_handler()
|
||||||
|
|
||||||
# Reduce the number of attempts when generating MXIDs.
|
# Reduce the number of attempts when generating MXIDs.
|
||||||
self.handler._sso_handler._MAP_USERNAME_RETRIES = 3
|
sso_handler = hs.get_sso_handler()
|
||||||
|
sso_handler._MAP_USERNAME_RETRIES = 3
|
||||||
|
|
||||||
return hs
|
return hs
|
||||||
|
|
||||||
|
@ -105,7 +98,7 @@ class SamlHandlerTestCase(HomeserverTestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(str(e.value), "localpart is invalid: föö")
|
self.assertEqual(str(e.value), "localpart is invalid: föö")
|
||||||
|
|
||||||
def test_map_userinfo_to_user_retries(self):
|
def test_map_saml_response_to_user_retries(self):
|
||||||
"""The mapping provider can retry generating an MXID if the MXID is already in use."""
|
"""The mapping provider can retry generating an MXID if the MXID is already in use."""
|
||||||
store = self.hs.get_datastore()
|
store = self.hs.get_datastore()
|
||||||
self.get_success(
|
self.get_success(
|
||||||
|
@ -121,7 +114,7 @@ class SamlHandlerTestCase(HomeserverTestCase):
|
||||||
# test_user is already taken, so test_user1 gets registered instead.
|
# test_user is already taken, so test_user1 gets registered instead.
|
||||||
self.assertEqual(mxid, "@test_user1:test")
|
self.assertEqual(mxid, "@test_user1:test")
|
||||||
|
|
||||||
# Register all of the potential usernames for a particular username.
|
# Register all of the potential mxids for a particular SAML username.
|
||||||
self.get_success(
|
self.get_success(
|
||||||
store.register_user(user_id="@tester:test", password_hash=None)
|
store.register_user(user_id="@tester:test", password_hash=None)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue