Test closing and reopening the browser with jasmine? - jasmine

In some cases I have locally set session cookies that are supposed to vanish when the browser is closed and reopened, and in other cases I have persistent cookies.
These cookies are set dynamically according to application logic. I'd like write to tests for them, but that requires the ability to automate closing and reopening the browser.
To clarify, the test needs to
invoke the code that sets the cookies
close and reopen browser
verify assertions about whether the cookies are still set or not
report the results.
How can I do this with Jasmine?

Related

How do I allow secure http(not s) cookies with Cypress and Firefox?

I have a simple Cypress test that tests login. The page it is logging into is running on port 80 as http for testing. Because of this the cookies are not set to secure. When I try running the test I get....
Cookie “token” has been rejected because a non-HTTPS cookie can’t be set as “secure”.
If I run in a regular private Firefox window this does not happen. Is there a Cypress config setting I need or something?
If I convert to secure = false cookie it works. However, the secure cookie via http doesn't block it on a regular private FF browser.
Cypress has an open issue for Firefox not recognizing localhost as a secure context.
For the time being, I recommend testing in another browser. Alternatively, you could not set the secure flag on the cookie when working locally, but a number of recent web technologies depend on secure contexts (e.g., service workers), so you could encounter the same underlying issue while testing other parts of your site.

Automated script logs out using JMeter

I am trying to automate testing of a web application.
I have recorded the test using JMeter proxy template (JMeter version is 3.2) and couple of times when I ran the test in the JMeter it ran properly but after sometime only some part runs properly.
Following are the steps I am doing:
Hitting the URL
Logging into the application
changing some feature in the application
and so on.
All the steps ran perfectly first few times but then after that only till login everything runs properly.
Just to be sure I tried passing the jsessionid from the first request to the next requests using the Regular "Expression Extractor". I can see in the View Results Tree that jsessionid is passed properly but next page after the step two still takes me into the login screen.
Any help will be very much appreciated.
I have attached screenshot for better understanding:
The response header of logged in page includes a sessionid which is used by another request while logging in.
All the sessionID are properly maintained still after logging in the next page takes me to the login page instead displaying what was done next in the recording.
When it comes to load testing of JSF-based web applications you need to take care at least of the following dynamic parameters:
JSESSIONID
javax.faces.Viewstate
JSESSIONID is a normal HTTP cookie so it is quite enough to add a HTTP Cookie Manager to deal with it
javax.faces.Viewstate is client state management mechanism which also acts as a security token to verify user's origin. So you will need to properly correlate it, i.e. extract from previous response using one of JMeter PostProcessors, store into a JMeter Variable and add as a parameter to the next request. Remember to do this for each and every request.
There might be more application specific dynamic parameters, the easiest way of detecting them is recording the same request (or scenario) 2 times, compare the recorded scripts, detect and work around the differences.

Opera does not delete session cookie when browser close

I perform following javascript code in Opera javascript console
document.cookie='test=abc'
then I close all tabs one by one and then I close the browser.
After that when I open browser again cookie value test=abc is still in document.cookie variable.
I tried to reseach the problem and found this on official opera website http://help.opera.com/Windows/9.50/en/cookies.html:
If no expiration date is assigned to it, a cookie expires at the end of the session, when you exit the browser. A cookie that expires at end of session is called a session cookie.
It means that Opera should follow standart behavior with session cookies, but it doesn't.
Also I found this Firefox session cookies:
Firefox has a feature where you close Firefox and it offers to save all your tabs, and then you restore the browser and those tabs come back. That's called session restore. What I didn't realize is that it'll also restore all the session cookies for those pages too! It treats it like you had never closed the browser.
So, just in case, before closing the browser (Opera in my case) I closed all tabs one by one. But it didn't help too. Session cookie wasn't deleted.
Opera version: 17.0.1241.53;
Operation system: Windows 7 32-bit
The only thing that works is the manual block list, the manual clear on exit doesnt work either. Ofc the block all works, but that also shuts down the internet. You can also use extensions like privacy badger to control suspect cookies, but then again how secure are the extensions? Dont get me started on that. I am not paranoid, you however should be..

Session Management in Tomcat

I have developed a simple web-app with 2 servlets A and B.
I have a few doubts related to session management for the web-app by Tomcat.
NOTE - I have disabled cookies in my web-browser (Chrome) while accessing the web-app.
1.) When the web-app is first hit, Servlet A gets invoked. Servlet A accesses the session from the request and does a simple sysout of the session hashcode. It then does a sendRedirect to servlet B.
[According to my understanding, since this is the first request, Tomcat will send a cookie containing the new session ID back to the browser. However, since we have not "encoded" the redirect URL using HttpResponse.encodeRedirectURL(), the redirect URL will not contain the session ID appended to it. Please correct me if I am wrong here.]
2.) Since cookies are disabled in my browser, it'll ignore the session ID sent back in the cookie and issue a new request to the redirect URL (which also does not have the session ID appended to it).
3.) The new request causes servlet B to be invoked, whoch also accesses the request session and does a sysout of the session hashcode.
What perplexes me is that both Servlets A and B output the same session hashcode, which means that they get the same session from both requests.
How does the second request from the browser map to the same session as before, even though no session ID has been sent ?
Thanks !
There are only 2 ways to pass sessions between requests: Cookie and URL rewrite. If you don't see the session ID in the URL, it must be cookies.
Are you sure the cookie is disabled? It should be easy to see from a HTTP header trace.
Are you certain you've disabled "in memory" cookies? Often browsers will let you disable persistent cookies which are saved to disk, but they'll still allow the transient in memory cookies which only stay resident during a browser session.
I recommend Wireshark for analyzing the HTTP stream. That way you can see the cookies that are sent and received by your browser.
This is strange.
When I tested the application yesterday, it was exhibiting a behaviour similar to what I have described. However, as I test the application now, it behaves perfectly, as I expect it to.
The cause could probably be that I did not restart my browser session after disabling cookies.
Will let you guys know if I experience the same behaviour again.
Thanks for your time guys !

Can you reliably set or delete a cookie during the server side processing of an Ajax (XHR) call?

I have done a bit of testing on this myself (During the server side processing of a DWR Framework Ajax request handler to be exact) and it seems you CAN successfully manipulate cookies, but this goes against much that I have read on Ajax best practices and how browsers interpret the response from an XmlHttpRequest. Note I have tested on:
IE 6 and 7
Firefox 2 and 3
Safari
and in all cases standard cookie operations on the HttpServletResponse object during Ajax request handling were correctly interpreted by the browser, but I would like to know if it best practice to push the cookie manipulation to the client side, or if this (much cleaner) server side cookie handling can be trusted.
I would welcome answers both specific to the DWR Framework and Ajax in general.
XMLHttpRequest always uses the Web Browser's connection framework. This is a requirement for AJAX programs to work correctly as the user would get logged out if the XHR object lacked access to the browser's cookie pool.
It's theoretically possible for a web browser to simply share session cookies without using the browser's connection framework, but this has never (to my knowledge) happened in practice. Even the Flash plugin uses the Web Browser's connections.
Thus the end result is that it IS safe to manipulate cookies via AJAX. Just keep in mind that the AJAX call might never happen. They are not guaranteed events, so don't count on them.
In the context of DWR it may not be "safe".
From reading the DWR site it says:
It is important that you treat the HTTP request and response as read-only. While HTTP headers might get through OK, there is a good chance that some browsers will ignore them.
I've taken this to mean that setting cookies or request attributes is a no-no.
Saying that, I have code which does set request attributes (code I wrote before I read that page) and it appears to work fine (apart from deleting cookies which I mentioned in my comment above).
Manipulating cookies on the client side is rather the opposite of "best practice". And it shouldn't be necessary, either. HttpOnly cookies weren't introduced for nothing.

Resources