Exemple #1
0
 def setUp(self):
     self.verifier = RemoteVerifier()
Exemple #2
0
 def setUp(self):
     self.verifier = RemoteVerifier()
Exemple #3
0
class TestRemoteVerifier(unittest.TestCase, VerifierTestCases):

    def setUp(self):
        self.verifier = RemoteVerifier()

    def test_handling_of_valid_response_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return '{"email": "*****@*****.**", '\
                           ' "status": "okay", '\
                           ' "audience": "http://myfavoritebeer.org"}'
            return response
        self.verifier.urlopen = urlopen
        data = self.verifier.verify(EXPIRED_ASSERTION)
        self.assertEquals(data["email"], "*****@*****.**")

    def test_handling_of_invalid_content_length_header_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def info():
                    return {"Content-Length": "forty-two"}
                @staticmethod  # NOQA
                def read(size):
                    raise RuntimeError  # pragma: nocover
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_invalid_json_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return "SERVER RETURNS SOMETHING THAT ISNT JSON"
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_incorrect_audience_returned_by_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return '{"email": "*****@*****.**", '\
                           ' "status": "okay", '\
                           '"audience": "WRONG"}'
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(AudienceMismatchError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_500_error_from_server(self):
        def urlopen(url, data):
            raise ConnectionError("500 Server Error")
        self.verifier.urlopen = urlopen
        self.assertRaises(ValueError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_503_error_from_server(self):
        def urlopen(url, data):
            raise ConnectionError("503 Back Off Will Ya?!")
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)
Exemple #4
0
class TestRemoteVerifier(unittest.TestCase, VerifierTestCases):

    def setUp(self):
        self.verifier = RemoteVerifier()

    def test_expired_assertion_dev(self):
        self.verifier.verifier_url = "https://dev.diresworb.org/verify"
        super(TestRemoteVerifier, self).test_expired_assertion_dev()

    def test_handling_of_valid_response_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return '{"email": "*****@*****.**", '\
                           ' "status": "okay", '\
                           ' "audience": "http://myfavoritebeer.org"}'
            return response
        self.verifier.urlopen = urlopen
        data = self.verifier.verify(EXPIRED_ASSERTION)
        self.assertEquals(data["email"], "*****@*****.**")

    def test_handling_of_invalid_content_length_header_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def info():
                    return {"Content-Length": "forty-two"}
                @staticmethod
                def read(size):
                    raise RuntimeError  # pragma: nocover
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_invalid_json_from_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return "SERVER RETURNS SOMETHING THAT ISNT JSON"
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_incorrect_audience_returned_by_server(self):
        def urlopen(url, data):
            class response(object):
                @staticmethod
                def read():
                    return '{"email": "*****@*****.**", '\
                           ' "status": "okay", '\
                           '"audience": "WRONG"}'
            return response
        self.verifier.urlopen = urlopen
        self.assertRaises(AudienceMismatchError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_500_error_from_server(self):
        def urlopen(url, data):
            raise ConnectionError("500 Server Error")
        self.verifier.urlopen = urlopen
        self.assertRaises(ValueError,
                          self.verifier.verify, EXPIRED_ASSERTION)

    def test_handling_of_503_error_from_server(self):
        def urlopen(url, data):
            raise ConnectionError("503 Back Off Will Ya?!")
        self.verifier.urlopen = urlopen
        self.assertRaises(ConnectionError,
                          self.verifier.verify, EXPIRED_ASSERTION)