def test_openid_listener(self, names, expectation): """ Test different openid listener configurations. 401 is success here since it means we hit the handler and auth failed. """ config = { "port": 8080, "type": "http", "bind_addresses": ["0.0.0.0"], "resources": [{"names": names}], } # Listen with the config self.hs._listener_http(self.hs.get_config(), parse_listener_def(config)) # Grab the resource from the site that was told to listen site = self.reactor.tcpServers[0][1] try: self.resource = site.resource.children[b"_matrix"].children[b"federation"] except KeyError: if expectation == "no_resource": return raise request, channel = self.make_request( "GET", "/_matrix/federation/v1/openid/userinfo" ) self.render(request) self.assertEqual(channel.code, 401)
def _make_request(self, method, path): """Create a request from the method/path and return a channel with the response.""" request, channel = make_request(self.reactor, method, path, shorthand=False) request.prepath = [] # This doesn't get set properly by make_request. # Create a site and query for the resource. site = SynapseSite( "test", "site_tag", parse_listener_def({ "type": "http", "port": 0 }), self.resource, "1.0", ) request.site = site resource = site.getResourceFor(request) # Finally, render the resource and return the channel. render(request, resource, self.reactor) return channel
def _make_request(self, method: bytes, path: bytes) -> FakeChannel: """Create a request from the method/path and return a channel with the response.""" # Create a site and query for the resource. site = SynapseSite( "test", "site_tag", parse_listener_def({"type": "http", "port": 0}), self.resource, "1.0", max_request_body_size=1234, reactor=self.reactor, ) # render the request and return the channel channel = make_request(self.reactor, site, method, path, shorthand=False) return channel