Merge ~blake-rouse/maas:fix-1850230 into maas:master

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: 39a66420d152500f8ea071c59010b610417110e2
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~blake-rouse/maas:fix-1850230
Merge into: maas:master
Diff against target: 43 lines (+10/-3)
2 files modified
src/maasserver/views/account.py (+5/-2)
src/maasserver/views/tests/test_account.py (+5/-1)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Review via email: mp+374842@code.launchpad.net

Commit message

Fix LP: #1850230 - Set login cookies on 204 return.

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/views/account.py b/src/maasserver/views/account.py
2index a1bca7a..c6da946 100644
3--- a/src/maasserver/views/account.py
4+++ b/src/maasserver/views/account.py
5@@ -50,9 +50,12 @@ class LoginJSONView(LoginView):
6 """A `LoginView` that conditionally returns JSON instead of a HTML view."""
7
8 def form_valid(self, form):
9+ resp = super().form_valid(form)
10 if wants_json_response(self.request):
11- return HttpResponse(status=204)
12- return super().form_valid(form)
13+ resp204 = HttpResponse(status=204)
14+ resp204.cookies = resp.cookies
15+ resp = resp204
16+ return resp
17
18 def form_invalid(self, form):
19 if wants_json_response(self.request):
20diff --git a/src/maasserver/views/tests/test_account.py b/src/maasserver/views/tests/test_account.py
21index 9ccfa5b..6aae2b6 100644
22--- a/src/maasserver/views/tests/test_account.py
23+++ b/src/maasserver/views/tests/test_account.py
24@@ -11,7 +11,7 @@ import http.client
25 from django.conf import settings
26 from django.contrib.auth import REDIRECT_FIELD_NAME, SESSION_KEY
27 from lxml.html import fromstring, tostring
28-from testtools.matchers import ContainsDict, Equals
29+from testtools.matchers import ContainsDict, Equals, MatchesSetwise
30
31 from maasserver.models.config import Config
32 from maasserver.models.event import Event
33@@ -121,6 +121,10 @@ class TestLogin(MAASServerTestCase):
34 HTTP_ACCEPT="application/json",
35 )
36 self.assertThat(response, HasStatusCode(http.client.NO_CONTENT))
37+ self.assertThat(
38+ response.cookies.keys(),
39+ MatchesSetwise(Equals("csrftoken"), Equals("sessionid")),
40+ )
41
42 def test_login_json_returns_400_on_bad_authentication(self):
43 password = factory.make_string()

Subscribers

People subscribed via source and target branches