ó *oPc@`sśdZddlmZmZddlZddlmZddlmZde fd„ƒYZ de ej fd „ƒYZ d e ej fd „ƒYZd e ej fd „ƒYZdS(s- Test cases for L{twisted.python.randbytes}. i(tdivisiontabsolute_importN(tunittest(t randbytestSecureRandomTestCaseBasecB`seZdZd„ZRS(s1 Base class for secureRandom test cases. cC`srxktddƒD]Z}||ƒ}|jt|ƒ|ƒ||ƒ}|jt|ƒ|ƒ|j||ƒqWdS(s| The given random bytes source should return the number of bytes requested each time it is called and should probably not return the same bytes on two consecutive calls (although this is a perfectly legitimate occurrence and rejecting it may generate a spurious failure -- maybe we'll get lucky and the heat death with come first). iiN(tranget assertEqualtlentassertNotEquals(tselftsourcetnbyteststs2((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyt_checks   (t__name__t __module__t__doc__R(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyRstSecureRandomTestCasecB`seZdZd„ZRS(s4 Test secureRandom under normal conditions. cC`s|jtjƒdS(sŁ L{randbytes.secureRandom} should return a string of the requested length and make some effort to make its result otherwise unpredictable. N(RRt secureRandom(R ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyt test_normal-s(RRRR(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR(stConditionalSecureRandomTestCasecB`s2eZdZd„Zd„Zd„Zd„ZRS(s< Test random sources one by one, then remove it to. cC`stjƒ|_dS(sJ Create a L{randbytes.RandomFactory} to use in the tests. N(Rt RandomFactorytfactory(R ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pytsetUp<scC`stjƒ‚dS(sL A factory raising an error when a source is not available. N(RtSourceNotAvailable(R R ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyt errorFactoryCscC`s|j|jjƒdS(sy L{RandomFactory._osUrandom} should work as a random source whenever L{os.urandom} is available. N(RRt _osUrandom(R ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_osUrandomJsc`slˆjˆj_ˆjtjˆjjdƒ‡fd†}ˆjtdt |ƒ}ˆj t |ƒdƒdS(st Remove all secure sources and assert it raises a failure. Then try the fallback parameter. ic`sˆjjddtƒS(Nitfallback(RRtTrue((R (s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pytwrapperZssPurandom unavailable - proceeding with non-cryptographically secure random sourceN( RRRt assertRaisesRtSecureRandomNotAvailableRt assertWarnstRuntimeWarningt__file__RR(R RR ((R s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_withoutAnythingRs  (RRRRRRR%(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR6s    tRandomTestCaseBasecB`s eZdZd„Zd„ZRS(s% 'Normal' random test cases. cC`s|jtjƒdS(s" Test basic case. N(RRtinsecureRandom(R ((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyRkscC`s)tjƒ}d|_|j|jƒdS(sG Test C{insecureRandom} without C{random.getrandbits}. N(RRtNonet getrandbitsRR'(R R((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyttest_withoutGetrandbitsrs  (RRRRR*(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyR&fs (Rt __future__RRtost twisted.trialRttwisted.pythonRtobjectRtTestCaseRtSynchronousTestCaseRR&(((s?/usr/lib/python2.7/dist-packages/twisted/test/test_randbytes.pyts /