
    <e/                         d dl Z d dlZd dlZd dlZd dlZd dlmZmZ 	 d dlZn# e	$ r dZY nw xY wej
        Z G d dej                  Zd Zedk    r e             dS dS )    N)	os_helperrun_unittestc                   2   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Z ej        ej        dk    d           ej        e du d          e!j"        d                                     Z#dS ) NetrcTestCasec                    t          j        |          }d}t          j        dk    r|dz  }t	          t
          |d          5 }|                    |           d d d            n# 1 swxY w Y   	 t          j        t
                    }t          j	        t
                     n# t          j	        t
                     w xY w|S )Nwcygwintzutf-8)encoding)
textwrapdedentsysplatformopentemp_filenamewritenetrcosunlink)self	test_datamodefpnrcs        &/usr/lib/python3.11/test/test_netrc.pymake_nrczNetrcTestCase.make_nrc   s    OI..	<8##CKD-888 	 BHHY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 	%+m,,CIm$$$$BIm$$$$
s   A%%A),A)1B$ $B?c                     |                      d          }|                     |j        d         d           |                     |j        d         d           d S )Nz            machine host.domain.com password pass1 login log1 account acct1
            default login log2 password pass2 account acct2
            host.domain.comlog1acct1pass1defaultlog2acct2pass2r   assertEqualhostsr   r   s     r    test_toplevel_non_ordered_tokensz.NetrcTestCase.test_toplevel_non_ordered_tokens   _    mm    	#457QRRR9-/IJJJJJ    c                     |                      d          }|                     |j        d         d           |                     |j        d         d           d S )Nz            machine host.domain.com login log1 password pass1 account acct1
            default login log2 password pass2 account acct2
            r   r   r#   r$   r(   r+   s     r   test_toplevel_tokensz"NetrcTestCase.test_toplevel_tokens"   r-   r.   c                     d}|                      |          }|                     |j        ddgddgd           |                     t          j        | j         |                    d          d d                    d S )	Nz            macdef macro1
            line1
            line2

            macdef macro2
            line3
            line4

        zline1
zline2
zline3
zline4
)macro1macro2 )r   r)   macrosassertRaisesr   NetrcParseErrorrstrip)r   datar   s      r   test_macroszNetrcTestCase.test_macros*   s    	 mmD!!I0F1:I0F&H &H 	I 	I 	I 	%/++c**3B3/	1 	1 	1 	1 	1r.   c                     d}|D ]8}|                      |          }|                     |j        d         d           9d}|D ]8}|                      |          }|                     |j        d         d           9d S )N)zmachine host.domain.comzmachine host.domain.com loginzmachine host.domain.com accountz machine host.domain.com passwordz(machine host.domain.com login "" accountz)machine host.domain.com login "" passwordz+machine host.domain.com account "" passwordr   ) r=   r=   )r#   zdefault loginzdefault accountzdefault passwordzdefault login "" accountzdefault login "" passwordzdefault account "" passwordr#   r(   )r   r:   itemr   s       r   test_optional_tokensz"NetrcTestCase.test_optional_tokens<   s    
  	I 	ID--%%CSY'89<HHHH
  	A 	AD--%%CSYy1<@@@@	A 	Ar.   c                 `    d}|D ](}|                      t          j        | j        |           )d S )N)zinvalid host.domain.comzmachine host.domain.com invalidzDmachine host.domain.com login log password pass account acct invalidzdefault host.domain.com invalidzDdefault host.domain.com login log password pass account acct invalid)r7   r   r8   r   )r   r:   r>   s      r   test_invalid_tokensz!NetrcTestCase.test_invalid_tokensV   sH    
  	J 	JDe3T]DIIII	J 	Jr.   c                 8   |                      |          }|dk    r&|                     |j        d         |ddf           d S |dk    r&|                     |j        d         d|df           d S |dk    r&|                     |j        d         dd|f           d S d S )Nloginr   acctpassaccountlogpasswordr(   )r   r   tokenvalues       r   _test_token_xzNetrcTestCase._test_token_xa   s    mmC  GSY'89E66;RSSSSSiSY'89E5&;QRRRRRj  SY'89E65;QRRRRR ! r.   c                     |                      ddd           |                      ddd           |                      ddd	           d S )
NzW            machine host.domain.com login "log" password pass account acct
            rC   rG   zW            machine host.domain.com login log password pass account "acct"
            rF   rD   zW            machine host.domain.com login log password "pass" account acct
            rH   rE   rK   r   s    r   test_token_value_quotesz%NetrcTestCase.test_token_value_quotesj   sv     %	! 	! 	! 	 F	$ 	$ 	$ 	 V	% 	% 	% 	% 	%r.   c                    |                      ddd           |                      ddd           |                      ddd           |                      ddd           |                      d	d
d           |                      dd
d           d S )NzW            machine host.domain.com login \"log password pass account acct
            rC   z"logzY            machine host.domain.com login "\"log" password pass account acct
            zW            machine host.domain.com login log password pass account \"acct
            rF   z"acctzY            machine host.domain.com login log password pass account "\"acct"
            zW            machine host.domain.com login log password \"pass account acct
            rH   z"passzY            machine host.domain.com login log password "\"pass" account acct
            rM   rN   s    r   test_token_value_escapez%NetrcTestCase.test_token_value_escapeu   s     &	" 	" 	" 	 &	" 	" 	" 	 G	% 	% 	% 	 G	% 	% 	% 	 W	& 	& 	& 	 W	& 	& 	& 	& 	&r.   c                     |                      ddd           |                      ddd           |                      ddd	           d S )
NzX            machine host.domain.com login "lo g" password pass account acct
            rC   zlo gzX            machine host.domain.com login log password "pas s" account acct
            rH   zpas szX            machine host.domain.com login log password pass account "acc t"
            rF   zacc trM   rN   s    r   test_token_value_whitespacez)NetrcTestCase.test_token_value_whitespace   sv     &	" 	" 	" 	 W	& 	& 	& 	 G	% 	% 	% 	% 	%r.   c                     |                      ddd           |                      ddd           |                      ddd           d S )NuV               machine host.domain.com login ¡¢ password pass account acct
            rC   u   ¡¢uU               machine host.domain.com login log password pass account ¡¢
            rF   uU               machine host.domain.com login log password ¡¢ account acct
            rH   rM   rN   s    r   test_token_value_non_asciiz(NetrcTestCase.test_token_value_non_ascii   sv     *	& 	& 	& 	 J	( 	( 	( 	 Z	) 	) 	) 	) 	)r.   c                     |                      ddd           |                      ddd           |                      ddd	           d S )
NzV            machine host.domain.com login #log password pass account acct
            rC   z#logzV            machine host.domain.com login log password pass account #acct
            rF   z#acctzV            machine host.domain.com login log password #pass account acct
            rH   #passrM   rN   s    r   test_token_value_leading_hashz+NetrcTestCase.test_token_value_leading_hash   v     &	" 	" 	" 	 G	% 	% 	% 	 W	& 	& 	& 	& 	&r.   c                     |                      ddd           |                      ddd           |                      ddd	           d S )
NzV            machine host.domain.com login log# password pass account acct
            rC   zlog#zV            machine host.domain.com login log password pass account acct#
            rF   zacct#zV            machine host.domain.com login log password pass# account acct
            rH   zpass#rM   rN   s    r   test_token_value_trailing_hashz,NetrcTestCase.test_token_value_trailing_hash   rY   r.   c                     |                      ddd           |                      ddd           |                      ddd	           d S )
NzV            machine host.domain.com login lo#g password pass account acct
            rC   zlo#gzV            machine host.domain.com login log password pass account ac#ct
            rF   zac#ctzV            machine host.domain.com login log password pa#ss account acct
            rH   zpa#ssrM   rN   s    r   test_token_value_internal_hashz,NetrcTestCase.test_token_value_internal_hash   rY   r.   rE   c                     |                      |          }|                     |j        d         dd|f           |                     |j        d         d           d S )Nfoo.domain.combarr=   zbar.domain.com)foor=   rE   r(   )r   r   passwds      r   _test_commentzNetrcTestCase._test_comment   s]    mmC  #34ub&6IJJJ#346IJJJJJr.   c                 0    |                      d           d S )Nz            # comment
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            rc   rN   s    r    test_comment_before_machine_linez.NetrcTestCase.test_comment_before_machine_line   )      	 	 	 	 	r.   c                 0    |                      d           d S )Nz            #comment
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            re   rN   s    r   )test_comment_before_machine_line_no_spacez7NetrcTestCase.test_comment_before_machine_line_no_space   rg   r.   c                 0    |                      d           d S )Nz            #
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            re   rN   s    r   *test_comment_before_machine_line_hash_onlyz8NetrcTestCase.test_comment_before_machine_line_hash_only   rg   r.   c                 Z    |                      d           |                      d           d S )Nz            machine foo.domain.com login bar password pass
            # comment
            machine bar.domain.com login foo password pass
            z            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            # comment
            re   rN   s    r   test_comment_after_machine_linez-NetrcTestCase.test_comment_after_machine_line   H      	 	 	
 	  	 	 	 	 	r.   c                 Z    |                      d           |                      d           d S )Nz            machine foo.domain.com login bar password pass
            #comment
            machine bar.domain.com login foo password pass
            z            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            #comment
            re   rN   s    r   (test_comment_after_machine_line_no_spacez6NetrcTestCase.test_comment_after_machine_line_no_space   rn   r.   c                 Z    |                      d           |                      d           d S )Nz            machine foo.domain.com login bar password pass
            #
            machine bar.domain.com login foo password pass
            z            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            #
            re   rN   s    r   )test_comment_after_machine_line_hash_onlyz7NetrcTestCase.test_comment_after_machine_line_hash_only   rn   r.   c                 0    |                      d           d S )Nz            machine foo.domain.com login bar password pass # comment
            machine bar.domain.com login foo password pass
            re   rN   s    r   #test_comment_at_end_of_machine_linez1NetrcTestCase.test_comment_at_end_of_machine_line   )      	 	 	 	 	r.   c                 0    |                      d           d S )Nz            machine foo.domain.com login bar password pass #comment
            machine bar.domain.com login foo password pass
            re   rN   s    r   ,test_comment_at_end_of_machine_line_no_spacez:NetrcTestCase.test_comment_at_end_of_machine_line_no_space  ru   r.   c                 2    |                      dd           d S )Nz            machine foo.domain.com login bar password #pass #comment
            machine bar.domain.com login foo password pass
            rW   re   rN   s    r   1test_comment_at_end_of_machine_line_pass_has_hashz?NetrcTestCase.test_comment_at_end_of_machine_line_pass_has_hash
  s.      	 	 	 	 	r.   posixzPOSIX only testNz"security check requires pwd modulec                    t           j        }t          j        |           |                     t           j        |           t          j                            |d          }t          |d          5 }|	                    d           d d d            n# 1 swxY w Y   t          j
                    5 }|                    d|           t          j        |d           t          j                    }|                     |j        d         d           t          j        |d           |                     t          j        t          j                   d d d            n# 1 swxY w Y   t          |d          5 }|	                    d	           d d d            n# 1 swxY w Y   t          j
                    5 }|                    d|           t          j        |d           t          j                    }|                     |j        d         d
           t          j        |d           |                     |j        d         d
           d d d            d S # 1 swxY w Y   d S )Nz.netrcwtz                machine foo.domain.com login bar password pass
                default login foo password pass
                HOMEi  r_   )r`   r=   rE   i  z                machine foo.domain.com login anonymous password pass
                default login foo password pass
                )	anonymousr=   rE   )r   TESTFNr   mkdir
addCleanuprmtreepathjoinr   r   EnvironmentVarGuardsetchmodr   r)   r*   r7   r8   )r   dfnfenvironr   s         r   test_securityzNetrcTestCase.test_security  s2    
	(!,,,W\\!X&&"d^^ 	qGG    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 *,, 	BKK"""HR+--CSY'7802 2 2HRe3U[AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B "d^^ 	qGG    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 *,, 	8KK"""HR+--CSY'7868 8 8HRSY'7868 8 8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8sJ   1BBB1BEE #E 7FF F7BII!I)rE   )$__name__
__module____qualname__r   r,   r0   r;   r?   rA   rK   rO   rQ   rS   rU   rX   r[   r]   rc   rf   ri   rk   rm   rp   rr   rt   rw   ry   unittest
skipUnlessr   nameskipIfpwdr   skip_unless_working_chmodr    r.   r   r   r      s         K K KK K K1 1 1$A A A4	J 	J 	JS S S	% 	% 	%& & &(	% 	% 	%	) 	) 	)	& 	& 	&	& 	& 	&	& 	& 	&K K K K
      
 
 

 
 

 
 
       XG+->??X_SD["FGG(!8 !8 )( HG @?!8 !8 !8r.   r   c                  .    t          t                     d S )N)r   r   r   r.   r   	test_mainr   7  s    r.   __main__)r   r   r   r   r   test.supportr   r   r   ImportErrorr   r   TestCaser   r   r   r   r.   r   <module>r      s    ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) 0 0 0 0 0 0 0 0JJJJ   
CCC  j8 j8 j8 j8 j8H% j8 j8 j8X	      zIKKKKK s   # --