Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix #336: usernames with dot rejected by api. #362

Merged
merged 5 commits into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include LICENSE.txt
include pykeg/setup.cfg
recursive-include pykeg *.html *.css *.js *.png
recursive-include deploy *
recursive-include pykeg/testdata *
4 changes: 4 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
machine:
services:
- mysql
- redis
2 changes: 1 addition & 1 deletion deploy/travis/local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'USER': 'root',
'PASSWORD': '',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB'}}}
'init_command': 'SET default_storage_engine=INNODB'}}}

KEGBOT_ROOT = HOME + '/kegbot-data'

Expand Down
3 changes: 3 additions & 0 deletions pykeg/core/kb_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@

# Low volume threshold: 15% full
KEG_VOLUME_LOW_PERCENT = 0.15

# Valid usernames.
USERNAME_REGEX = '^[\w.@+-]+$'
2 changes: 1 addition & 1 deletion pykeg/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class User(AbstractBaseUser):
'@/./+/-/_ characters'),
validators=[
validators.RegexValidator(
re.compile('^[\w.@+-]+$'),
re.compile(kb_common.USERNAME_REGEX),
_('Enter a valid username.'),
'invalid')])
display_name = models.CharField(
Expand Down
2 changes: 0 additions & 2 deletions pykeg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@
NOSE_ARGS = [
'--exe',
'--rednose',
'--exclude',
'.*(foursquare|twitter|untappd).*',
]

# Storage
Expand Down
16 changes: 16 additions & 0 deletions pykeg/web/api/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ def test_record_drink(self):
active_user = users[0]
self.assertEquals(self.normal_user.username, active_user.username)

def test_record_drink_usernames(self):
new_keg_data = {
'keg_size': 'half-barrel',
'beverage_name': 'Test Brew',
'producer_name': 'Test Producer',
'style_name': 'Test Style,'
}
response, data = self.post('taps/1/activate', data=new_keg_data,
HTTP_X_KEGBOT_API_KEY=self.apikey.key)
self.assertEquals(data.meta.result, 'ok')

models.User.objects.create(username='test.123')
response, data = self.post('taps/1', HTTP_X_KEGBOT_API_KEY=self.apikey.key,
data={'ticks': 1000, 'username': 'test.123'})
self.assertEquals(data.meta.result, 'ok')

@override_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend')
@override_settings(EMAIL_FROM_ADDRESS='test-from@example')
def test_registration(self):
Expand Down
3 changes: 2 additions & 1 deletion pykeg/web/api/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from django import forms

from pykeg.core import models
from pykeg.core.kb_common import USERNAME_REGEX

ALL_METERS = models.FlowMeter.objects.all()
ALL_TOGGLES = models.FlowToggle.objects.all()
Expand All @@ -28,7 +29,7 @@ class DrinkPostForm(forms.Form):
"""Form to handle posts to /tap/<tap_id>/"""
ticks = forms.IntegerField()
volume_ml = forms.FloatField(required=False)
username = forms.RegexField(required=False, max_length=30, regex=r"^[\w-]+$")
username = forms.RegexField(required=False, max_length=30, regex=USERNAME_REGEX)
pour_time = forms.IntegerField(required=False)
now = forms.IntegerField(required=False)
duration = forms.IntegerField(required=False)
Expand Down