Skip to content
Snippets Groups Projects
test_matrixfederationclient.py 37 KiB
Newer Older
  • Learn to ignore specific revisions
  •         """
            # Mock out the `MatrixFederationHttpClient` of the `federation_sender` instance
            # so we can act like some remote server responding to requests
            mock_client_on_federation_sender = Mock()
            mock_agent_on_federation_sender = create_autospec(Agent, spec_set=True)
            mock_client_on_federation_sender.agent = mock_agent_on_federation_sender
    
            # Create the `federation_sender` worker
            self.make_worker_hs(
                "synapse.app.generic_worker",
                {
                    "worker_name": "federation_sender",
                    # Test that we aren't able to proxy any outbound federation requests
                    # when `worker_replication_secret` is wrong.
                    "worker_replication_secret": "wrong",
                },
                federation_http_client=mock_client_on_federation_sender,
            )
    
            # This federation request from the main process should be proxied through the
            # `federation_sender` worker off but will fail here because it's using the wrong
            # authorization.
            test_request_from_main_process_d = defer.ensureDeferred(
                self.hs.get_federation_http_client().get_json("remoteserv:8008", "foo/bar")
            )
    
            # Pump the reactor so our deferred goes through the motions. We pump with 10
            # seconds (0.1 * 100) so the `MatrixFederationHttpClient` runs out of retries
            # and finally passes along the error response.
            self.pump(0.1)
    
            # Make sure that the request was *NOT* proxied through the `federation_sender`
            # worker
            mock_agent_on_federation_sender.request.assert_not_called()
    
            failure_res = self.failureResultOf(test_request_from_main_process_d)
            self.assertIsInstance(failure_res.value, HttpResponseException)
            self.assertEqual(failure_res.value.code, 401)