Funkload and cookies

1.3k Views Asked by At

I have trouble setting up funkload to work well with cookies. I turn on fl-record and perform a series of requests of which each is sending a cookie. If I use the command without supplying a folder path, the output is stored in TCPWatch-Proxy format and I can see the contents of all the cookies, so I know that they are sent.

For example this is the contents of watch0003.request:

GET http://mydomainnamehere.pl/api/world/me/ HTTP/1.1
Host: mydomainnamehere.pl
Proxy-Connection: keep-alive
Referer: http://mydomainnamehere.pl/test/engine/
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pl,en-US;q=0.8,en;q=0.6,fr-FR;q=0.4,fr;q=0.2
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: Beacon-ClientID=<<<some-beaconpush-id-here>>>; sessionid=<<<some-session-id>>>; fbs_<<<some-facebook-id>>>="access_token=<<<some-access-token>>>&expires=1308254400&secret=<<<some-secret>>>&session_key=<<<some-session-key>>>&sig=<<<some-signature>>>&uid=<<<some-user-id>>>"; Beacon-Preferred-Client=WebSocket

However if I run fl-record with a name of the test case and by doing so order funkload to store the output as a python test, all the Cookies are omitted. There isn't a single line in the code that would have anything to do with them:

import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase
from webunit.utility import Upload
from funkload.utils import Data
#from funkload.utils import xmlrpc_get_credential

class Simple(FunkLoadTestCase):

    def setUp(self):
        """Setting up test."""
        self.logd("setUp")
        self.server_url = self.conf_get('main', 'url')
        # XXX here you can setup the credential access like this
        # credential_host = self.conf_get('credential', 'host')
        # credential_port = self.conf_getInt('credential', 'port')
        # self.login, self.password = xmlrpc_get_credential(credential_host,
        #                                                   credential_port,
        # XXX replace with a valid group
        #                                                   'members')

    def test_simple(self):
        # The description should be set in the configuration file
        server_url = self.server_url
        # begin of test ---------------------------------------------

        ...

        # /tmp/tmp5Nv5lW_funkload/watch0003.request
        self.get(server_url + "/api/world/me/",
                 description="Get /api/world/me/")

        ...

        # end of test -----------------------------------------------

    def tearDown(self):
        """Setting up test."""
        self.logd("tearDown.\n")

if __name__ in ('main', '__main__'):
    unittest.main()

There is also a configuration file, but nothing about cookies there either.

On the other hand the documentation states that fl has (Cookie support). I've also found some bugfixes in the previous releases concerning Cookie support so I can assume this isn't just an empty statement. I've also found a point in one of the changelogs that states that "deleted cookies" are not included in the output. This got me wondering that maybe the problem is that the cookies as they were recorded are marked for deletion or are recognized as such by fl upon conversion from the TCP-Watch format to an actual testcase. This is just a wild guess however.

I'd like to know:

  • If you ever had successes with support of funkload for cookies. If so, which version were you using.
  • Of your general experiences with funkload and whether or not it is worth using in a more complex setup.

EDIT

Apparently some of the requests that are recorded by TCPWatch are totally ignored and not included in the output test case. Anybody has idea why would it do that? Does it have anything to do with redirection?

EDIT(2)

Ok, it does. This one thing actually makes sense. It leaves out the results of redirection as these will be generated by simply following HTTP 302 Found. However the question of cookies still remains unexplained.

2

There are 2 best solutions below

2
On

I've found a bug in Funkload. Funkload isn't handling correctly the cookies with a leading '.' in the domain. At the moment all that cookies are being silently ignored.

Check this branch: https://github.com/sbook/FunkLoad

I've already send a pull request: https://github.com/nuxeo/FunkLoad/pull/32

0
On

I see this old post not answered, so I thought I could post:

In Python: Identify the name of cookie you are sending. mine is 'csrftoken' in header and same one in post as 'csrfmiddlewaretoken'> intially I get the value of cookie then pass the same in post for authentication. Example:

    res = self.get ( server_url + '/login/', description = 'Get url' ).cookies.itervalues ( ).next ( )
    morsel_str = res [ '/' ] [ 'csrftoken' ]
    csrftoken = morsel_str.value
    # Once Cookie found include it in params
    params = [
        [ 'csrfmiddlewaretoken', csrftoken ],
        [ 'username', 'username..' ],
        [ 'password', '********' ] ]
    self.setHeader ( 'cookie', 'csrftoken={0}'.format ( csrftoken ) )
    resp = self.post ( server_url + '/login/', params, description = "Post /login/" )