Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Remove misguided throttling attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Feb 28, 2017
1 parent 012ce92 commit 271607d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 46 deletions.
3 changes: 0 additions & 3 deletions defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ TEAM_REVIEW_REPO=gratipay/test-gremlin
TEAM_REVIEW_USERNAME=
TEAM_REVIEW_TOKEN=

# anything Postgres can interpret as an interval
RESEND_VERIFICATION_THRESHOLD="3 minutes"

RAISE_SIGNIN_NOTIFICATIONS=no

# speeds up npm syncing; should be true on production and Travis
Expand Down
3 changes: 0 additions & 3 deletions gratipay/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class EmailNotVerified(ProblemChangingEmail):
class TooManyEmailAddresses(ProblemChangingEmail):
msg = "You've reached the maximum number of email addresses we allow."

class ResendingTooFast(ProblemChangingEmail):
msg = "Sorry, please try resending the verification email again in a minute or two."


class ProblemChangingNumber(Exception):
def __str__(self):
Expand Down
16 changes: 2 additions & 14 deletions gratipay/models/participant/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import gratipay
from gratipay.exceptions import EmailAlreadyVerified, EmailTaken, CannotRemovePrimaryEmail
from gratipay.exceptions import EmailNotVerified, TooManyEmailAddresses, ResendingTooFast
from gratipay.exceptions import EmailNotVerified, TooManyEmailAddresses
from gratipay.security.crypto import constant_time_compare
from gratipay.utils import encode_for_querystring

Expand Down Expand Up @@ -41,25 +41,20 @@ class Email(object):
"""

def add_email(self, email, resend_threshold='3 minutes'):
def add_email(self, email):
"""Add an email address for a participant.
This is called when adding a new email address, and when resending the
verification email for an unverified email address.
:param unicode email: the email address to add
:param unicode resend_threshold: the time interval within which a
previous call to this function will cause the current call to fail
with ``ResendingTooFast``
:returns: ``None``
:raises EmailAlreadyVerified: if the email is already verified for
this participant
:raises EmailTaken: if the email is verified for a different participant
:raises TooManyEmailAddresses: if the participant already has 10 emails
:raises ResendingTooFast: if the participant has added an email within the
time limit specified by ``resend_threshold``
"""

Expand All @@ -83,13 +78,6 @@ def add_email(self, email, resend_threshold='3 minutes'):
nonce = str(uuid.uuid4())
verification_start = utcnow()

nrecent = self.db.one( "SELECT count(*) FROM emails WHERE address=%s AND "
"%s - verification_start < %s"
, (email, verification_start, resend_threshold)
)
if nrecent:
raise ResendingTooFast()

try:
with self.db.get_cursor() as c:
self.app.add_event(c, 'participant', dict(id=self.id, action='add', values=dict(email=email)))
Expand Down
1 change: 0 additions & 1 deletion gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ def env():
TEAM_REVIEW_USERNAME = unicode,
TEAM_REVIEW_TOKEN = unicode,
RAISE_SIGNIN_NOTIFICATIONS = is_yesish,
RESEND_VERIFICATION_THRESHOLD = unicode,
REQUIRE_YAJL = is_yesish,
GUNICORN_OPTS = unicode,
)
Expand Down
25 changes: 4 additions & 21 deletions tests/py/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

import json
import sys
import time

from gratipay.exceptions import CannotRemovePrimaryEmail, EmailTaken, EmailNotVerified
from gratipay.exceptions import TooManyEmailAddresses, ResendingTooFast
from gratipay.exceptions import TooManyEmailAddresses
from gratipay.testing import P
from gratipay.testing.email import QueuedEmailHarness, SentEmailHarness
from gratipay.models.participant import email as _email
from gratipay.utils import encode_for_querystring
from gratipay.cli import queue_branch_email as _queue_branch_email


class AliceAndResend(QueuedEmailHarness):
class Alice(QueuedEmailHarness):

def setUp(self):
QueuedEmailHarness.setUp(self)
self.alice = self.make_participant('alice', claimed_time='now')
self._old_threshold = self.client.website.env.resend_verification_threshold
self.client.website.env.resend_verification_threshold = '0 seconds'

def tearDown(self):
self.client.website.env.resend_verification_threshold = self._old_threshold


class TestEndpoints(AliceAndResend):
class TestEndpoints(Alice):

def hit_email_spt(self, action, address, user='alice', should_fail=False):
f = self.client.PxST if should_fail else self.client.POST
Expand Down Expand Up @@ -210,7 +204,7 @@ def test_remove_email(self):
self.hit_email_spt('remove', '[email protected]')


class TestFunctions(AliceAndResend):
class TestFunctions(Alice):

def test_cannot_update_email_to_already_verified(self):
bob = self.make_participant('bob', claimed_time='now')
Expand Down Expand Up @@ -241,17 +235,6 @@ def test_cannot_add_too_many_emails(self):
with self.assertRaises(TooManyEmailAddresses):
self.alice.add_email('[email protected]')

def test_cannot_resend_verification_too_frequently(self):
self.alice.add_email('[email protected]')
time.sleep(0.05)
with self.assertRaises(ResendingTooFast):
self.alice.add_email('[email protected]', '0.1 seconds')

def test_can_resend_verification_after_a_while(self):
self.alice.add_email('[email protected]')
time.sleep(0.15)
self.alice.add_email('[email protected]', '0.1 seconds')

def test_html_escaping(self):
self.alice.add_email("foo'[email protected]")
last_email = self.get_last_email()
Expand Down
6 changes: 3 additions & 3 deletions tests/py/test_take_over.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def test_email_addresses_merging(self):
alice.verify_email('[email protected]', alice.get_email('[email protected]').nonce)
bob_github = self.make_elsewhere('github', 2, 'bob')
bob = bob_github.opt_in('bob')[0].participant
bob.add_email('[email protected]', '0 seconds')
bob.add_email('[email protected]')
bob.verify_email('[email protected]', bob.get_email('[email protected]').nonce)
bob.add_email('[email protected]', '0 seconds')
bob.add_email('[email protected]', '0 seconds')
bob.add_email('[email protected]')
bob.add_email('[email protected]')
alice.take_over(bob_github, have_confirmation=True)

alice_emails = {e.address: e for e in alice.get_emails()}
Expand Down
2 changes: 1 addition & 1 deletion www/~/%username/emails/modify.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if not participant.email_lang:
msg = None
if action in ('add-email', 'resend'):
try:
participant.add_email(address, website.env.resend_verification_threshold)
participant.add_email(address)
except EmailTaken:
raise Response(400, _( "{email_address} is already linked to a different Gratipay account."
, email_address=address
Expand Down

0 comments on commit 271607d

Please sign in to comment.