ChannelsLiveServerTestCase session cookie creation error
See original GitHub issueMy functional tests use following code snippets to log user in:
def create_session_cookie(self, username, password):
# First, create a new test user
User = get_user_model()
user = User.objects.create_user(username=username, password=password)
# Then create the authenticated session using the new user credentials
session = SessionStore()
session[SESSION_KEY] = user.pk
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
session[HASH_SESSION_KEY] = user.get_session_auth_hash()
session.save()
# Finally, create the cookie dictionary
cookie = {
'name': settings.SESSION_COOKIE_NAME,
'value': session.session_key,
'secure': False,
'path': '/',
}
return cookie
def create_cookie_and_go_to_page(self, email):
session_cookie = self.create_session_cookie(
username=email, password='top_secret'
)
# visit some url in your domain to setup Selenium.
# (404 pages load the quickest)
self.browser.get(self.server_url + '/404.html')
# add the newly created session cookie to selenium webdriver.
self.browser.add_cookie(session_cookie)
# refresh to exchange cookies with the server.
self.browser.refresh()
# This time user should present as logged in.
self.browser.get(self.server_url)
and I use it as:
class DjangoTest(StaticLiveServerTestCase):
def test_django(self):
self.create_cookie_and_go_to_page('email@example.com')
Also I used to test my channels pages (installed with pip install git+git://github.com/django/channels.git@master#egg=channels
) like this:
class ChannelsTest(ChannelsLiveServerTestCase):
def test_channels(self):
self.create_cookie_and_go_to_page('email@example.com')
, but with ChannelsLiveServerTestCase
something has gone wrong in recent commits to master. It simply shows Bad Request (400) page after self.browser.get(self.server_url + '/404.html')
call. If I revert to channels==2.0.2 from PyPI then it goes well, but css and js are broken with that version. I tried to locate error on a specific commit or dependency version, but without success.
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (11 by maintainers)
Top Results From Across the Web
Error when loading cookies into a Python request session
You can create a session. The session class handles cookies between requests. s = requests.Session() ...
Read more >Session Cookie Error - Wiley Online Library
Question: Why am I receiving a Session Cookie Error? Answer: This error occurs when we are unable to send a cookie to your...
Read more >An invalid domain [.xxx.xxxxxl] was specified for this cookie
Exception occured during SESSION cookie creation. ... the SP side after IDP authentication, the browser gets error 500 and
Read more >IT20994: DATAPOWER DOES NOT SET A PROPER ... - IBM
In a failover scenario the HTTP client is left with a DPJSESSIONID cookie of the failed server even though requests now flow to...
Read more >Invalid session cookie - Oracle Communities
SessionBean or creating a new one with ... I did this to cope with invalid session cookie error that seemed to be because...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed it, it was
ALLOWED_HOSTS
not being set.Great job, thank you!