[Twisted-Python] mail and web server authentication: yet to come or already there?

Stefano Debenedetti ste at webaccess.mozquito.com
Thu Nov 21 19:48:25 EST 2002

Hello Andrew, thanks a lot for the answer, I write some more comments inline:

Andrew Bennetts wrote:
> On Wed, Nov 20, 2002 at 09:42:08PM +0100, Stefano Debenedetti wrote:
>>(is HTTP 
>>basic auth implemented somewhere btw?)  
> I *think* twisted.web.guard has this functionality... I've heard it's going
> to be overhauled at some point, it's not as nice as it could be.

Unfortunately this seems to handle authentication at an application level while I need to use HTTP protocol authentication mechanisms, ok I'll have to give it a go myself.
> I'm even less of a twisted.mail expert than a twisted.web expert, but I
> think that twisted.mail's auth stuff predates twisted.cred, and we haven't
> had time to migrate it to twisted.cred yet.

Again, I'm going to try and do that, of course it would be easier if I had some more samples of twisted.cred I could start from :-)
> Hmm.  That looks like a dubious change to me.  Wouldn't that fail for
> headers like:
>     To: Mr. Example <dude at example.com>
> I'm not familiar with smtp.py though...

:-) seems you are victim of a similar misunderstanding of SMTP that I had until recently: MAIL FROM and RCPT TO can only specify a mail address (in angle brackets). Headers like:
To: Mr. Example <dude at example.com>

go after the DATA command so they are not affected by this modification. 
Indeed the current code is already handling RFC821 correctly, as that RFC doesn't allow to put spaces after the column and before the first angle bracket but I have at least one mailer that does that and I've seen other SMTP implementations that forgive that (for example see [1]), so I'll post my patch here again:

$ diff -u smtp.py_orig smtp.py
--- smtp.py_orig        2002-11-01 05:47:10.000000000 +0100
+++ smtp.py     2002-11-22 00:04:24.000000000 +0100
@@ -122,7 +122,7 @@

     def do_MAIL(self, rest):
-        from_ = rest[len("MAIL:<"):-len(">")]
+        from_ = rest[string.find(rest, "<")+1:-len(">")]
         self.validateFrom(self.__helo, from_, self._fromValid,

@@ -134,7 +134,7 @@
         self.sendCode(550, 'No mail for you!')

     def do_RCPT(self, rest):
-        to = rest[len("TO:<"):-len(">")]
+        to = rest[string.find(rest, "<")+1:-len(">")]
         user = User(to, self.__helo, self, self.__from)
         self.validateTo(user, self._toValid, self._toInvalid)
If you think it is not correct to be forgiving towards non-RFC-compliant mailers, fine but IMHO some modifications to the existing code should be done anyway, otherwise mailers that send that space won't receive any error message and think everything went OK but twisted.mail won't be able to send the mail because as things are now it will try to send it to: "<dude at example.com" therefore failing silently (from sender's perspective).
> 1. Twisted doesn't require any C modules to be compiled -- they're basically
>    just optional speed-ups.  In fact the only C module in Twisted that works
>    on Windows is cBanana; cReactor and portmap don't apply to Windows
>    because it doesn't have the relevant APIs.
> 2. I've heard it's possible to use the mingw port of gcc to compile python
>    extensions... search comp.lang.python or google for details.

Yes but the setup.py installer tries to compile at least cBanana and fails if that fails. I tried to use mingw but I end up with a long list of compilation errors, I am probably still doing something wrong and by googling I get to three or four fairly different explanations of how to do that so I guess it's still not as straightforward as a dummy user like me would require, anyway if it's not important I'll leave that aside for now :-)

So even at the second attempt the only way to run the Twisted installer for me was to remove the parts of setup.py that mention external modules, that makes me feel like a bad boy but I found no other solution.
> Eek.  The UI shouldn't crash, but regardless usually I use "runtests -t",
> i.e. run in text mode.
> Unfortunately Win32 support isn't 100% -- which tests are failing for you?

Thanks for the -t tip. I found out that the testcases hang only if I use the cygwin python and that they behave differently if I run them with the -t flag, I copy here (by hand) the outputs of the graphical UI, both under cygwin and with regular python:

under cygwin the graphical UI hangs while running test #155, with 181 tests remaining, after notifying the following:

Failure: testLongFileListings (twisted.test.test_ftp.FTPPassiveClientAndServerTest)
Failure: testRetr (twisted.test.test_ftp.FTPPassiveClientAndServerTest)
Failure: testCorrectOrder (twisted.test.test_internet.callFromThreadTestCase)
Error: testCorrectOrder (twisted.test.test_internet.callFromThreadTestCase)

outside of cygwin the UI doesn't crash and manages to complete the tests, here are the results:

Failure: testRetr (twisted.test.test_ftp.FTPPassiveClientAndServerTest)
Failure: test_internet (twisted.test.test_import.AtLeastImportTestCase)
Failure: testCallLater (twisted.test.test_internet.InterfaceTestCase)
Failure: testCorrectOrder (twisted.test.test_internet.callFromThreadTestCase)
Error: testCorrectOrder (twisted.test.test_internet.callFromThreadTestCase)
Error: testOutput (twisted.test.test_iutils.UtilsTestCase)
Error: testValue (twisted.test.test_iutils.UtilsTestCase)
Failure: testNoPermission (twisted.test.test_logfile.LogFileTestCase)
Error: testEcho (twisted.test.test_process.ProcessTestCase)
Error: testProcess (twisted.test.test_process.ProcessTestCase)
Error: testStdinReader (twisted.test.test_process.Win32ProcessTestCase)
Failure: testRebuild (twisted.test.test_rebuild.RebuildTestCase)
Failure: testCannotBind (twisted.test.test_tcp.CannotBindTestCase)
Error: testReconnect (twisted.test.test_tcp.ConnectorTestCase)
Error: testUserFail (twisted.test.test_tcp.ConnectorTestCase)
Error: testUserFail (twisted.test.test_tcp.ConnectorTestCase)
Error: testFailing (twisted.test.test_tcp.LoopbackTestCase)
Error: testMessages (twisted.test.test_unix.UnixSocketTestCase)

Please find attached also the results of the tests with the -t flag, also both under cygwin and with regular python, the tests outside of cygwin gave me different results on different executions so the files inside the zip I attach are four.

Maybe I should think twice about that potato-frying job, don't wanna go back to java.... :-)

thanks, ciao

[1] http://jakarta.apache.org/james/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: runtests_output.zip
Type: application/x-zip-compressed
Size: 6508 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20021122/f6049e48/attachment.bin 

More information about the Twisted-Python mailing list