コード例 #1
0
ファイル: test_cas.py プロジェクト: y-pankaj/synapse
    def test_map_cas_user_to_existing_user(self):
        """Existing users can log in with CAS account."""
        store = self.hs.get_datastore()
        self.get_success(
            store.register_user(user_id="@test_user:test", password_hash=None))

        # stub out the auth handler
        auth_handler = self.hs.get_auth_handler()
        auth_handler.complete_sso_login = simple_async_mock()

        # Map a user via SSO.
        cas_response = CasResponse("test_user", {})
        request = _mock_request()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))

        # check that the auth handler got called as expected
        auth_handler.complete_sso_login.assert_called_once_with(
            "@test_user:test", request, "redirect_uri", None)

        # Subsequent calls should map to the same mxid.
        auth_handler.complete_sso_login.reset_mock()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))
        auth_handler.complete_sso_login.assert_called_once_with(
            "@test_user:test", request, "redirect_uri", None)
コード例 #2
0
ファイル: test_cas.py プロジェクト: ZOE-Cash/zoe-matrix
    def test_required_attributes(self):
        """The required attributes must be met from the CAS response."""

        # stub out the auth handler
        auth_handler = self.hs.get_auth_handler()
        auth_handler.complete_sso_login = simple_async_mock()

        # The response doesn't have the proper userGroup or department.
        cas_response = CasResponse("test_user", {})
        request = _mock_request()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))
        auth_handler.complete_sso_login.assert_not_called()

        # The response doesn't have any department.
        cas_response = CasResponse("test_user", {"userGroup": "staff"})
        request.reset_mock()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))
        auth_handler.complete_sso_login.assert_not_called()

        # Add the proper attributes and it should succeed.
        cas_response = CasResponse("test_user", {
            "userGroup": ["staff", "admin"],
            "department": ["sales"]
        })
        request.reset_mock()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))

        # check that the auth handler got called as expected
        auth_handler.complete_sso_login.assert_called_once_with(
            "@test_user:test",
            "cas",
            request,
            "redirect_uri",
            None,
            new_user=True)
コード例 #3
0
ファイル: test_cas.py プロジェクト: y-pankaj/synapse
    def test_map_cas_user_to_invalid_localpart(self):
        """CAS automaps invalid characters to base-64 encoding."""

        # stub out the auth handler
        auth_handler = self.hs.get_auth_handler()
        auth_handler.complete_sso_login = simple_async_mock()

        cas_response = CasResponse("föö", {})
        request = _mock_request()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))

        # check that the auth handler got called as expected
        auth_handler.complete_sso_login.assert_called_once_with(
            "@f=c3=b6=c3=b6:test", request, "redirect_uri", None)
コード例 #4
0
ファイル: test_cas.py プロジェクト: y-pankaj/synapse
    def test_map_cas_user_to_user(self):
        """Ensure that mapping the CAS user returned from a provider to an MXID works properly."""

        # stub out the auth handler
        auth_handler = self.hs.get_auth_handler()
        auth_handler.complete_sso_login = simple_async_mock()

        cas_response = CasResponse("test_user", {})
        request = _mock_request()
        self.get_success(
            self.handler._handle_cas_response(request, cas_response,
                                              "redirect_uri", ""))

        # check that the auth handler got called as expected
        auth_handler.complete_sso_login.assert_called_once_with(
            "@test_user:test", request, "redirect_uri", None)