Ϫf8dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddlZddlZddlZddlZddlZddlmZmZmZdd lmZdd lmZdd lmZdd lmZdd lm Z ddl!m"Z"ddl#m$Z$m%Z%Gdde$jLZ'GddejPjRZ*GddZ+GddZ,GddejZZ.Gdde$j^Z0GddejbZ2Gdde2Z3Gd d!ejhZ5Gd"d#e$j^Z6e ejnGd$d%Z8Gd&d'Z9d(Z:Gd)d*e$j^Z;Gd+d,e$j^Z<Gd-d.Z=Gd/d0e$j^Z>Gd1d2Z?d3Z@e%je@eB4ZCd5ZDe%jeDeB4ZEGd6d7e?e$j^ZFGd8d9e?e$j^ZGGd:d;e5ZHGd<d=eFZIGd>d?eGZJGd@dAe5ZKGdBdCeFZLGdDdEeGZMGdFdGe$jLZNGdHdIe$jLZOGdJdKe$jLZPy)Lz- Test cases for L{twisted.mail.pop3} module. N) OrderedDict)md5)BytesIO) implementer) verifyClass)credinternetmail)IUsernameHashedPassword)defer)LineSendingProtocol)pop3)loopback)failure)unittestutilc4eZdZdZdZdZdZdZdZdZ y) UtilityTestszl Test the various helper functions and classes used by the POP3 server protocol implementation. cg}ttjgd}tj|j |d}t|}|j |gt||j |gt||j |gt||j |gdtdD] }t||j |gdy)z Test creating a LineBuffer and feeding it some lines. The lines should build up in its internal buffer for a while and then get spat out to the writer. )0123456789)rrr)rrrrrrrrN) iter itertoolscycler_IteratorBufferextend assertEqualnextrange)selfoutputinputcins =/usr/lib/python3/dist-packages/twisted/mail/test/test_pop3.pytest_LineBufferingzUtilityTests.test_LineBuffering(s Y__%GHI  q 9 G $ Q $ Q $ Q !45q A G  !QRcg}tgd}tj|j|d}|D]}|j |gdy)z Test that a LineBuffer flushes everything when its iterator is exhausted, and itself raises StopIteration. )abr)rN)rrr!r"r#)r&r'r(r)r*s r,test_FinishLineBufferingz%UtilityTests.test_FinishLineBuffering=sM _%  q 9 A   1r.cN|jtjddy)zb Test that the thing that spits out POP3 'success responses' works right. sGreat.s +OK Great. N)r#rsuccessResponser&s r,test_SuccessResponseFormatterz*UtilityTests.test_SuccessResponseFormatterIs --i8:KLr.cttjgd}|j|dttjgdd}|j|dy)zX Test that the function which formats stat lines does so appropriately. s +OK 0 0 ) riu's +OK 4 10142 N)listrformatStatResponser#)r&statLines r,test_StatLineFormatterz#UtilityTests.test_StatLineFormatterPsZ//34R8 >2//0BCDRH #56r.cttjg}|j|ddgttjgd}|j|gdy)z} Test that the function which formats the lines in response to a LIST command does so appropriately. +OK 0 . )d)s+OK 4 s1 1 s2 2 s3 3 s4 100 rAN)r;rformatListResponser#)r& listLiness r,test_ListLineFormatterz#UtilityTests.test_ListLineFormatterZsW 0045  \8$<=00@A    V r.cgd}ttjg|j}|j |ddgttjgd|j}|j |gdttjgd|j}|j |gdy) zy Test that the function which formats lines in response to a UIDL command does so appropriately. )abcdefghi+OK rA){iO)rM1 abc s2 def 3 ghi rA)rNrO)rMrPrQrAN)r;rformatUIDListResponse __getitem__r#)r&uidsrGs r,test_UIDListLineFormatterz&UtilityTests.test_UIDListLineFormatterhs %33B8H8HIJ  [($;<33OTEUEUVW   X 33NDDTDTUV  $WXr.N) __name__ __module__ __qualname____doc__r-r2r6r>rHrUr.r,rr"s( S* 2M7  Yr.rceZdZdZdZdZy) MyVirtualPOP3z2 A virtual-domain-supporting POP3 server. c|j|\}}|jjdj|||j|S)a7 Authenticate against a user against a virtual domain. @param user: The username. @param digest: The digested password. @return: A three-tuple like the one returned by L{IRealm.requestAvatar}. The mailbox will be for the user given by C{user}. baz.com) lookupDomainservicedomainsauthenticateUserAPOPmagic)r&userdigestdomains r,rcz"MyVirtualPOP3.authenticateUserAPOPsG((. f||##J/DD &$**f  r.NrVrWrXrYrdrcrZr.r,r\r\zs E r.r\c(eZdZdZdZdZdZdZy) DummyDomainz- A virtual domain for a POP3 server. ci|_yNusersr5s r,__init__zDummyDomain.__init__s  r.c"g|j|<y)zV Create a mailbox for a new user. @param name: The username. Nrm)r&names r,addUserzDummyDomain.addUsers  4r.c@|j|j|y)z Add a message to the mailbox of the named user. @param name: The username. @param message: The contents of the message. N)rnappend)r&rqmessages r, addMessagezDummyDomain.addMessages 4(r.cVtjt|j|dfS)ae Succeed with a L{ListMailbox}. @param name: The name of the user authenticating. @param digest: ignored @param magic: ignored @param domain: ignored @return: A three-tuple like the one returned by L{IRealm.requestAvatar}. The mailbox will be for the user given by C{name}. cyrlrZrZr.r,z2DummyDomain.authenticateUserAPOP..r.)rIMailbox ListMailboxrn)r&rqrfrdrgs r,rcz DummyDomain.authenticateUserAPOPs#}}k$**T*:;\IIr.N)rVrWrXrYrorrrvrcrZr.r,rjrjs) Jr.rjc6eZdZdZdZd dZdZdZdZdZ y) r|z@ A simple in-memory list implementation of L{IMailbox}. c||_y)z, @param list: The messages. Nr;)r&r;s r,rozListMailbox.__init__s  r.Nc|#|jDcgc] }t|c}St|j|Scc}wz Get some message information. @param i: See L{pop3.IMailbox.listMessages}. @return: See L{pop3.IMailbox.listMessages}. )r;len)r&r*ls r, listMessageszListMailbox.listMessagess: 9$(II.qCF. .499Q<  /s>c2t|j|Sz Get the message content. @param i: See L{pop3.IMailbox.getMessage}. @return: See L{pop3.IMailbox.getMessage}. )rr;r&r*s r, getMessagezListMailbox.getMessagestyy|$$r.c|S)z Construct a UID by using the given index value. @param i: See L{pop3.IMailbox.getUidl}. @return: See L{pop3.IMailbox.getUidl}. rZrs r,getUidlzListMailbox.getUidls r.c"d|j|<yzm Wipe the message at the given index. @param i: See L{pop3.IMailbox.deleteMessage}. r.Nrrs r, deleteMessagezListMailbox.deleteMessages  ! r.cy)z= No-op. @see: L{pop3.IMailbox.sync} NrZr5s r,synczListMailbox.syncrzr.rl) rVrWrXrYrorrrrrrZr.r,r|r|s% !% r.r|c.eZdZdZdZdZdZdZdZy)MyPOP3DownloaderzE A POP3 client which downloads all messages from the server. chtjj|||jddy)zK Authenticate. @param line: The welcome response. s hello@baz.comsworldN)r POP3Clienthandle_WELCOMEapopr&lines r,rzMyPOP3Downloader.handle_WELCOMEs' &&tT2 "H-r.c|j}|d}|dk7rtd|d|dg|_|jdy)zc Require an I{OK} response to I{APOP}. @param line: The I{APOP} response. r+OKz code is: z , parts is:  rBN)splitAssertionErrorlinesretr)r&rpartscodes r, handle_APOPzMyPOP3Downloader.handle_APOPsK  Qx 6> 9TF-wa!HI I  ! r.c:|jj|y)zh Record one line of message information. @param line: A I{RETR} response line. N)rrtrs r,handle_RETR_continuez%MyPOP3Downloader.handle_RETR_continues $r.cjdj|jdz|_|jy)z: Record the received message information.  N)joinrruquitr5s r,handle_RETR_endz MyPOP3Downloader.handle_RETR_ends&zz$**-5  r.c0|dddk7rtd|zy)zc Require an I{OK} response to I{QUIT}. @param line: The I{QUIT} response. NrDrscode is )rrs r, handle_QUITzMyPOP3Downloader.handle_QUITs' 8v  t!34 4 r.N) rVrWrXrYrrrrrrZr.r,rrs .  5r.rcveZdZdZdZdeefzZdZdZdZ e jdge _ d Z y ) POP3Testsz! Tests for L{pop3.POP3}. s-Subject: urgent Someone set up us the bomb! s{+OK +OK Authentication succeeded +OK 1 0 . +OK %d Subject: urgent Someone set up us the bomb! . +OK cdtjj|_i|j_t |jjd<|jjdj d|jjdjd|jy)zC Set up a POP3 server with virtual domain support. r_shelloN) r protocolFactoryfactoryrbrjrrrvrur5s r,setUpzPOP3Tests.setUpBs| ((002 ! +6= Z( Z(00: Z(33HdllKr.ctgdt}j|_fd}t j |j |S)zL Messages can be downloaded over a loopback TCP connection. )sAPOP hello@baz.com worldUIDLRETR 1QUITczdjjdz}j|jy)N )rresponser#expectedOutput)ignoredr'clientr&s r,checkz&POP3Tests.test_messages..check[s0\\&//2W.checkis=   ^33T\\ B  # # *C DE r.)r\rrarr loopbackAsyncr)r&rdrrs` @@r, test_loopbackzPOP3Tests.test_loopbackasH!?<<)+   " "8^ <}}U##r.z*twisted.mail.pop3.POP3Client is deprecated)ruc4tjj}i|_t |jd<t }||_|jtj|jdd}|j|jddy)zP Look up a user in a domain which this server does not support. stwistedmatrix.comsnobody@baz.comspasswordrzno such domain baz.comN) r rrrbrjr\ra assertRaisesr POP3Errorrcr#args)r&rrexcs r,test_incorrectDomainzPOP3Tests.test_incorrectDomainvs}##++-0; ,-  NNF779JK  !&>?r.N) rVrWrXrYrurrrrrrsuppressrrZr.r,rr'sZG  G N LG*$$  JKM @r.rceZdZdZdZdZy) DummyPOP3zF A simple POP3 server with a hard-coded mailbox for any user. r]cDtjttdfS)z Succeed with a L{DummyMailbox}. @param user: ignored @param password: ignored @return: A three-tuple like the one returned by L{IRealm.requestAvatar}. cyrlrZrZr.r,ryz0DummyPOP3.authenticateUserAPOP..rzr.rr{ DummyMailbox ValueError)r&repasswords r,rczDummyPOP3.authenticateUserAPOPs}}l:6 DDr.NrhrZr.r,rrs E Er.rceZdZdZdZy) DummyPOP3AuthzL Class to test successful authentication in twisted.mail.pop3.POP3. ctjjt|_tjj }|j |||jj|yrl)rportalPortal TestRealmcheckers'InMemoryUsernamePasswordDatabaseDontUserrregisterChecker)r&rerchs r,rozDummyPOP3Auth.__init__sLkk((5 ]] B B D 4" ##B'r.N)rVrWrXrYrorZr.r,rrs (r.rc6eZdZdZdgZdZd dZdZdZdZ y) rz An in-memory L{pop3.IMailbox} implementation. @ivar messages: A sequence of L{bytes} defining the messages in this mailbox. @ivar exceptionType: The type of exception to raise when an out-of-bounds index is addressed. s,From: moshe To: moshe How are you, friend? cBtjdd|_||_yrl)rmessages exceptionType)r&rs r,rozDummyMailbox.__init__s$--a0 *r.Nc|#|jDcgc] }t|c}S|t|jk\r|jt|j|Scc}wr)rrr)r&r*ms r,rzDummyMailbox.listMessagess[ 9$(MM2qCF2 2 DMM" "$$& &4==#$$3sA&c2t|j|Sr)rrrs r,rzDummyMailbox.getMessagest}}Q'((r.c^|t|jk\r|jd|fzS)z Construct a UID which is simply the string representation of the given index. @param i: See L{pop3.IMailbox.getUidl}. @return: See L{pop3.IMailbox.getUidl}. s%d)rrrrs r,rzDummyMailbox.getUidls0 DMM" "$$& &t|r.c"d|j|<yr)rrs r,rzDummyMailbox.deleteMessages  ar.rl) rVrWrXrYrrorrrrrZr.r,rrs+DDH+ %) r.rceZdZdZddZdZdZdZdZdZ d Z ddggfd Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZy)AnotherPOP3Testsz( Additional L{pop3.POP3} tests. Nc|r|n t}t|}tj||}|j |j |||S)aO Assert that when C{lines} are delivered to L{pop3.POP3} it responds with C{expectedOutput}. @param lines: A sequence of L{bytes} representing lines to deliver to the server. @param expectedOutput: A sequence of L{bytes} representing the expected response from the server. @param protocolInstance: Instance of L{twisted.mail.pop3.POP3} or L{None}. If L{None}, a new DummyPOP3 will be used. @return: A L{Deferred} that fires when the lines have been delivered and the output checked. )rr rrr _cbRunTest)r&rrprotocolInstancedummyrrs r,runTestzAnotherPOP3Tests.runTestsE"%5 )+$U+  " "5& 1}}T__fe^LLr.c|jdj|dj|j|jt j t d|S)Nrr)r#rrrrrr)r&rrrrs r,rzAnotherPOP3Tests._cbRunTestsJ n5w||FOO7TU W__Y7P-QRSr.c.|jgdgdS)a4 Test a lot of different POP3 commands in an extremely pipelined scenario. This test may cover legitimate behavior, but the intent and granularity are not very good. It would likely be an improvement to split it into a number of smaller, more focused tests. )sAPOP moshez dummyLISTrrRETR 2sDELE 1rr) +OK +OK Authentication succeededs+OK 1s1 44.+OK s1 0rs+OK 44s From: moshes To: mosher.sHow are you, friend?rs -ERR Bad message number argumentrs-ERR message deletedrrr5s r, test_bufferzAnotherPOP3Tests.test_buffers||    r.c.|jgdgdS)z) Test the no-op command. )sAPOP spiv dummysNOOPr)rrrrrr5s r, test_noopzAnotherPOP3Tests.test_noop,s|| 2 P  r.cd}|jddgdd|zdg}|jtj}|j t |d|S)zi Sending a command with invalid UTF-8 characters will raise a L{pop3.POP3Error}. s&not authenticated yet: cannot do PASSsPASSrrs(-ERR bad protocol or server: POP3Error: rrB)rflushLoggedErrorsrrr#r)r&errorrerrorss r,test_badUTF8CharactersInCommandz0AnotherPOP3Tests.test_badUTF8CharactersInCommand5sa = LL ' ";eC  ''7 Va(r.ct}tjj|_dddd|j_t ddg}tj||}|j|j|S)z L{pop3.POP3} responds to an I{AUTH} command with a list of supported authentication types based on its factory's C{challengers}. N)sAuth1s secondAuthsauthLastsAUTHr) rr rrr challengersr rrr_cbTestAuthListing)r&prrs r,test_authListingz!AnotherPOP3Tests.test_authListingGsu K%%--/ +/SW X $    " "1f -}}T44f==r.c|j|jdjd|jt |jddgd|j|jddy)NrBrrCr)sAUTH1sAUTHLASTs SECONDAUTHr) assertTruer startswithr#sorted)r&rrs r,rz#AnotherPOP3Tests._cbTestAuthListingYsa *55f=>  6??1Q' (*P  +T2r.c|s|}|s|}gd}||k(r ||k(rgd}djd|gdjd|gg}||dgzz }||dgzz }|j||t||S) a Test a login with PASS. If L{real_user} matches L{tried_user} and L{real_password} matches L{tried_password}, a successful login will be expected. Otherwise an unsuccessful login will be expected. @type real_user: L{bytes} @param real_user: The user to test. @type real_password: L{bytes} @param real_password: The password of the test user. @type tried_user: L{bytes} or L{None} @param tried_user: The user to call USER with. If None, real_user will be used. @type tried_password: L{bytes} or L{None} @param tried_password: The password to call PASS with. If None, real_password will be used. @type after_auth_input: L{list} of l{bytes} @param after_auth_input: Extra protocol input after authentication. @type after_auth_output: L{list} of l{bytes} @param after_auth_output: Extra protocol output after authentication. )r+OK USER accepted, send PASSs-ERR Authentication failed)rrr USERPASSrr)r)rrr) r& real_user real_password tried_usertried_passwordafter_auth_inputafter_auth_outputr fullInputs r,run_PASSzAnotherPOP3Tests.run_PASS`sH"J*N   "}'FH IIw + , IIw/ 0 % 11 % 11||  *9mD  r.cP|jdjd|gdggdS)z Test protocol violation produced by calling PASS before USER. @type password: L{bytes} @param password: A password to test. rrr)rs-ERR USER required before PASSr)rr)r&rs r,run_PASS_before_USERz%AnotherPOP3Tests.run_PASS_before_USERs. || YY* +W 5 I  r.c$|jdS)z> Test PASS before USER with a wrong password. foozrr5s r,test_illegal_PASS_before_USERz.AnotherPOP3Tests.test_illegal_PASS_before_USERs((11r.c$|jdS)z? Test PASS before USER with an empty password. r.rr5s r,test_empty_PASS_before_USERz,AnotherPOP3Tests.test_empty_PASS_before_USERs((--r.c$|jdS)zI Test PASS before USER with an password that is a space. rrr5s r,test_one_space_PASS_before_USERz0AnotherPOP3Tests.test_one_space_PASS_before_USERs((..r.c$|jdS)zK Test PASS before USER with a password containing a space. fooz barzrr5s r,test_space_PASS_before_USERz,AnotherPOP3Tests.test_space_PASS_before_USERs((66r.c$|jdS)zS Test PASS before USER with a password containing multiple spaces. fooz barz asdfrr5s r,%test_multiple_spaces_PASS_before_USERz6AnotherPOP3Tests.test_multiple_spaces_PASS_before_USERs(():;;r.c$|jdS)zS Test PASS before USER with a password containing tabs and spaces. fooz barz crazy@! rr5s r,&test_other_whitespace_PASS_before_USERz7AnotherPOP3Tests.test_other_whitespace_PASS_before_USERs(()BCCr.c&|jddS)z1 Test PASS with a good password. testuserrrr5s r,test_good_PASSzAnotherPOP3Tests.test_good_PASSs}}['22r.c&|jddS)? Test PASS with a password containing a space. r/r&r0r5s r,test_space_PASSz AnotherPOP3Tests.test_space_PASSs}}[,77r.c&|jddS)r3r/r)r0r5s r,test_multiple_spaces_PASSz*AnotherPOP3Tests.test_multiple_spaces_PASSs}}[*;<r0r5s r,test_wrong_space_PASSz&AnotherPOP3Tests.test_wrong_space_PASSs}}[,|}TTr.c*|jdddS)r3r/r)s foozbarz r>r0r5s r,test_wrong_multiple_spaces_PASSz0AnotherPOP3Tests.test_wrong_multiple_spaces_PASSs"}} *>  r.c&|jddSr8r0r5s r, test_wrong_other_whitespace_PASSz1AnotherPOP3Tests.test_wrong_other_whitespace_PASSr:r.cdg}djddgg}|jdd||j|jtj S)zM After logging in, test a dummy command that is not defined. s DUMMY COMMANDrs'-ERR bad protocol or server: POP3Error:sUnknown protocol command: DUMMYr/ testpassword)rr)rrrrrr)r& extra_input extra_outputs r,test_wrong_commandz#AnotherPOP3Tests.test_wrong_commandsf(( II>6  }}  (*  +d,,dnn =  >r.rl)rVrWrXrYrrrrrr rrrr r"r$r'r*r-r1r4r6r9r<r?rArCrErJrZr.r,rrsM, ( T $>$3? B  2 . / 7 < D 3 8 = E L K U  E >r.rcJeZdZdZdZdZeddgZdZdZ dZ dZ d Z y ) TestServerFactoryz A L{pop3.IServerFactory} implementation, for use by the test suite, with some behavior controlled by the values of (settable) public attributes and other behavior based on values hard-coded both here and in some test methods. cy)W Return the hard-coded value. @return: L{pop3.IServerFactory} zTest Implementation StringrZr5s r,cap_IMPLEMENTATIONz$TestServerFactory.cap_IMPLEMENTATION's ,r.cy)rN<rZr5s r, cap_EXPIREzTestServerFactory.cap_EXPIRE/s r.)sSCHEME_1N)sSCHEME_2Ncy)rNxrZr5s r,cap_LOGIN_DELAYz!TestServerFactory.cap_LOGIN_DELAY9s r.Tc|jSrN)puer5s r,perUserExpirationz#TestServerFactory.perUserExpirationCs xxr.c|jSrW)puldr5s r,perUserLoginDelayz#TestServerFactory.perUserLoginDelayMs yyr.N) rVrWrXrYrOrRrrrUrXrYr[r\rZr.r,rLrLsA,24GHIK C Dr.rLceZdZdZdZdZy) TestMailboxz An incomplete L{IMailbox} implementation with certain per-user values hard-coded and known by tests in this module. This is useful for testing the server's per-user capability implementation. rEN)rVrWrXrY loginDelaymessageExpirationrZr.r,r^r^VsJr.r^c6|D]}|j||y)aG Assert that the given capability is included in all of the capability sets. @param testcase: A L{unittest.TestCase} to use to make assertions. @param s: The capability for which to check. @type s: L{bytes} @param caps: The capability sets in which to check. @type caps: L{tuple} of iterable N)assertIn)testcasescapsr)s r, containedrgds# !Q r.c@eZdZdZdZdZdZdZdZdZ dZ d Z y ) CapabilityTestsz@ Tests for L{pop3.POP3}'s per-user capability handling. ct}tj}t|_t j j||_|j|j|j|_ |jj|_t}t!|_t j j||_|j|jj|_|j't)j*t-dy)> Create a POP3 server with some capabilities. rN)rrPOP3rLrr r FileWrapper transportconnectionMadedo_CAPAlistCapabilitiesrfgetvalue splitlinespcapsr^mboxlpcapsrrrrr&rers r,rzCapabilityTests.setUpzs I IIK%' ''33A6   &&( ZZ\,,. I''33A6  jjl--/  3L)MNOr.c^t|d|j|j|jy)zB The server can advertise the I{UIDL} capability. rNrgrfrtrvr5s r, test_UIDLzCapabilityTests.test_UIDL  $DJJ Dr.c^t|d|j|j|jy)zA The server can advertise the I{TOP} capability. sTOPNryr5s r,test_TOPzCapabilityTests.test_TOPs  $ 4::t{{Cr.c^t|d|j|j|jy)zB The server can advertise the I{USER} capability. rNryr5s r, test_USERzCapabilityTests.test_USERr{r.cvt|d|j|jt|d|jy)zj The server can advertise its per-user expiration as well as a global expiration. sEXPIRE 60 USERs EXPIRE 25Nryr5s r, test_EXPIREzCapabilityTests.test_EXPIREs+ $)499djjA$ dkk2r.c^t|d|j|j|jy)zE The server can advertise its implementation string. s)IMPLEMENTATION Test Implementation StringNryr5s r,test_IMPLEMENTATIONz#CapabilityTests.test_IMPLEMENTATIONs'   8 II JJ KK  r.c^t|d|j|j|jy)zH The server can advertise the SASL schemes it supports. sSASL SCHEME_1 SCHEME_2Nryr5s r, test_SASLzCapabilityTests.test_SASLs! $1499djj$++Vr.ct|d|j|j|jd|jy)zc The can advertise a per-user login delay as well as a global login delay. sLOGIN-DELAY 120 USERsLOGIN-DELAY 100N)rgrfrtrcrvr5s r,test_LOGIN_DELAYz CapabilityTests.test_LOGIN_DELAYs. $/DJJG ($++6r.N) rVrWrXrYrrzr}rrrrrrZr.r,ririus4P,E D E 3  W 7r.ric"eZdZdZdZdZdZy)GlobalCapabilitiesTestsz> Tests for L{pop3.POP3}'s global capability handling. ct}tj}t|_dx|j_|j_tjj||_ |j|j|j|_|jj!|_t}t%|_tjj||_ |j|jj!|_|j+t-j.t1dy)rkFrN)rrrlrLrrXr[r rrmrnrorprqrfrrrsrtr^rurvrrrrrws r,rzGlobalCapabilitiesTests.setUps I IIK%' )..  ''33A6   &&( ZZ\,,. I''33A6  jjl--/  3L)MNOr.c^t|d|j|j|jy)zG I{EXPIRE} is in the server's advertised capabilities. s EXPIRE 60Nryr5s r,rz#GlobalCapabilitiesTests.test_EXPIREs  $ diiT[[Ir.c^t|d|j|j|jy)zL I{LOGIN-DELAY} is in the server's advertised capabilities. sLOGIN-DELAY 120Nryr5s r,rz(GlobalCapabilitiesTests.test_LOGIN_DELAYs! $*DIItzz4;;Or.N)rVrWrXrYrrrrZr.r,rrsP.J Pr.rceZdZdZdZy)rzI An L{IRealm} which knows about a single test account's mailbox. cR|dk(r!tjttdfSJ)aE Retrieve a mailbox for I{testuser} or fail. @param avatarId: See L{IRealm.requestAvatar}. @param mind: See L{IRealm.requestAvatar}. @param interfaces: See L{IRealm.requestAvatar}. @raises: L{AssertionError} when requesting an C{avatarId} other than I{testuser}. r/cyrlrZrZr.r,ryz)TestRealm.requestAvatar..rzr.r)r&avatarIdmind interfacess r, requestAvatarzTestRealm.requestAvatars' { "==,z":LH Hur.N)rVrWrXrYrrZr.r,rrs  r.rceZdZdZdZy) SASLTestsz7 Tests for L{pop3.POP3}'s SASL implementation. ctj}t|_dtj j i|j_tjjt|_tjj}|jdd|jj|t}t j"j%||_|j)|j+d|j-|j/j1ddk\|j+d|j/j3dd d }t5j6|}t9j:d|t< j?jAd }|j+t5jBd |z|j-|jD|j-|j/j3dj1ddk\|jGtIjJtMdy )z A CRAM-MD5-based SASL login attempt succeeds if it uses a username and a hashed password known to the server's credentials checker. sCRAM-MD5r/rGsCAPAs SASL CRAM-MD5rs AUTH CRAM-MD5r8rCN) digestmodasciis testuser rr)'rrlrLrr credentialsCramMD5Credentialsrrrrrrrrrrr rrmrnro lineReceivedr rrfindrsbase64 b64decodehmacHMACr hexdigestencode b64encoderurrrr)r&rrrechalrs r,test_ValidLoginzSASLTests.test_ValidLogins IIK%' !,d.>.>.Q.Q R ;;%%ik2 ]] B B D ;0   $ I''33A6   w  ))*:;q@A '(zz|&&(,QR0% IIots ; E E G N Nw W  v'' x(?@A   //1"5::6BaGH 3L)MNOr.N)rVrWrXrYrrZr.r,rrs Pr.rczeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZy) CommandMixinzI Tests for all the commands a POP3 server is allowed to receive. s1From: guy To: fellow More message text for you. c^tj}|j|j|_t |_||_t}tjj||_ |j|jd|jd||_y)z Make a POP3 server protocol instance hooked up to a simple mailbox and a transport that buffers output to a BytesIO. rN)rrl mailboxTyperrur;schedule pop3Serverrr rrmrnroseektruncate pop3Transportr&rres r,rzCommandMixin.setUp5s~ IIK!!$"4"45  I''33A6   q  1 r.cr|jjtjt dy)zo Disconnect the server protocol so it can clean up anything it might need to clean up. rN)rrrrrr5s r,tearDownzCommandMixin.tearDownFs( && OOI&?@ A r.cL|jjjy)zz Do some of the things that the reactor would take care of, if the reactor were actually running. N)rrn_checkProducerr5s r,_flushzCommandMixin._flushOs !!002r.c||j}|j}|jd|j|j |j d|j d|jd|jd|j|j |j dy)z Test the two forms of list: with a message index number, which should return a short-form response, and without a message index number, which should return a long-form response, one line per message. sLIST 1 +OK 1 44 rrs+OK 1 1 44 . Nrrrrr#rrrrrs r, test_LISTzCommandMixin.test_LISTWs OO    y!  7 q  1  w  '@Ar.c&|j}|j}|jd|j|j d|j d|j d|jd|j|j d|j d|j d|jd|j|j d|j d|j dy) zo Test that non-integers and out-of-bound integers produce appropriate error responses. sLIST as -ERR Invalid message-number: a rsLIST 0s -ERR Invalid message-number: 0 sLIST 2s -ERR Invalid message-number: 2 Nrrrr#rrrrrs r,test_LISTWithBadArgumentz%CommandMixin.test_LISTWithBadArgumentjs OO    y! 'LM q  1  y! 'LM q  1  y! 'LM q  1 r.c\|j}|j}|jd|j|j d|j d|j d|jd|j|j|j dy)zy Test the two forms of the UIDL command. These are just like the two forms of the LIST command. sUIDL 1r@rrs+OK 1 0 . N)rrrr#rrrrrrs r,rzzCommandMixin.test_UIDLs| OO    y! |4 q  1  w  '>?r.c&|j}|j}|jd|j|j d|j d|j d|jd|j|j d|j d|j d|jd|j|j d|j d|j dy)z Test that UIDL with a non-integer or an out-of-bounds integer produces the appropriate error response. sUIDL a"-ERR Bad message number argument rsUIDL 0sUIDL 2Nrrs r,test_UIDLWithBadArgumentz%CommandMixin.test_UIDLWithBadArguments OO    y! 'NO q  1  y! 'NO q  1  y! 'NO q  1 r.c|j}|j}|jd|j|j |j dy)z Test the single form of the STAT command, which returns a short-form response of the number of messages in the mailbox and their total size. sSTATrN)rrrrr#rrrs r, test_STATzCommandMixin.test_STATsC OO    w  7r.c|j}|j}|jd|j|j |j d|j d|jdy)z- Test downloading a message. rs;+OK 44 From: moshe To: moshe How are you, friend? . rNrrs r, test_RETRzCommandMixin.test_RETRsa OO    y!   JJL   q  1 r.c&|j}|j}|jd|j|j d|j d|j d|jd|j|j d|j d|j d|jd|j|j d|j d|j dy)z Test that trying to download a message with a bad argument, either not an integer or an out-of-bounds integer, fails with the appropriate error response. sRETR arrsRETR 0rNrrs r,test_RETRWithBadArgumentz%CommandMixin.test_RETRWithBadArguments OO    y! 'NO q  1  y! 'NO q  1  y! 'NO q  1 r.c|j}|j}|jjj |j |j d|j|j|jdy)zQ Test downloading the headers and part of the body of a message. sTOP 1 0s9+OK Top of message follows From: moshe To: moshe . N) rrrurrt extraMessagerrr#rrrs r,r}zCommandMixin.test_TOPse OO    t001 z"   JJL  r.c|j}|j}|jjj |j |j d|j|jd|jd|jd|j d|j|jd|jd|jd|j d|j|jd|jd|jd|j d|j|jd|jd|jd|j d|j|jd|jd|jdy ) a$ Test that trying to download a message with a bad argument, either a message number which isn't an integer or is an out-of-bounds integer or a number of lines which isn't an integer or is a negative integer, fails with the appropriate error response. sTOP 1 as-ERR Bad line count argument rsTOP 1 -1sTOP a 1rsTOP 0 1sTOP 3 1N rrrurrtrrr#rrrrrs r,test_TOPWithBadArgumentz$CommandMixin.test_TOPWithBadArgumentsQ OO    t001 z" 'JK q  1  {# 'JK q  1  z" 'NO q  1  z" 'NO q  1  z" 'NO q  1 r.c8|j}|j}|jjj |j |j d|j|jd|jd|jdy)z Test the exceedingly pointless LAST command, which tells you the highest message index which you have already downloaded. LASTr@rNrrs r, test_LASTzCommandMixin.test_LASTsl OO    t001 w |4 q  1 r.c|j}|j}|jjj |j |j d|j|jd|jd|j d|j|jd|jd|jdy)zM Test that issuing a RETR command updates the LAST response. rrr+OK 2 N rrrurrtrrrrrr#rrrs r,test_RetrieveUpdatesHighestz(CommandMixin.test_RetrieveUpdatesHighest's OO    t001 y!  q  1  w |4 q  1 r.cz|j}|j}|jjj |j |j d|j|jd|jd|j d|j|jdy)zL Test that issuing a TOP command updates the LAST response. sTOP 2 10rrrNrrs r,test_TopUpdatesHighestz#CommandMixin.test_TopUpdatesHighest8s OO    t001 {#  q  1  w |4r.c|j}|j}|jjj |j |j d|j|j d|j|jd|jd|j d|j|jdy)z Test that downloading a message with a smaller index than the current LAST response doesn't change the LAST response. rsTOP 1 10rrrNrrs r,test_HighestOnlyProgressesz'CommandMixin.test_HighestOnlyProgressesGs OO    t001 y!  {#  q  1  w |4r.c|j}|j}|jjj |j |j d|j|j d|jd|jd|j d|j|jdy)zH Test that issuing RSET changes the LAST response to 0. rsRSETrrr@Nrrs r,test_ResetClearsHighestz$CommandMixin.test_ResetClearsHighestYs OO    t001 y!  w q  1  w |4r.N)rVrWrXrYrrrrrrrzrrrrr}rrrrrrrZr.r,rr)sfL" 3B&.@". 8*0 &"H " 55$5r.rz}twisted.mail.pop3.IMailbox.listMessages may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.)rucategoryzxtwisted.mail.pop3.IMailbox.getUidl may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.cpeZdZdZeZeZdZe ge_ dZ e ge _ dZ e ge _ dZe ge_ y)IndexErrorCommandTestsz Run all of the command tests against a mailbox which raises IndexError when an out of bounds request is made. This behavior will be deprecated shortly and then removed. c,tj|S)z An attempt to get metadata about a message with a bad argument fails with an I{ERR} response even if the mailbox implementation raises L{IndexError}. )rrr5s r,rz/IndexErrorCommandTests.test_LISTWithBadArgument 44T::r.c,tj|S)z An attempt to look up the UID of a message with a bad argument fails with an I{ERR} response even if the mailbox implementation raises L{IndexError}. )rrr5s r,rz/IndexErrorCommandTests.test_UIDLWithBadArgumentrr.c,tj|S)z An attempt to download some of a message with a bad argument fails with an I{ERR} response even if the mailbox implementation raises L{IndexError}. )rrr5s r,rz.IndexErrorCommandTests.test_TOPWithBadArguments 33D99r.c,tj|S)z An attempt to download a message with a bad argument fails with an I{ERR} response even if the mailbox implementation raises L{IndexError}. )rrr5s r,rz/IndexErrorCommandTests.test_RETRWithBadArgumentrr.N)rVrWrXrY IndexErrorrrrr_listMessageSuppressionrr_getUidlSuppressionrrrZr.r,rr}sb MK;*A(A%;*=(=%:)@'@$;*A(A%r.rceZdZdZeZeZy)ValueErrorCommandTestsa Run all of the command tests against a mailbox which raises ValueError when an out of bounds request is made. This is the correct behavior and after support for mailboxes which raise IndexError is removed, this will become just C{CommandTestCase}. N)rVrWrXrYrrrrrZr.r,rrsMKr.rceZdZdZddZy)SyncDeferredMailboxzo Mailbox which has a listMessages implementation which returns a Deferred which has already fired. NcTtjtj||S)z Synchronously list messages. @type n: L{int} or L{None} @param n: The 0-based index of the message. @return: A L{Deferred} which already has a message list result. )r succeedrr)r&r+s r,rz SyncDeferredMailbox.listMessagess }}\66tQ?@@r.rl)rVrWrXrYrrZr.r,rrs  Ar.rceZdZdZeZy)"IndexErrorSyncDeferredCommandTestsz{ Run all of the L{IndexErrorCommandTests} tests with a synchronous-Deferred returning IMailbox implementation. NrVrWrXrYrrrZr.r,rr &Kr.rceZdZdZeZy)"ValueErrorSyncDeferredCommandTestsz{ Run all of the L{ValueErrorCommandTests} tests with a synchronous-Deferred returning IMailbox implementation. NrrZr.r,rrrr.rceZdZdZdZddZy)AsyncDeferredMailboxzo Mailbox which has a listMessages implementation which returns a Deferred which has not yet fired. cDg|_tj|g|i|yrl)waitingrro)r&r0kws r,rozAsyncDeferredMailbox.__init__s! d-Q-"-r.Nctj}|jj|tj ||f|S)z Record a new unfired L{Deferred} in C{self.waiting} and return it. @type n: L{int} or L{None} @param n: The 0-based index of the message. @return: The L{Deferred} )r Deferredrrtrr)r&r+rs r,rz!AsyncDeferredMailbox.listMessagess9 NN  Q 9 9$ BCDr.rl)rVrWrXrYrorrZr.r,rrs . r.rceZdZdZeZdZy)#IndexErrorAsyncDeferredCommandTests} Run all of the L{IndexErrorCommandTests} tests with an asynchronous-Deferred returning IMailbox implementation. c4|jjjrc|jjjj\}}|j ||jjjrct j |yzH Fire whatever Deferreds we've built up in our mailbox. N)rrurpopcallbackrrr&rr0s r,rz*IndexErrorAsyncDeferredCommandTests._flushioo""**??''//335DAq JJqMoo""** %%d+r.NrVrWrXrYrrrrZr.r,rr 'K,r.rceZdZdZeZdZy)#ValueErrorAsyncDeferredCommandTestsrc4|jjjrc|jjjj\}}|j ||jjjrct j |yr)rrurrrrrrs r,rz*ValueErrorAsyncDeferredCommandTests._flushrr.NrrZr.r,rr rr.rceZdZdZdZy) POP3MiscTestsz} Miscellaneous tests more to do with module/package structure than anything to do with the Post Office Protocol. ctjj}|jD]}|j t ||y)z This test checks that all names listed in twisted.mail.pop3.__all__ are actually present in the module. N)twistedr r__all__r hasattr)r&modattrs r,test_allzPOP3MiscTests.test_all#s9 llKK 0D OOGC. / 0r.N)rVrWrXrYr rZr.r,rrs  0r.rceZdZdZdZy)POP3ClientDeprecationTestszI Tests for the now deprecated L{twisted.mail.pop3client} module. cddlm}|j|jg}|j |ddt |j |ddd|j t |d|y) z A deprecation warning is emitted when directly importing the now deprected pop3client module. This test might fail is some other code has already imported it. No code should use the deprected module. r) pop3client)offendingFunctionsrruzXtwisted.mail.pop3client was deprecated in Twisted 21.2.0. Use twisted.mail.pop3 instead.rBN) twisted.mailr flushWarningstest_deprecationr#DeprecationWarningr)r&r warningsShowns r,rz+POP3ClientDeprecationTests.test_deprecation2sx ,**t?T?T>U*V  q)*57IJ  ! Y ' - ]+Q/r.N)rVrWrXrYrrZr.r,rr-s r.rceZdZdZy)APOPCredentialsTestsc^|jtttjy)zl L{APOPCredentials} implements L{twisted.cred.credentials.IUsernameHashedPassword}. N)r rr rAPOPCredentialsr5s r, test_implementsIUsernamePasswordz5APOPCredentialsTests.test_implementsIUsernamePasswordHs  $;T=Q=QRSr.N)rVrWrXrrZr.r,rrGsTr.r)QrYrrr collectionsrhashlibriorzope.interfacerzope.interface.verifyrtwisted.cred.checkersrtwisted.cred.portaltwisted.internet.protocoltwisted.mail.pop3twisted.mail.protocolsrr r twisted.cred.credentialsr twisted.internetr twisted.internet.testingr rrtwisted.protocolsrtwisted.pythonr twisted.trialrrSynchronousTestCaser protocols VirtualPOP3r\rjr|rrTestCaserrlrrMailboxrrIServerFactoryrLr^rgrirrrr_listMessageDeprecationrPendingDeprecationWarningr_getUidlDeprecationrrrrrrrrrrrrrZr.r,r5s  #&- ((<"8&"(UY8//UYp DNN.. 0&J&JR5 5 p15t15h\@!!\@~E E( (I (94<<9xy>x((y>x  T !44"4n   "M7h''M7`&Ph//&PR*#P!!#PL~5~5D   ($-- #.G   $dmm *C 0B\8+<+<0Bf \8+<+< A,A$&)?&&)?&<2,*@,$,*@,$ 0H00 0 !=!=4T877Tr.