U
    
W[„  ã                   @   s>   d dl mZmZ d dlmZ d dlmZ G dd„ dejƒZdS )é    )ÚcredentialsÚerror)Útap)Úunittestc                   @   s\   e Zd ZdZdZe dd¡Ze dd¡Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ ZdS )ÚWordsTapTestsz7
    Ensures that the twisted.words.tap API works.
    s   admin:admin
joe:foo
s   admins   joes   barc                 C   s4   |   ¡ | _t| jdƒ| _| j | j¡ | j ¡  dS )z/
        Create a file with two users.
        ÚwbN)ZmktempÚfilenameÚopenÚfileÚwriteÚPASSWD_TEXTÚflush©Úself© r   ú=/usr/lib/python3/dist-packages/twisted/words/test/test_tap.pyÚsetUp   s    
zWordsTapTests.setUpc                 C   s   | j  ¡  dS )z0
        Close the dummy user database.
        N)r
   Úcloser   r   r   r   ÚtearDown   s    zWordsTapTests.tearDownc                 C   s*   t  ¡ }| ddg¡ |  |d d¡ dS )zM
        Tests that the --hostname parameter gets passed to Options.
        z
--hostnameZmyhostZhostnameN)r   ÚOptionsÚparseOptionsÚassertEqual©r   Úoptr   r   r   Útest_hostname%   s    zWordsTapTests.test_hostnamec                 C   s(   t  ¡ }| d| jjg¡ |  |¡ dS )zI
        Tests the --passwd command for backwards-compatibility.
        z--passwdN©r   r   r   r
   ÚnameÚ
_loginTestr   r   r   r   Útest_passwd.   s    zWordsTapTests.test_passwdc                 C   s,   t  ¡ }| dd| jj g¡ |  |¡ dS )zD
        Tests that the --auth command generates a checker.
        z--authzfile:Nr   r   r   r   r   Ú	test_auth7   s    zWordsTapTests.test_authc                    sT   ˆ   t|d ƒd¡ |d d }ˆ  | ˆ j¡tj¡ ‡ fdd„}| ˆ j¡ |¡S )zå
        This method executes both positive and negative authentication
        tests against whatever credentials checker has been stored in
        the Options class.

        @param opt: An instance of L{tap.Options}.
        ZcredCheckersé   r   c                    s   ˆ   | ˆ jj¡ d S )N)r   ÚadminÚusername)r"   r   r   r   Ú
_gotAvatarL   s    z,WordsTapTests._loginTest.<locals>._gotAvatar)	r   ÚlenZassertFailureZrequestAvatarIdÚjoeWrongr   ZUnauthorizedLoginr!   ZaddCallback)r   r   Zcheckerr#   r   r   r   r   @   s    ÿzWordsTapTests._loginTestN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ZUsernamePasswordr!   r%   r   r   r   r   r   r   r   r   r   r   r   
   s   
			r   N)	Ztwisted.credr   r   Ztwisted.wordsr   Ztwisted.trialr   ZTestCaser   r   r   r   r   Ú<module>   s   