@@ -0,0 +1,2254 @@
+# -*- coding: utf-8 -*-%0A# Copyright 2018 New Vector Ltd%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0Afrom mock import patch, Mock%0Afrom parameterized import parameterized%0A%0Afrom synapse.app.federation_reader import FederationReaderServer%0A%0Afrom tests.unittest import HomeserverTestCase%0A%0A%0A@patch(%22synapse.app.homeserver.KeyApiV2Resource%22, new=Mock())%0Aclass FederationReaderOpenIDListenerTests(HomeserverTestCase):%0A    def make_homeserver(self, reactor, clock):%0A        hs = self.setup_test_homeserver(%0A            http_client=None, homeserverToUse=FederationReaderServer,%0A        )%0A        return hs%0A%0A    @parameterized.expand(%5B%0A        (%5B%22federation%22%5D, %22auth_fail%22),%0A        (%5B%5D, %22no_resource%22),%0A        (%5B%22openid%22, %22federation%22%5D, %22auth_fail%22),%0A        (%5B%22openid%22%5D, %22auth_fail%22),%0A    %5D)%0A    def test_openid_listener(self, names, expectation):%0A        %22%22%22%0A        Test different openid listener configurations.%0A%0A        401 is success here since it means we hit the handler and auth failed.%0A        %22%22%22%0A        config = %7B%0A            %22port%22: 8080,%0A            %22bind_addresses%22: %5B%220.0.0.0%22%5D,%0A            %22resources%22: %5B%7B%22names%22: names%7D%5D,%0A        %7D%0A%0A        # Listen with the config%0A        self.hs._listen_http(config)%0A%0A        # Grab the resource from the site that was told to listen%0A        site = self.reactor.tcpServers%5B0%5D%5B1%5D%0A        try:%0A            self.resource = (%0A                site.resource.children%5Bb%22_matrix%22%5D.children%5Bb%22federation%22%5D.children%5Bb%22v1%22%5D%0A            )%0A        except KeyError:%0A            if expectation == %22no_resource%22:%0A                return%0A            raise%0A%0A        request, channel = self.make_request(%22GET%22, %22/_matrix/federation/v1/openid/userinfo%22)%0A        self.render(request)%0A%0A        self.assertEqual(channel.code, 401)%0A

Add tests for the openid lister for FederationReaderServer