diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37744de --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Created by https://www.gitignore.io + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_simple.py b/tests/test_simple.py new file mode 100644 index 0000000..04a87bd --- /dev/null +++ b/tests/test_simple.py @@ -0,0 +1,39 @@ +from flask import Flask +from flask_sslify import SSLify +from pytest import fixture + + +@fixture +def sslify(): + app = Flask(__name__) + app.config['DEBUG'] = False + app.config['TESTING'] = False + app.config['SERVER_NAME'] = 'example.com' + sslify = SSLify(app) + + @app.route('/') + def home(): + return 'home' + + return sslify + + +def test_default_config(sslify): + assert sslify.hsts_include_subdomains is False + assert sslify.permanent is False + assert sslify.skip_list is None + + +def test_redirection(sslify): + client = sslify.app.test_client() + r = client.get('/') + assert r.status_code == 302 + assert r.headers['Location'] == 'https://example.com/' + + +def test_hsts_header(sslify): + client = sslify.app.test_client() + r = client.get('/', base_url='https://example.com') + assert r.status_code == 200 + assert r.data == 'home' + assert r.headers['Strict-Transport-Security'] == 'max-age=31536000'