Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Aug 19, 2019
2 parents 52277ab + 56b91ca commit 9ac321b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
8 changes: 1 addition & 7 deletions flask_beet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
from .utils import unique_request_id
from .views import bp

# Convenient references
_security = LocalProxy(lambda: current_app.extensions["security"])
_datastore = LocalProxy(lambda: _security.datastore)
_db = LocalProxy(lambda: _datastore.db)
_user = LocalProxy(lambda: _datastore.user_model)


#: Default configuration
_default_config = {
Expand All @@ -31,7 +25,7 @@

class Beet(object):
def __init__(self, app=None):
if app is not None:
if app is not None: # pragma: no cover
self.init_app(app)

def init_app(self, app):
Expand Down
3 changes: 2 additions & 1 deletion flask_beet/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from flask_wtf import FlaskForm
from wtforms import SubmitField, TextAreaField
from wtforms.validators import DataRequired, ValidationError
Expand Down Expand Up @@ -25,7 +26,7 @@ def __call__(self, FlaskForm, field):
ret = field.signedMessage.verify()
except Exception as e:
raise ValidationError(str(e))
if not ret:
if not ret: # pragma: no cover
raise ValidationError(self.message)
field.signed_by_account = field.signedMessage.signed_by_account
field.signed_by_name = field.signedMessage.signed_by_name
Expand Down
1 change: 0 additions & 1 deletion flask_beet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# Convenient references
_security = LocalProxy(lambda: app.extensions["security"])
_datastore = LocalProxy(lambda: _security.datastore)
_db = LocalProxy(lambda: _datastore.db)
_user = LocalProxy(lambda: _datastore.user_model)


Expand Down
29 changes: 27 additions & 2 deletions tests/test_beet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class User(db.Model, UserMixin, BeetMixin):
1f2104580464
-----END BITSHARES SIGNED MESSAGE-----"""

_invalid_payload_signed_message = """-----BEGIN BITSHARES SIGNED MESSAGE-----
_invalid_signature_signed_message = """-----BEGIN BITSHARES SIGNED MESSAGE-----
abcsfasFasfasf
-----BEGIN META-----
account=xeroc
Expand All @@ -84,6 +84,17 @@ class User(db.Model, UserMixin, BeetMixin):
1f210458337f3cf13b80c46ae04b5cfe8ee2ff094bc559fbb663a5cd345015cfec24b3dafc111fbdb7099c347885eb96e8453d3fb2b72e23e3e9e446fb61540464
-----END BITSHARES SIGNED MESSAGE-----"""

_invalid_payload_signed_message = """-----BEGIN BITSHARES SIGNED MESSAGE-----
sfasfasas
-----BEGIN META-----
account=xeroc
memokey=BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE
block=40215253
timestamp=2019-08-19T12:53:45
-----BEGIN SIGNATURE-----
2033d1e0b276941849a3575bcd0d802b9befeb6177065dbbe0a6e11872e84e31e42e2e3357691744cdbace60b3336b89f1bb38c45f335c0ea08673b2e92288c6a9
-----END BITSHARES SIGNED MESSAGE-----"""


class TestCases(TestCase):
def create_app(self):
Expand All @@ -107,6 +118,9 @@ def setup_user(self):
user.set_beet_account_name("xeroc")
db.session.add(user)
db.session.commit()
db.session.refresh(user)

self.assertEqual(user.get_beet_account_name(), "xeroc")

def test_form(self):
rep = self.client.get("/beet/login")
Expand Down Expand Up @@ -145,15 +159,26 @@ def test_login_invalidsignature(self):
self.assertEqual(rep.status_code, 200)
self.assertIn(b"No Decoder accepted the message", rep.data)

def test_login_invalidsig(self):
self.setup_user()
rep = self.client.get("/beet/login")
rep = self.client.post(
"/beet/login",
data=dict(message=_invalid_signature_signed_message, submit="Login"),
)
self.assertEqual(rep.status_code, 200)
self.assertIn(b"The signature doesn't match the memo key", rep.data)

def test_login_invalidpayload(self):
self.setup_user()
rep = self.client.get("/beet/login")
rep = self.client.post(
"/beet/login",
data=dict(message=_invalid_payload_signed_message, submit="Login"),
follow_redirects=True,
)
self.assertEqual(rep.status_code, 200)
self.assertIn(b"The signature doesn't match the memo key", rep.data)
self.assertIn(b"Invalid payload!", rep.data)

def test_image(self):
rep = self.client.get("/beet/img/beet.png")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
import re
from unittest import TestCase
from flask_beet.utils import unique_request_id


class Testcases(TestCase):
def test_new_username(self):
x = unique_request_id()
assert re.match(
r"^[a-f0-9-]{8}-[a-f0-9-]{4}-[a-f0-9-]{4}-[a-f0-9-]{4}-[a-f0-9-]{12}$", x
)

0 comments on commit 9ac321b

Please sign in to comment.