From 7a27ff7a2f2c02e386bd09138bb171cc3fd9906c Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 13 Feb 2019 11:16:01 +0100 Subject: [PATCH] Pull in latest devel --- .coveragerc | 4 ++ .gitignore | 1 + .gitlab-ci.yml | 3 + config.py | 9 ++- config_local.py | 9 --- ivatar/ivataraccount/models.py | 4 +- ivatar/ivataraccount/views.py | 1 - ivatar/test_static_pages.py | 80 ++++++++++++++++++++++++ ivatar/test_views.py | 65 +++++++++++++++++++ ivatar/tools/templates/check_domain.html | 28 +++++++++ ivatar/tools/test_views.py | 72 +++++++++++++++++++++ ivatar/tools/views.py | 4 +- templates/base.html | 2 +- templates/base_home.html | 2 +- templates/footer.html | 2 +- templates/home.html | 6 +- 16 files changed, 267 insertions(+), 25 deletions(-) delete mode 100644 config_local.py create mode 100644 ivatar/test_static_pages.py create mode 100644 ivatar/test_views.py create mode 100644 ivatar/tools/templates/check_domain.html create mode 100644 ivatar/tools/test_views.py diff --git a/.coveragerc b/.coveragerc index 01c3fe6..b023fc9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,10 @@ [run] plugins = django_coverage_plugin +omit = + node_modules/* + .virtualenv/* + import_libravatar.py [html] extra_css = coverage_extra_style.css diff --git a/.gitignore b/.gitignore index 5ffd46b..ba7af6f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ htmlcov/ .ropeproject/ db.sqlite3.SAVE node_modules/ +config_local.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index de476e1..3214a43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,9 @@ before_script: test_and_coverage: stage: test script: + - echo 'from ivatar.settings import TEMPLATES' > config_local.py + - echo 'TEMPLATES[0]["OPTIONS"]["debug"] = True' >> config_local.py + - echo "DEBUG = True" >> config_local.py - python manage.py collectstatic --noinput - coverage run --source . manage.py test -v3 - coverage report --fail-under=70 diff --git a/config.py b/config.py index c18cc61..317bebd 100644 --- a/config.py +++ b/config.py @@ -49,16 +49,14 @@ TEMPLATES[0]['OPTIONS']['context_processors'].append( OPENID_CREATE_USERS = True OPENID_UPDATE_DETAILS_FROM_SREG = True -SITE_NAME = os.environ.get('SITE_NAME', 'ivatar') -IVATAR_VERSION = '0.1' +SITE_NAME = os.environ.get('SITE_NAME', 'libravatar') +IVATAR_VERSION = '1.0' SECURE_BASE_URL = os.environ.get('SECURE_BASE_URL', 'https://avatars.linux-kernel.at/avatar/') BASE_URL = os.environ.get('BASE_URL', 'http://avatars.linux-kernel.at/avatar/') LOGIN_REDIRECT_URL = reverse_lazy('profile') MAX_LENGTH_EMAIL = 254 # http://stackoverflow.com/questions/386294 -SERVER_EMAIL = 'accounts@mg.linux-kernel.at' -DEFAULT_FROM_EMAIL = SERVER_EMAIL MAX_NUM_PHOTOS = 5 MAX_NUM_UNCONFIRMED_EMAILS = 5 @@ -97,7 +95,7 @@ BOOTSTRAP4 = { } if 'EMAIL_BACKEND' in os.environ: - EMAIL_BACKEND = os.environ['EMAIL_BACKEND'] + EMAIL_BACKEND = os.environ['EMAIL_BACKEND'] # pragma: no cover else: if 'test' in sys.argv or 'collectstatic' in sys.argv: EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' @@ -108,6 +106,7 @@ else: } EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend' # pragma: no cover +SERVER_EMAIL = os.environ.get('SERVER_EMAIL', 'ivatar@mg.linux-kernel.at') DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL', 'ivatar@mg.linux-kernel.at') try: diff --git a/config_local.py b/config_local.py deleted file mode 100644 index cb6aa6a..0000000 --- a/config_local.py +++ /dev/null @@ -1,9 +0,0 @@ -''' -Local config -''' - -from ivatar.settings import TEMPLATES # noqa - -SESSION_COOKIE_SECURE = False -DEBUG = True -TEMPLATES[0]['OPTIONS']['debug'] = True diff --git a/ivatar/ivataraccount/models.py b/ivatar/ivataraccount/models.py index fc4a611..804d6c2 100644 --- a/ivatar/ivataraccount/models.py +++ b/ivatar/ivataraccount/models.py @@ -31,7 +31,7 @@ from libravatar import libravatar_url from ivatar.settings import MAX_LENGTH_EMAIL, logger from ivatar.settings import MAX_PIXELS, AVATAR_MAX_SIZE, JPEG_QUALITY from ivatar.settings import MAX_LENGTH_URL -from ivatar.settings import SECURE_BASE_URL, SITE_NAME, SERVER_EMAIL +from ivatar.settings import SECURE_BASE_URL, SITE_NAME, DEFAULT_FROM_EMAIL from .gravatar import get_photo as get_gravatar_photo @@ -383,7 +383,7 @@ class UnconfirmedEmail(BaseAccountModel): # if settings.DEBUG: # print('DEBUG: %s' % link) send_mail( - email_subject, email_body, SERVER_EMAIL, + email_subject, email_body, DEFAULT_FROM_EMAIL, [self.email]) return True diff --git a/ivatar/ivataraccount/views.py b/ivatar/ivataraccount/views.py index 9a9f2fb..6802980 100644 --- a/ivatar/ivataraccount/views.py +++ b/ivatar/ivataraccount/views.py @@ -145,7 +145,6 @@ class RemoveUnconfirmedEmailView(SuccessMessageMixin, View): return HttpResponseRedirect(reverse_lazy('profile')) -@method_decorator(login_required, name='dispatch') class ConfirmEmailView(SuccessMessageMixin, TemplateView): ''' View class for confirming an unconfirmed email address diff --git a/ivatar/test_static_pages.py b/ivatar/test_static_pages.py new file mode 100644 index 0000000..5191509 --- /dev/null +++ b/ivatar/test_static_pages.py @@ -0,0 +1,80 @@ +''' +Test our views in ivatar.ivataraccount.views and ivatar.views +''' +# pylint: disable=too-many-lines +from urllib.parse import urlsplit +from io import BytesIO +import io +import os +import django +from django.test import TestCase +from django.test import Client +from django.urls import reverse +from django.contrib.auth.models import User +from django.contrib.auth import authenticate +import hashlib + +from libravatar import libravatar_url + +from PIL import Image + +os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings' +django.setup() + +# pylint: disable=wrong-import-position +from ivatar import settings +from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT +from ivatar.ivataraccount.models import Photo, ConfirmedOpenId +from ivatar.utils import random_string +# pylint: enable=wrong-import-position + + +class Tester(TestCase): # pylint: disable=too-many-public-methods + ''' + Main test class + ''' + client = Client() + user = None + username = random_string() + password = random_string() + email = '%s@%s.%s' % (username, random_string(), random_string(2)) + # Dunno why random tld doesn't work, but I'm too lazy now to investigate + openid = 'http://%s.%s.%s/' % (username, random_string(), 'org') + + def login(self): + ''' + Login as user + ''' + self.client.login(username=self.username, password=self.password) + + def setUp(self): + ''' + Prepare for tests. + - Create user + ''' + self.user = User.objects.create_user( + username=self.username, + password=self.password, + ) + + def test_contact_page(self): + """ + Test contact page + """ + response = self.client.get(reverse('contact')) + self.assertEqual(response.status_code, 200, 'no 200 ok?') + + def test_description_page(self): + """ + Test description page + """ + response = self.client.get(reverse('description')) + self.assertEqual(response.status_code, 200, 'no 200 ok?') + + def test_security_page(self): + """ + Test security page + """ + response = self.client.get(reverse('security')) + self.assertEqual(response.status_code, 200, 'no 200 ok?') + diff --git a/ivatar/test_views.py b/ivatar/test_views.py new file mode 100644 index 0000000..dbed347 --- /dev/null +++ b/ivatar/test_views.py @@ -0,0 +1,65 @@ +''' +Test our views in ivatar.ivataraccount.views and ivatar.views +''' +# pylint: disable=too-many-lines +from urllib.parse import urlsplit +from io import BytesIO +import io +import os +import django +from django.test import TestCase +from django.test import Client +from django.urls import reverse +from django.contrib.auth.models import User +from django.contrib.auth import authenticate +import hashlib + +from libravatar import libravatar_url + +from PIL import Image + +os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings' +django.setup() + +# pylint: disable=wrong-import-position +from ivatar import settings +from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT +from ivatar.ivataraccount.models import Photo, ConfirmedOpenId +from ivatar.utils import random_string +# pylint: enable=wrong-import-position + + +class Tester(TestCase): # pylint: disable=too-many-public-methods + ''' + Main test class + ''' + client = Client() + user = None + username = random_string() + password = random_string() + email = '%s@%s.%s' % (username, random_string(), random_string(2)) + # Dunno why random tld doesn't work, but I'm too lazy now to investigate + openid = 'http://%s.%s.%s/' % (username, random_string(), 'org') + + def login(self): + ''' + Login as user + ''' + self.client.login(username=self.username, password=self.password) + + def setUp(self): + ''' + Prepare for tests. + - Create user + ''' + self.user = User.objects.create_user( + username=self.username, + password=self.password, + ) + + def test_incorrect_digest(self): + """ + Test incorrect digest + """ + response = self.client.get('/avatar/%s' % 'x'*65) + self.assertEqual(response.status_code, 200, 'no 200 ok?') diff --git a/ivatar/tools/templates/check_domain.html b/ivatar/tools/templates/check_domain.html new file mode 100644 index 0000000..f7e8db4 --- /dev/null +++ b/ivatar/tools/templates/check_domain.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load static %} + +{% block title %}{% trans 'Check e-mail or openid' %}{% endblock title %} + +{% block content %} + +

{% trans 'Check domain' %}

+ +
+
+{% csrf_token %} +
+
+
+ +
+
+
+ +{% if result %} +
+

Domain check - TODO TODO

+

+{% endif %} +

+{% endblock content %} diff --git a/ivatar/tools/test_views.py b/ivatar/tools/test_views.py new file mode 100644 index 0000000..4520efb --- /dev/null +++ b/ivatar/tools/test_views.py @@ -0,0 +1,72 @@ +''' +Test our views in ivatar.ivataraccount.views and ivatar.views +''' +# pylint: disable=too-many-lines +from urllib.parse import urlsplit +from io import BytesIO +import io +import os +import django +from django.test import TestCase +from django.test import Client +from django.urls import reverse +from django.contrib.auth.models import User +from django.contrib.auth import authenticate +import hashlib + +from libravatar import libravatar_url + +from PIL import Image + +os.environ['DJANGO_SETTINGS_MODULE'] = 'ivatar.settings' +django.setup() + +# pylint: disable=wrong-import-position +from ivatar import settings +from ivatar.ivataraccount.forms import MAX_NUM_UNCONFIRMED_EMAILS_DEFAULT +from ivatar.ivataraccount.models import Photo, ConfirmedOpenId +from ivatar.utils import random_string +# pylint: enable=wrong-import-position + + +class Tester(TestCase): # pylint: disable=too-many-public-methods + ''' + Main test class + ''' + client = Client() + user = None + username = random_string() + password = random_string() + email = '%s@%s.%s' % (username, random_string(), random_string(2)) + # Dunno why random tld doesn't work, but I'm too lazy now to investigate + openid = 'http://%s.%s.%s/' % (username, random_string(), 'org') + + def login(self): + ''' + Login as user + ''' + self.client.login(username=self.username, password=self.password) + + def setUp(self): + ''' + Prepare for tests. + - Create user + ''' + self.user = User.objects.create_user( + username=self.username, + password=self.password, + ) + + def test_check(self): + """ + Test check page + """ + response = self.client.get(reverse('tools_check')) + self.assertEqual(response.status_code, 200, 'no 200 ok?') + + def test_check_domain(self): + """ + Test check domain page + """ + response = self.client.get(reverse('tools_check_domain')) + self.assertEqual(response.status_code, 200, 'no 200 ok?') diff --git a/ivatar/tools/views.py b/ivatar/tools/views.py index c4ac253..548970c 100644 --- a/ivatar/tools/views.py +++ b/ivatar/tools/views.py @@ -69,8 +69,8 @@ class CheckView(FormView): mail_hash256 = hash_obj.hexdigest() size = form.cleaned_data['size'] if form.cleaned_data['openid']: - if form.cleaned_data['openid'][-1] != '/': - form.cleaned_data['openid'] += '/' + if not form.cleaned_data['openid'].startswith('http://') and not form.cleaned_data['openid'].startswith('https://'): + form.cleaned_data['openid'] = 'http://%s' % form.cleaned_data['openid'] openidurl = libravatar_url( openid=form.cleaned_data['openid'], size=form.cleaned_data['size'], diff --git a/templates/base.html b/templates/base.html index f31128f..edf54e7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,7 +1,7 @@ {% load static %} {% load i18n %} {% include 'header.html' %} -iVatar :: {% block title %}{% trans 'Freeing the Web, one face at a time!' %}{% endblock title %} +{{ site_name }} :: {% block title %}{% trans 'Freeing the Web, one face at a time!' %}{% endblock title %} {% spaceless %}
diff --git a/templates/base_home.html b/templates/base_home.html index b96ee7b..dce29a5 100644 --- a/templates/base_home.html +++ b/templates/base_home.html @@ -1,7 +1,7 @@ {% load static %} {% load i18n %} {% include 'header.html' %} -iVatar :: {% block title %}{% trans 'Freeing the Web, one face at a time!' %}{% endblock title %} +{{ site_name }} :: {% block title %}{% trans 'Freeing the Web, one face at a time!' %}{% endblock title %} {% spaceless %}
diff --git a/templates/footer.html b/templates/footer.html index bab879c..f2528c8 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -4,7 +4,7 @@