
    Yfl	                    x    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e
j                  Zd	S )
    )annotations)credentialserror)FilePasswordDB)defer)unittest)tapc                      e Zd ZdZdZ ej        dd          Z ej        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   barreturnNonec                    |                                  | _        t          | j        d          | _        | j                            | j                   | j                                         dS )z/
        Create a file with two users.
        wbN)mktempfilenameopenfilewritePASSWD_TEXTflushselfs    M/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_tap.pysetUpzWordsTapTests.setUp   sU     --		()))	    c                8    | j                                          dS )z0
        Close the dummy user database.
        N)r   closer   s    r   tearDownzWordsTapTests.tearDown   s     		r   c                    t          j                    }|                    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   opts     r   test_hostnamezWordsTapTests.test_hostname%   sH     kmm,1222Z(33333r   c                    t          j                    }|                    d| j        j        g           |                     |           dS )zI
        Tests the --passwd command for backwards-compatibility.
        z--passwdNr	   r"   r#   r   name
_loginTestr%   s     r   test_passwdzWordsTapTests.test_passwd-   sD     kmm*din5666r   c                    t          j                    }|                    dd| j        j        z   g           |                     |           dS )zD
        Tests that the --auth command generates a checker.
        z--authzfile:Nr)   r%   s     r   	test_authzWordsTapTests.test_auth5   sI     kmm(Gdin$<=>>>r   r&   tap.Optionsdefer.Deferred[None]c                H                          t          |d                   d           |d         d         }                     |                     j                  t
          j                   d	 f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                H                         | j        j                   d S )N)r$   adminr4   )r4   r   s    r   
_gotAvatarz,WordsTapTests._loginTest.<locals>._gotAvatarK   s$    Xtz':;;;;;r   )r4   r5   r   r   )	r$   lenassertFailurerequestAvatarIdjoeWrongr   UnauthorizedLoginr7   addCallback)r   r&   checkerr8   s   `   r   r+   zWordsTapTests._loginTest=   s     	S0111555"%n"5a"8##DM22E4K	
 	
 	
	< 	< 	< 	< 	< 	< &&tz22>>zJJJr   N)r   r   )r&   r/   r   r0   )__name__
__module____qualname____doc__r   r   UsernamePasswordr7   r<   r   r   r'   r,   r.   r+    r   r   r   r      s          ,K(K(8<<E+{+FF;;H      4 4 4 4      K K K K K Kr   r   N)
__future__r   twisted.credr   r   twisted.cred.checkersr   twisted.internetr   twisted.trialr   twisted.wordsr	   TestCaser   rE   r   r   <module>rM      s    # " " " " " + + + + + + + + 0 0 0 0 0 0 " " " " " " " " " " " "      AK AK AK AK AKH% AK AK AK AK AKr   