Cookie Testing

What is Cookie?
Cookie is a temporary piece of information stored in a text file on user’s local drive by web server every time the computer is connected to the internet. This information is later used by web browser to retrieve information from that machine. Generally cookie contains personalized user data or information that is used to communicate between different web pages.

What is the use of Cookies?
Cookies are nothing but the user’s online identity and used to track where the user navigated throughout the web site pages.

For example if you are accessing domain http://www.testing.com/x.htm then web browser will simply query to testing.com web server for the page x.htm. Next time if you type page as http://www.testing.com/y.htm then new request is send to testing.com web server for sending 2.html page and web server doesn’t know anything about to whom the previous page x.htm served.

What if you want the previous history of this user communication with the web server? You need to maintain the user state and interaction between web browser and web server somewhere. This is where cookie comes into picture. Cookies serve the purpose of maintaining the user interactions with web server.

How cookies work?
The HTTP protocol used to exchange information files on the web is used to maintain the cookies. There are two types of HTTP protocol. Stateless HTTP and Stateful HTTP protocol. Stateless HTTP protocol does not keep any record of previously accessed web page history. While Stateful HTTP protocol does keep some record of previous web browser and web server interactions and this protocol is used by cookies to maintain the user interactions.

Whenever the user visits a webpage that is using cookie, a small code inside that HTML page writes a text file on users machine called cookie. Generally this is a call to some language script to write the cookie like cookies in Java Script, PHP, Perl.
Here is one example of the code that is used to write cookie and can be placed inside any HTML page:

Set-Cookie: NAME=; expires=; path=; domain=.

When a user visits the same page or domain later time this cookie is read from disk and used to identify the second and subsequent visits of the same user on that domain.

Generally two types of cookies are there:

1) Session cookies: This cookie is active till the browser that invoked the cookie is open. When we close the browser this session cookie gets deleted. Also there is a way to set the expiration time for this cookie.
2) Persistent cookies: These cookies are written permanently on user machine and lasts for months or years.

Where cookies are stored?
When any web page application writes cookie it get saved in a text file on user hard disk drive. The path where the cookies get stored varies for different browsers. E.g. Internet explorer store cookies on path “C:\Documents and Settings\Default User\Cookies”
Here the “Default User” can be replaced by the current user you logged in as. Like “Administrator”, or user name like “Sam” etc.
In Firefox browser to see the cookies that are stored: Open the Firefox browser, click on Tools->Options->Privacy and then “Show cookies” button.

How cookies are stored?
Lets take example of cookie written by say google.com on Mozilla Firefox browser:
On Mozilla Firefox browser when you open the page google.com, a cookie will get written on your hard disk. To view this cookie click on “Show cookies” button from Tools->Options->Privacy. Click on google.com site under this cookie list. You can see different cookies written by google.com domain with different names. Given below the description for one particular cookie named _utmz.

Name: _utmz (cookie name)
Content: 173272373.1215690934.1.1.utmccn=(direct)utmcsr=(direct)utmcmd=(none)
Domain: google.com
Path: /support/talk/
Send For: Any type of connection
Expires: Friday, January 09, 2009 5:25:34 AM

Applications where cookies can be used:

1) Shopping carts:
Cookies are used for maintaining online ordering system. Cookies remember what a user wants to buy. If the user adds some products in their shopping cart and if due to some reason the user doesn’t want to buy those products this time and closes the browser window, the next time the same user visits the purchase page he can see all the products he added in shopping cart in his last visit.

2) User sessions:
Cookies can track user sessions to particular domain using user ID and password.

3) Personalized sites:
When user visits certain pages they are asked which pages they don’t want to visit or display. User options are get stored in cookie and till the user is online, those pages are not shown to him.

4) User tracking:
To track number of unique visitors online at particular time.


Disadvantages of cookies:

1) Security issues:
Cookies can sometimes store user's personal information. If some hacker hacks these cookies, then the hacker can get access to the user's personal information. Even corrupted cookies can be read by different domains and can potentially lead to security issues.

2) Sensitive information:
Some sites may store user's sensitive information in cookies, which should not be allowed due to privacy concerns.



Test cases for cookie testing:

1) Check if your application is writing cookies properly on hard disk.

2) As a Cookie privacy policy make sure from your design documents that no personal or sensitive data is stored in the cookie.

3) If you have no option than saving sensitive data in cookie make sure data stored in cookie is stored in encrypted format so that others can not decrypt it.

4) Make sure that there is no overuse of cookies on your site under test. Overuse of cookies will annoy users if browser is prompting for cookies more often and this could result in loss of site traffic and eventually loss of business.

5) Disable the cookies from your browser settings: If you are using cookies on your site, your sites major functionality will not work by disabling the cookies. Then try to access the web site under test. Navigate through the site. See if appropriate messages are displayed to user like “For smooth functioning of this site make sure that cookies are enabled on your browser”. There should not be any page crash due to disabling the cookies. (Please make sure that you close all browsers, delete all previously written cookies before performing this test)

6) Accepts/Reject some cookies: The best way to check web site functionality is, not to accept all cookies. If you are writing 10 cookies in your web application then randomly accept some cookies say accept 5 and reject 5 cookies. For executing this test case you can set browser options to prompt whenever cookie is being written to disk. On this prompt window you can either accept or reject cookie. Try to access major functionality of web site. See if pages are getting crashed or data is getting corrupted.

7) Delete cookie: Allow site to write the cookies and then close all browsers and manually delete all cookies for web site under test. Access the web pages and check the behavior of the pages.

8) Corrupt the cookies: Corrupting cookie is easy. You know where cookies are stored. Manually edit the cookie in notepad and change the parameters to some vague values. Like alter the cookie content, Name of the cookie or expiry date of the cookie and see the site functionality. In some cases corrupted cookies allow to read the data inside it for any other domain. This should not happen in case of your web site cookies. Note that the cookies written by one domain say rediff.com can’t be accessed by other domain say yahoo.com unless and until the cookies are corrupted and someone trying to hack the cookie data.

9 ) Checking the deletion of cookies from your web application page: Some times cookie written by domain say rediff.com may be deleted by same domain but by different page under that domain. This is the general case if you are testing some ‘action tracking’ web portal. Action tracking or purchase tracking pixel is placed on the action web page and when any action or purchase occurs by user the cookie written on disk get deleted to avoid multiple action logging from same cookie. Check if reaching to your action or purchase page deletes the cookie properly and no more invalid actions or purchase get logged from same user.

10) Cookie Testing on Multiple browsers: This is the important case to check if your web application page is writing the cookies properly on different browsers as intended and site works properly using these cookies. You can test your web application on Major used browsers like Internet explorer (Various versions), Mozilla Firefox, Netscape, Opera etc.

11) If your web application is using cookies to maintain the logging state of any user then log in to your web application using some username and password. In many cases you can see the logged in user ID parameter directly in browser address bar. Change this parameter to different value say if previous user ID is 100 then make it 101 and press enter. The proper access message should be displayed to user and user should not be able to see other users account.

These are some of the main test cases for testing website cookies. More test scenarios can be derived from these by combining the above scenarios.