Compare commits

...

8 Commits

Author SHA1 Message Date
Patrick Cloke 6b77f3e865 Remove an unused parameter. 2020-12-01 13:30:58 -05:00
Patrick Cloke 6b1ac9a396 Lint. 2020-12-01 13:29:32 -05:00
Patrick Cloke 837bbf9e23
Update changelog. 2020-12-01 13:12:18 -05:00
Patrick Cloke 1ab9ad13e2 Use default_config method. 2020-12-01 13:10:09 -05:00
Patrick Cloke ef2e79f2d1 Use singletons for handlers. 2020-12-01 12:51:05 -05:00
Patrick Cloke 6a581821d7 Remove unused HTTP code. 2020-12-01 12:48:16 -05:00
Patrick Cloke 1de016a9b5 Update comments. 2020-12-01 12:47:41 -05:00
Patrick Cloke 91792568c4 Fix a left-over OIDC term. 2020-12-01 12:38:30 -05:00
3 changed files with 29 additions and 36 deletions

View File

@ -1 +1 @@
Add tests for SAML integration.
Add additional error checking for OpenID Connect and SAML mapping providers.

View File

@ -23,7 +23,7 @@ import pymacaroons
from twisted.python.failure import Failure
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.types import UserID
@ -127,13 +127,8 @@ async def get_json(url):
class OidcHandlerTestCase(HomeserverTestCase):
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"
config = self.default_config()
def default_config(self):
config = super().default_config()
config["public_baseurl"] = BASE_URL
oidc_config = {
"enabled": True,
@ -149,19 +144,24 @@ class OidcHandlerTestCase(HomeserverTestCase):
oidc_config.update(config.get("oidc_config", {}))
config["oidc_config"] = oidc_config
hs = self.setup_test_homeserver(
http_client=self.http_client,
proxied_http_client=self.http_client,
config=config,
)
return 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.
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.
self.handler._sso_handler._MAP_USERNAME_RETRIES = 3
sso_handler._MAP_USERNAME_RETRIES = 3
return hs
@ -832,7 +832,7 @@ class OidcHandlerTestCase(HomeserverTestCase):
# test_user is already taken, so test_user1 gets registered instead.
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(
store.register_user(user_id="@tester:test", password_hash=None)
)

View File

@ -12,11 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
import attr
from synapse.handlers.saml_handler import SamlHandler
from synapse.handlers.sso import MappingException
from tests.unittest import HomeserverTestCase
@ -53,12 +50,8 @@ class TestMappingProvider:
class SamlHandlerTestCase(HomeserverTestCase):
def make_homeserver(self, reactor, clock):
self.http_client = Mock(spec=["get_json"])
self.http_client.user_agent = "Synapse Test"
config = self.default_config()
def default_config(self):
config = super().default_config()
config["public_baseurl"] = BASE_URL
saml_config = {
"sp_config": {"metadata": {}},
@ -68,16 +61,16 @@ class SamlHandlerTestCase(HomeserverTestCase):
}
config["saml2_config"] = saml_config
hs = self.setup_test_homeserver(
http_client=self.http_client,
proxied_http_client=self.http_client,
config=config,
)
return 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.
self.handler._sso_handler._MAP_USERNAME_RETRIES = 3
sso_handler = hs.get_sso_handler()
sso_handler._MAP_USERNAME_RETRIES = 3
return hs
@ -105,7 +98,7 @@ class SamlHandlerTestCase(HomeserverTestCase):
)
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."""
store = self.hs.get_datastore()
self.get_success(
@ -121,7 +114,7 @@ class SamlHandlerTestCase(HomeserverTestCase):
# test_user is already taken, so test_user1 gets registered instead.
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(
store.register_user(user_id="@tester:test", password_hash=None)
)