o
    ¼>hl	  ã                   @  sb   d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd„ de
jƒZd	S )
é    )Úannotations)ÚcredentialsÚerror)ÚFilePasswordDB)Údefer)Úunittest)Útapc                   @  sh   e Zd ZdZdZe dd¡Ze dd¡Zddd	„Z	dd
d„Z
ddd„Zddd„Zddd„Zddd„ZdS )ÚWordsTapTestsz7
    Ensures that the twisted.words.tap API works.
    s   admin:admin
joe:foo
s   admins   joes   barÚreturnÚNonec                 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   ú{/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-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_auth5   s   zWordsTapTests.test_authr!   útap.Optionsúdefer.Deferred[None]c                   sV   ˆ   t|d ƒd¡ |d d }ˆ  | ˆ j¡tj¡ d‡ 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   Úusernameúbytes | tuple[()]r
   r   c                   s   ˆ   | ˆ jj¡ d S )N)r   Úadminr,   )r,   r   r   r   Ú
_gotAvatarK   s   z,WordsTapTests._loginTest.<locals>._gotAvatarN)r,   r-   r
   r   )	r   ÚlenÚassertFailureÚrequestAvatarIdÚjoeWrongr   ÚUnauthorizedLoginr.   ÚaddCallback)r   r!   Úcheckerr/   r   r   r   r%   =   s   ÿzWordsTapTests._loginTestN)r
   r   )r!   r(   r
   r)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚUsernamePasswordr.   r3   r   r   r"   r&   r'   r%   r   r   r   r   r	      s    

	


r	   N)Ú
__future__r   Útwisted.credr   r   Útwisted.cred.checkersr   Útwisted.internetr   Útwisted.trialr   Útwisted.wordsr   ÚTestCaser	   r   r   r   r   Ú<module>   s   