Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
e9135914
Commit
e9135914
authored
9 years ago
by
Alice Heaton
Browse files
Options
Downloads
Plain Diff
Merge branch 'csrf-fix' into develop
parents
361154d5
94ad296d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
django/website/hid/tests/login_tests.py
+37
-0
37 additions, 0 deletions
django/website/hid/tests/login_tests.py
django/website/hid/views.py
+11
-0
11 additions, 0 deletions
django/website/hid/views.py
django/website/settings.py
+1
-0
1 addition, 0 deletions
django/website/settings.py
with
49 additions
and
0 deletions
django/website/hid/tests/login_tests.py
0 → 100644
+
37
−
0
View file @
e9135914
from
__future__
import
unicode_literals
,
absolute_import
import
pytest
from
django.core.urlresolvers
import
reverse
from
django.test
import
Client
from
django.utils.six.moves.urllib.parse
import
urlsplit
from
users.models
import
User
@pytest.mark.django_db
def
test_user_directed_to_login_page_when_csrf_error
():
username
=
'
william
'
password
=
'
passw0rd
'
User
.
objects
.
create_user
(
username
,
'
william@example.com
'
,
password
)
client
=
Client
(
enforce_csrf_checks
=
True
)
data
=
{
'
username
'
:
username
,
'
password
'
:
password
,
'
csrfmiddlewaretoken
'
:
'
notavalidtoken
'
}
response
=
client
.
post
(
reverse
(
'
login
'
),
data
=
data
,
follow
=
True
)
assert
hasattr
(
response
,
'
redirect_chain
'
)
assert
len
(
response
.
redirect_chain
)
>
0
,
"
Response didn
'
t redirect
"
assert
response
.
redirect_chain
[
0
][
1
]
==
302
url
,
_
=
response
.
redirect_chain
[
-
1
]
scheme
,
netloc
,
path
,
query
,
fragment
=
urlsplit
(
url
)
assert
path
==
reverse
(
'
login
'
)
url
,
_
=
response
.
redirect_chain
[
-
2
]
scheme
,
netloc
,
path
,
query
,
fragment
=
urlsplit
(
url
)
assert
path
==
reverse
(
'
dashboard
'
)
assert
response
.
status_code
==
200
This diff is collapsed.
Click to expand it.
django/website/hid/views.py
+
11
−
0
View file @
e9135914
from
django.contrib
import
messages
from
django.contrib.auth.views
import
login
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponseRedirect
from
django.utils.translation
import
ugettext
as
_
...
...
@@ -220,3 +221,13 @@ def process_items(request):
messages
.
error
(
request
,
_
(
'
Unknown action
'
))
return
HttpResponseRedirect
(
redirect_url
)
def
csrf_failure
(
request
,
reason
=
''
):
# If the user presses the back button in the browser to go back to the
# login page and logs in again, they will get a CSRF error page because
# the token will be wrong.
# We override this with a redirect to the dashboard, which if not already
# logged in, will redirect to the login page (with a fresh token).
return
HttpResponseRedirect
(
reverse
(
'
dashboard
'
))
This diff is collapsed.
Click to expand it.
django/website/settings.py
+
1
−
0
View file @
e9135914
...
...
@@ -390,5 +390,6 @@ else:
)
########## END TEMPLATE CONFIGURATION
CSRF_FAILURE_VIEW
=
'
hid.views.csrf_failure
'
########## Your stuff: Below this line define 3rd party libary settings
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment