angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Clear cookies before every test begins

Open esprehn opened this issue 15 years ago • 10 comments

before each it() (and associated beforeEach etc.) we should clear the cookies. We cannot clear the cookies on every navigateTo() otherwise you couldn't navigateTo() inside a test to check if there's persistent state that works in your app.

esprehn avatar Dec 15 '10 01:12 esprehn

this behavior, while correct, should be documented so that it's not a surprise to users.

IgorMinar avatar Jan 08 '11 23:01 IgorMinar

Is there any way to clear the cookies manually? As far as I can tell, cookies are not cleared, making it difficult to test sessions.

dbrunner avatar Jan 27 '12 07:01 dbrunner

Something like this should work: http://pastie.org/3261820

You might have better luck requesting a URL from the server in beforeEach() that responds with cookie headers. That's also better since HttpOnly cookies can never be reset from JS, and your session cookies should really be HttpOnly for security reasons.

ex.

beforeEach(function() {
  browser().navigateTo('/newsession');
});

Where that page responds with a blank document but with Set-Cookie headers that cause your session cookies to expire (or just send new ones).

esprehn avatar Jan 27 '12 08:01 esprehn

Elliott, thank you very much for this insightful advice! We will take the approach you recommend.

Regards,

David

On Fri, Jan 27, 2012 at 12:03 AM, Elliott Sprehn < [email protected]

wrote:

Something like this should work: http://pastie.org/3261820

You might have better luck requesting a URL from the server in beforeEach() that responds with cookie headers. That's also better since HttpOnly cookies can never be reset from JS, and your session cookies should really be HttpOnly for security reasons.

ex.

beforeEach(function() { browser().navigateTo('/newsession'); });

Where that page responds with a blank document but with Set-Cookie headers that cause your session cookies to expire (or just send new ones).


Reply to this email directly or view it on GitHub: https://github.com/angular/angular.js/issues/195#issuecomment-3683321

dbrunner avatar Jan 27 '12 20:01 dbrunner

In http://pastie.org/3261820

instead of this:

var injector = $window.angular.injector(['ng']);

you should do:

var injector = $window.angular.element($window.document.body).inheritedData('$injector');

It's bit weird, I know :-D You don't want to create new injector, instead you want to get hold of current injector, which is assigned to jq data ('$injector'), so you need to wrap the element by jq from within the iframe ($document is iframe's document, but wrapped by jq in the main frame).

vojtajina avatar Jan 27 '12 22:01 vojtajina

Thank you very much for your advice and clarifications. This is very interesting. I can understand the need for these gymnastics given that I'm trying to do something I shouldn't (actually, I will use the navigateTo approach you suggested), but are there ever good reasons for needing to do this? If so, it seems like a cleaner approach might be desirable!

Regards,

David

On Fri, Jan 27, 2012 at 2:26 PM, Vojta Jina < [email protected]

wrote:

In http://pastie.org/3261820

instead of this:

var injector = $window.angular.injector(['ng']);

you should do:

var injector = $window.angular.element($window.document.body).inheritedData('$injector');

It's bit weird, I know :-D You don't want to create new injector, instead you want to get hold of current injector, which is assigned to jq data ('$injector'), so you need to wrap the element by jq from within the iframe ($document is iframe's document, but wrapped by jq in the main frame).


Reply to this email directly or view it on GitHub: https://github.com/angular/angular.js/issues/195#issuecomment-3695318

dbrunner avatar Jan 28 '12 01:01 dbrunner

You need gymnastic, because you are actually getting into a running app in the iframe :-D

We should provide some helpers (dsl) for getting hold of some basic stuff like $injector, I think that's a valid requirement.

vojtajina avatar Jan 28 '12 01:01 vojtajina

Cool... Makes sense to me!

On Jan 27, 2012, at 5:48 PM, Vojta [email protected] wrote:

You need gymnastic, because you are actually getting into a running app in the iframe :-D

We should provide some helpers (dsl) for getting hold of some basic stuff like $injector, I think that's a valid requirement.


Reply to this email directly or view it on GitHub: https://github.com/angular/angular.js/issues/195#issuecomment-3697392

dbrunner avatar Jan 28 '12 01:01 dbrunner

Thanks guys =D

juniorconte avatar Jul 10 '13 12:07 juniorconte

too old. likely resolved or we don't care any more. closing. please reopen if you still care.

we are migrating to use Protractor which gives you full control over the browser so flushing cookies is much easier.

IgorMinar avatar Aug 24 '13 07:08 IgorMinar