a ze@sfdZddlZddlZddlZGdddejZGdddejZGdddejZed krbe dS) zTest the secrets module. As most of the functions in secrets are thin wrappers around functions defined elsewhere, we don't need to test them exhaustively. Nc@s0eZdZdZddZddZddZdd Zd S) Compare_Digest_Testsz%Test secrets.compare_digest function.c CsNdD]D}|d}|d}|t|||t|d|dqdS)N)aZbcdZxyz123dutf-8) assertTruesecretscompare_digestencodeselfsrbrE/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_secrets.py test_equals zCompare_Digest_Tests.test_equalc Csz|tdd|tdddD]L}|dd}|dd}|t|||t|d |d q(dS) NabcZabcdsabcsabcd)xZmnZa1b2c3rqkr)Z assertFalserrr r rrr test_unequals  z!Compare_Digest_Tests.test_unequalcCsRd}|d}t|tsJt|ts*J|ttj|||ttj||dS)NZabcder)r isinstancestrbytes assertRaises TypeErrorrr)r rr rrrtest_bad_types$s  z#Compare_Digest_Tests.test_bad_typescCs,|tddt|tddtdS)NrZxyz)assertIsInstancerrbool)r rrr test_bool-szCompare_Digest_Tests.test_boolN)__name__ __module__ __qualname____doc__rrrrrrrrrs   rc@s(eZdZdZddZddZddZdS) Random_Testsz*Test wrappers around SystemRandom methods.cCsVd}dD]H}tdD]:}t|}|d|kos zRandom_Tests.test_choicecCsJtddD]}|t|t|q |ttjd|ttjddS)Nr(r4r)r)ZassertInr randbelowr ValueError)r r+rrrtest_randbelowDszRandom_Tests.test_randbelowN)rr r!r"r-r7r;rrrrr#3sr#c@s0eZdZdZddZddZddZdd Zd S) Token_TestszTest token functions.c CstjtjtjfD]}|j|dp|j}z |Wn tyR|d|Yn0z |dWn ty|d|Yn0Wdq1s0Yqtj}| t td|| t tdd|dS)N)funcz$%s cannot be called with no argumentz%s cannot be called with Noner() r token_bytes token_hex token_urlsafesubTestrrZfailZDEFAULT_ENTROPY assertEquallen)r r=namesizerrrtest_token_defaultsOs     4zToken_Tests.test_token_defaultsc CsbdD]X}|j|d8|t|t|tt||Wdq1sR0YqdS)N)r.r0rr,)rArrr>rrBrC)r r,rrrtest_token_bytesaszToken_Tests.test_token_bytesc Cs|dD]r}|j|dRt|}||t|t|d||tdd|DWdq1sl0YqdS)N)r.r%ZrHr(css|]}|tjvVqdSN)string hexdigits.0crrr oz-Token_Tests.test_token_hex..) rArr?rrrBrCrallr r,r rrrtest_token_hexhs   zToken_Tests.test_token_hexc s|tjtjddD]b}|j|dBt|}||t|t fdd|DWdq1sl0YqdS)Nz-_)r. LrHc3s|]}|vVqdSrLrrOZlegalrrrRxrSz1Token_Tests.test_token_urlsafe..) rM ascii_lettersdigitsrArr@rrrrTrUrrZrtest_token_urlsafeqs   zToken_Tests.test_token_urlsafeN)rr r!r"rFrIrVr]rrrrr<Ls  r<__main__) r"rZunittestrMZTestCaserr#r<rmainrrrrs$/