예제 #1
0
def test_parse_remote_response(
    caplog,
):  # noqa: D202 - inline class requires a blank line
    """Test parsing Content-Type header for _parse_remote_response."""

    class FakeResponse:
        def __init__(self, header):
            self.headers = {"Content-Type": header}
            self.text = "{}"

    with caplog.at_level(logging.WARNING, logger="oic.utils.keyio"):
        kb_public = KeyBundle(source="file://./foo.jwks")

        res = FakeResponse("application/json;encoding=utf-8")
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ("oic.utils.keyio", logging.WARNING, "Wrong Content_type")
        ]
        caplog.clear()

        res = FakeResponse("application/json")
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ("oic.utils.keyio", logging.WARNING, "Wrong Content_type")
        ]
        caplog.clear()

        res = FakeResponse("Application/json")
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ("oic.utils.keyio", logging.WARNING, "Wrong Content_type")
        ]
        caplog.clear()

        res = FakeResponse("text/plain")
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples == [
            ("oic.utils.keyio", logging.WARNING, "Wrong Content_type")
        ]
예제 #2
0
def test_parse_remote_response(caplog):
    """
    Tests parsing Content-Type header for _parse_remote_response
    """
    class FakeResponse():
        def __init__(self, header):
            self.headers = {"Content-Type": header}
            self.text = "{}"

    with caplog.at_level(logging.WARNING, logger='oic.utils.keyio'):
        kb_public = KeyBundle(source='file://./foo.jwks')

        res = FakeResponse('application/json;encoding=utf-8')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('application/json')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('Application/json')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('text/plain')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples == [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
예제 #3
0
def test_parse_remote_response(caplog):
    """
    Tests parsing Content-Type header for _parse_remote_response
    """
    class FakeResponse():
        def __init__(self, header):
            self.headers = {"Content-Type": header}
            self.text = "{}"

    with caplog.at_level(logging.WARNING, logger='oic.utils.keyio'):
        kb_public = KeyBundle(source='file://./foo.jwks')

        res = FakeResponse('application/json;encoding=utf-8')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('application/json')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('Application/json')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples != [
            ('oic.utils.keyio', logging.WARNING, 'Wrong Content_type')
        ]
        caplog.clear()

        res = FakeResponse('text/plain')
        kb_public._parse_remote_response(res)
        assert caplog.record_tuples == [('oic.utils.keyio', logging.WARNING,
                                         'Wrong Content_type')]