Skip to content

Commit ef3f007

Browse files
committed
Change microcopy for missing csrf to follow mismatched csrf. Fix tests.
1 parent 4ed123a commit ef3f007

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

roundup/cgi/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ def handle_csrf(self, xmlrpc=False):
12521252
if key is None: # we do not have an @csrf token
12531253
if enforce == 'required':
12541254
logger.error(self._("Required csrf field missing for user%s"), current_user)
1255-
raise UsageError(self._("Csrf token is missing."))
1255+
raise UsageError(self._("We can't validate your session (csrf failure). Re-enter any unsaved data and try again."))
12561256
elif enforce == 'logfailure':
12571257
# FIXME include url
12581258
logger.warning(self._("csrf field not supplied by user%s"), current_user)

test/test_cgi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
958958
# roundup will report a missing token.
959959
cl.db.config['WEB_CSRF_ENFORCE_TOKEN'] = 'required'
960960
cl.inner_main()
961-
match_at=out[0].find('<p>Csrf token is missing.</p>')
961+
match_at=out[0].find("<p>We can't validate your session (csrf failure). Re-enter any unsaved data and try again.</p>")
962962
print("result of subtest 6a:", out[0], match_at)
963963
self.assertEqual(match_at, 33)
964964
del(out[0])
@@ -971,7 +971,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
971971
cl.form = db_test_base.makeForm(form2)
972972

973973
cl.inner_main()
974-
match_at=out[0].find('Invalid csrf token found: booogus')
974+
match_at=out[0].find("We can't validate your session (csrf failure). Re-enter any unsaved data and try again.")
975975
print("result of subtest 7:", out[0])
976976
self.assertEqual(match_at, 36)
977977
del(out[0])
@@ -999,7 +999,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
999999
# try a replay attack
10001000
cl.inner_main()
10011001
# This should fail as token was wiped by last run.
1002-
match_at=out[0].find('Invalid csrf token found: %s'%nonce)
1002+
match_at=out[0].find("We can't validate your session (csrf failure). Re-enter any unsaved data and try again.")
10031003
print("replay of csrf after post use", out[0])
10041004
print("result of subtest 10:", out[0])
10051005
self.assertEqual(match_at, 36)
@@ -1030,7 +1030,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
10301030
cl.env.update({'REQUEST_METHOD': 'POST'})
10311031
print(cl.env)
10321032
cl.inner_main()
1033-
match_at=out[0].find('Invalid csrf token found: %s'%nonce)
1033+
match_at=out[0].find("We can't validate your session (csrf failure). Re-enter any unsaved data and try again.")
10341034
print("post failure after get", out[0])
10351035
print("result of subtest 13:", out[0])
10361036
self.assertEqual(match_at, 36)

0 commit comments

Comments
 (0)