o
    ¯b|  ã                   @   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)Úunittest)Útapc                   @   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)Ú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
--hostnameÚmyhostÚ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_auth1   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}.
        ÚcredCheckersé   r   c                    s   ˆ   | ˆ jj¡ d S )N)r   ÚadminÚusername)r&   r   r   r   Ú
_gotAvatarG   s   z,WordsTapTests._loginTest.<locals>._gotAvatar)	r   ÚlenÚassertFailureÚrequestAvatarIdÚjoeWrongr   ÚUnauthorizedLoginr%   ÚaddCallback)r   r   Úcheckerr'   r   r   r   r    9   s   ÿzWordsTapTests._loginTestN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚUsernamePasswordr%   r+   r   r   r   r!   r"   r    r   r   r   r   r   	   s    	r   N)	Útwisted.credr   r   Útwisted.trialr   Útwisted.wordsr   ÚTestCaser   r   r   r   r   Ú<module>   s   