def testVerify(spec, pub, priv, closed, proxy):
"""
Runs a single test case against verify.verifyDEP() and returns the
result and potentially an error message. In addition to the elements
understood by run_test.runTest(), this function also understands the
"expectedException" element, which indicates the name of the exception
the verifyDEP() function is expected to throw, and the
"exceptionReceipt" element, which indicates the receipt at which an
exception is expected to occur. If "exceptionReceipt" is omitted, the
expected exception may occur anywhere in the generated DEP. If
"expectedException" is omitted, verifyDEP() must not throw any
exception.
:param spec: The test case specification as a dict structure.
:param pub: The public key or certificate. For a closed system a public
key must be used, for an open system a certificate must be used.
:param priv: The private key used to sign the generated receipts.
:param closed: Indicates whether the system is a closed system (True) or
an open system (False).
:param proxy: An object implementing RKSVVerificationProxyI. This will
be used to do the actual verification.
:return: A TestVerifyResult indicating the result of the test and an
error message. If the result is OK, the message is None.
"""
try:
keymat = [(pub, priv)] * spec['numberOfSignatureDevices']
deps, cc = run_test.runTest(spec, keymat, closed)
except Exception as e:
return TestVerifyResult.ERROR, e
rN, mN = _testVerify(spec, deps, cc, False, proxy)
rP, mP = _testVerify(spec, deps, cc, True, proxy)
if rN == rP and str(mN) == str(mP):
return rN, mN
r = TestVerifyResult.FAIL
if rN == TestVerifyResult.ERROR or rP == TestVerifyResult.ERROR:
r = TestVerifyResult.ERROR
return r, Exception(
_('Result mismatch: without parsing {}:>{}<, with parsing {}:>{}<').format(
rN.name, mN, rP.name, mP))
评论列表
文章目录