Forum Discussion

bob_ingalls's avatar
bob_ingalls
New Contributor
16 years ago

How do I set assertion for Set-Cookie in the response header

I need to create an assertion to check that a value exists in the Set-Cookie of the response header. 

HTTP/1.1 200 OK
Date: Thu, 11 Sep 2008 15:34:32 GMT
Transfer-Encoding: chunked
P3P: Custom Header Value: policyref="<>", CP="NOI ADM DEV PSAi OUR STP IND DEM"
Set-Cookie: MyName=MyValue;


I want to set an assert to verify "MyValue" is set correctly.  How do I do that?

6 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    please try creating a script assertion with the following content:

    assert messageExchange.responseHeaders["Set-Cookie"].equals( "MyName=MyValue;" )

    regards!

    /Ole
    eviware.com
  • Thanks, Ole.  Works great except that I want to check for a variable within the cookie.  For example, "MyValue=somedata${Property#propertyName}somemoredata"

    In other words, each each time I run this the cookie value changes dependent on a property I send to the request.

    Is that possible?
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    Try the following:

    def value = messageExchange.responseHeaders["Set-Cookie"]
    assert( value.equals( context.expand( 'MyValue=somedata${Property#propertyName}somemoredata' ))

    regards!

    /Ole
    eviware.com
  • Thanks Ole. 

    Is it possible to add a wild card to this?  For example, there is a date string (the cookie expires on...).  I don't really care what the date is so it's OK to just replace it with a wildcard.

    So the whole cookie looks like this:

    MATCH=%7B%22mmUser%22%3A%22mmuser${Properties#number}%22%2C%22mmOpenId%22%3A%22OpenID${Properties#number}%22%7D; Domain=.xxx.net; Expires=Sun, 15-Mar-2009 14:02:46 GMT; Path=/

    And I want to search for:
    MATCH=%7B%22mmUser%22%3A%22mmuser${Properties#number}%22%2C%22mmOpenId%22%3A%22OpenID${Properties#number}%22%7D; Domain=.xxx.net; Expires=*
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    well, easiest is maybe to just trim the Set-Cookie string after the expires value;


    def value = messageExchange.responseHeaders["Set-Cookie"]
    value = value.substring( 0, value.indexOf( "; Expires=" ))
    ...

    (this will of course also remove the "; Expires=" part of the header..)

    would that work?

    regards,

    /Ole
    eviware.com