[TIP] Capture HTTP traffic

Olemis Lang olemis at gmail.com
Fri Nov 5 06:36:27 PDT 2010


On Fri, Nov 5, 2010 at 3:52 AM, Alex <alex.lavoro.propio at gmail.com> wrote:
>
[...]
>
> I prefer not to hijack host configuration, use a proxy, or mock the
> server, since they either result in a lot of work, and difficult to be
> deployed in a CI server like Hudson, in which the test are not only
> run automatically, but the "setup" (hijack host file) and "restore" of
> the test environment is also preferably done automatically.
>

JFTR ... we have a similar situation in TracRpc Plugin functional test
suite . In that case the 'black-box' target is tracd standalone
server, but any other software would be the same since it just
considers a process launched via subprocess . This is CI-ed using
Hudson. Ports are reserved by reading /proc filesystem (see ciutils
for further details ;o). Writing a proxy for testing is as simple as

{{{
#!python

class TC(TestCase) :
    def test_XXX(self):
        def wsgi_proxy(environ, start_response):
            # Record assertion targets
            # (i.e. to_assert is shared by two processes)
            to_assert = XXX
            # Return fake request
        from wsgiref.simple_server import make_server
        httpd = make_server(host, port, wsgi_proxy)
        httpd.handle_request()      # Time-out would be nice ...
        # Wait a little if necessary ... then move on
        self.assertXXX(to_assert)

}}}

What I'm trying to say is that I've seen people doing things like
these before and it's not as scary as it seems ... This is just a
sketch . I'm sure you'll can find better ways to do this , if you
choose this way .

;o)

> The best solution would be a high-level (HTTP-level) Python
> module/wrapper for 'pycap', which operates in 'packet' level.
>
[...]
>
> I cannot find anything which does what I've just describe. Please
> correct if I am wrong.
>

... but this way may be interesting as well , specially if proxy setup
of C app turns out to be complicated . But in a dedicated test slave
global proxy setup might help .

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list