Mercurial > p > roundup > code
comparison test/test_cgi.py @ 5976:71c68961d9f4
- issue2550920 - Optionally detect duplicate username at registration.
Added config option to allow detection of duplicate username when the
user tries to register. Previously user was rejected when dupliate
name found at confirmation step.
Optional as it can make username guessing easier.
Testing is in place for this.
Also attempted to make the unfriendly error message:
'node with key "username" exists'
into a translatable friendly error:
"Username 'username' already exists."
This is missing any test. It is also fragile as I capture the
ValueError exception and see that the exception matches:
'node with key "username" exists'
If it does reassert the friendly message. Otherwise just re-raise
existing exception. If the "node with key..." message is translated
the friendly override will not trigger.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 09 Nov 2019 16:33:42 -0500 |
| parents | fe334430ca07 |
| children | fefdf5f97c50 |
comparison
equal
deleted
inserted
replaced
| 5975:59842a3e8108 | 5976:71c68961d9f4 |
|---|---|
| 13 | 13 |
| 14 import pytest | 14 import pytest |
| 15 | 15 |
| 16 from roundup.cgi import client, actions, exceptions | 16 from roundup.cgi import client, actions, exceptions |
| 17 from roundup.cgi.exceptions import FormError, NotFound, Redirect | 17 from roundup.cgi.exceptions import FormError, NotFound, Redirect |
| 18 from roundup.exceptions import UsageError | 18 from roundup.exceptions import UsageError, Reject |
| 19 from roundup.cgi.templating import HTMLItem, HTMLRequest, NoTemplate | 19 from roundup.cgi.templating import HTMLItem, HTMLRequest, NoTemplate |
| 20 from roundup.cgi.templating import HTMLProperty, _HTMLItem, anti_csrf_nonce | 20 from roundup.cgi.templating import HTMLProperty, _HTMLItem, anti_csrf_nonce |
| 21 from roundup.cgi.form_parser import FormParser | 21 from roundup.cgi.form_parser import FormParser |
| 22 from roundup import init, instance, password, hyperdb, date | 22 from roundup import init, instance, password, hyperdb, date |
| 23 from roundup.anypy.strings import StringIO, u2s, b2s | 23 from roundup.anypy.strings import StringIO, u2s, b2s |
| 1540 k = self.db.keyword.getnode('1') | 1540 k = self.db.keyword.getnode('1') |
| 1541 self.assertEqual(k.name, 'newkey1') | 1541 self.assertEqual(k.name, 'newkey1') |
| 1542 k = self.db.keyword.getnode('2') | 1542 k = self.db.keyword.getnode('2') |
| 1543 self.assertEqual(k.name, 'newkey2') | 1543 self.assertEqual(k.name, 'newkey2') |
| 1544 | 1544 |
| 1545 def testRegisterAction(self): | 1545 def testRegisterActionDelay(self): |
| 1546 from roundup.cgi.timestamp import pack_timestamp | 1546 from roundup.cgi.timestamp import pack_timestamp |
| 1547 | 1547 |
| 1548 # need to set SENDMAILDEBUG to prevent | 1548 # need to set SENDMAILDEBUG to prevent |
| 1549 # downstream issue when email is sent on successful | 1549 # downstream issue when email is sent on successful |
| 1550 # issue creation. Also delete the file afterwards | 1550 # issue creation. Also delete the file afterwards |
| 1605 # FIXME check that email output makes sense at some point | 1605 # FIXME check that email output makes sense at some point |
| 1606 | 1606 |
| 1607 # clean up from email log | 1607 # clean up from email log |
| 1608 if os.path.exists(SENDMAILDEBUG): | 1608 if os.path.exists(SENDMAILDEBUG): |
| 1609 os.remove(SENDMAILDEBUG) | 1609 os.remove(SENDMAILDEBUG) |
| 1610 | |
| 1611 def testRegisterActionUnusedUserCheck(self): | |
| 1612 # need to set SENDMAILDEBUG to prevent | |
| 1613 # downstream issue when email is sent on successful | |
| 1614 # issue creation. Also delete the file afterwards | |
| 1615 # just tomake sure that someother test looking for | |
| 1616 # SENDMAILDEBUG won't trip over ours. | |
| 1617 if 'SENDMAILDEBUG' not in os.environ: | |
| 1618 os.environ['SENDMAILDEBUG'] = 'mail-test1.log' | |
| 1619 SENDMAILDEBUG = os.environ['SENDMAILDEBUG'] | |
| 1620 | |
| 1621 nodeid = self.db.user.create(username='iexist', | |
| 1622 password=password.Password('foo')) | |
| 1623 | |
| 1624 # enable check and remove delay time | |
| 1625 self.db.config.WEB_REGISTRATION_PREVALIDATE_USERNAME = 1 | |
| 1626 self.db.config.WEB_REGISTRATION_DELAY = 0 | |
| 1627 | |
| 1628 # Make a request with existing user. Use iexist. | |
| 1629 # do not need opaqueregister as we have disabled the delay check | |
| 1630 cl = self._make_client({'username':'iexist', 'password':'secret', | |
| 1631 '@confirm@password':'secret', 'address':'iexist@bork.bork'}, | |
| 1632 nodeid=None, userid='2') | |
| 1633 with self.assertRaises(Reject) as cm: | |
| 1634 actions.RegisterAction(cl).handle() | |
| 1635 self.assertEqual(cm.exception.args, | |
| 1636 ("Username 'iexist' is already used.",)) | |
| 1637 | |
| 1638 cl = self._make_client({'username':'i-do@not.exist', | |
| 1639 'password':'secret', | |
| 1640 '@confirm@password':'secret', 'address':'iexist@bork.bork'}, | |
| 1641 nodeid=None, userid='2') | |
| 1642 self.assertRaises(Redirect, actions.RegisterAction(cl).handle) | |
| 1643 | |
| 1610 | 1644 |
| 1611 def testserve_static_files(self): | 1645 def testserve_static_files(self): |
| 1612 # make a client instance | 1646 # make a client instance |
| 1613 cl = self._make_client({}) | 1647 cl = self._make_client({}) |
| 1614 | 1648 |
