Made it the same as oictest/src/rrtest
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
__author__ = 'rolandh'
|
||||
|
||||
from oic.oauth2.message import ErrorResponse
|
||||
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
INFORMATION = 0
|
||||
OK = 1
|
||||
WARNING = 2
|
||||
@@ -10,8 +15,11 @@ INTERACTION = 5
|
||||
STATUSCODE = ["INFORMATION", "OK", "WARNING", "ERROR", "CRITICAL",
|
||||
"INTERACTION"]
|
||||
|
||||
CONT_JSON = "application/json"
|
||||
CONT_JWT = "application/jwt"
|
||||
|
||||
class Check():
|
||||
|
||||
class Check(object):
|
||||
""" General test
|
||||
"""
|
||||
|
||||
@@ -30,7 +38,8 @@ class Check():
|
||||
|
||||
def __call__(self, conv=None, output=None):
|
||||
_stat = self.response(**self._func(conv))
|
||||
output.append(_stat)
|
||||
if output is not None:
|
||||
output.append(_stat)
|
||||
return _stat
|
||||
|
||||
def response(self, **kwargs):
|
||||
@@ -67,6 +76,71 @@ class Error(Check):
|
||||
status = ERROR
|
||||
|
||||
|
||||
class WrapException(CriticalError):
|
||||
"""
|
||||
A runtime exception
|
||||
"""
|
||||
cid = "exception"
|
||||
msg = "Test tool exception"
|
||||
|
||||
def _func(self, conv=None):
|
||||
self._status = self.status
|
||||
self._message = traceback.format_exception(*sys.exc_info())
|
||||
return {}
|
||||
|
||||
|
||||
class Other(CriticalError):
|
||||
""" Other error """
|
||||
msg = "Other error"
|
||||
|
||||
|
||||
class CheckHTTPResponse(CriticalError):
|
||||
"""
|
||||
Checks that the HTTP response status is within the 200 or 300 range
|
||||
"""
|
||||
cid = "check-http-response"
|
||||
msg = "OP error"
|
||||
|
||||
def _func(self, conv):
|
||||
_response = conv.last_response
|
||||
_content = conv.last_content
|
||||
|
||||
res = {}
|
||||
if _response.status_code >= 400:
|
||||
self._status = self.status
|
||||
self._message = self.msg
|
||||
if CONT_JSON in _response.headers["content-type"]:
|
||||
try:
|
||||
err = ErrorResponse().deserialize(_content, "json")
|
||||
self._message = err.to_json()
|
||||
except Exception:
|
||||
res["content"] = _content
|
||||
else:
|
||||
res["content"] = _content
|
||||
res["url"] = conv.position
|
||||
res["http_status"] = _response.status_code
|
||||
else:
|
||||
# might still be an error message
|
||||
try:
|
||||
err = ErrorResponse().deserialize(_content, "json")
|
||||
err.verify()
|
||||
self._message = err.to_json()
|
||||
self._status = self.status
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
res["url"] = conv.position
|
||||
|
||||
return res
|
||||
|
||||
class InteractionNeeded(CriticalError):
|
||||
"""
|
||||
A Webpage was displayed for which no known interaction is defined.
|
||||
"""
|
||||
cid = "interaction-needed"
|
||||
msg = "Unexpected page"
|
||||
|
||||
def _func(self, conv=None):
|
||||
self._status = self.status
|
||||
self._message = None
|
||||
return {"url": conv.position}
|
||||
|
||||
@@ -26,6 +26,7 @@ class FlowException(Exception):
|
||||
class InteractionNeeded(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def NoneFunc():
|
||||
return None
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import cookielib
|
||||
import sys
|
||||
import traceback
|
||||
from rrtest import FatalError
|
||||
from rrtest.check import ExpectedError
|
||||
from rrtest.check import INTERACTION
|
||||
@@ -10,7 +12,12 @@ from rrtest.status import STATUSCODE
|
||||
__author__ = 'rolandh'
|
||||
|
||||
|
||||
class Conversation():
|
||||
class Conversation(object):
|
||||
"""
|
||||
:ivar response: The received HTTP messages
|
||||
:ivar protocol_response: List of the received protocol messages
|
||||
"""
|
||||
|
||||
def __init__(self, client, config, trace, interaction,
|
||||
check_factory=None, msg_factory=None,
|
||||
features=None, verbose=False):
|
||||
@@ -27,6 +34,7 @@ class Conversation():
|
||||
"rp": cookielib.CookieJar(),
|
||||
"service": cookielib.CookieJar()}
|
||||
|
||||
self.protocol_response = []
|
||||
self.last_response = None
|
||||
self.last_content = None
|
||||
self.response = None
|
||||
@@ -62,7 +70,9 @@ class Conversation():
|
||||
chk = self.check_factory(test)()
|
||||
chk(self, self.test_output)
|
||||
if bryt:
|
||||
raise FatalError(test)
|
||||
e = FatalError(test)
|
||||
e.trace = "".join(traceback.format_exception(*sys.exc_info()))
|
||||
raise e
|
||||
|
||||
def test_sequence(self, sequence):
|
||||
for test in sequence:
|
||||
|
||||
Reference in New Issue
Block a user