o
    ¯b€
  ã                   @   sX   d 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ƒZd	S )
z
Tests for L{twisted.tap.ftp}.
é    )ÚcredentialsÚerror)Úversions)ÚFilePath)ÚOptions)ÚTestCasec                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚFTPOptionsTestszJ
    Tests for the command line option parser used for C{twistd ftp}.
    )s   iamusers   thisispasswordc                 C   s2   |   ¡ | _t| jƒ}| d | j¡¡ tƒ | _dS )z/
        Create a file with two users.
        ó   :N)ÚmktempÚfilenamer   Ú
setContentÚjoinÚusernamePasswordr   Úoptions)ÚselfÚf© r   ú?/usr/lib/python3/dist-packages/twisted/test/test_ftp_options.pyÚsetUp   s   

zFTPOptionsTests.setUpc                 C   s$   |   t dddd¡| jj| j¡ dS )zs
        The C{--password-file} option will emit a warning stating that
        said option is deprecated.
        ÚTwistedé   é   r   N)ÚcallDeprecatedr   ÚVersionr   Úopt_password_filer   ©r   r   r   r   Útest_passwordfileDeprecation   s
   ýz,FTPOptionsTests.test_passwordfileDeprecationc                 C   sB   t | jd ƒ}| j dd| j g¡ |  t | jd ƒ|d ¡ dS )zf
        The C{--auth} command-line option will add a checker to the list of
        checkers
        ÚcredCheckersú--authúfile:r   N)Úlenr   ÚparseOptionsr   ÚassertEqual)r   ÚnumCheckersr   r   r   Útest_authAdded*   s   zFTPOptionsTests.test_authAddedc                    sT   ˆ j  ddˆ j g¡ ˆ j d d }t ˆ jd d¡}| |¡ ‡ fdd„d	d„ ¡S )
z×
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that fails with L{UnauthorizedLogin} when
        presented with credentials that are unknown to that checker.
        r   r   r   éÿÿÿÿr   Úfakec                    s
   ˆ   d¡S )Nz!Wrong password should raise error)Úfail)Úignorer   r   r   Ú<lambda>=   s   
 z2FTPOptionsTests.test_authFailure.<locals>.<lambda>c                 S   s   |   tj¡S ©N)Útrapr   ÚUnauthorizedLogin)Úerrr   r   r   r)   >   s    )r   r!   r   r   ÚUsernamePasswordr   ÚrequestAvatarIdÚaddCallbacks)r   ÚcheckerÚinvalidr   r   r   Útest_authFailure3   s   

þz FTPOptionsTests.test_authFailurec                    sJ   ˆj  ddˆj g¡ ˆj d d }tjˆjŽ ‰ | ˆ ¡ ‡ ‡fdd„¡S )zË
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that returns the avatar id when presented with credentials
        that are known to that checker.
        r   r   r   r%   c                    s   ˆ  | ˆ j¡S r*   )r"   Úusername)r4   ©Úcorrectr   r   r   r)   K   s    z2FTPOptionsTests.test_authSuccess.<locals>.<lambda>)r   r!   r   r   r.   r   r/   ÚaddCallback)r   r1   r   r5   r   Útest_authSuccessA   s   
ÿz FTPOptionsTests.test_authSuccessN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r$   r3   r8   r   r   r   r   r      s    		r   N)r<   Útwisted.credr   r   Útwisted.pythonr   Útwisted.python.filepathr   Útwisted.tap.ftpr   Útwisted.trial.unittestr   r   r   r   r   r   Ú<module>   s   