
    Vhl	                    z    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y	)
    )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y)WordsTapTestsz7
    Ensures that the twisted.words.tap API works.
    s   admin:admin
joe:foo
s   admins   joes   barc                    | j                         | _        t        | j                  d      | _        | j                  j	                  | j
                         | j                  j                          y)z/
        Create a file with two users.
        wbN)mktempfilenameopenfilewritePASSWD_TEXTflushselfs    K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_tap.pysetUpzWordsTapTests.setUp   sG     -			(()		    c                8    | j                   j                          y)z0
        Close the dummy user database.
        N)r   closer   s    r   tearDownzWordsTapTests.tearDown   s     			r   c                |    t        j                         }|j                  ddg       | j                  |d   d       y)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%   s6     kkm,12Z(3r   c                    t        j                         }|j                  d| j                  j                  g       | j                  |       y)zI
        Tests the --passwd command for backwards-compatibility.
        z--passwdNr	   r    r!   r   name
_loginTestr#   s     r   test_passwdzWordsTapTests.test_passwd-   s6     kkm*diinn56r   c                    t        j                         }|j                  dd| j                  j                  z   g       | j                  |       y)zD
        Tests that the --auth command generates a checker.
        z--authzfile:Nr'   r#   s     r   	test_authzWordsTapTests.test_auth5   s;     kkm(Gdiinn$<=>r   c                "     j                  t        |d         d       |d   d   } j                  |j                   j                        t
        j                         d fd}|j                   j                        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                R    j                  | j                  j                         y )N)r"   adminusername)r2   r   s    r   
_gotAvatarz,WordsTapTests._loginTest.<locals>._gotAvatarK   s    Xtzz':':;r   )r2   zbytes | tuple[()]returnNone)	r"   lenassertFailurerequestAvatarIdjoeWrongr   UnauthorizedLoginr1   addCallback)r   r$   checkerr3   s   `   r   r)   zWordsTapTests._loginTest=   s}     	S0115"%n"5a"8##DMM2E4K4K	
	< &&tzz2>>zJJr   N)r4   r5   )r$   ztap.Optionsr4   zdefer.Deferred[None])__name__
__module____qualname____doc__r   r   UsernamePasswordr1   r9   r   r   r%   r*   r,   r)    r   r   r   r      sU     ,K(K((8<E+{++FF;H4Kr   r   N)
__future__r   twisted.credr   r   twisted.cred.checkersr   twisted.internetr   twisted.trialr   twisted.wordsr	   TestCaser   rB   r   r   <module>rJ      s/    # + 0 " " AKH%% AKr   