HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/mail/test/__pycache__/test_mailmail.cpython-38.pyc
U


W[�2�@s�dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZdd
lmZddlmZddlmZGd
d�de�ZdS)zi
Tests for L{twisted.mail.scripts.mailmail}, the implementation of the
command line program I{mailmail}.
�N)�version)�Deferred)�smtp)�mailmail)�parseOptions)�NativeStringIO)�Failure)�platformType)�
MemoryReactor)�TestCasec@s�eZdZdZe�Zdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zedkr�de_dd�Zedkr�de_d d!�Zd"d#�Zd$d%�Zd&S)'�OptionsTestsz�
    Tests for L{parseOptions} which parses command line arguments and reads
    message text from stdin to produce an L{Options} instance which can be
    used to send a message.
    csft��_ddlm}m}|�j�}��td||d��d�_d�_d�_	�fdd�}��td|�dS)	zz
        Override some things in mailmail, so that we capture C{stdout},
        and do not call L{reactor.stop}.
        r)�textFileLogObserver�LoggerZ_log)ZobserverNcs.|�_|�_|�_tj||j|j|j�jd�S)N)Zreactor)	�host�options�identr�sendmail�sender�to�body�
memoryReactor)rrr��self��A/usr/lib/python3/dist-packages/twisted/mail/test/test_mailmail.pyr1s�z$OptionsTests.setUp.<locals>.sendmailr)
r�outZtwisted.loggerr
r�patchrrrr)rr
rZlogObserverrrrr�setUp"s
zOptionsTests.setUpcCs2|�tdtd��|�ttg�}|�|jd�dS)z�
        If no recipients are given in the argument list and there is no
        recipient header in the message text, L{parseOptions} raises
        L{SystemExit} with a string describing the problem.
        �stdinzSubject: foo

Hello, goodbye.
)zNo recipients specified.N)r�sysr�assertRaises�
SystemExitr�assertEqual�args�r�excrrr�test_unspecifiedRecipients;s

�z'OptionsTests.test_unspecifiedRecipientscCs"|�ttdg�}|�|jd�dS)z�
        The I{-bp} option for listing queue information is unsupported and
        if it is passed to L{parseOptions}, L{SystemExit} is raised.
        z-bp�zUnsupported option.N�r r!rr"r#r$rrr�test_listQueueInformationIsz&OptionsTests.test_listQueueInformationcCs"|�ttdg�}|�|jd�dS)z�
        The I{-bs} option for using stdin and stdout as the SMTP transport
        is unsupported and if it is passed to L{parseOptions}, L{SystemExit}
        is raised.
        z-bsr'Nr(r$rrr�test_stdioTransportRsz OptionsTests.test_stdioTransportcCs@|�ttdg�}|�|jd�|�ttdg�}|�|jd�dS)z�
        The I{-i} and I{-oi} options for ignoring C{"."} by itself on a line
        are unsupported and if either is passed to L{parseOptions},
        L{SystemExit} is raised.
        z-ir'z-oiNr(r$rrr�test_ignoreFullStop\sz OptionsTests.test_ignoreFullStopcCs"|�ttdg�}|�|jd�dS)z�
        The I{-om} option for copying the sender if they appear in an alias
        expansion is unsupported and if it is passed to L{parseOptions},
        L{SystemExit} is raised.
        z-omr'Nr(r$rrr�test_copyAliasedSenderhsz#OptionsTests.test_copyAliasedSendercCsNt�}|�td|�|�ttd�}|�|jd�|��}|�|d�	t
��dS)z~
        The I{--version} option displays the version and raises
        L{SystemExit} with L{None} as the exit code.
        �stdoutz	--versionNzmailmail version: {}
)rrrr r!rr"�code�getvalue�formatr)rrZsystemExitCode�datarrr�test_versionrs�zOptionsTests.test_versioncCs.td�}|�td|�td�}|�|j�dS)zA
        The I{-odb} flag specifies background delivery.
        �
rz-odbN)rrrr�
assertTrue�
background�rr�orrr�test_backgroundDelivery�sz$OptionsTests.test_backgroundDeliverycCs.td�}|�td|�td�}|�|j�dS)zB
        The I{-odf} flags specifies foreground delivery.
        r3rz-odfN)rrrrZassertFalser5r6rrr�test_foregroundDelivery�sz$OptionsTests.test_foregroundDeliverycCs4td�}|�td|�td�}|�t|j�d�dS)zd
        The I{-t} flags specifies that recipients should be obtained
        from headers.
        zTo: Curly <invaliduser2@example.com>
Cc: Larry <invaliduser1@example.com>
Bcc: Moe <invaliduser3@example.com>

Oh, a wise guy?
r�-t�N)rrrrr"�lenrr6rrr�test_recipientsFromHeaders�s�z'OptionsTests.test_recipientsFromHeaderscCs6td�}|�td|�tdddg�}|�|jd�dS)zw
        When a message has no I{From:} header, a I{From:} value can be
        specified with the I{-F} flag.
        z3To: invaliduser2@example.com
Subject: A wise guy?

r�-Fz Larry <invaliduser1@example.com>r:N�rrrrr"rr6rrr�test_setFrom�s�zOptionsTests.test_setFromcCs6td�}|�td|�tdddg�}|�|jd�dS)z�
        The I{-F} flag specifies the From: value.  However, I{-F} flag is
        overriden by the value of From: in the e-mail header.
        zLTo: Curly <invaliduser4@example.com>
From: Shemp <invaliduser4@example.com>
rr>z"Groucho <invaliduser5@example.com>r:zinvaliduser4@example.comNr?r6rrr�!test_overrideFromFlagByFromHeader�s�z.OptionsTests.test_overrideFromFlagByFromHeadercCstd}td�}|�td|�|�td|�t��|�|jjt���|�|jj	dg�|�
|jj�|�tj
�dS)z�
        Call L{mailmail.run}, and specify I{-oep} to print errors
        to stderr.  The sender, to, and printErrors options should be
        set and there should be no failure.
        �ztest_mailmail.py�invaliduser2@example.comz-oepr3�argvrrCN)rrrr�runr"rr�getloginrr4ZprintErrorsZassertIsNoneZfailed)rrDrrrr�test_runErrorsToStderr�sz#OptionsTests.test_runErrorsToStderrZwin32zImailmail.run() does not work on win32 due to lack of support for getuid()c	Cs�td�}|�td|�|��}t��}t��}t|d��}|�d�	||��W5QRX|�t
d|�d}|�td|�t
��|�|j
��d�|�|j
��d	�|�|j
��d
�dS)z�
        Error messages for illegal UID value, illegal GID value, and illegal
        identity entry will be sent to stderr.
        r3r�wa[useraccess]
allow=invaliduser2,invaliduser1
deny=invaliduser3,invaliduser4,{}
order=allow,deny
[groupaccess]
allow=invalidgid1,invalidgid2
deny=invalidgid1,invalidgid2,{}
order=deny,allow
[identity]
localhost=funny
[addresses]
smarthost=localhost
default_domain=example.com
Z	LOCAL_CFGrBrDz3Illegal UID in \[useraccess\] section: invaliduser1z3Illegal GID in \[groupaccess\] section: invalidgid1z,Illegal entry in \[identity\] section: funnyN)rrr�mktemp�os�getuid�getgid�open�writer0rrE�assertRegexrr/)rr�filenameZmyUidZmyGid�frDrrr�test_readInvalidConfig�s.����z#OptionsTests.test_readInvalidConfigc	Cs<ddlm}|��}t|d��}|�|�W5QRX||�S)a�
        Read a mailmail configuration file.

        The mailmail script checks the twisted.mail.scripts.mailmail.GLOBAL_CFG
        variable and then the twisted.mail.scripts.mailmail.LOCAL_CFG
        variable for the path to its  config file.

        @param config: path to config file
        @type config: L{str}

        @return: A parsed config.
        @rtype: L{twisted.mail.scripts.mailmail.Configuration}
        r)�
loadConfigrH)�twisted.mail.scripts.mailmailrSrIrMrN)r�configrSrPrQrrr�getConfigFromFile
s
zOptionsTests.getConfigFromFilecCsN|�d�}|�|jd�|�d�}|�|jd�|�d�}|�|jd�|�|jd�|�d�}|�d|j�|�|jdd	d
g�|�d�}|�|jdg�|�d
�}|�|jddg�|�d�}|�|jddg�|�|jddg�|�d�}|�|jdg�|�d�}|�|j	dg�|�d�}|�|jddg�|�|j	ddg�dS)zj
        L{twisted.mail.scripts.mailmail.loadConfig}
        parses the config file for mailmail.
        z 
[addresses]
smarthost=localhostZ	localhostz'
[addresses]
default_domain=example.comzexample.comz;
[addresses]
smarthost=localhost
default_domain=example.comz1
[identity]
host1=invalid
host2=username:passwordZhost1Zhost2ZusernameZpasswordz+
[useraccess]
allow=invalid1,35
order=allow�#z#
[useraccess]
deny=35,36
order=deny�$z/
[useraccess]
allow=35,36
deny=37,38
order=deny�%�&z(
[groupaccess]
allow=gid1,41
order=allow�)z!
[groupaccess]
deny=41
order=denyz6
[groupaccess]
allow=41,42
deny=43,44
order=allow,deny�*�+�,N)
rVr"Z	smarthostZdomainZassertNotInZ
identitiesZ	allowUIDsZdenyUIDsZ	allowGIDsZdenyGIDs)rrUrrr�test_loadConfig&s0









zOptionsTests.test_loadConfigcsB�fdd�}��td|�t��}d|_tt��}t�||�dS)z�
        L{twisted.mail.scripts.mailmail.senderror} sends mail back to the
        sender if an error occurs while sending mail to the recipient.
        cs0��|d���|dg���|��d�t�S)Nzpostmaster@�
testsender�
ValueError)rOr"r/r)rrZ	recipientrrrrrqsz-OptionsTests.test_senderror.<locals>.sendmailrr`N)rrrZOptionsrrraZ	senderror)rrZoptsZfailrrr�test_senderrorls
zOptionsTests.test_senderrorN)�__name__�
__module__�__qualname__�__doc__r
rrr&r)r*r+r,r2r8r9r=r@rArGr	�skiprRrVr_rbrrrrrs0	





�1Fr)rfrJrZtwisted.copyrightrZtwisted.internet.deferrZtwisted.mailrZtwisted.mail.scriptsrrTrZtwisted.python.compatrZtwisted.python.failurerZtwisted.python.runtimer	Ztwisted.test.proto_helpersr
Ztwisted.trial.unittestrrrrrr�<module>s