a ze@sbddlZddlZddlZddlZddlZddlZddlmZGdddejZ e dkr^e dS)N)supportc@seZdZddZddZddZddZd d Zd d Zd dZ d)ddZ ddZ ddZ ddZ ddZddZddZeejdkdd d!Zd"d#Zd$d%Zd&d'Zd(S)* NetrcTestCasecCs|t|}d}tjdkr |d7}t\}}tj||d}||Wdn1sZ0Y| tj |t |S)Nwcygwint)mode) textwrapdedentsysplatformtempfilemkstemposfdopenwrite addCleanupunlinknetrc)selfZ test_datarZtemp_fdZ temp_filenamefprC/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_netrc.pymake_nrcs   (zNetrcTestCase.make_nrccCsP|d}||jdd||jdd||}||j|jdS)Nz machine host1.domain.com login log1 password pass1 account acct1 default login log2 password pass2 zhost1.domain.com)Zlog1Zacct1Zpass1default)log2NZpass2)r assertEqualhosts__repr__)rnrcZnrc2rrr test_defaults  zNetrcTestCase.test_defaultcCs*|d}||jddgddgddS)Nz macdef macro1 line1 line2 macdef macro2 line3 line4 zline1 zline2 zline3 zline4 )Zmacro1Zmacro2)rrZmacros)rrrrr test_macross zNetrcTestCase.test_macroscCs&||}||jddd|fdS)Nzhost.domain.comlogZacctrrrrrpasswdrrr_test_passwords+s zNetrcTestCase._test_passwordscCs|dddS)NzV machine host.domain.com login log password #pass account acct #passr%rrrrtest_password_with_leading_hash/sz-NetrcTestCase.test_password_with_leading_hashcCs|dddS)NzV machine host.domain.com login log password pass# account acct zpass#r'r(rrr test_password_with_trailing_hash4sz.NetrcTestCase.test_password_with_trailing_hashcCs|dddS)NzV machine host.domain.com login log password pa#ss account acct zpa#ssr'r(rrr test_password_with_internal_hash9sz.NetrcTestCase.test_password_with_internal_hashpasscCs8||}||jddd|f||jdddS)Nfoo.domain.combarzbar.domain.com)ZfooNr,r"r#rrr _test_comment>s zNetrcTestCase._test_commentcCs|ddS)Nz # comment machine foo.domain.com login bar password pass machine bar.domain.com login foo password pass r/r(rrr test_comment_before_machine_lineCsz.NetrcTestCase.test_comment_before_machine_linecCs|ddS)Nz #comment machine foo.domain.com login bar password pass machine bar.domain.com login foo password pass r0r(rrr)test_comment_before_machine_line_no_spaceJsz7NetrcTestCase.test_comment_before_machine_line_no_spacecCs|ddS)Nz # machine foo.domain.com login bar password pass machine bar.domain.com login foo password pass r0r(rrr*test_comment_before_machine_line_hash_onlyQsz8NetrcTestCase.test_comment_before_machine_line_hash_onlycCs|ddS)Nz machine foo.domain.com login bar password pass # comment machine bar.domain.com login foo password pass r0r(rrr#test_comment_at_end_of_machine_lineXsz1NetrcTestCase.test_comment_at_end_of_machine_linecCs|ddS)Nz machine foo.domain.com login bar password pass #comment machine bar.domain.com login foo password pass r0r(rrr,test_comment_at_end_of_machine_line_no_space^sz:NetrcTestCase.test_comment_at_end_of_machine_line_no_spacecCs|dddS)Nz machine foo.domain.com login bar password #pass #comment machine bar.domain.com login foo password pass r&r0r(rrr1test_comment_at_end_of_machine_line_pass_has_hashdsz?NetrcTestCase.test_comment_at_end_of_machine_line_pass_has_hashposixzPOSIX only testcCstj}t||tj|tj|d}t|d}| dWdn1sV0Yt ^}| d|t |dt }||jddt |d|t jt j Wdn1s0YdS) N.netrcZwtz machine foo.domain.com login bar password pass default login foo password pass HOMEr-)r.Nr,i)rTESTFNrmkdirrrmtreepathjoinopenrEnvironmentVarGuardsetchmodrrr assertRaisesZNetrcParseError)rdfnfenvironrrrr test_securityks  (     zNetrcTestCase.test_securitycCsdtj}t||tj|t*}|d||t t j Wdn1sV0YdS)Nr9) rr;rr<rr=rArBrDFileNotFoundErrorr)rrErHrrrtest_file_not_found_in_homes    z)NetrcTestCase.test_file_not_found_in_homecCs|jttjdddS)NZunlikely_netrc)file)rDrJrr(rrrtest_file_not_found_explicits z*NetrcTestCase.test_file_not_found_explicitcstjt|tjtjd}t|d}| dWdn1sV0Yt |dtjj gfdd}t tjd|4t }|d\}}}||d Wdn1s0Y|dS) Nr8rz.machine foo.domain.com login bar password passr:csZ|t4}|d|d|}|WdS1sL0YdS)Nr9 USERPROFILE)appendrrArB)srHresultZcalledZ fake_homeZorig_expanduserrrfake_expandusers     z8NetrcTestCase.test_home_not_set..fake_expanduser expanduserr-r.)rr;rr<rr=r>r?r@rrCrTZ swap_attrrZauthenticatorsrZ assertTrue)rZfake_netrc_pathrGrSrZloginZaccountpasswordrrRrtest_home_not_sets  ( *zNetrcTestCase.test_home_not_setN)r,)__name__ __module__ __qualname__rrr r%r)r*r+r/r1r2r3r4r5r6unittestZ skipUnlessrnamerIrKrMrVrrrrrs&     r__main__) rrrZr r rtestrZTestCaserrWmainrrrrs 0 %