svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

Multiple set-cookie failed using extract_binds #203

Open ap1459777123 opened 8 years ago

ap1459777123 commented 8 years ago

Hi, I've written a test to check my app's login function.

- test:
    - name: 'login user'
    - url: {template: '/$version/user/session'}
    - method: 'POST'
    - body: {template: '{"email": "$email", "pwd": "$pwd", "remember": "true"}'}
    - headers: {
        'Content-Type': 'application/json'}
    - expected_status: [201]
    - extract_binds:
        - 'cookie': { header: 'set-cookie'}

- test:
    - name: 'Check login status after login'
    - url: {template: '/$version/user/session'}
    - headers: {template: {'Cookie': '$cookie'}}
    - expected_status: [200]
    - validators:
        - compare: {
            jsonpath_mini: 'user',
            comparator: 'eq',
            expected: {template: '$username'}}

When adding remember: true in first req's body, there would be two Set-cookie in the resp, session and remember_token. And the $cookie variable would be set to list ['remember_token=somestring; Path=/', 'session=anotherstring; HttpOnly; Path=/'].

After appending $cookie back to req's header in test 2 (check login), the verbose req's header (using --verbose --log=DEBUG --interactive=True to run pyresttest) would be: Cookie:['remember_token=somestring; Path=/', 'session=anotherstring; HttpOnly; Path=/']

Yet server only got: 'cookies': {'HttpOnly; Path': u"/']", "['remember_token": u'somestring'} in req header's cookie part.

If I remove remember: true in first req's body, there would be only one Set-cookie in the resp. And everything goes normal. Server would got: 'cookies': {'HttpOnly; Path': u'/', 'session': u'anotherstring'} still seems weird.

Therefore I think if there are cookie parse errors when using extract_binds.

PKiman commented 4 years ago

I have the same problem and the syntax to extract multiple cookies doesn't make sense:

  - extract_binds: 
    - 'c1': { header: 'set-cookie'}
    - 'c2': { header: 'set-cookie'} 
    - 'c3': { header: 'set-cookie'} 
    - 'jwt': { header: 'set-cookie'} 

The variables will never know which cookie variable corresponds to which cookie value