From af0f0c202f577fcc8ac399687b0fdca97c1137ff Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 10:15:39 -0400 Subject: [PATCH 1/6] Update MANIFEST.in --- MANIFEST.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 5538354..9f402fd 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ +include CHANGES LICENSE recursive-include tests *.py -recursive-include flask_security/templates *.* \ No newline at end of file +recursive-include flask_security/templates *.* From 40409af1dda11fa522d53537fb6e36550adfe4b3 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 10:22:57 -0400 Subject: [PATCH 2/6] Fix documentation issue #145 --- docs/customizing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/customizing.rst b/docs/customizing.rst index 4edf619..f2a3faf 100644 --- a/docs/customizing.rst +++ b/docs/customizing.rst @@ -132,11 +132,11 @@ Overriding these templates is simple: Each template is passed a template context object that includes values for any links that are required in the email. If you require more values in the templates you can specify an email context processor with the -``email_context_processor`` decorator. For example:: +``mail_context_processor`` decorator. For example:: security = Security(app, user_datastore) # This processor is added to all emails - @security.email_context_processor + @security.mail_context_processor def security_mail_processor(): return dict(hello="world") From 1e958115e16ada402f6b9d2df255453429b5ca93 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 11:55:13 -0400 Subject: [PATCH 3/6] Fix tests --- tests/__init__.py | 19 ++++--------------- tests/configured_tests.py | 4 ++-- tests/signals_tests.py | 3 +-- tests/test_app/peewee_app.py | 4 ++-- tests/test_app/sqlalchemy.py | 2 -- 5 files changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index d5e7d56..92df3f2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,18 +22,11 @@ class SecurityTest(TestCase): app = self._create_app(self.AUTH_CONFIG or {}, **app_kwargs) app.debug = False app.config['TESTING'] = True + app.config['WTF_CSRF_ENABLED'] = False self.app = app self.client = app.test_client() - with self.client.session_transaction() as session: - session['csrf'] = 'csrf_token' - - csrf_hmac = hmac.new(self.app.config['SECRET_KEY'], - 'csrf_token'.encode('utf8'), - digestmod=sha1) - self.csrf_token = '##' + csrf_hmac.hexdigest() - def _create_app(self, auth_config, **kwargs): return create_app(auth_config, **kwargs) @@ -43,16 +36,13 @@ class SecurityTest(TestCase): headers=headers) def _post(self, route, data=None, content_type=None, follow_redirects=True, headers=None): - if isinstance(data, dict): - data['csrf_token'] = self.csrf_token - content_type = content_type or 'application/x-www-form-urlencoded' return self.client.post(route, data=data, follow_redirects=follow_redirects, content_type=content_type, headers=headers) def register(self, email, password='password'): - data = dict(email=email, password=password, csrf_token=self.csrf_token) + data = dict(email=email, password=password) return self.client.post('/register', data=data, follow_redirects=True) def authenticate(self, email="matt@lp.com", password="password", endpoint=None, **kwargs): @@ -62,11 +52,10 @@ class SecurityTest(TestCase): def json_authenticate(self, email="matt@lp.com", password="password", endpoint=None): data = """{ "email": "%s", - "password": "%s", - "csrf_token": "%s" + "password": "%s" }""" return self._post(endpoint or '/login', content_type="application/json", - data=data % (email, password, self.csrf_token)) + data=data % (email, password)) def logout(self, endpoint=None): return self._get(endpoint or '/logout', follow_redirects=True) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index af27be0..e2220a4 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -77,7 +77,7 @@ class ConfiguredSecurityTests(SecurityTest): self.assertIn('Page 1', r.data) def test_register_json(self): - data = '{ "email": "dude@lp.com", "password": "password", "csrf_token":"%s" }' % self.csrf_token + data = '{ "email": "dude@lp.com", "password": "password"}' r = self._post('/register', data=data, content_type='application/json') data = json.loads(r.data) self.assertEquals(data['meta']['code'], 200) @@ -559,7 +559,7 @@ class PasswordlessTests(SecurityTest): self.assertIn(msg, r.data) def test_request_login_token_with_json_and_valid_email(self): - data = '{"email": "matt@lp.com", "password": "password", "csrf_token":"%s"}' % self.csrf_token + data = '{"email": "matt@lp.com", "password": "password"}' r = self._post('/login', data=data, content_type='application/json') self.assertEquals(r.status_code, 200) self.assertNotIn('error', r.data) diff --git a/tests/signals_tests.py b/tests/signals_tests.py index ff045cb..cdf179c 100644 --- a/tests/signals_tests.py +++ b/tests/signals_tests.py @@ -173,8 +173,7 @@ class ChangeableSignalsTests(SignalTest): client.post('/change', data=dict(password='password', new_password='newpassword', - new_password_confirm='newpassword', - csrf_token=self.csrf_token)) + new_password_confirm='newpassword')) self.assertEqual(mocks.signals_sent(), set([password_changed])) user = self.app.security.datastore.find_user(email='joe@lp.com') calls = mocks[password_changed] diff --git a/tests/test_app/peewee_app.py b/tests/test_app/peewee_app.py index 954a977..8b4fc05 100644 --- a/tests/test_app/peewee_app.py +++ b/tests/test_app/peewee_app.py @@ -18,7 +18,7 @@ from tests.test_app import create_app as create_base_app, populate_data, \ def create_app(config, **kwargs): app = create_base_app(config) app.config['DATABASE'] = { - 'name': 'example2.db', + 'name': 'peewee.db', 'engine': 'peewee.SqliteDatabase' } db = Database(app) @@ -50,7 +50,7 @@ def create_app(config, **kwargs): def before_first_request(): for Model in (Role, User, UserRoles): Model.drop_table(fail_silently=True) - Model.create_table(fail_silently=True) + Model.create_table() populate_data(app.config.get('USER_COUNT', None)) app.security = Security(app, datastore=PeeweeUserDatastore(db, User, Role, UserRoles), **kwargs) diff --git a/tests/test_app/sqlalchemy.py b/tests/test_app/sqlalchemy.py index ec23b01..d1af62b 100644 --- a/tests/test_app/sqlalchemy.py +++ b/tests/test_app/sqlalchemy.py @@ -16,8 +16,6 @@ from tests.test_app import create_app as create_base_app, populate_data, \ def create_app(config, **kwargs): app = create_base_app(config) - - #app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root@localhost/flask_security_test' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' db = SQLAlchemy(app) From 6b3d65d6d6cc01d60a4ed7ae80d98bd5a34bd821 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 12:20:56 -0400 Subject: [PATCH 4/6] Fix flask-login test setting --- tests/test_app/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_app/__init__.py b/tests/test_app/__init__.py index 53b3de0..379e4ec 100644 --- a/tests/test_app/__init__.py +++ b/tests/test_app/__init__.py @@ -16,6 +16,7 @@ def create_app(config): app.debug = True app.config['SECRET_KEY'] = 'secret' app.config['TESTING'] = True + app.config['LOGIN_DISABLED'] = False for key, value in config.items(): app.config[key] = value From 13422e046fc80d5cad35901f813819e73eb3cdf3 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 13:00:03 -0400 Subject: [PATCH 5/6] Use bcrypt instead of py-bcrypt --- .travis.yml | 2 +- tox.ini | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index dd84116..c933e3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ python: install: - pip install . --quiet - "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install importlib --quiet --use-mirrors; fi" - - pip install nose simplejson Flask-SQLAlchemy Flask-MongoEngine Flask-Peewee py-bcrypt MySQL-python --quiet + - pip install nose simplejson Flask-SQLAlchemy Flask-MongoEngine Flask-Peewee bcrypt MySQL-python --quiet before_script: - mysql -e 'create database flask_security_test;' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9746aea --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +[tox] +envlist = py26, py27, pypy + +[testenv] +deps = + nose + simplejson + Flask-SQLAlchemy + Flask-MongoEngine + Flask-Peewee + bcrypt + +commands = nosetests [] From 0103bf4269822644e93b144992e3957d33455399 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Tue, 3 Sep 2013 13:08:13 -0400 Subject: [PATCH 6/6] Remove pypy tests --- .travis.yml | 3 +-- tox.ini | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c933e3b..6fae2be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,11 @@ language: python python: - "2.6" - "2.7" - - "pypy" install: - pip install . --quiet - "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install importlib --quiet --use-mirrors; fi" - - pip install nose simplejson Flask-SQLAlchemy Flask-MongoEngine Flask-Peewee bcrypt MySQL-python --quiet + - pip install nose simplejson Flask-SQLAlchemy Flask-MongoEngine Flask-Peewee py-bcrypt MySQL-python --quiet before_script: - mysql -e 'create database flask_security_test;' diff --git a/tox.ini b/tox.ini index 9746aea..411086c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27, pypy +envlist = py26, py27 [testenv] deps = @@ -8,6 +8,6 @@ deps = Flask-SQLAlchemy Flask-MongoEngine Flask-Peewee - bcrypt + py-bcrypt commands = nosetests []