From 024cb991bf19a9ab9619ad739b0fa171429faab4 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 7 Jan 2016 19:47:11 +0100 Subject: [PATCH 01/93] first commit' --- .gitignore | 75 ++++++++++++++++++++ README.md | 0 __init__.py | 0 api/__init__.py | 0 api/admin.py | 5 ++ api/apps.py | 5 ++ api/migrations/0001_initial.py | 49 +++++++++++++ api/migrations/__init__.py | 0 api/models.py | 42 +++++++++++ api/permissions.py | 0 api/serializers.py | 17 +++++ api/tests.py | 0 api/urls.py | 11 +++ api/views.py | 38 ++++++++++ lesspass/__init__.py | 0 lesspass/settings.py | 153 +++++++++++++++++++++++++++++++++++++++++ lesspass/urls.py | 8 +++ lesspass/wsgi.py | 7 ++ manage.py | 10 +++ requirements.txt | 3 + 20 files changed, 423 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 __init__.py create mode 100644 api/__init__.py create mode 100644 api/admin.py create mode 100644 api/apps.py create mode 100644 api/migrations/0001_initial.py create mode 100644 api/migrations/__init__.py create mode 100644 api/models.py create mode 100644 api/permissions.py create mode 100644 api/serializers.py create mode 100644 api/tests.py create mode 100644 api/urls.py create mode 100644 api/views.py create mode 100644 lesspass/__init__.py create mode 100644 lesspass/settings.py create mode 100644 lesspass/urls.py create mode 100644 lesspass/wsgi.py create mode 100644 manage.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7323d4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,75 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# 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/ +### VirtualEnv template +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +.Python +[Bb]in +[Ii]nclude +[Ll]ib +/mysqlclient-1.3.7-cp34-none-win32.whl +[Ss]cripts +pyvenv.cfg +pip-selfcheck.json +/config +*.sqlite3 +/frontend/node_modules +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..131557b --- /dev/null +++ b/api/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from api.models import PasswordInfo, Entry + +admin.site.register(Entry) +admin.site.register(PasswordInfo) diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..d87006d --- /dev/null +++ b/api/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + name = 'api' diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py new file mode 100644 index 0000000..f97f5e0 --- /dev/null +++ b/api/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-01-07 19:39 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Entry', + fields=[ + ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), + ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('site', models.CharField(max_length=255)), + ('title', models.CharField(default=True, max_length=255, null=True)), + ('username', models.CharField(default=True, max_length=255, null=True)), + ('email', models.EmailField(default=True, max_length=254, null=True)), + ('description', models.TextField(default=True, null=True)), + ('url', models.URLField(default=True, null=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='PasswordInfo', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('counter', models.IntegerField(default=1)), + ('settings', models.TextField()), + ('length', models.IntegerField(default=12)), + ], + ), + migrations.AddField( + model_name='entry', + name='password', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.PasswordInfo'), + ), + ] diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..6f1e0af --- /dev/null +++ b/api/models.py @@ -0,0 +1,42 @@ +import uuid + +from django.db import models + + +class DateMixin(models.Model): + created = models.DateTimeField(auto_now_add=True, verbose_name='created') + modified = models.DateTimeField(auto_now=True, verbose_name='modified') + + class Meta: + abstract = True + + +class PasswordInfo(models.Model): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + counter = models.IntegerField(default=1) + settings = models.TextField() + length = models.IntegerField(default=12) + + class Meta: + verbose_name_plural = "Password info" + + def __str__(self): + return str(self.id) + + +class Entry(DateMixin): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + site = models.CharField(max_length=255) + password = models.ForeignKey(PasswordInfo) + + title = models.CharField(max_length=255, null=True, blank=True) + username = models.CharField(max_length=255, null=True, blank=True) + email = models.EmailField(null=True, blank=True) + description = models.TextField(null=True, blank=True) + url = models.URLField(null=True, blank=True) + + class Meta: + verbose_name_plural = "Entries" + + def __str__(self): + return self.title diff --git a/api/permissions.py b/api/permissions.py new file mode 100644 index 0000000..e69de29 diff --git a/api/serializers.py b/api/serializers.py new file mode 100644 index 0000000..e643d4c --- /dev/null +++ b/api/serializers.py @@ -0,0 +1,17 @@ +from api import models +from rest_framework import serializers + + +class PasswordInfoSerializer(serializers.ModelSerializer): + class Meta: + model = models.PasswordInfo + fields = ('counter', 'settings', 'length') + + +class EntrySerializer(serializers.ModelSerializer): + password = PasswordInfoSerializer() + + class Meta: + model = models.Entry + fields = ('id', 'site', 'password', 'title', 'username', 'email', 'description', 'url', 'created', 'modified') + read_only_fields = ('created', 'modified') diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..e69de29 diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..16b62ae --- /dev/null +++ b/api/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url, include +from rest_framework.routers import DefaultRouter + +from api import views + +router = DefaultRouter() +router.register(r'auth', views.AuthViewSet, base_name="auth") + +urlpatterns = [ + url(r'^', include(router.urls)), +] diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..02db232 --- /dev/null +++ b/api/views.py @@ -0,0 +1,38 @@ +import json + +from django.contrib.auth import login, authenticate +from rest_framework import status, permissions, viewsets +from rest_framework.response import Response + + +class AuthViewSet(viewsets.ViewSet): + permission_classes = (permissions.AllowAny,) + + @staticmethod + def list(request, format=None): + if request.user.is_authenticated(): + user = { + 'id': request.user.id, + 'email': request.user.email, + 'is_admin': request.user.is_staff, + 'is_authenticated': True + } + else: + user = { + 'id': None, + 'email': None, + 'is_admin': False, + 'is_authenticated': False + } + + return Response({ + 'user': user + }) + + @staticmethod + def post(request): + user = authenticate(username=request.data.get('username'), password=request.data.get('password')) + if user and user.is_active: + login(request, user) + return Response(status=status.HTTP_201_CREATED) + return Response(status=status.HTTP_401_UNAUTHORIZED) diff --git a/lesspass/__init__.py b/lesspass/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lesspass/settings.py b/lesspass/settings.py new file mode 100644 index 0000000..c728a77 --- /dev/null +++ b/lesspass/settings.py @@ -0,0 +1,153 @@ +import os + +from smartconfigparser import Config + +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +CONFIG_PATH = os.path.join(BASE_DIR, 'config') +if not os.path.exists(CONFIG_PATH): + os.makedirs(CONFIG_PATH) + +CONFIG_FILE = os.path.join(CONFIG_PATH, 'config.ini') +config = Config() +config.read(CONFIG_FILE) + +try: + SECRET_KEY = config.get('DJANGO', 'SECRET_KEY') +except: + print('SECRET_KEY not found! Generating a new one...') + import random + + SECRET_KEY = "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*(-_=+)") for i in range(50)]) + if not config.has_section('DJANGO'): + config.add_section('DJANGO') + config.set('DJANGO', 'SECRET_KEY', SECRET_KEY) + with open(CONFIG_FILE, 'wt') as f: + config.write(f) + +DEBUG = config.getboolean('DJANGO', 'DEBUG', False) + +ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1']) + +INSTALLED_APPS = [ + 'api.apps.ApiConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework', + + 'django.contrib.sites', + 'allauth', + 'allauth.account', + 'allauth.socialaccount', + + 'allauth.socialaccount.providers.persona', +] + +MIDDLEWARE_CLASSES = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'lesspass.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'lesspass.wsgi.application' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = False + +STATIC_URL = '/static/' + +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',), + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', + 'PAGE_SIZE': 20, + 'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.OrderingFilter', + 'rest_framework.filters.SearchFilter',), + 'DEFAULT_RENDERER_CLASSES': ( + 'rest_framework.renderers.JSONRenderer', + 'rest_framework.renderers.BrowsableAPIRenderer', + ), + 'DEFAULT_PARSER_CLASSES': ( + 'rest_framework.parsers.JSONParser', + ) +} + +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'allauth.account.auth_backends.AuthenticationBackend', +) + +SITE_ID = 1 + +SOCIALACCOUNT_PROVIDERS = { + 'persona': { + 'AUDIENCE': config.get('DJANGO', 'PERSONA_AUDIENCE', 'https://lesspass.com'), + 'REQUEST_PARAMETERS': { + 'siteName': config.get('DJANGO', 'PERSONA_SITE_NAME', 'lesspass') + } + } +} + +ACCOUNT_AUTHENTICATION_METHOD = "email" +ACCOUNT_EMAIL_REQUIRED = True +ACCOUNT_USERNAME_REQUIRED = False +ACCOUNT_LOGIN_ON_PASSWORD_RESET = True +ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/lesspass/urls.py b/lesspass/urls.py new file mode 100644 index 0000000..153cc5a --- /dev/null +++ b/lesspass/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import include, url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), + url(r'^api/', include('api.urls')), + url(r'^accounts/', include('allauth.urls')), +] diff --git a/lesspass/wsgi.py b/lesspass/wsgi.py new file mode 100644 index 0000000..bc4d7c4 --- /dev/null +++ b/lesspass/wsgi.py @@ -0,0 +1,7 @@ +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lesspass.settings") + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..1571b63 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lesspass.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..983d990 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Django==1.9.1 +djangorestframework==3.3.2 +smartconfigparser==0.1.1 \ No newline at end of file From 514e9df72e34109f1133378d60611db34adad803 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 7 Jan 2016 22:48:01 +0100 Subject: [PATCH 02/93] add entry CRUD models --- api/migrations/0001_initial.py | 24 ++++++--- api/models.py | 2 + api/permissions.py | 6 +++ api/serializers.py | 39 +++++++++++++++ api/tests.py | 0 api/tests/__init__.py | 0 api/tests/factories.py | 39 +++++++++++++++ api/tests/tests_entries.py | 109 +++++++++++++++++++++++++++++++++++++++++ api/urls.py | 1 + api/views.py | 11 ++++- lesspass/settings.py | 3 +- requirements.dev.txt | 2 + requirements.txt | 3 +- 13 files changed, 229 insertions(+), 10 deletions(-) delete mode 100644 api/tests.py create mode 100644 api/tests/__init__.py create mode 100644 api/tests/factories.py create mode 100644 api/tests/tests_entries.py create mode 100644 requirements.dev.txt diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py index f97f5e0..751b130 100644 --- a/api/migrations/0001_initial.py +++ b/api/migrations/0001_initial.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.1 on 2016-01-07 19:39 +# Generated by Django 1.9.1 on 2016-01-07 19:49 from __future__ import unicode_literals +from django.conf import settings from django.db import migrations, models import django.db.models.deletion import uuid @@ -12,6 +13,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ @@ -22,14 +24,14 @@ class Migration(migrations.Migration): ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('site', models.CharField(max_length=255)), - ('title', models.CharField(default=True, max_length=255, null=True)), - ('username', models.CharField(default=True, max_length=255, null=True)), - ('email', models.EmailField(default=True, max_length=254, null=True)), - ('description', models.TextField(default=True, null=True)), - ('url', models.URLField(default=True, null=True)), + ('title', models.CharField(blank=True, max_length=255, null=True)), + ('username', models.CharField(blank=True, max_length=255, null=True)), + ('email', models.EmailField(blank=True, max_length=254, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('url', models.URLField(blank=True, null=True)), ], options={ - 'abstract': False, + 'verbose_name_plural': 'Entries', }, ), migrations.CreateModel( @@ -40,10 +42,18 @@ class Migration(migrations.Migration): ('settings', models.TextField()), ('length', models.IntegerField(default=12)), ], + options={ + 'verbose_name_plural': 'Password info', + }, ), migrations.AddField( model_name='entry', name='password', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.PasswordInfo'), ), + migrations.AddField( + model_name='entry', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='entries', to=settings.AUTH_USER_MODEL), + ), ] diff --git a/api/models.py b/api/models.py index 6f1e0af..d52b7a9 100644 --- a/api/models.py +++ b/api/models.py @@ -1,6 +1,7 @@ import uuid from django.db import models +from django.contrib.auth.models import User class DateMixin(models.Model): @@ -26,6 +27,7 @@ class PasswordInfo(models.Model): class Entry(DateMixin): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='entries') site = models.CharField(max_length=255) password = models.ForeignKey(PasswordInfo) diff --git a/api/permissions.py b/api/permissions.py index e69de29..55155c8 100644 --- a/api/permissions.py +++ b/api/permissions.py @@ -0,0 +1,6 @@ +from rest_framework import permissions + + +class IsOwner(permissions.BasePermission): + def has_object_permission(self, request, view, obj): + return obj.user == request.user diff --git a/api/serializers.py b/api/serializers.py index e643d4c..a75310c 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,8 +1,29 @@ +import json + from api import models from rest_framework import serializers +from django.utils.translation import ugettext_lazy as _ + + +class JsonSettingsField(serializers.Field): + default_error_messages = { + 'invalid': _('Value must be valid JSON.') + } + + def to_representation(self, value): + return json.loads(value) + + def to_internal_value(self, data): + try: + return json.dumps(data) + except (TypeError, ValueError): + self.fail('invalid') + class PasswordInfoSerializer(serializers.ModelSerializer): + settings = JsonSettingsField() + class Meta: model = models.PasswordInfo fields = ('counter', 'settings', 'length') @@ -15,3 +36,21 @@ class EntrySerializer(serializers.ModelSerializer): model = models.Entry fields = ('id', 'site', 'password', 'title', 'username', 'email', 'description', 'url', 'created', 'modified') read_only_fields = ('created', 'modified') + + def create(self, validated_data): + password_data = validated_data.pop('password') + user = self.context['request'].user + password_info = models.PasswordInfo.objects.create(**password_data) + return models.Entry.objects.create(user=user, password=password_info, **validated_data) + + def update(self, instance, validated_data): + password_data = validated_data.pop('password') + passwordInfo = instance.password + for attr, value in password_data.items(): + setattr(passwordInfo, attr, value) + passwordInfo.save() + + for attr, value in validated_data.items(): + setattr(instance, attr, value) + instance.save() + return instance diff --git a/api/tests.py b/api/tests.py deleted file mode 100644 index e69de29..0000000 diff --git a/api/tests/__init__.py b/api/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/tests/factories.py b/api/tests/factories.py new file mode 100644 index 0000000..1eb78ae --- /dev/null +++ b/api/tests/factories.py @@ -0,0 +1,39 @@ +import factory + +from api import models + + +class UserFactory(factory.DjangoModelFactory): + class Meta: + model = models.User + + username = factory.Sequence(lambda n: 'username{0}'.format(n)) + first_name = factory.Faker('first_name') + last_name = factory.Faker('last_name') + email = factory.LazyAttribute(lambda a: '{0}.{1}@oslab.fr'.format(a.first_name, a.last_name).lower()) + password = factory.PostGenerationMethodCall('set_password', 'password') + is_staff = False + + +class AdminFactory(UserFactory): + is_staff = True + + +class PasswordInfoFactory(factory.DjangoModelFactory): + class Meta: + model = models.PasswordInfo + + settings = '["lowercase", "uppercase", "numbers", "symbols"]' + + +class EntryFactory(factory.DjangoModelFactory): + class Meta: + model = models.Entry + + user = factory.SubFactory(UserFactory) + password = factory.SubFactory(PasswordInfoFactory) + + title = 'twitter' + site = 'twitter' + username = 'guillaume20100' + url = 'https://twitter.com/' diff --git a/api/tests/tests_entries.py b/api/tests/tests_entries.py new file mode 100644 index 0000000..4d7207c --- /dev/null +++ b/api/tests/tests_entries.py @@ -0,0 +1,109 @@ +import json + +from rest_framework.test import APITestCase, APIClient + +from api import models +from api.tests import factories + + +class LogoutApiTestCase(APITestCase): + def test_get_entries_403(self): + response = self.client.get('/api/entries/') + self.assertEqual(403, response.status_code) + + +class LoginApiTestCase(APITestCase): + def setUp(self): + self.user = factories.UserFactory() + self.client = APIClient() + self.client.force_authenticate(user=self.user) + + def test_get_empty_entries(self): + request = self.client.get('/api/entries/') + self.assertEqual(0, len(request.data['results'])) + + def test_retrieve_its_own_entries(self): + entry = factories.EntryFactory(user=self.user) + request = self.client.get('/api/entries/') + self.assertEqual(1, len(request.data['results'])) + self.assertEqual(entry.site, request.data['results'][0]['site']) + + def test_cant_retrieve_other_entries(self): + not_my_entry = factories.EntryFactory(user=factories.UserFactory()) + request = self.client.get('/api/entries/%s/' % not_my_entry.id) + self.assertEqual(404, request.status_code) + + def test_delete_its_own_entries(self): + entry = factories.EntryFactory(user=self.user) + self.assertEqual(1, models.Entry.objects.all().count()) + request = self.client.delete('/api/entries/%s/' % entry.id) + self.assertEqual(204, request.status_code) + self.assertEqual(0, models.Entry.objects.all().count()) + + def test_cant_delete_other_entry(self): + not_my_entry = factories.EntryFactory(user=factories.UserFactory()) + self.assertEqual(1, models.Entry.objects.all().count()) + request = self.client.delete('/api/entries/%s/' % not_my_entry.id) + self.assertEqual(404, request.status_code) + self.assertEqual(1, models.Entry.objects.all().count()) + + def test_create_entry(self): + entry = { + "site": "twitter", + "password": { + "counter": 1, + "settings": [ + "lowercase", + "uppercase", + "numbers", + "symbols" + ], + "length": 12 + }, + "title": "twitter", + "username": "guillaume20100", + "email": "guillaume@oslab.fr", + "description": "", + "url": "https://twitter.com/" + } + self.assertEqual(0, models.Entry.objects.count()) + self.assertEqual(0, models.PasswordInfo.objects.count()) + self.client.post('/api/entries/', entry) + self.assertEqual(1, models.Entry.objects.count()) + self.assertEqual(1, models.PasswordInfo.objects.count()) + + def test_update_entry(self): + entry = factories.EntryFactory(user=self.user) + self.assertNotEqual('facebook', entry.site) + new_entry = { + "site": "facebook", + "password": { + "counter": 1, + "settings": [ + "lowercase", + "uppercase", + "numbers" + ], + "length": 12 + }, + "title": "facebook", + "username": "", + "email": "", + "description": "", + "url": "https://facebook.com/" + } + self.client.put('/api/entries/%s/' % entry.id, new_entry) + entry_updated = models.Entry.objects.get(id=entry.id) + self.assertEqual('facebook', entry_updated.site) + self.assertEqual(3, len(json.loads(entry_updated.password.settings))) + + def test_cant_update_other_entry(self): + not_my_entry = factories.EntryFactory(user=factories.UserFactory()) + self.assertEqual('twitter', not_my_entry.site) + new_entry = { + "site": "facebook", + "password": {"settings": []} + } + request = self.client.put('/api/entries/%s/' % not_my_entry.id, new_entry) + self.assertEqual(404, request.status_code) + self.assertEqual(1, models.Entry.objects.all().count()) diff --git a/api/urls.py b/api/urls.py index 16b62ae..c7560e2 100644 --- a/api/urls.py +++ b/api/urls.py @@ -5,6 +5,7 @@ from api import views router = DefaultRouter() router.register(r'auth', views.AuthViewSet, base_name="auth") +router.register(r'entries', views.EntryViewSet, base_name='entries') urlpatterns = [ url(r'^', include(router.urls)), diff --git a/api/views.py b/api/views.py index 02db232..f33d156 100644 --- a/api/views.py +++ b/api/views.py @@ -1,4 +1,5 @@ -import json +from api import models, serializers +from api.permissions import IsOwner from django.contrib.auth import login, authenticate from rest_framework import status, permissions, viewsets @@ -36,3 +37,11 @@ class AuthViewSet(viewsets.ViewSet): login(request, user) return Response(status=status.HTTP_201_CREATED) return Response(status=status.HTTP_401_UNAUTHORIZED) + + +class EntryViewSet(viewsets.ModelViewSet): + serializer_class = serializers.EntrySerializer + permission_classes = (permissions.IsAuthenticated, IsOwner,) + + def get_queryset(self): + return models.Entry.objects.filter(user=self.request.user) diff --git a/lesspass/settings.py b/lesspass/settings.py index c728a77..40787ee 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -125,7 +125,8 @@ REST_FRAMEWORK = { ), 'DEFAULT_PARSER_CLASSES': ( 'rest_framework.parsers.JSONParser', - ) + ), + 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } AUTHENTICATION_BACKENDS = ( diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..9083937 --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,2 @@ +-r requirements.txt +factory-boy==2.6.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 983d990..a344e93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django==1.9.1 djangorestframework==3.3.2 -smartconfigparser==0.1.1 \ No newline at end of file +smartconfigparser==0.1.1 +django-allauth==0.24.1 \ No newline at end of file From 4bbc01af4e29859956b716534ec48ac5107e6f27 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 7 Jan 2016 22:52:47 +0100 Subject: [PATCH 03/93] add travis test file --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0d87943 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +python: + - "3.4" + - "3.5" +install: + - pip install -r requirements.dev.txt +script: + - python manage.py test \ No newline at end of file From f696a27081f7a5f0a440582dc61d4be9dd6e9b6c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 7 Jan 2016 23:04:31 +0100 Subject: [PATCH 04/93] update documentation --- .travis.yml | 11 +++++------ README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d87943..ed14d72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: python python: - - "3.4" - - "3.5" -install: - - pip install -r requirements.dev.txt -script: - - python manage.py test \ No newline at end of file + - 3.4 + - 3.5 + +install: pip install -r requirements.dev.txt +script: python manage.py test \ No newline at end of file diff --git a/README.md b/README.md index e69de29..6b03067 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,26 @@ +[![Build Status](https://travis-ci.org/oslab-fr/lesspass-server.svg)](https://travis-ci.org/oslab-fr/lesspass-server) + +# lesspass-server + +lesspass-server is the CRUD API for lesspass + +## requirements + + * python 3.4 + +## install + +install dependencies + + pip install -r requirements.dev.txt + +start application + + python manage.py runserver + + +## tests + +run tests + + python manage.py test \ No newline at end of file From 5f470249594a936083a153a362662e107f0dbf9c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 14 Jan 2016 11:57:48 +0100 Subject: [PATCH 05/93] add docker files --- .dockerignore | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 7 +++ docker-compose.yml | 15 ++++++ lesspass/settings.py | 27 +++++----- manage.py | 0 requirements.txt | 3 +- start.sh | 5 ++ 7 files changed, 177 insertions(+), 17 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml mode change 100644 => 100755 manage.py create mode 100755 start.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..edc4e7a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,137 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# 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/ +### Node template +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git +node_modules +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a24b034 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.4 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /app +WORKDIR /app +ADD requirements.txt /app/ +RUN pip install -r requirements.txt +ADD . /app/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..dfc6887 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +db: + image: postgres:9.5 + restart: always + volumes: + - dbdata:/var/lib/postgresql/data +web: + restart: always + build: . + command: ./start.sh + volumes: + - .:/code + ports: + - "8000:8000" + links: + - db diff --git a/lesspass/settings.py b/lesspass/settings.py index 40787ee..f2a8ed7 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -42,9 +42,7 @@ INSTALLED_APPS = [ 'django.contrib.sites', 'allauth', 'allauth.account', - 'allauth.socialaccount', - - 'allauth.socialaccount.providers.persona', + 'allauth.socialaccount' ] MIDDLEWARE_CLASSES = [ @@ -63,8 +61,7 @@ ROOT_URLCONF = 'lesspass.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - ], + 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -81,11 +78,18 @@ WSGI_APPLICATION = 'lesspass.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': config.get('DATABASE', 'engine', 'django.db.backends.postgresql_psycopg2'), + 'NAME': config.get('DATABASE', 'name', 'postgres'), + 'USER': config.get('DATABASE', 'user', 'postgres'), + 'PASSWORD': config.get('DATABASE', 'password', ''), + 'HOST': config.get('DATABASE', 'host', 'db'), + 'PORT': config.get('DATABASE', 'port', '5432'), } } +# Password validation +# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators + AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', @@ -136,15 +140,6 @@ AUTHENTICATION_BACKENDS = ( SITE_ID = 1 -SOCIALACCOUNT_PROVIDERS = { - 'persona': { - 'AUDIENCE': config.get('DJANGO', 'PERSONA_AUDIENCE', 'https://lesspass.com'), - 'REQUEST_PARAMETERS': { - 'siteName': config.get('DJANGO', 'PERSONA_SITE_NAME', 'lesspass') - } - } -} - ACCOUNT_AUTHENTICATION_METHOD = "email" ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_USERNAME_REQUIRED = False diff --git a/manage.py b/manage.py old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt index a344e93..550d787 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Django==1.9.1 djangorestframework==3.3.2 smartconfigparser==0.1.1 -django-allauth==0.24.1 \ No newline at end of file +django-allauth==0.24.1 +psycopg2==2.6.1 diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..bd17332 --- /dev/null +++ b/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cd /app +python manage.py migrate +python manage.py runserver 0.0.0.0:8000 \ No newline at end of file From bea20cade7c9928ce640f7bf5325823edde0a710 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 14 Jan 2016 12:29:21 +0100 Subject: [PATCH 06/93] modify travis file --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ed14d72..5a22598 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,11 @@ language: python python: - 3.4 - 3.5 - install: pip install -r requirements.dev.txt -script: python manage.py test \ No newline at end of file +script: python manage.py test +services: + - postgresql +addons: + postgresql: "9.5" +before_script: + - psql -c 'create database db;' -U postgres \ No newline at end of file From b071e3dadf6bb31aac5a201ce64e3feae69b8101 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 14 Jan 2016 14:56:56 +0100 Subject: [PATCH 07/93] add docker compose for production --- .gitignore | 2 +- .travis.yml | 10 +++++----- config/config.test.ini | 7 +++++++ docker-compose.production.yml | 13 +++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 config/config.test.ini create mode 100644 docker-compose.production.yml diff --git a/.gitignore b/.gitignore index 7323d4f..c37c97d 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,7 @@ target/ [Ss]cripts pyvenv.cfg pip-selfcheck.json -/config +/config/config.ini *.sqlite3 /frontend/node_modules .idea/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5a22598..71a2a4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,11 @@ language: python python: - 3.4 - 3.5 -install: pip install -r requirements.dev.txt -script: python manage.py test -services: - - postgresql addons: postgresql: "9.5" +services: + - postgresql before_script: - - psql -c 'create database db;' -U postgres \ No newline at end of file + - mv config/config.test.ini config/config.ini +install: pip install -r requirements.dev.txt +script: python manage.py test diff --git a/config/config.test.ini b/config/config.test.ini new file mode 100644 index 0000000..0666335 --- /dev/null +++ b/config/config.test.ini @@ -0,0 +1,7 @@ +[DATABASE] +engine = django.db.backends.postgresql_psycopg2 +name = postgres +user = postgres +password = +host = localhost +port = 5432 \ No newline at end of file diff --git a/docker-compose.production.yml b/docker-compose.production.yml new file mode 100644 index 0000000..ac69f90 --- /dev/null +++ b/docker-compose.production.yml @@ -0,0 +1,13 @@ +db: + image: postgres:9.5 + restart: always + volumes: + - dbdata:/var/lib/postgresql/data +web: + restart: always + image: oslab/lesspass-drf + command: ./start.sh + ports: + - "8000:8000" + links: + - db From 693afd6e3aea0ea0e6070b9cd040de9edf93b126 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 14 Jan 2016 15:45:27 +0100 Subject: [PATCH 08/93] fix deployment error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 71a2a4e..f1e2675 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ python: - 3.4 - 3.5 addons: - postgresql: "9.5" + postgresql: "9.4" services: - postgresql before_script: From 59fb83889ea0ec744dec3ec3f3b1f4e0b1b14fdc Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 15 Jan 2016 16:06:37 +0100 Subject: [PATCH 09/93] modify docker compose files --- docker-compose.production.yml | 2 +- docker-compose.yml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docker-compose.production.yml b/docker-compose.production.yml index ac69f90..c92e818 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -8,6 +8,6 @@ web: image: oslab/lesspass-drf command: ./start.sh ports: - - "8000:8000" + - "80:8000" links: - db diff --git a/docker-compose.yml b/docker-compose.yml index dfc6887..47b2996 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,8 @@ db: image: postgres:9.5 - restart: always volumes: - dbdata:/var/lib/postgresql/data web: - restart: always build: . command: ./start.sh volumes: From 9a314272315ea4512353d65071c651e80370c83e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 16 Jan 2016 18:16:39 +0100 Subject: [PATCH 10/93] add nginx container --- .travis.yml | 11 ++++++++--- Dockerfile | 10 +++------- __init__.py | 0 docker-compose.production.yml | 13 ------------- docker-compose.yml | 25 ++++++++++++++++++------- lesspass/settings.py | 14 ++++++++------ nginx/Dockerfile | 4 ++++ nginx/conf.d/django.conf | 17 +++++++++++++++++ nginx/nginx.conf | 28 ++++++++++++++++++++++++++++ requirements.dev.txt | 2 -- requirements.txt | 3 +++ start.sh | 4 ++-- 12 files changed, 91 insertions(+), 40 deletions(-) delete mode 100644 __init__.py delete mode 100644 docker-compose.production.yml create mode 100644 nginx/Dockerfile create mode 100644 nginx/conf.d/django.conf create mode 100644 nginx/nginx.conf delete mode 100644 requirements.dev.txt diff --git a/.travis.yml b/.travis.yml index f1e2675..6e1f568 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,12 @@ addons: postgresql: "9.4" services: - postgresql -before_script: - - mv config/config.test.ini config/config.ini -install: pip install -r requirements.dev.txt +env: + - DATABASE_ENGINE=django.db.backends.postgresql_psycopg2 + - DATABASE_NAME=postgres + - DATABASE_USER=postgres + - DATABASE_PASSWORD= + - DATABASE_HOST=localhost + - DATABASE_PORT=5432 +install: pip install -r requirements.txt script: python manage.py test diff --git a/Dockerfile b/Dockerfile index a24b034..ca9b5d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,3 @@ -FROM python:3.4 -ENV PYTHONUNBUFFERED 1 -RUN mkdir /app -WORKDIR /app -ADD requirements.txt /app/ -RUN pip install -r requirements.txt -ADD . /app/ \ No newline at end of file +FROM django:onbuild + +CMD ./start.sh diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/docker-compose.production.yml b/docker-compose.production.yml deleted file mode 100644 index c92e818..0000000 --- a/docker-compose.production.yml +++ /dev/null @@ -1,13 +0,0 @@ -db: - image: postgres:9.5 - restart: always - volumes: - - dbdata:/var/lib/postgresql/data -web: - restart: always - image: oslab/lesspass-drf - command: ./start.sh - ports: - - "80:8000" - links: - - db diff --git a/docker-compose.yml b/docker-compose.yml index 47b2996..cdc67ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,24 @@ db: - image: postgres:9.5 + restart: always + image: postgres:9.4 volumes: - - dbdata:/var/lib/postgresql/data -web: + - postgres_db:/var/lib/postgresql/data +django: + restart: always build: . - command: ./start.sh + expose: + - "8000" volumes: - - .:/code - ports: - - "8000:8000" + - django_www:/usr/src/app/www links: - db + command: ./start.sh +nginx: + restart: always + build: ./nginx/ + ports: + - "80:80" + volumes_from: + - django + links: + - django diff --git a/lesspass/settings.py b/lesspass/settings.py index f2a8ed7..b27eea9 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -78,12 +78,12 @@ WSGI_APPLICATION = 'lesspass.wsgi.application' DATABASES = { 'default': { - 'ENGINE': config.get('DATABASE', 'engine', 'django.db.backends.postgresql_psycopg2'), - 'NAME': config.get('DATABASE', 'name', 'postgres'), - 'USER': config.get('DATABASE', 'user', 'postgres'), - 'PASSWORD': config.get('DATABASE', 'password', ''), - 'HOST': config.get('DATABASE', 'host', 'db'), - 'PORT': config.get('DATABASE', 'port', '5432'), + 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.postgresql_psycopg2'), + 'NAME': os.getenv('DATABASE_NAME', 'postgres'), + 'USER': os.getenv('DATABASE_USER', 'postgres'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD', ''), + 'HOST': os.getenv('DATABASE_HOST', 'db'), + 'PORT': os.getenv('DATABASE_PORT', '5432'), } } @@ -147,3 +147,5 @@ ACCOUNT_LOGIN_ON_PASSWORD_RESET = True ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..edab741 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx + +RUN rm /etc/nginx/conf.d/default.conf +COPY conf.d/django.conf /etc/nginx/conf.d/django.conf diff --git a/nginx/conf.d/django.conf b/nginx/conf.d/django.conf new file mode 100644 index 0000000..01e7c36 --- /dev/null +++ b/nginx/conf.d/django.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + + location /static { + autoindex on; + alias /usr/src/app/www/static; + } + + location / { + proxy_pass http://django:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..b9a5f64 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,28 @@ +worker_processes 1; + +events { + + worker_connections 1024; + +} + +http { + + server { + listen 80 default_server; + server_name _; + + + location /static { + alias /app/www; + } + + location / { + proxy_pass http://web:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + } +} diff --git a/requirements.dev.txt b/requirements.dev.txt deleted file mode 100644 index 9083937..0000000 --- a/requirements.dev.txt +++ /dev/null @@ -1,2 +0,0 @@ --r requirements.txt -factory-boy==2.6.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 550d787..27196d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,6 @@ djangorestframework==3.3.2 smartconfigparser==0.1.1 django-allauth==0.24.1 psycopg2==2.6.1 +gunicorn==19.4.5 +# tests +factory-boy==2.6.0 \ No newline at end of file diff --git a/start.sh b/start.sh index bd17332..f19c263 100755 --- a/start.sh +++ b/start.sh @@ -1,5 +1,5 @@ #!/bin/sh -cd /app python manage.py migrate -python manage.py runserver 0.0.0.0:8000 \ No newline at end of file +python manage.py collectstatic --clear --no-input +gunicorn lesspass.wsgi:application -w 2 -b :8000 From a684f5e8521e50c01c1e7b157e07b30f209e3778 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 16 Jan 2016 18:32:13 +0100 Subject: [PATCH 11/93] fix env variables for travis --- .travis.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e1f568..e332ccd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,6 @@ addons: services: - postgresql env: - - DATABASE_ENGINE=django.db.backends.postgresql_psycopg2 - - DATABASE_NAME=postgres - - DATABASE_USER=postgres - - DATABASE_PASSWORD= - - DATABASE_HOST=localhost - - DATABASE_PORT=5432 + - DATABASE_ENGINE=django.db.backends.postgresql_psycopg2 DATABASE_NAME=postgres DATABASE_USER=postgres DATABASE_PASSWORD= DATABASE_HOST=localhost DATABASE_PORT=5432 install: pip install -r requirements.txt script: python manage.py test From b37c196ed232ad324d2eac86937bd4a929b9ce48 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 16 Jan 2016 18:38:25 +0100 Subject: [PATCH 12/93] allowed domains for production --- lesspass/settings.py | 2 +- nginx/conf.d/django.conf | 2 +- nginx/nginx.conf | 28 ---------------------------- 3 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 nginx/nginx.conf diff --git a/lesspass/settings.py b/lesspass/settings.py index b27eea9..210d892 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -27,7 +27,7 @@ except: DEBUG = config.getboolean('DJANGO', 'DEBUG', False) -ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1']) +ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '*.oslab.fr', '*.lesspass.com']) INSTALLED_APPS = [ 'api.apps.ApiConfig', diff --git a/nginx/conf.d/django.conf b/nginx/conf.d/django.conf index 01e7c36..a111198 100644 --- a/nginx/conf.d/django.conf +++ b/nginx/conf.d/django.conf @@ -1,6 +1,6 @@ server { listen 80; - server_name localhost; + server_name localhost *.oslab.fr *.lesspass.com; location /static { autoindex on; diff --git a/nginx/nginx.conf b/nginx/nginx.conf deleted file mode 100644 index b9a5f64..0000000 --- a/nginx/nginx.conf +++ /dev/null @@ -1,28 +0,0 @@ -worker_processes 1; - -events { - - worker_connections 1024; - -} - -http { - - server { - listen 80 default_server; - server_name _; - - - location /static { - alias /app/www; - } - - location / { - proxy_pass http://web:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - } - } -} From c08cae038147384dedb6739f2541c5a0cebc91cc Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 17 Jan 2016 19:35:39 +0100 Subject: [PATCH 13/93] fix wild card allowed host in settings --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 210d892..e43c97b 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -27,7 +27,7 @@ except: DEBUG = config.getboolean('DJANGO', 'DEBUG', False) -ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '*.oslab.fr', '*.lesspass.com']) +ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '.oslab.fr', '.lesspass.com']) INSTALLED_APPS = [ 'api.apps.ApiConfig', From 6db74acd3a4a3e6e048b72cc86c615bd1ca4415e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 17 Jan 2016 19:38:16 +0100 Subject: [PATCH 14/93] clean nginx config files --- nginx/Dockerfile | 2 +- nginx/conf.d/django.conf | 17 ----------------- nginx/django.conf | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 nginx/conf.d/django.conf create mode 100644 nginx/django.conf diff --git a/nginx/Dockerfile b/nginx/Dockerfile index edab741..3320224 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,4 +1,4 @@ FROM nginx RUN rm /etc/nginx/conf.d/default.conf -COPY conf.d/django.conf /etc/nginx/conf.d/django.conf +COPY django.conf /etc/nginx/conf.d/django.conf diff --git a/nginx/conf.d/django.conf b/nginx/conf.d/django.conf deleted file mode 100644 index a111198..0000000 --- a/nginx/conf.d/django.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 80; - server_name localhost *.oslab.fr *.lesspass.com; - - location /static { - autoindex on; - alias /usr/src/app/www/static; - } - - location / { - proxy_pass http://django:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - } -} diff --git a/nginx/django.conf b/nginx/django.conf new file mode 100644 index 0000000..a111198 --- /dev/null +++ b/nginx/django.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost *.oslab.fr *.lesspass.com; + + location /static { + autoindex on; + alias /usr/src/app/www/static; + } + + location / { + proxy_pass http://django:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } +} From c58e70d887f2fb3a69bce9baf4d235e260fed775 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 23 Jan 2016 13:30:24 +0100 Subject: [PATCH 15/93] add Dockerfile --- Dockerfile | 3 +++ config/config.test.ini | 7 ------- lesspass/urls.py | 2 +- start.sh | 2 ++ 4 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 config/config.test.ini diff --git a/Dockerfile b/Dockerfile index ca9b5d3..85cbed9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ FROM django:onbuild +RUN apt-get update && apt-get install -y \ + netcat + CMD ./start.sh diff --git a/config/config.test.ini b/config/config.test.ini deleted file mode 100644 index 0666335..0000000 --- a/config/config.test.ini +++ /dev/null @@ -1,7 +0,0 @@ -[DATABASE] -engine = django.db.backends.postgresql_psycopg2 -name = postgres -user = postgres -password = -host = localhost -port = 5432 \ No newline at end of file diff --git a/lesspass/urls.py b/lesspass/urls.py index 153cc5a..3dc64d9 100644 --- a/lesspass/urls.py +++ b/lesspass/urls.py @@ -2,7 +2,7 @@ from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ + url(r'^', include('api.urls')), url(r'^admin/', admin.site.urls), - url(r'^api/', include('api.urls')), url(r'^accounts/', include('allauth.urls')), ] diff --git a/start.sh b/start.sh index f19c263..659265c 100755 --- a/start.sh +++ b/start.sh @@ -1,5 +1,7 @@ #!/bin/sh +while ! nc -z db 5432; do sleep 3; done + python manage.py migrate python manage.py collectstatic --clear --no-input gunicorn lesspass.wsgi:application -w 2 -b :8000 From d523ebcf0945e6ad863cd09e9ee616f51d378e7c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 23 Jan 2016 13:34:25 +0100 Subject: [PATCH 16/93] fix documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b03067..f778015 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ lesspass-server is the CRUD API for lesspass install dependencies - pip install -r requirements.dev.txt + pip install -r requirements.txt start application @@ -23,4 +23,4 @@ start application run tests - python manage.py test \ No newline at end of file + python manage.py test From 5c7c93b72b15dff3817ba1ffb7bf93962ab1ac1e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 26 Jan 2016 22:14:28 +0100 Subject: [PATCH 17/93] remove django alloauth and fix tests --- .dockerignore | 137 --------------------------------------------------- Dockerfile | 6 --- docker-compose.yml | 24 --------- lesspass/settings.py | 14 ------ lesspass/urls.py | 3 +- nginx/Dockerfile | 4 -- nginx/django.conf | 17 ------- requirements.txt | 1 - 8 files changed, 1 insertion(+), 205 deletions(-) delete mode 100644 .dockerignore delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml delete mode 100644 nginx/Dockerfile delete mode 100644 nginx/django.conf diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index edc4e7a..0000000 --- a/.dockerignore +++ /dev/null @@ -1,137 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -### Python template -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# 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/ -### Node template -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git -node_modules -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio - -*.iml - -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties - diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 85cbed9..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM django:onbuild - -RUN apt-get update && apt-get install -y \ - netcat - -CMD ./start.sh diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index cdc67ec..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ -db: - restart: always - image: postgres:9.4 - volumes: - - postgres_db:/var/lib/postgresql/data -django: - restart: always - build: . - expose: - - "8000" - volumes: - - django_www:/usr/src/app/www - links: - - db - command: ./start.sh -nginx: - restart: always - build: ./nginx/ - ports: - - "80:80" - volumes_from: - - django - links: - - django diff --git a/lesspass/settings.py b/lesspass/settings.py index e43c97b..3644f66 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -40,9 +40,6 @@ INSTALLED_APPS = [ 'rest_framework', 'django.contrib.sites', - 'allauth', - 'allauth.account', - 'allauth.socialaccount' ] MIDDLEWARE_CLASSES = [ @@ -87,8 +84,6 @@ DATABASES = { } } -# Password validation -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -135,17 +130,8 @@ REST_FRAMEWORK = { AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', - 'allauth.account.auth_backends.AuthenticationBackend', ) -SITE_ID = 1 - -ACCOUNT_AUTHENTICATION_METHOD = "email" -ACCOUNT_EMAIL_REQUIRED = True -ACCOUNT_USERNAME_REQUIRED = False -ACCOUNT_LOGIN_ON_PASSWORD_RESET = True -ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = False - EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') diff --git a/lesspass/urls.py b/lesspass/urls.py index 3dc64d9..7ffb69f 100644 --- a/lesspass/urls.py +++ b/lesspass/urls.py @@ -2,7 +2,6 @@ from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ - url(r'^', include('api.urls')), + url(r'^api/', include('api.urls')), url(r'^admin/', admin.site.urls), - url(r'^accounts/', include('allauth.urls')), ] diff --git a/nginx/Dockerfile b/nginx/Dockerfile deleted file mode 100644 index 3320224..0000000 --- a/nginx/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM nginx - -RUN rm /etc/nginx/conf.d/default.conf -COPY django.conf /etc/nginx/conf.d/django.conf diff --git a/nginx/django.conf b/nginx/django.conf deleted file mode 100644 index a111198..0000000 --- a/nginx/django.conf +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 80; - server_name localhost *.oslab.fr *.lesspass.com; - - location /static { - autoindex on; - alias /usr/src/app/www/static; - } - - location / { - proxy_pass http://django:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Host $server_name; - } -} diff --git a/requirements.txt b/requirements.txt index 27196d8..d477770 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ Django==1.9.1 djangorestframework==3.3.2 smartconfigparser==0.1.1 -django-allauth==0.24.1 psycopg2==2.6.1 gunicorn==19.4.5 # tests From 36ea4ec31917c6ac1a46f8f5d4de4178e85c6291 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Wed, 27 Jan 2016 10:56:48 +0100 Subject: [PATCH 18/93] add jwt for authentification --- .gitignore | 2 +- api/urls.py | 3 ++- lesspass/settings.py | 18 ++++++++++++------ requirements.txt | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c37c97d..df14443 100644 --- a/.gitignore +++ b/.gitignore @@ -69,7 +69,7 @@ target/ [Ss]cripts pyvenv.cfg pip-selfcheck.json -/config/config.ini +config *.sqlite3 /frontend/node_modules .idea/ \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index c7560e2..5bfab84 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,12 +1,13 @@ +import rest_framework_jwt.views from django.conf.urls import url, include from rest_framework.routers import DefaultRouter from api import views router = DefaultRouter() -router.register(r'auth', views.AuthViewSet, base_name="auth") router.register(r'entries', views.EntryViewSet, base_name='entries') urlpatterns = [ url(r'^', include(router.urls)), + url(r'^auth/', rest_framework_jwt.views.obtain_jwt_token), ] diff --git a/lesspass/settings.py b/lesspass/settings.py index 3644f66..7eab443 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -38,8 +38,6 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', - - 'django.contrib.sites', ] MIDDLEWARE_CLASSES = [ @@ -84,7 +82,6 @@ DATABASES = { } } - AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', @@ -113,11 +110,20 @@ USE_TZ = False STATIC_URL = '/static/' REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',), + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.IsAuthenticated', + ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 20, - 'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.OrderingFilter', - 'rest_framework.filters.SearchFilter',), + 'DEFAULT_FILTER_BACKENDS': ( + 'rest_framework.filters.OrderingFilter', + 'rest_framework.filters.SearchFilter', + ), + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.SessionAuthentication', + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', + ), 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', 'rest_framework.renderers.BrowsableAPIRenderer', diff --git a/requirements.txt b/requirements.txt index d477770..6f52e2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ Django==1.9.1 djangorestframework==3.3.2 +djangorestframework-jwt==1.7.2 smartconfigparser==0.1.1 psycopg2==2.6.1 gunicorn==19.4.5 From a0bcc7467f1d24b1d0a3ef5e01c7acb5a0d0acfb Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 8 Feb 2016 18:33:24 +0100 Subject: [PATCH 19/93] use custom user model with DRF --- Dockerfile | 6 ++++ api/admin.py | 65 +++++++++++++++++++++++++++++++++++++++++- api/migrations/0001_initial.py | 17 +++++++++-- api/models.py | 59 ++++++++++++++++++++++++++++++++++++-- api/urls.py | 2 +- lesspass/settings.py | 2 ++ requirements.txt | 2 +- 7 files changed, 145 insertions(+), 8 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..395170a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM django:onbuild + +RUN apt-get update && apt-get install -y \ + netcat + +CMD ./start.sh diff --git a/api/admin.py b/api/admin.py index 131557b..1f69f63 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,5 +1,68 @@ +from api.models import PasswordInfo, Entry, LessPassUser + +from django import forms from django.contrib import admin -from api.models import PasswordInfo, Entry +from django.contrib.auth.models import Group +from django.contrib.auth.admin import UserAdmin as BaseUserAdmin +from django.contrib.auth.forms import ReadOnlyPasswordHashField + + +class UserCreationForm(forms.ModelForm): + password1 = forms.CharField(label='Password', widget=forms.PasswordInput) + password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput) + + class Meta: + model = LessPassUser + fields = ('email',) + + def clean_password2(self): + password1 = self.cleaned_data.get("password1") + password2 = self.cleaned_data.get("password2") + if password1 and password2 and password1 != password2: + raise forms.ValidationError("Passwords don't match") + return password2 + + def save(self, commit=True): + user = super(UserCreationForm, self).save(commit=False) + user.set_password(self.cleaned_data["password1"]) + if commit: + user.save() + return user + + +class UserChangeForm(forms.ModelForm): + password = ReadOnlyPasswordHashField() + + class Meta: + model = LessPassUser + fields = ('email', 'password', 'is_active', 'is_admin') + + def clean_password(self): + return self.initial["password"] + + +class LessPassUserAdmin(BaseUserAdmin): + form = UserChangeForm + add_form = UserCreationForm + + list_display = ('email', 'is_admin',) + list_filter = ('is_admin',) + fieldsets = ( + (None, {'fields': ('email', 'password')}), + ('Permissions', {'fields': ('is_admin',)}), + ) + add_fieldsets = ( + (None, { + 'classes': ('wide',), + 'fields': ('email', 'password1', 'password2')} + ), + ) + search_fields = ('email',) + ordering = ('email',) + filter_horizontal = () + admin.site.register(Entry) admin.site.register(PasswordInfo) +admin.site.register(LessPassUser, LessPassUserAdmin) +admin.site.unregister(Group) diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py index 751b130..da4a59b 100644 --- a/api/migrations/0001_initial.py +++ b/api/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.1 on 2016-01-07 19:49 +# Generated by Django 1.9.2 on 2016-02-04 21:50 from __future__ import unicode_literals from django.conf import settings @@ -13,11 +13,24 @@ class Migration(migrations.Migration): initial = True dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( + name='LessPassUser', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('email', models.EmailField(max_length=255, unique=True, verbose_name='email address')), + ('is_active', models.BooleanField(default=True)), + ('is_admin', models.BooleanField(default=False)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( name='Entry', fields=[ ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), diff --git a/api/models.py b/api/models.py index d52b7a9..d852ae0 100644 --- a/api/models.py +++ b/api/models.py @@ -1,7 +1,60 @@ import uuid - from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import ( + BaseUserManager, AbstractBaseUser +) + + +class LesspassUserManager(BaseUserManager): + def create_user(self, email, password=None): + if not email: + raise ValueError('Users must have an email address') + + user = self.model( + email=self.normalize_email(email), + ) + + user.set_password(password) + user.save(using=self._db) + return user + + def create_superuser(self, email, password): + user = self.create_user(email, password=password, ) + user.is_admin = True + user.save(using=self._db) + return user + + +class LessPassUser(AbstractBaseUser): + email = models.EmailField(verbose_name='email address', max_length=255, unique=True) + is_active = models.BooleanField(default=True) + is_admin = models.BooleanField(default=False) + + objects = LesspassUserManager() + + USERNAME_FIELD = 'email' + + def get_full_name(self): + return self.email + + def get_short_name(self): + return self.email + + def __str__(self): + return self.email + + def has_perm(self, perm, obj=None): + return True + + def has_module_perms(self, app_label): + return True + + @property + def is_staff(self): + return self.is_admin + + class Meta: + verbose_name_plural = "Users" class DateMixin(models.Model): @@ -27,7 +80,7 @@ class PasswordInfo(models.Model): class Entry(DateMixin): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='entries') + user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='entries') site = models.CharField(max_length=255) password = models.ForeignKey(PasswordInfo) diff --git a/api/urls.py b/api/urls.py index 5bfab84..ae62af5 100644 --- a/api/urls.py +++ b/api/urls.py @@ -9,5 +9,5 @@ router.register(r'entries', views.EntryViewSet, base_name='entries') urlpatterns = [ url(r'^', include(router.urls)), - url(r'^auth/', rest_framework_jwt.views.obtain_jwt_token), + url(r'^sessions/', rest_framework_jwt.views.obtain_jwt_token), ] diff --git a/lesspass/settings.py b/lesspass/settings.py index 7eab443..b528b68 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -141,3 +141,5 @@ AUTHENTICATION_BACKENDS = ( EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') + +AUTH_USER_MODEL = 'api.LessPassUser' diff --git a/requirements.txt b/requirements.txt index 6f52e2a..08c0733 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==1.9.1 +Django==1.9.2 djangorestframework==3.3.2 djangorestframework-jwt==1.7.2 smartconfigparser==0.1.1 From ae18c16ba2622e0b46b8095742a3184db5105bda Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 9 Feb 2016 07:44:12 +0100 Subject: [PATCH 20/93] add www in gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index df14443..668cb57 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,5 @@ pip-selfcheck.json config *.sqlite3 /frontend/node_modules -.idea/ \ No newline at end of file +.idea/ +www/ From 962f1ce21ba04b5326c44de32c339a75ad4e5a1b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 9 Feb 2016 07:47:39 +0100 Subject: [PATCH 21/93] fix error in test factories --- api/tests/factories.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/tests/factories.py b/api/tests/factories.py index 1eb78ae..9e74bcf 100644 --- a/api/tests/factories.py +++ b/api/tests/factories.py @@ -5,12 +5,8 @@ from api import models class UserFactory(factory.DjangoModelFactory): class Meta: - model = models.User - - username = factory.Sequence(lambda n: 'username{0}'.format(n)) - first_name = factory.Faker('first_name') - last_name = factory.Faker('last_name') - email = factory.LazyAttribute(lambda a: '{0}.{1}@oslab.fr'.format(a.first_name, a.last_name).lower()) + model = models.LessPassUser + email = factory.Sequence(lambda n: 'u{0}@lesspass.com'.format(n)) password = factory.PostGenerationMethodCall('set_password', 'password') is_staff = False From bb202ed987ecb703fbafd57276175b5666aa138e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 18 Feb 2016 09:23:37 +0100 Subject: [PATCH 22/93] update travis image link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f778015..271d713 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/oslab-fr/lesspass-server.svg)](https://travis-ci.org/oslab-fr/lesspass-server) +[![Build Status](https://travis-ci.org/lesspass/api.svg?branch=master)](https://travis-ci.org/lesspass/api) # lesspass-server From 16b9828e6bc61cd9cb6bb9599672f6f947b581b4 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Wed, 23 Mar 2016 22:12:11 +0100 Subject: [PATCH 23/93] add supervisord to manage django --- Dockerfile | 18 +++++++++++++++--- README.md | 26 -------------------------- entrypoint.sh | 8 ++++++++ requirements.txt | 4 ++-- start.sh | 7 ------- supervisord.conf | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 38 deletions(-) delete mode 100644 README.md create mode 100644 entrypoint.sh delete mode 100755 start.sh create mode 100755 supervisord.conf diff --git a/Dockerfile b/Dockerfile index 395170a..655c3aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,18 @@ -FROM django:onbuild +FROM python:3.5 +RUN mkdir /backend +WORKDIR /backend RUN apt-get update && apt-get install -y \ - netcat + supervisor \ + netcat \ + && rm -rf /var/lib/apt/lists/* +ADD requirements.txt /backend/ +RUN pip install -r requirements.txt +ADD . /backend/ -CMD ./start.sh +COPY entrypoint.sh / +RUN chmod 755 /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +CMD ["/usr/bin/supervisord"] diff --git a/README.md b/README.md deleted file mode 100644 index 271d713..0000000 --- a/README.md +++ /dev/null @@ -1,26 +0,0 @@ -[![Build Status](https://travis-ci.org/lesspass/api.svg?branch=master)](https://travis-ci.org/lesspass/api) - -# lesspass-server - -lesspass-server is the CRUD API for lesspass - -## requirements - - * python 3.4 - -## install - -install dependencies - - pip install -r requirements.txt - -start application - - python manage.py runserver - - -## tests - -run tests - - python manage.py test diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2104d56 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +while ! nc -z db 5432; do sleep 3; done + +python manage.py migrate +python manage.py collectstatic --clear --no-input + +exec "$@" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 08c0733..54e2c49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -Django==1.9.2 -djangorestframework==3.3.2 +Django==1.9.4 +djangorestframework==3.3.3 djangorestframework-jwt==1.7.2 smartconfigparser==0.1.1 psycopg2==2.6.1 diff --git a/start.sh b/start.sh deleted file mode 100755 index 659265c..0000000 --- a/start.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -while ! nc -z db 5432; do sleep 3; done - -python manage.py migrate -python manage.py collectstatic --clear --no-input -gunicorn lesspass.wsgi:application -w 2 -b :8000 diff --git a/supervisord.conf b/supervisord.conf new file mode 100755 index 0000000..fe59bc8 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true +logfile=/dev/null +pidfile=/var/run/supervisord.pid + +[program:gunicorn] +directory=/backend +command=gunicorn cscreports.wsgi:application -w 2 -b :8000 +autostart=true +autorestart=true +redirect_stderr=true +stdout_logfile=/var/log/lesspass.log +stdout_logfile_maxbytes=5MB +stdout_logfile_backups=5 \ No newline at end of file From 3c7eabd784fdddc7d4ada40d2f89c6f47bcdddb5 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 1 Apr 2016 21:24:36 +0200 Subject: [PATCH 24/93] set jwt authentication class first --- lesspass/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index b528b68..5979251 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -120,9 +120,9 @@ REST_FRAMEWORK = { 'rest_framework.filters.SearchFilter', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.BasicAuthentication', 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', From 388acd33c8798b8a911708f27b186195c436dc6e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 2 Apr 2016 13:59:14 +0200 Subject: [PATCH 25/93] fix error in status code --- api/tests/tests_entries.py | 4 ++-- requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/tests/tests_entries.py b/api/tests/tests_entries.py index 4d7207c..e6a7b03 100644 --- a/api/tests/tests_entries.py +++ b/api/tests/tests_entries.py @@ -7,9 +7,9 @@ from api.tests import factories class LogoutApiTestCase(APITestCase): - def test_get_entries_403(self): + def test_get_entries_401(self): response = self.client.get('/api/entries/') - self.assertEqual(403, response.status_code) + self.assertEqual(401, response.status_code) class LoginApiTestCase(APITestCase): diff --git a/requirements.txt b/requirements.txt index 54e2c49..f00061b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==1.9.4 +Django==1.9.5 djangorestframework==3.3.3 djangorestframework-jwt==1.7.2 smartconfigparser==0.1.1 From b27b3295c323c64fb67f351226a39fb472daf6db Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 4 Apr 2016 09:13:20 +0200 Subject: [PATCH 26/93] add jwt urls --- api/urls.py | 4 +++- lesspass/settings.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/urls.py b/api/urls.py index ae62af5..7dabfbf 100644 --- a/api/urls.py +++ b/api/urls.py @@ -9,5 +9,7 @@ router.register(r'entries', views.EntryViewSet, base_name='entries') urlpatterns = [ url(r'^', include(router.urls)), - url(r'^sessions/', rest_framework_jwt.views.obtain_jwt_token), + url(r'^token-auth/', rest_framework_jwt.views.obtain_jwt_token), + url(r'^token-verify/', rest_framework_jwt.views.verify_jwt_token), + url(r'^token-refresh/', rest_framework_jwt.views.refresh_jwt_token), ] diff --git a/lesspass/settings.py b/lesspass/settings.py index 5979251..db61651 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -138,6 +138,10 @@ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', ) +JWT_AUTH = { + 'JWT_ALLOW_REFRESH': True, +} + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') From 11b553c83dfb301c9f51f1806256bc704df232da Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 4 Apr 2016 16:07:21 +0200 Subject: [PATCH 27/93] set JWT expiration to 12 hours --- lesspass/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index db61651..ffec96a 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -1,4 +1,5 @@ import os +import datetime from smartconfigparser import Config @@ -139,6 +140,7 @@ AUTHENTICATION_BACKENDS = ( ) JWT_AUTH = { + 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=12), 'JWT_ALLOW_REFRESH': True, } From 29ad5fe67cc1e22f4b0114eb605066273474bdad Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 4 Apr 2016 19:32:28 +0200 Subject: [PATCH 28/93] add search and ordering field for entries --- api/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/views.py b/api/views.py index f33d156..9b04780 100644 --- a/api/views.py +++ b/api/views.py @@ -42,6 +42,8 @@ class AuthViewSet(viewsets.ViewSet): class EntryViewSet(viewsets.ModelViewSet): serializer_class = serializers.EntrySerializer permission_classes = (permissions.IsAuthenticated, IsOwner,) + search_fields = ('site', 'email',) + ordering_fields = ('site', 'email', 'created') def get_queryset(self): return models.Entry.objects.filter(user=self.request.user) From ca80f8348e5e79f1df78e6d1ebff85ea8dc44aad Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Wed, 6 Apr 2016 14:11:08 +0200 Subject: [PATCH 29/93] simplify api --- api/migrations/0001_initial.py | 7 ++++--- api/models.py | 5 +++-- api/serializers.py | 10 ++++++---- api/tests/tests_entries.py | 15 ++++----------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/api/migrations/0001_initial.py b/api/migrations/0001_initial.py index da4a59b..6fbce26 100644 --- a/api/migrations/0001_initial.py +++ b/api/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.2 on 2016-02-04 21:50 +# Generated by Django 1.9.5 on 2016-04-06 10:11 from __future__ import unicode_literals from django.conf import settings @@ -27,7 +27,7 @@ class Migration(migrations.Migration): ('is_admin', models.BooleanField(default=False)), ], options={ - 'abstract': False, + 'verbose_name_plural': 'Users', }, ), migrations.CreateModel( @@ -36,7 +36,8 @@ class Migration(migrations.Migration): ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('site', models.CharField(max_length=255)), + ('login', models.CharField(default='', max_length=255)), + ('site', models.CharField(default='', max_length=255)), ('title', models.CharField(blank=True, max_length=255, null=True)), ('username', models.CharField(blank=True, max_length=255, null=True)), ('email', models.EmailField(blank=True, max_length=254, null=True)), diff --git a/api/models.py b/api/models.py index d852ae0..2013300 100644 --- a/api/models.py +++ b/api/models.py @@ -81,7 +81,8 @@ class PasswordInfo(models.Model): class Entry(DateMixin): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='entries') - site = models.CharField(max_length=255) + login = models.CharField(max_length=255, default='') + site = models.CharField(max_length=255, default='') password = models.ForeignKey(PasswordInfo) title = models.CharField(max_length=255, null=True, blank=True) @@ -94,4 +95,4 @@ class Entry(DateMixin): verbose_name_plural = "Entries" def __str__(self): - return self.title + return str(self.id) diff --git a/api/serializers.py b/api/serializers.py index a75310c..92877c7 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -30,11 +30,13 @@ class PasswordInfoSerializer(serializers.ModelSerializer): class EntrySerializer(serializers.ModelSerializer): + site = serializers.CharField(allow_blank=True) + login = serializers.CharField(allow_blank=True) password = PasswordInfoSerializer() class Meta: model = models.Entry - fields = ('id', 'site', 'password', 'title', 'username', 'email', 'description', 'url', 'created', 'modified') + fields = ('id', 'site', 'login', 'password', 'created', 'modified') read_only_fields = ('created', 'modified') def create(self, validated_data): @@ -45,10 +47,10 @@ class EntrySerializer(serializers.ModelSerializer): def update(self, instance, validated_data): password_data = validated_data.pop('password') - passwordInfo = instance.password + password_info = instance.password for attr, value in password_data.items(): - setattr(passwordInfo, attr, value) - passwordInfo.save() + setattr(password_info, attr, value) + password_info.save() for attr, value in validated_data.items(): setattr(instance, attr, value) diff --git a/api/tests/tests_entries.py b/api/tests/tests_entries.py index e6a7b03..87fbe7a 100644 --- a/api/tests/tests_entries.py +++ b/api/tests/tests_entries.py @@ -50,6 +50,7 @@ class LoginApiTestCase(APITestCase): def test_create_entry(self): entry = { "site": "twitter", + "login": "guillaume@oslab.fr", "password": { "counter": 1, "settings": [ @@ -60,11 +61,6 @@ class LoginApiTestCase(APITestCase): ], "length": 12 }, - "title": "twitter", - "username": "guillaume20100", - "email": "guillaume@oslab.fr", - "description": "", - "url": "https://twitter.com/" } self.assertEqual(0, models.Entry.objects.count()) self.assertEqual(0, models.PasswordInfo.objects.count()) @@ -77,6 +73,7 @@ class LoginApiTestCase(APITestCase): self.assertNotEqual('facebook', entry.site) new_entry = { "site": "facebook", + "login": "", "password": { "counter": 1, "settings": [ @@ -86,13 +83,9 @@ class LoginApiTestCase(APITestCase): ], "length": 12 }, - "title": "facebook", - "username": "", - "email": "", - "description": "", - "url": "https://facebook.com/" } - self.client.put('/api/entries/%s/' % entry.id, new_entry) + request = self.client.put('/api/entries/%s/' % entry.id, new_entry) + self.assertEqual(200, request.status_code, request.content.decode('utf-8')) entry_updated = models.Entry.objects.get(id=entry.id) self.assertEqual('facebook', entry_updated.site) self.assertEqual(3, len(json.loads(entry_updated.password.settings))) From 439a239d65d411ec12821757fe0369605e35474b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 12 Apr 2016 12:57:33 +0200 Subject: [PATCH 30/93] fix deployment errors --- Dockerfile | 3 ++- requirements.txt | 4 ++-- supervisord.conf | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 655c3aa..f6ef956 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN apt-get update && apt-get install -y \ netcat \ && rm -rf /var/lib/apt/lists/* ADD requirements.txt /backend/ +RUN pip install --upgrade pip RUN pip install -r requirements.txt ADD . /backend/ @@ -15,4 +16,4 @@ RUN chmod 755 /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -CMD ["/usr/bin/supervisord"] +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/requirements.txt b/requirements.txt index f00061b..0f5130e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ Django==1.9.5 djangorestframework==3.3.3 -djangorestframework-jwt==1.7.2 +djangorestframework-jwt==1.8.0 smartconfigparser==0.1.1 psycopg2==2.6.1 gunicorn==19.4.5 # tests -factory-boy==2.6.0 \ No newline at end of file +factory-boy==2.6.1 \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf index fe59bc8..78ddd8f 100755 --- a/supervisord.conf +++ b/supervisord.conf @@ -5,7 +5,7 @@ pidfile=/var/run/supervisord.pid [program:gunicorn] directory=/backend -command=gunicorn cscreports.wsgi:application -w 2 -b :8000 +command=gunicorn lesspass.wsgi:application -w 2 -b :8000 autostart=true autorestart=true redirect_stderr=true From c6d4db12d674b1441307fa5af8911fd29c68a5bd Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 17 May 2016 15:56:56 +0200 Subject: [PATCH 31/93] standardization of sub modules --- license | 21 +++++++++++++++++++++ readme.md | 7 +++++++ 2 files changed, 28 insertions(+) create mode 100644 license create mode 100644 readme.md diff --git a/license b/license new file mode 100644 index 0000000..6a8501b --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Guillaume Vincent (guillaumevincent.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..5a6d882 --- /dev/null +++ b/readme.md @@ -0,0 +1,7 @@ +[![Build Status](https://travis-ci.org/lesspass/api.svg?branch=master)](https://travis-ci.org/lesspass/api) + +# LessPass Backend + +api server with django rest framework for LessPass password manager + +[lesspass submodule](https://github.com/lesspass/lesspass) \ No newline at end of file From 0541a9e19bff94e1bd3933822db991c5220040ba Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 3 Jun 2016 12:14:17 +0200 Subject: [PATCH 32/93] add djoser for user management --- api/urls.py | 7 ++++--- lesspass/settings.py | 1 + requirements.txt | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/urls.py b/api/urls.py index 7dabfbf..442f4ce 100644 --- a/api/urls.py +++ b/api/urls.py @@ -9,7 +9,8 @@ router.register(r'entries', views.EntryViewSet, base_name='entries') urlpatterns = [ url(r'^', include(router.urls)), - url(r'^token-auth/', rest_framework_jwt.views.obtain_jwt_token), - url(r'^token-verify/', rest_framework_jwt.views.verify_jwt_token), - url(r'^token-refresh/', rest_framework_jwt.views.refresh_jwt_token), + url(r'^tokens/auth/', rest_framework_jwt.views.obtain_jwt_token), + url(r'^tokens/verify/', rest_framework_jwt.views.verify_jwt_token), + url(r'^tokens/refresh/', rest_framework_jwt.views.refresh_jwt_token), + url(r'^auth/', include('djoser.urls')), ] diff --git a/lesspass/settings.py b/lesspass/settings.py index ffec96a..d4ed5e1 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'djoser' ] MIDDLEWARE_CLASSES = [ diff --git a/requirements.txt b/requirements.txt index 0f5130e..8d08e6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,6 @@ djangorestframework-jwt==1.8.0 smartconfigparser==0.1.1 psycopg2==2.6.1 gunicorn==19.4.5 +djoser==0.4.3 # tests factory-boy==2.6.1 \ No newline at end of file From b9a61e96852bb85d9304685b8f20e0d4ddcfee53 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 3 Jun 2016 15:09:41 +0200 Subject: [PATCH 33/93] fix documentation --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5a6d882..88a182d 100644 --- a/readme.md +++ b/readme.md @@ -4,4 +4,4 @@ api server with django rest framework for LessPass password manager -[lesspass submodule](https://github.com/lesspass/lesspass) \ No newline at end of file +see [lesspass](https://github.com/lesspass/lesspass) project \ No newline at end of file From 2f5f1321b12269ea338ab06fb75e2659f41c8eb5 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 4 Jun 2016 20:18:44 +0200 Subject: [PATCH 34/93] improve admin page for better management --- api/admin.py | 23 ++++++++++++++++++++--- lesspass/settings.py | 2 -- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/api/admin.py b/api/admin.py index 1f69f63..5b97155 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,3 +1,4 @@ +from api import models from api.models import PasswordInfo, Entry, LessPassUser from django import forms @@ -5,6 +6,7 @@ from django.contrib import admin from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.forms import ReadOnlyPasswordHashField +from django.db.models import Count class UserCreationForm(forms.ModelForm): @@ -45,8 +47,8 @@ class LessPassUserAdmin(BaseUserAdmin): form = UserChangeForm add_form = UserCreationForm - list_display = ('email', 'is_admin',) - list_filter = ('is_admin',) + list_display = ('email', 'is_admin', 'column_entries_count') + list_filter = ('is_admin', 'is_active') fieldsets = ( (None, {'fields': ('email', 'password')}), ('Permissions', {'fields': ('is_admin',)}), @@ -61,8 +63,23 @@ class LessPassUserAdmin(BaseUserAdmin): ordering = ('email',) filter_horizontal = () + def get_queryset(self, request): + return models.LessPassUser.objects.annotate(entries_count=Count('entries')) -admin.site.register(Entry) + def column_entries_count(self, instance): + return instance.entries_count + + column_entries_count.short_description = 'Entries count' + column_entries_count.admin_order_field = 'entries_count' + + +class EntryAdmin(admin.ModelAdmin): + list_display = ('id', 'user',) + search_fields = ('user__email',) + ordering = ('user',) + + +admin.site.register(Entry, EntryAdmin) admin.site.register(PasswordInfo) admin.site.register(LessPassUser, LessPassUserAdmin) admin.site.unregister(Group) diff --git a/lesspass/settings.py b/lesspass/settings.py index d4ed5e1..58a6c0a 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -123,8 +123,6 @@ REST_FRAMEWORK = { ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', - 'rest_framework.authentication.BasicAuthentication', - 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', From 1564042f3561a9e282588ee4ba968970490353b4 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 4 Jun 2016 22:58:51 +0200 Subject: [PATCH 35/93] update readme --- readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/readme.md b/readme.md index 88a182d..7eea1ab 100644 --- a/readme.md +++ b/readme.md @@ -4,4 +4,16 @@ api server with django rest framework for LessPass password manager + - python 3 + - django rest framework + - django rest framework jwt + - djoser + - postgresql + - gunicorn + +## Tests + + pip install -r requirements.txt + python manage.py test + see [lesspass](https://github.com/lesspass/lesspass) project \ No newline at end of file From d6ada08f13415eeb4664dd982bcadafe911ca646 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 4 Jun 2016 23:03:49 +0200 Subject: [PATCH 36/93] update django to 1.9.6 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8d08e6d..5d8a4b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==1.9.5 +Django==1.9.6 djangorestframework==3.3.3 djangorestframework-jwt==1.8.0 smartconfigparser==0.1.1 From 536a57270a36d1ed64e0ac9c099f76fc8a7e8c3a Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 6 Jun 2016 08:48:50 +0200 Subject: [PATCH 37/93] update documentation --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7eea1ab..877207f 100644 --- a/readme.md +++ b/readme.md @@ -16,4 +16,4 @@ api server with django rest framework for LessPass password manager pip install -r requirements.txt python manage.py test -see [lesspass](https://github.com/lesspass/lesspass) project \ No newline at end of file +see [LessPass](https://github.com/lesspass/lesspass) project \ No newline at end of file From b6f57480139676803389303b7400603f297b95cf Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 18 Jun 2016 13:40:49 +0200 Subject: [PATCH 38/93] remove bad allowed host --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 58a6c0a..29bf1de 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -28,7 +28,7 @@ except: DEBUG = config.getboolean('DJANGO', 'DEBUG', False) -ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '.oslab.fr', '.lesspass.com']) +ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '.lesspass.com']) INSTALLED_APPS = [ 'api.apps.ApiConfig', From bd1c0d3ab0013706405811d1be587c92521a3caf Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 18 Jun 2016 13:41:45 +0200 Subject: [PATCH 39/93] move to alpine container --- Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6ef956..bf16e45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ -FROM python:3.5 +FROM python:3.5-alpine RUN mkdir /backend WORKDIR /backend -RUN apt-get update && apt-get install -y \ - supervisor \ - netcat \ - && rm -rf /var/lib/apt/lists/* +RUN apk update && apk upgrade +RUN apk add bash supervisor netcat-openbsd postgresql-dev gcc python3-dev musl-dev + ADD requirements.txt /backend/ RUN pip install --upgrade pip RUN pip install -r requirements.txt From 412eb497b3765141bd16e501344148b65aa8425b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 1 Jul 2016 16:13:33 +0200 Subject: [PATCH 40/93] 12 factor app logging system --- lesspass/settings.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index 29bf1de..de5bbe1 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -148,3 +148,17 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') AUTH_USER_MODEL = 'api.LessPassUser' + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + } + }, + 'root': { + 'handlers': ['console'], + 'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'), + } +} From 924d091d29435b0bf79988d1ece04883586036d1 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 23 Sep 2016 16:25:37 +0200 Subject: [PATCH 41/93] redirect supervisor logs to stdout and stderr --- supervisord.conf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/supervisord.conf b/supervisord.conf index 78ddd8f..caec4c0 100755 --- a/supervisord.conf +++ b/supervisord.conf @@ -9,6 +9,7 @@ command=gunicorn lesspass.wsgi:application -w 2 -b :8000 autostart=true autorestart=true redirect_stderr=true -stdout_logfile=/var/log/lesspass.log -stdout_logfile_maxbytes=5MB -stdout_logfile_backups=5 \ No newline at end of file +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 From bd9fdc537cba02f085a10f2c5c94458cc683146b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 23 Sep 2016 16:26:22 +0200 Subject: [PATCH 42/93] update python packages to latest versions --- requirements.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5d8a4b4..9ec002a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -Django==1.9.6 -djangorestframework==3.3.3 +Django==1.10.1 +djangorestframework==3.4.7 djangorestframework-jwt==1.8.0 -smartconfigparser==0.1.1 -psycopg2==2.6.1 -gunicorn==19.4.5 -djoser==0.4.3 +psycopg2==2.6.2 +gunicorn==19.6.0 +djoser==0.5.1 +envparse==0.2.0 # tests -factory-boy==2.6.1 \ No newline at end of file +factory-boy==2.7.0 From 172919e11f4f8e17ca2e49f06f1f0c49ffb25f68 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 23 Sep 2016 16:27:06 +0200 Subject: [PATCH 43/93] update gitignore file to add .sqlite3 files --- .gitignore | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 668cb57..319840e 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ htmlcov/ nosetests.xml coverage.xml *,cover +.hypothesis/ # Translations *.mo @@ -52,25 +53,41 @@ coverage.xml # Django stuff: *.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ -### VirtualEnv template -# Virtualenv -# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ -.Python -[Bb]in -[Ii]nclude -[Ll]ib -/mysqlclient-1.3.7-cp34-none-win32.whl -[Ss]cripts -pyvenv.cfg -pip-selfcheck.json -config -*.sqlite3 -/frontend/node_modules -.idea/ -www/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +/db.sqlite3 From c279a8e7400df45c7df0253dad3c4f116927c1ee Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 23 Sep 2016 16:27:28 +0200 Subject: [PATCH 44/93] use python3.5 default image in Docker --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf16e45..f6ef956 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ -FROM python:3.5-alpine +FROM python:3.5 RUN mkdir /backend WORKDIR /backend -RUN apk update && apk upgrade -RUN apk add bash supervisor netcat-openbsd postgresql-dev gcc python3-dev musl-dev - +RUN apt-get update && apt-get install -y \ + supervisor \ + netcat \ + && rm -rf /var/lib/apt/lists/* ADD requirements.txt /backend/ RUN pip install --upgrade pip RUN pip install -r requirements.txt From 4dca7f327a5fbbd374cbf9f962ad7b7407bbb9fc Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 24 Sep 2016 10:12:46 +0200 Subject: [PATCH 45/93] add password model --- api/migrations/0002_password.py | 38 ++++++++++++++++++++++++++++++++++++++ api/models.py | 18 ++++++++++++++++++ config/config.ini | 3 +++ lesspass/settings.py | 12 ++++++------ 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 api/migrations/0002_password.py create mode 100644 config/config.ini diff --git a/api/migrations/0002_password.py b/api/migrations/0002_password.py new file mode 100644 index 0000000..376cf50 --- /dev/null +++ b/api/migrations/0002_password.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-09-24 08:11 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Password', + fields=[ + ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), + ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('login', models.CharField(blank=True, max_length=255, null=True)), + ('site', models.CharField(blank=True, max_length=255, null=True)), + ('lowercase', models.BooleanField(default=True)), + ('uppercase', models.BooleanField(default=True)), + ('symbol', models.BooleanField(default=True)), + ('number', models.BooleanField(default=True)), + ('counter', models.IntegerField(default=1)), + ('length', models.IntegerField(default=12)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='passwords', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/api/models.py b/api/models.py index 2013300..c9b0b54 100644 --- a/api/models.py +++ b/api/models.py @@ -65,6 +65,24 @@ class DateMixin(models.Model): abstract = True +class Password(DateMixin): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='passwords') + login = models.CharField(max_length=255, null=True, blank=True) + site = models.CharField(max_length=255, null=True, blank=True) + + lowercase = models.BooleanField(default=True) + uppercase = models.BooleanField(default=True) + symbol = models.BooleanField(default=True) + number = models.BooleanField(default=True) + + counter = models.IntegerField(default=1) + length = models.IntegerField(default=12) + + def __str__(self): + return str(self.id) + + class PasswordInfo(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) counter = models.IntegerField(default=1) diff --git a/config/config.ini b/config/config.ini new file mode 100644 index 0000000..50358b9 --- /dev/null +++ b/config/config.ini @@ -0,0 +1,3 @@ +[DJANGO] +secret_key = 1*5j2@2s1x12h(vm^yx_e^k5jz)n^l=bre4^tgd1*8m#oo5xxy + diff --git a/lesspass/settings.py b/lesspass/settings.py index de5bbe1..ab0cabf 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -75,12 +75,12 @@ WSGI_APPLICATION = 'lesspass.wsgi.application' DATABASES = { 'default': { - 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.postgresql_psycopg2'), - 'NAME': os.getenv('DATABASE_NAME', 'postgres'), - 'USER': os.getenv('DATABASE_USER', 'postgres'), - 'PASSWORD': os.getenv('DATABASE_PASSWORD', ''), - 'HOST': os.getenv('DATABASE_HOST', 'db'), - 'PORT': os.getenv('DATABASE_PORT', '5432'), + 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.sqlite3'), + 'NAME': os.getenv('DATABASE_NAME', 'db.sqlite3'), + 'USER': os.getenv('DATABASE_USER', None), + 'PASSWORD': os.getenv('DATABASE_PASSWORD', None), + 'HOST': os.getenv('DATABASE_HOST', None), + 'PORT': os.getenv('DATABASE_PORT', None), } } From c24834fd4cd411a2565f0e007ddf3b43a4c7ffc9 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 24 Sep 2016 10:43:11 +0200 Subject: [PATCH 46/93] migrate entries to passwords --- api/admin.py | 7 ++++ api/data_migrations.py | 15 ++++++++ api/migrations/0003_mv_entries_to_password.py | 23 ++++++++++++ api/tests/factories.py | 10 ++++++ api/tests/tests_data_migrations.py | 51 +++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 api/data_migrations.py create mode 100644 api/migrations/0003_mv_entries_to_password.py create mode 100644 api/tests/tests_data_migrations.py diff --git a/api/admin.py b/api/admin.py index 5b97155..fb08d8c 100644 --- a/api/admin.py +++ b/api/admin.py @@ -79,6 +79,13 @@ class EntryAdmin(admin.ModelAdmin): ordering = ('user',) +class PasswordAdmin(admin.ModelAdmin): + list_display = ('id', 'user',) + search_fields = ('user__email',) + ordering = ('user',) + + +admin.site.register(models.Password, PasswordAdmin) admin.site.register(Entry, EntryAdmin) admin.site.register(PasswordInfo) admin.site.register(LessPassUser, LessPassUserAdmin) diff --git a/api/data_migrations.py b/api/data_migrations.py new file mode 100644 index 0000000..655dcc3 --- /dev/null +++ b/api/data_migrations.py @@ -0,0 +1,15 @@ +import json + +from api import models + + +def create_password_with(entry): + settings = json.dumps(entry.password.settings) + lowercase = 'lowercase' in settings + uppercase = 'uppercase' in settings + symbol = 'symbols' in settings + number = 'numbers' in settings + user = models.LessPassUser.objects.get(id=entry.user.id) + models.Password.objects.create(id=entry.id, site=entry.site, login=entry.login, user=user, + lowercase=lowercase, uppercase=uppercase, symbol=symbol, number=number, + counter=entry.password.counter, length=entry.password.length) diff --git a/api/migrations/0003_mv_entries_to_password.py b/api/migrations/0003_mv_entries_to_password.py new file mode 100644 index 0000000..ec11eec --- /dev/null +++ b/api/migrations/0003_mv_entries_to_password.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-09-24 08:13 +from __future__ import unicode_literals + +from django.db import migrations + +from api.data_migrations import create_password_with + + +def mv_entries_to_password(apps, schema_editor): + Entry = apps.get_model("api", "Entry") + for entry in Entry.objects.all(): + create_password_with(entry) + + +class Migration(migrations.Migration): + dependencies = [ + ('api', '0002_password'), + ] + + operations = [ + migrations.RunPython(mv_entries_to_password), + ] diff --git a/api/tests/factories.py b/api/tests/factories.py index 9e74bcf..15df854 100644 --- a/api/tests/factories.py +++ b/api/tests/factories.py @@ -6,6 +6,7 @@ from api import models class UserFactory(factory.DjangoModelFactory): class Meta: model = models.LessPassUser + email = factory.Sequence(lambda n: 'u{0}@lesspass.com'.format(n)) password = factory.PostGenerationMethodCall('set_password', 'password') is_staff = False @@ -33,3 +34,12 @@ class EntryFactory(factory.DjangoModelFactory): site = 'twitter' username = 'guillaume20100' url = 'https://twitter.com/' + + +class PasswordFactory(factory.DjangoModelFactory): + class Meta: + model = models.Password + + user = factory.SubFactory(UserFactory) + login = 'admin@oslab.fr' + site = 'lesspass.com' diff --git a/api/tests/tests_data_migrations.py b/api/tests/tests_data_migrations.py new file mode 100644 index 0000000..4933222 --- /dev/null +++ b/api/tests/tests_data_migrations.py @@ -0,0 +1,51 @@ +from django.test import TestCase + +from api import models +from api.tests import factories +from api.data_migrations import create_password_with + + +class DataMigrationTestCase(TestCase): + def setUp(self): + self.user = factories.UserFactory() + + def test_create_password_with_entry(self): + entry = factories.EntryFactory(user=self.user) + + create_password_with(entry) + + password = models.Password.objects.get(id=entry.id) + self.assertEqual(entry.user, password.user) + self.assertEqual(entry.login, password.login) + self.assertEqual(entry.site, password.site) + + def test_create_password_with_entry_copy_password_info(self): + entry = factories.EntryFactory(user=self.user) + + create_password_with(entry) + + password = models.Password.objects.get(id=entry.id) + self.assertTrue(password.lowercase) + self.assertTrue(password.uppercase) + self.assertTrue(password.symbol) + self.assertTrue(password.number) + self.assertEqual(entry.password.length, password.length) + self.assertEqual(entry.password.counter, password.counter) + + def test_create_password_robust(self): + password_info = factories.PasswordInfoFactory(settings='["lowercase", "numbers"]', counter=2, length=14) + entry = factories.EntryFactory(site='migration.com', login='contact@migration.com', + user=self.user, password=password_info) + + create_password_with(entry) + + password = models.Password.objects.get(id=entry.id) + self.assertEqual(self.user, password.user) + self.assertEqual('contact@migration.com', password.login) + self.assertEqual('migration.com', password.site) + self.assertTrue(password.lowercase) + self.assertFalse(password.uppercase) + self.assertFalse(password.symbol) + self.assertTrue(password.number) + self.assertEqual(14, password.length) + self.assertEqual(2, password.counter) From 18543b266fd809ba47a7b226510e73a9b4262942 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 24 Sep 2016 11:08:59 +0200 Subject: [PATCH 47/93] simplify API with simple model password --- api/admin.py | 16 ++--- api/models.py | 4 ++ api/serializers.py | 12 ++++ api/tests/factories.py | 4 +- api/tests/tests_passwords.py | 89 +++++++++++++++++++++++++++ api/urls.py | 2 +- api/views.py | 10 +++ config/config.ini | 3 - lesspass/settings.py | 141 ++++++++++++++++++++++--------------------- 9 files changed, 198 insertions(+), 83 deletions(-) create mode 100644 api/tests/tests_passwords.py delete mode 100644 config/config.ini diff --git a/api/admin.py b/api/admin.py index fb08d8c..271df48 100644 --- a/api/admin.py +++ b/api/admin.py @@ -47,7 +47,7 @@ class LessPassUserAdmin(BaseUserAdmin): form = UserChangeForm add_form = UserCreationForm - list_display = ('email', 'is_admin', 'column_entries_count') + list_display = ('email', 'is_admin', 'column_passwords_count') list_filter = ('is_admin', 'is_active') fieldsets = ( (None, {'fields': ('email', 'password')}), @@ -64,22 +64,22 @@ class LessPassUserAdmin(BaseUserAdmin): filter_horizontal = () def get_queryset(self, request): - return models.LessPassUser.objects.annotate(entries_count=Count('entries')) + return models.LessPassUser.objects.annotate(passwords_count=Count('passwords')) - def column_entries_count(self, instance): - return instance.entries_count + def column_passwords_count(self, instance): + return instance.passwords_count - column_entries_count.short_description = 'Entries count' - column_entries_count.admin_order_field = 'entries_count' + column_passwords_count.short_description = 'Password count' + column_passwords_count.admin_order_field = 'passwords_count' -class EntryAdmin(admin.ModelAdmin): +class PasswordAdmin(admin.ModelAdmin): list_display = ('id', 'user',) search_fields = ('user__email',) ordering = ('user',) -class PasswordAdmin(admin.ModelAdmin): +class EntryAdmin(admin.ModelAdmin): list_display = ('id', 'user',) search_fields = ('user__email',) ordering = ('user',) diff --git a/api/models.py b/api/models.py index c9b0b54..7ae1ac0 100644 --- a/api/models.py +++ b/api/models.py @@ -50,6 +50,10 @@ class LessPassUser(AbstractBaseUser): return True @property + def is_superuser(self): + return self.is_admin + + @property def is_staff(self): return self.is_admin diff --git a/api/serializers.py b/api/serializers.py index 92877c7..4e09357 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -56,3 +56,15 @@ class EntrySerializer(serializers.ModelSerializer): setattr(instance, attr, value) instance.save() return instance + + +class PasswordSerializer(serializers.ModelSerializer): + class Meta: + model = models.Password + fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbol', 'number', 'counter', 'length', + 'created', 'modified') + read_only_fields = ('created', 'modified') + + def create(self, validated_data): + user = self.context['request'].user + return models.Password.objects.create(user=user, **validated_data) diff --git a/api/tests/factories.py b/api/tests/factories.py index 15df854..29ee039 100644 --- a/api/tests/factories.py +++ b/api/tests/factories.py @@ -9,11 +9,11 @@ class UserFactory(factory.DjangoModelFactory): email = factory.Sequence(lambda n: 'u{0}@lesspass.com'.format(n)) password = factory.PostGenerationMethodCall('set_password', 'password') - is_staff = False + is_admin = False class AdminFactory(UserFactory): - is_staff = True + is_admin = True class PasswordInfoFactory(factory.DjangoModelFactory): diff --git a/api/tests/tests_passwords.py b/api/tests/tests_passwords.py new file mode 100644 index 0000000..c70c8bb --- /dev/null +++ b/api/tests/tests_passwords.py @@ -0,0 +1,89 @@ +from rest_framework.test import APITestCase, APIClient + +from api import models +from api.tests import factories + + +class LogoutApiTestCase(APITestCase): + def test_get_passwords_401(self): + response = self.client.get('/api/passwords/') + self.assertEqual(401, response.status_code) + + +class LoginApiTestCase(APITestCase): + def setUp(self): + self.user = factories.UserFactory() + self.client = APIClient() + self.client.force_authenticate(user=self.user) + + def test_get_empty_passwords(self): + request = self.client.get('/api/passwords/') + self.assertEqual(0, len(request.data['results'])) + + def test_retrieve_its_own_passwords(self): + password = factories.PasswordFactory(user=self.user) + request = self.client.get('/api/passwords/') + self.assertEqual(1, len(request.data['results'])) + self.assertEqual(password.site, request.data['results'][0]['site']) + + def test_cant_retrieve_other_passwords(self): + not_my_password = factories.PasswordFactory(user=factories.UserFactory()) + request = self.client.get('/api/passwords/%s/' % not_my_password.id) + self.assertEqual(404, request.status_code) + + def test_delete_its_own_passwords(self): + password = factories.PasswordFactory(user=self.user) + self.assertEqual(1, models.Password.objects.all().count()) + request = self.client.delete('/api/passwords/%s/' % password.id) + self.assertEqual(204, request.status_code) + self.assertEqual(0, models.Password.objects.all().count()) + + def test_cant_delete_other_password(self): + not_my_password = factories.PasswordFactory(user=factories.UserFactory()) + self.assertEqual(1, models.Password.objects.all().count()) + request = self.client.delete('/api/passwords/%s/' % not_my_password.id) + self.assertEqual(404, request.status_code) + self.assertEqual(1, models.Password.objects.all().count()) + + def test_create_password(self): + password = { + "site": "lesspass.com", + "login": "test@oslab.fr", + "lowercase": True, + "uppercase": True, + "number": True, + "symbol": True, + "counter": 1, + "length": 12 + } + self.assertEqual(0, models.Password.objects.count()) + self.client.post('/api/passwords/', password) + self.assertEqual(1, models.Password.objects.count()) + + def test_update_password(self): + password = factories.PasswordFactory(user=self.user) + self.assertNotEqual('facebook.com', password.site) + new_password = { + "site": "facebook.com", + "login": "test@oslab.fr", + "lowercase": True, + "uppercase": True, + "number": True, + "symbol": True, + "counter": 1, + "length": 12 + } + request = self.client.put('/api/passwords/%s/' % password.id, new_password) + self.assertEqual(200, request.status_code, request.content.decode('utf-8')) + password_updated = models.Password.objects.get(id=password.id) + self.assertEqual('facebook.com', password_updated.site) + + def test_cant_update_other_password(self): + not_my_password = factories.PasswordFactory(user=factories.UserFactory()) + self.assertEqual('lesspass.com', not_my_password.site) + new_password = { + "site": "facebook", + } + request = self.client.put('/api/passwords/%s/' % not_my_password.id, new_password) + self.assertEqual(404, request.status_code) + self.assertEqual(1, models.Password.objects.all().count()) diff --git a/api/urls.py b/api/urls.py index 442f4ce..35452c5 100644 --- a/api/urls.py +++ b/api/urls.py @@ -6,11 +6,11 @@ from api import views router = DefaultRouter() router.register(r'entries', views.EntryViewSet, base_name='entries') +router.register(r'passwords', views.PasswordViewSet, base_name='passwords') urlpatterns = [ url(r'^', include(router.urls)), url(r'^tokens/auth/', rest_framework_jwt.views.obtain_jwt_token), - url(r'^tokens/verify/', rest_framework_jwt.views.verify_jwt_token), url(r'^tokens/refresh/', rest_framework_jwt.views.refresh_jwt_token), url(r'^auth/', include('djoser.urls')), ] diff --git a/api/views.py b/api/views.py index 9b04780..4c60094 100644 --- a/api/views.py +++ b/api/views.py @@ -39,6 +39,16 @@ class AuthViewSet(viewsets.ViewSet): return Response(status=status.HTTP_401_UNAUTHORIZED) +class PasswordViewSet(viewsets.ModelViewSet): + serializer_class = serializers.PasswordSerializer + permission_classes = (permissions.IsAuthenticated, IsOwner,) + search_fields = ('site', 'email',) + ordering_fields = ('site', 'email', 'created') + + def get_queryset(self): + return models.Password.objects.filter(user=self.request.user) + + class EntryViewSet(viewsets.ModelViewSet): serializer_class = serializers.EntrySerializer permission_classes = (permissions.IsAuthenticated, IsOwner,) diff --git a/config/config.ini b/config/config.ini deleted file mode 100644 index 50358b9..0000000 --- a/config/config.ini +++ /dev/null @@ -1,3 +0,0 @@ -[DJANGO] -secret_key = 1*5j2@2s1x12h(vm^yx_e^k5jz)n^l=bre4^tgd1*8m#oo5xxy - diff --git a/lesspass/settings.py b/lesspass/settings.py index ab0cabf..5703d90 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -1,37 +1,28 @@ +import logging import os +import random +import sys import datetime - -from smartconfigparser import Config +from envparse import env BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -CONFIG_PATH = os.path.join(BASE_DIR, 'config') -if not os.path.exists(CONFIG_PATH): - os.makedirs(CONFIG_PATH) -CONFIG_FILE = os.path.join(CONFIG_PATH, 'config.ini') -config = Config() -config.read(CONFIG_FILE) +def get_secret_key(secret_key): + if not secret_key: + return "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*(-_=+)") for i in range(50)]) + return secret_key + -try: - SECRET_KEY = config.get('DJANGO', 'SECRET_KEY') -except: - print('SECRET_KEY not found! Generating a new one...') - import random +SECRET_KEY = env('SECRET_KEY', preprocessor=get_secret_key, default=None) - SECRET_KEY = "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$^&*(-_=+)") for i in range(50)]) - if not config.has_section('DJANGO'): - config.add_section('DJANGO') - config.set('DJANGO', 'SECRET_KEY', SECRET_KEY) - with open(CONFIG_FILE, 'wt') as f: - config.write(f) +DEBUG = env.bool('DJANGO_DEBUG', default=True) -DEBUG = config.getboolean('DJANGO', 'DEBUG', False) +ALLOWED_HOSTS = [] -ALLOWED_HOSTS = config.getlist('DJANGO', 'ALLOWED_HOSTS', ['localhost', '127.0.0.1', '.lesspass.com']) +ADMIN = [('Guillaume Vincent', 'guillaume@oslab.fr'), ] INSTALLED_APPS = [ - 'api.apps.ApiConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -39,16 +30,15 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', - 'djoser' + 'api' ] -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] @@ -75,28 +65,20 @@ WSGI_APPLICATION = 'lesspass.wsgi.application' DATABASES = { 'default': { - 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.sqlite3'), - 'NAME': os.getenv('DATABASE_NAME', 'db.sqlite3'), - 'USER': os.getenv('DATABASE_USER', None), - 'PASSWORD': os.getenv('DATABASE_PASSWORD', None), - 'HOST': os.getenv('DATABASE_HOST', None), - 'PORT': os.getenv('DATABASE_PORT', None), + 'ENGINE': env('DATABASE_ENGINE', default='django.db.backends.sqlite3'), + 'NAME': env('DATABASE_NAME', default=os.path.join(BASE_DIR, 'db.sqlite3')), + 'USER': env('DATABASE_USER', default=None), + 'PASSWORD': env('DATABASE_PASSWORD', default=None), + 'HOST': env('DATABASE_HOST', default=None), + 'PORT': env('DATABASE_PORT', default=None), } } AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, + {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, + {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, + {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, + {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] LANGUAGE_CODE = 'en-us' @@ -107,22 +89,52 @@ USE_I18N = True USE_L10N = True -USE_TZ = False +USE_TZ = True STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') + +MEDIA_URL = '/media/' + +MEDIA_ROOT = os.path.join(BASE_DIR, 'www', 'media') + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + } + }, + 'root': { + 'handlers': ['console'], + 'level': env('DJANGO_LOG_LEVEL', default='DEBUG'), + } +} + +AUTH_USER_MODEL = 'api.LessPassUser' + +JWT_AUTH = { + 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=12), + 'JWT_ALLOW_REFRESH': True, +} + +EMAIL_BACKEND = 'django.api.mail.backends.console.EmailBackend' + REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', - 'PAGE_SIZE': 20, + 'PAGE_SIZE': 50, 'DEFAULT_FILTER_BACKENDS': ( 'rest_framework.filters.OrderingFilter', 'rest_framework.filters.SearchFilter', ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', + 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', @@ -134,31 +146,22 @@ REST_FRAMEWORK = { 'TEST_REQUEST_DEFAULT_FORMAT': 'json' } -AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', -) -JWT_AUTH = { - 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=12), - 'JWT_ALLOW_REFRESH': True, -} +class DisableMigrations(object): + def __contains__(self, item): + return True -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + def __getitem__(self, item): + return "notmigrations" -STATIC_ROOT = os.path.join(BASE_DIR, 'www', 'static') -AUTH_USER_MODEL = 'api.LessPassUser' - -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - } - }, - 'root': { - 'handlers': ['console'], - 'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'), - } -} +TESTS_IN_PROGRESS = False +if 'test' in sys.argv[1:] or 'jenkins' in sys.argv[1:]: + logging.disable(logging.CRITICAL) + PASSWORD_HASHERS = ( + 'django.contrib.auth.hashers.MD5PasswordHasher', + ) + DEBUG = False + TEMPLATE_DEBUG = False + TESTS_IN_PROGRESS = True + MIGRATION_MODULES = DisableMigrations() From e4ba809a13d2920f0e76c8a9729cc58d4ceb2a11 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 26 Sep 2016 09:00:59 +0200 Subject: [PATCH 48/93] add CORS support --- lesspass/settings.py | 4 ++++ requirements.txt | 1 + 2 files changed, 5 insertions(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index 5703d90..804bdb5 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -30,12 +30,14 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'corsheaders', 'api' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -43,6 +45,8 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +CORS_ORIGIN_ALLOW_ALL = True + ROOT_URLCONF = 'lesspass.urls' TEMPLATES = [ diff --git a/requirements.txt b/requirements.txt index 9ec002a..c33f6a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Django==1.10.1 +django-cors-middleware==1.3.1 djangorestframework==3.4.7 djangorestframework-jwt==1.8.0 psycopg2==2.6.2 From 3d9182143210a71df06d09e34cad5e814040f8d2 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 27 Sep 2016 18:04:05 +0200 Subject: [PATCH 49/93] modify symbols and numbers fields --- api/data_migrations.py | 6 +++--- api/migrations/0002_password.py | 4 ++-- api/models.py | 4 ++-- api/serializers.py | 2 +- api/tests/tests_data_migrations.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/data_migrations.py b/api/data_migrations.py index 655dcc3..bf4c01c 100644 --- a/api/data_migrations.py +++ b/api/data_migrations.py @@ -7,9 +7,9 @@ def create_password_with(entry): settings = json.dumps(entry.password.settings) lowercase = 'lowercase' in settings uppercase = 'uppercase' in settings - symbol = 'symbols' in settings - number = 'numbers' in settings + symbols = 'symbols' in settings + numbers = 'numbers' in settings user = models.LessPassUser.objects.get(id=entry.user.id) models.Password.objects.create(id=entry.id, site=entry.site, login=entry.login, user=user, - lowercase=lowercase, uppercase=uppercase, symbol=symbol, number=number, + lowercase=lowercase, uppercase=uppercase, symbols=symbols, numbers=numbers, counter=entry.password.counter, length=entry.password.length) diff --git a/api/migrations/0002_password.py b/api/migrations/0002_password.py index 376cf50..473e34b 100644 --- a/api/migrations/0002_password.py +++ b/api/migrations/0002_password.py @@ -25,8 +25,8 @@ class Migration(migrations.Migration): ('site', models.CharField(blank=True, max_length=255, null=True)), ('lowercase', models.BooleanField(default=True)), ('uppercase', models.BooleanField(default=True)), - ('symbol', models.BooleanField(default=True)), - ('number', models.BooleanField(default=True)), + ('symbols', models.BooleanField(default=True)), + ('numbers', models.BooleanField(default=True)), ('counter', models.IntegerField(default=1)), ('length', models.IntegerField(default=12)), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='passwords', to=settings.AUTH_USER_MODEL)), diff --git a/api/models.py b/api/models.py index 7ae1ac0..bd66ea6 100644 --- a/api/models.py +++ b/api/models.py @@ -77,8 +77,8 @@ class Password(DateMixin): lowercase = models.BooleanField(default=True) uppercase = models.BooleanField(default=True) - symbol = models.BooleanField(default=True) - number = models.BooleanField(default=True) + symbols = models.BooleanField(default=True) + numbers = models.BooleanField(default=True) counter = models.IntegerField(default=1) length = models.IntegerField(default=12) diff --git a/api/serializers.py b/api/serializers.py index 4e09357..c14753b 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -61,7 +61,7 @@ class EntrySerializer(serializers.ModelSerializer): class PasswordSerializer(serializers.ModelSerializer): class Meta: model = models.Password - fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbol', 'number', 'counter', 'length', + fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbols', 'numbers', 'counter', 'length', 'created', 'modified') read_only_fields = ('created', 'modified') diff --git a/api/tests/tests_data_migrations.py b/api/tests/tests_data_migrations.py index 4933222..f1c1337 100644 --- a/api/tests/tests_data_migrations.py +++ b/api/tests/tests_data_migrations.py @@ -27,8 +27,8 @@ class DataMigrationTestCase(TestCase): password = models.Password.objects.get(id=entry.id) self.assertTrue(password.lowercase) self.assertTrue(password.uppercase) - self.assertTrue(password.symbol) - self.assertTrue(password.number) + self.assertTrue(password.symbols) + self.assertTrue(password.numbers) self.assertEqual(entry.password.length, password.length) self.assertEqual(entry.password.counter, password.counter) @@ -45,7 +45,7 @@ class DataMigrationTestCase(TestCase): self.assertEqual('migration.com', password.site) self.assertTrue(password.lowercase) self.assertFalse(password.uppercase) - self.assertFalse(password.symbol) - self.assertTrue(password.number) + self.assertFalse(password.symbols) + self.assertTrue(password.numbers) self.assertEqual(14, password.length) self.assertEqual(2, password.counter) From 0953c4d2a538b3c43ce645c6bea1359b22acc59d Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 1 Oct 2016 14:57:13 +0200 Subject: [PATCH 50/93] make API reflect core interface --- api/models.py | 13 ++++++++++++- api/serializers.py | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/models.py b/api/models.py index bd66ea6..b0fdf25 100644 --- a/api/models.py +++ b/api/models.py @@ -80,12 +80,23 @@ class Password(DateMixin): symbols = models.BooleanField(default=True) numbers = models.BooleanField(default=True) - counter = models.IntegerField(default=1) length = models.IntegerField(default=12) + counter = models.IntegerField(default=1) def __str__(self): return str(self.id) + def options(self): + return { + 'lowercase': self.lowercase, + 'uppercase': self.uppercase, + 'symbols': self.symbols, + 'numbers': self.numbers, + 'counter': self.counter, + 'length': self.length, + + } + class PasswordInfo(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) diff --git a/api/serializers.py b/api/serializers.py index c14753b..31818a8 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -61,8 +61,7 @@ class EntrySerializer(serializers.ModelSerializer): class PasswordSerializer(serializers.ModelSerializer): class Meta: model = models.Password - fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbols', 'numbers', 'counter', 'length', - 'created', 'modified') + fields = ('id', 'login', 'site', 'options', 'created', 'modified') read_only_fields = ('created', 'modified') def create(self, validated_data): From db040c0a1af38d2991a0505dc5c243828142b7ce Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 6 Oct 2016 00:14:47 +0200 Subject: [PATCH 51/93] add issue template --- ISSUE_TEMPLATE | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ISSUE_TEMPLATE diff --git a/ISSUE_TEMPLATE b/ISSUE_TEMPLATE new file mode 100644 index 0000000..6b2ed8e --- /dev/null +++ b/ISSUE_TEMPLATE @@ -0,0 +1,9 @@ +**Thank you for taking your time to fill out an issue.** + +To make it easier to manage, can you put this issue in LessPass super project ? + +https://github.com/lesspass/lesspass/issues + +:heart: + +Thanks \ No newline at end of file From 631be216b2a7f0b0aa8d053db335f03ac6b95b0c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 8 Oct 2016 13:02:21 +0200 Subject: [PATCH 52/93] JWT is valid during 15 minutes --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 804bdb5..2835af5 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -120,7 +120,7 @@ LOGGING = { AUTH_USER_MODEL = 'api.LessPassUser' JWT_AUTH = { - 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=12), + 'JWT_EXPIRATION_DELTA': datetime.timedelta(minutes=15), 'JWT_ALLOW_REFRESH': True, } From f35e0b6c8710e41aee37fa6eba333e037ff84f4a Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 9 Oct 2016 19:04:50 +0200 Subject: [PATCH 53/93] add reset password functionality --- lesspass/settings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 2835af5..e1793d9 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -31,6 +31,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', + 'djoser', 'api' ] @@ -124,7 +125,7 @@ JWT_AUTH = { 'JWT_ALLOW_REFRESH': True, } -EMAIL_BACKEND = 'django.api.mail.backends.console.EmailBackend' +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( @@ -169,3 +170,8 @@ if 'test' in sys.argv[1:] or 'jenkins' in sys.argv[1:]: TEMPLATE_DEBUG = False TESTS_IN_PROGRESS = True MIGRATION_MODULES = DisableMigrations() + +DJOSER = { + 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', + 'ACTIVATION_URL': '#/activate/{uid}/{token}' +} From b5384c44cb614bd1d861893b7c4218fb966ec835 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 11 Oct 2016 11:32:47 +0200 Subject: [PATCH 54/93] update serializer to match frontend api --- api/models.py | 11 ----------- api/serializers.py | 3 ++- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/api/models.py b/api/models.py index b0fdf25..5e055e6 100644 --- a/api/models.py +++ b/api/models.py @@ -86,17 +86,6 @@ class Password(DateMixin): def __str__(self): return str(self.id) - def options(self): - return { - 'lowercase': self.lowercase, - 'uppercase': self.uppercase, - 'symbols': self.symbols, - 'numbers': self.numbers, - 'counter': self.counter, - 'length': self.length, - - } - class PasswordInfo(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) diff --git a/api/serializers.py b/api/serializers.py index 31818a8..c14753b 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -61,7 +61,8 @@ class EntrySerializer(serializers.ModelSerializer): class PasswordSerializer(serializers.ModelSerializer): class Meta: model = models.Password - fields = ('id', 'login', 'site', 'options', 'created', 'modified') + fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbols', 'numbers', 'counter', 'length', + 'created', 'modified') read_only_fields = ('created', 'modified') def create(self, validated_data): From 05c302d291119e9b2a0fccb9f5ae60bf1ad00703 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 15 Oct 2016 13:07:21 +0200 Subject: [PATCH 55/93] add SECURE_PROXY_SSL_HEADER in settings --- lesspass/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index e1793d9..46acb8c 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -175,3 +175,5 @@ DJOSER = { 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', 'ACTIVATION_URL': '#/activate/{uid}/{token}' } + +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') From bbd2f8255a67dfe02aa8ab30901a57257be321f2 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 15 Oct 2016 13:21:00 +0200 Subject: [PATCH 56/93] fix Docker hub build error --- Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6ef956..f6c16c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,12 @@ RUN apt-get update && apt-get install -y \ ADD requirements.txt /backend/ RUN pip install --upgrade pip RUN pip install -r requirements.txt -ADD . /backend/ -COPY entrypoint.sh / -RUN chmod 755 /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +ADD entrypoint.sh /backend/ +RUN chmod 755 /backend/entrypoint.sh +ENTRYPOINT ["/backend/entrypoint.sh"] + +ADD . /backend/ -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] From dd4caf3bffe46955d9ed9cda7e725090577cec4c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 11:05:24 +0200 Subject: [PATCH 57/93] update Dockerfile and entrypoint --- Dockerfile | 19 ++++++++++--------- entrypoint.sh | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) mode change 100644 => 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index f6c16c0..d1f2301 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,21 @@ FROM python:3.5 -RUN mkdir /backend -WORKDIR /backend RUN apt-get update && apt-get install -y \ supervisor \ netcat \ && rm -rf /var/lib/apt/lists/* -ADD requirements.txt /backend/ + +RUN mkdir /backend +WORKDIR /backend +COPY requirements.txt /backend/ RUN pip install --upgrade pip RUN pip install -r requirements.txt +COPY api/ /backend/api/ +COPY lesspass/ /backend/lesspass/ +COPY manage.py /backend/manage.py -ADD entrypoint.sh /backend/ -RUN chmod 755 /backend/entrypoint.sh -ENTRYPOINT ["/backend/entrypoint.sh"] - -ADD . /backend/ +COPY entrypoint.sh / +ENTRYPOINT ["/entrypoint.sh"] -ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/entrypoint.sh b/entrypoint.sh old mode 100644 new mode 100755 index 2104d56..c6ceac8 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash while ! nc -z db 5432; do sleep 3; done From 7276c4f038fb79053fcb4b21ff647304e62b1357 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 11:29:53 +0200 Subject: [PATCH 58/93] remove static files from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 319840e..d69e37d 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,4 @@ ENV/ .ropeproject /db.sqlite3 +www/ \ No newline at end of file From 50fb81eae87c92f6eeaeaa099603ec6ee5b43797 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 19:03:23 +0200 Subject: [PATCH 59/93] try to use alpine to reduce image size --- Dockerfile | 7 ++----- entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1f2301..cb4d93a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ -FROM python:3.5 +FROM python:3.5-alpine -RUN apt-get update && apt-get install -y \ - supervisor \ - netcat \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache supervisor netcat-openbsd postgresql-dev gcc python3-dev musl-dev RUN mkdir /backend WORKDIR /backend diff --git a/entrypoint.sh b/entrypoint.sh index c6ceac8..2104d56 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh while ! nc -z db 5432; do sleep 3; done From 97098921cf9b5f8d39700ce0158d0dfd7a391b15 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 19:08:36 +0200 Subject: [PATCH 60/93] try to fix Docker hub error --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb4d93a..a662b0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,12 @@ WORKDIR /backend COPY requirements.txt /backend/ RUN pip install --upgrade pip RUN pip install -r requirements.txt + COPY api/ /backend/api/ COPY lesspass/ /backend/lesspass/ COPY manage.py /backend/manage.py - COPY entrypoint.sh / -ENTRYPOINT ["/entrypoint.sh"] - COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +ENTRYPOINT ["/entrypoint.sh"] CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] From 891f28d8f94c9e2f059a062c04a2087db3b3d3d5 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 23:09:35 +0200 Subject: [PATCH 61/93] configure COOKIE_SECURE and ALLOWED_HOSTS options --- lesspass/settings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 46acb8c..bc485e6 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -16,9 +16,9 @@ def get_secret_key(secret_key): SECRET_KEY = env('SECRET_KEY', preprocessor=get_secret_key, default=None) -DEBUG = env.bool('DJANGO_DEBUG', default=True) +DEBUG = env.bool('DJANGO_DEBUG', default=False) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = env('ALLOWED_HOSTS', cast=list, default=['localhost', '127.0.0.1', '.lesspass.com']) ADMIN = [('Guillaume Vincent', 'guillaume@oslab.fr'), ] @@ -177,3 +177,5 @@ DJOSER = { } SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +SESSION_COOKIE_SECURE = True +CSRF_COOKIE_SECURE = True From 20fa906e097b286344c5d3a8ba5bf3d09d074985 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 16 Oct 2016 23:15:34 +0200 Subject: [PATCH 62/93] fix Docker hub error --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a662b0d..7e8fdd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,9 @@ RUN pip install -r requirements.txt COPY api/ /backend/api/ COPY lesspass/ /backend/lesspass/ COPY manage.py /backend/manage.py -COPY entrypoint.sh / -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] + +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] From 24787822ec43910875b3e81f3d3eca4f3e3c2ba5 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 18:30:45 +0200 Subject: [PATCH 63/93] add email config in settings --- lesspass/settings.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index bc485e6..ecb6e13 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -125,8 +125,6 @@ JWT_AUTH = { 'JWT_ALLOW_REFRESH': True, } -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', @@ -173,9 +171,22 @@ if 'test' in sys.argv[1:] or 'jenkins' in sys.argv[1:]: DJOSER = { 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', - 'ACTIVATION_URL': '#/activate/{uid}/{token}' + 'ACTIVATION_URL': '#/activate/{uid}/{token}', + 'SEND_ACTIVATION_EMAIL': True } SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True + +if DEBUG: + EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.console.EmailBackend') +else: + EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend') +EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost') +EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', '') +EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', '') +EMAIL_PORT = os.getenv('EMAIL_PORT', 25) +EMAIL_SUBJECT_PREFIX = os.getenv('EMAIL_SUBJECT_PREFIX', '[LessPass] ') +EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', False) +EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', False) From 717801d5b8c0a0a27cbd703e8e3ac83e738a0b29 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 18:47:13 +0200 Subject: [PATCH 64/93] update env parsing --- lesspass/settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index ecb6e13..1de90cc 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -186,7 +186,7 @@ else: EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost') EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', '') EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', '') -EMAIL_PORT = os.getenv('EMAIL_PORT', 25) +EMAIL_PORT = env.int('EMAIL_PORT', default=25) EMAIL_SUBJECT_PREFIX = os.getenv('EMAIL_SUBJECT_PREFIX', '[LessPass] ') -EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', False) -EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', False) +EMAIL_USE_TLS = env.bool('EMAIL_USE_TLS', default=False) +EMAIL_USE_SSL = env.bool('EMAIL_USE_TLS', default=False) From 3b606409be7e31e0cf8a47c559ee1afeefe83d0e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 18:49:31 +0200 Subject: [PATCH 65/93] WTF Docker hub ! --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e8fdd4..6c23dc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY lesspass/ /backend/lesspass/ COPY manage.py /backend/manage.py COPY entrypoint.sh / -ENTRYPOINT ["/entrypoint.sh"] - COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +ENTRYPOINT ["/entrypoint.sh"] CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] From 84a75db64e26c5e7d97fa3ee549b19802d96ce47 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 19:26:51 +0200 Subject: [PATCH 66/93] fix error in env variable --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 1de90cc..8e6bcd7 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -189,4 +189,4 @@ EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', '') EMAIL_PORT = env.int('EMAIL_PORT', default=25) EMAIL_SUBJECT_PREFIX = os.getenv('EMAIL_SUBJECT_PREFIX', '[LessPass] ') EMAIL_USE_TLS = env.bool('EMAIL_USE_TLS', default=False) -EMAIL_USE_SSL = env.bool('EMAIL_USE_TLS', default=False) +EMAIL_USE_SSL = env.bool('EMAIL_USE_SSL', default=False) From 4a50d90d96d57fd7547532cd55b17c17aa6c393f Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 19:39:43 +0200 Subject: [PATCH 67/93] add DEFAULT_FROM_EMAIL env variable --- lesspass/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index 8e6bcd7..21bd758 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -183,6 +183,7 @@ if DEBUG: EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.console.EmailBackend') else: EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend') +DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'contact@lesspass.com') EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost') EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', '') EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', '') From 4bf1f34577c4b558de69703d461147786335b581 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 23:15:40 +0200 Subject: [PATCH 68/93] don't send activation email for now --- lesspass/settings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 21bd758..1207653 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -171,8 +171,7 @@ if 'test' in sys.argv[1:] or 'jenkins' in sys.argv[1:]: DJOSER = { 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', - 'ACTIVATION_URL': '#/activate/{uid}/{token}', - 'SEND_ACTIVATION_EMAIL': True + 'ACTIVATION_URL': '#/activate/{uid}/{token}' } SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') From 161d406e57948e4ce76e415589ef6c90e926dcb9 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 18 Oct 2016 23:16:02 +0200 Subject: [PATCH 69/93] fix supervisor warning message --- supervisord.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/supervisord.conf b/supervisord.conf index caec4c0..a58d751 100755 --- a/supervisord.conf +++ b/supervisord.conf @@ -8,7 +8,6 @@ directory=/backend command=gunicorn lesspass.wsgi:application -w 2 -b :8000 autostart=true autorestart=true -redirect_stderr=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr From 2d75927749614221fafe146811df841d9ddf9004 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 20 Oct 2016 11:20:26 +0200 Subject: [PATCH 70/93] add license in readme --- readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 877207f..f901c03 100644 --- a/readme.md +++ b/readme.md @@ -16,4 +16,9 @@ api server with django rest framework for LessPass password manager pip install -r requirements.txt python manage.py test -see [LessPass](https://github.com/lesspass/lesspass) project \ No newline at end of file +## License + +MIT © [Guillaume Vincent](http://guillaumevincent.com) + + +## [LessPass project](https://github.com/lesspass/lesspass) \ No newline at end of file From ff2c49d4bfce04290861965e241a35dc883800ed Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 20 Oct 2016 14:00:22 +0200 Subject: [PATCH 71/93] update ISSUE_TEMPLATE file --- ISSUE_TEMPLATE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ISSUE_TEMPLATE b/ISSUE_TEMPLATE index 6b2ed8e..f6acdd8 100644 --- a/ISSUE_TEMPLATE +++ b/ISSUE_TEMPLATE @@ -1,3 +1,5 @@ + + **Thank you for taking your time to fill out an issue.** To make it easier to manage, can you put this issue in LessPass super project ? From 1f415b1821ee8167e3d3956438886cd65a6a4cd5 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 25 Oct 2016 08:40:02 +0200 Subject: [PATCH 72/93] remove useless entries and password info models --- Dockerfile | 4 +- api/admin.py | 10 +- api/data_migrations.py | 15 --- api/migrations/0003_mv_entries_to_password.py | 16 +++- .../0004_remove_entries_password_info_models.py | 29 ++++++ api/models.py | 33 ------- api/serializers.py | 56 ----------- api/tests/factories.py | 20 ---- api/tests/tests_data_migrations.py | 51 ----------- api/tests/tests_entries.py | 102 --------------------- api/urls.py | 1 - api/views.py | 47 +--------- 12 files changed, 48 insertions(+), 336 deletions(-) delete mode 100644 api/data_migrations.py create mode 100644 api/migrations/0004_remove_entries_password_info_models.py delete mode 100644 api/tests/tests_data_migrations.py delete mode 100644 api/tests/tests_entries.py diff --git a/Dockerfile b/Dockerfile index 6c23dc1..7e8fdd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY lesspass/ /backend/lesspass/ COPY manage.py /backend/manage.py COPY entrypoint.sh / -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf - ENTRYPOINT ["/entrypoint.sh"] + +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/api/admin.py b/api/admin.py index 271df48..e10a793 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,5 +1,5 @@ from api import models -from api.models import PasswordInfo, Entry, LessPassUser +from api.models import LessPassUser from django import forms from django.contrib import admin @@ -79,14 +79,6 @@ class PasswordAdmin(admin.ModelAdmin): ordering = ('user',) -class EntryAdmin(admin.ModelAdmin): - list_display = ('id', 'user',) - search_fields = ('user__email',) - ordering = ('user',) - - admin.site.register(models.Password, PasswordAdmin) -admin.site.register(Entry, EntryAdmin) -admin.site.register(PasswordInfo) admin.site.register(LessPassUser, LessPassUserAdmin) admin.site.unregister(Group) diff --git a/api/data_migrations.py b/api/data_migrations.py deleted file mode 100644 index bf4c01c..0000000 --- a/api/data_migrations.py +++ /dev/null @@ -1,15 +0,0 @@ -import json - -from api import models - - -def create_password_with(entry): - settings = json.dumps(entry.password.settings) - lowercase = 'lowercase' in settings - uppercase = 'uppercase' in settings - symbols = 'symbols' in settings - numbers = 'numbers' in settings - user = models.LessPassUser.objects.get(id=entry.user.id) - models.Password.objects.create(id=entry.id, site=entry.site, login=entry.login, user=user, - lowercase=lowercase, uppercase=uppercase, symbols=symbols, numbers=numbers, - counter=entry.password.counter, length=entry.password.length) diff --git a/api/migrations/0003_mv_entries_to_password.py b/api/migrations/0003_mv_entries_to_password.py index ec11eec..270f299 100644 --- a/api/migrations/0003_mv_entries_to_password.py +++ b/api/migrations/0003_mv_entries_to_password.py @@ -4,7 +4,21 @@ from __future__ import unicode_literals from django.db import migrations -from api.data_migrations import create_password_with +import json + +from api import models + + +def create_password_with(entry): + settings = json.dumps(entry.password.settings) + lowercase = 'lowercase' in settings + uppercase = 'uppercase' in settings + symbols = 'symbols' in settings + numbers = 'numbers' in settings + user = models.LessPassUser.objects.get(id=entry.user.id) + models.Password.objects.create(id=entry.id, site=entry.site, login=entry.login, user=user, + lowercase=lowercase, uppercase=uppercase, symbols=symbols, numbers=numbers, + counter=entry.password.counter, length=entry.password.length) def mv_entries_to_password(apps, schema_editor): diff --git a/api/migrations/0004_remove_entries_password_info_models.py b/api/migrations/0004_remove_entries_password_info_models.py new file mode 100644 index 0000000..5fbb071 --- /dev/null +++ b/api/migrations/0004_remove_entries_password_info_models.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.1 on 2016-10-25 06:33 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0003_mv_entries_to_password'), + ] + + operations = [ + migrations.RemoveField( + model_name='entry', + name='password', + ), + migrations.RemoveField( + model_name='entry', + name='user', + ), + migrations.DeleteModel( + name='Entry', + ), + migrations.DeleteModel( + name='PasswordInfo', + ), + ] diff --git a/api/models.py b/api/models.py index 5e055e6..3e7601b 100644 --- a/api/models.py +++ b/api/models.py @@ -85,36 +85,3 @@ class Password(DateMixin): def __str__(self): return str(self.id) - - -class PasswordInfo(models.Model): - id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - counter = models.IntegerField(default=1) - settings = models.TextField() - length = models.IntegerField(default=12) - - class Meta: - verbose_name_plural = "Password info" - - def __str__(self): - return str(self.id) - - -class Entry(DateMixin): - id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - user = models.ForeignKey(LessPassUser, on_delete=models.CASCADE, related_name='entries') - login = models.CharField(max_length=255, default='') - site = models.CharField(max_length=255, default='') - password = models.ForeignKey(PasswordInfo) - - title = models.CharField(max_length=255, null=True, blank=True) - username = models.CharField(max_length=255, null=True, blank=True) - email = models.EmailField(null=True, blank=True) - description = models.TextField(null=True, blank=True) - url = models.URLField(null=True, blank=True) - - class Meta: - verbose_name_plural = "Entries" - - def __str__(self): - return str(self.id) diff --git a/api/serializers.py b/api/serializers.py index c14753b..0b79438 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,62 +1,6 @@ -import json - from api import models from rest_framework import serializers -from django.utils.translation import ugettext_lazy as _ - - -class JsonSettingsField(serializers.Field): - default_error_messages = { - 'invalid': _('Value must be valid JSON.') - } - - def to_representation(self, value): - return json.loads(value) - - def to_internal_value(self, data): - try: - return json.dumps(data) - except (TypeError, ValueError): - self.fail('invalid') - - -class PasswordInfoSerializer(serializers.ModelSerializer): - settings = JsonSettingsField() - - class Meta: - model = models.PasswordInfo - fields = ('counter', 'settings', 'length') - - -class EntrySerializer(serializers.ModelSerializer): - site = serializers.CharField(allow_blank=True) - login = serializers.CharField(allow_blank=True) - password = PasswordInfoSerializer() - - class Meta: - model = models.Entry - fields = ('id', 'site', 'login', 'password', 'created', 'modified') - read_only_fields = ('created', 'modified') - - def create(self, validated_data): - password_data = validated_data.pop('password') - user = self.context['request'].user - password_info = models.PasswordInfo.objects.create(**password_data) - return models.Entry.objects.create(user=user, password=password_info, **validated_data) - - def update(self, instance, validated_data): - password_data = validated_data.pop('password') - password_info = instance.password - for attr, value in password_data.items(): - setattr(password_info, attr, value) - password_info.save() - - for attr, value in validated_data.items(): - setattr(instance, attr, value) - instance.save() - return instance - class PasswordSerializer(serializers.ModelSerializer): class Meta: diff --git a/api/tests/factories.py b/api/tests/factories.py index 29ee039..db2a425 100644 --- a/api/tests/factories.py +++ b/api/tests/factories.py @@ -16,26 +16,6 @@ class AdminFactory(UserFactory): is_admin = True -class PasswordInfoFactory(factory.DjangoModelFactory): - class Meta: - model = models.PasswordInfo - - settings = '["lowercase", "uppercase", "numbers", "symbols"]' - - -class EntryFactory(factory.DjangoModelFactory): - class Meta: - model = models.Entry - - user = factory.SubFactory(UserFactory) - password = factory.SubFactory(PasswordInfoFactory) - - title = 'twitter' - site = 'twitter' - username = 'guillaume20100' - url = 'https://twitter.com/' - - class PasswordFactory(factory.DjangoModelFactory): class Meta: model = models.Password diff --git a/api/tests/tests_data_migrations.py b/api/tests/tests_data_migrations.py deleted file mode 100644 index f1c1337..0000000 --- a/api/tests/tests_data_migrations.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.test import TestCase - -from api import models -from api.tests import factories -from api.data_migrations import create_password_with - - -class DataMigrationTestCase(TestCase): - def setUp(self): - self.user = factories.UserFactory() - - def test_create_password_with_entry(self): - entry = factories.EntryFactory(user=self.user) - - create_password_with(entry) - - password = models.Password.objects.get(id=entry.id) - self.assertEqual(entry.user, password.user) - self.assertEqual(entry.login, password.login) - self.assertEqual(entry.site, password.site) - - def test_create_password_with_entry_copy_password_info(self): - entry = factories.EntryFactory(user=self.user) - - create_password_with(entry) - - password = models.Password.objects.get(id=entry.id) - self.assertTrue(password.lowercase) - self.assertTrue(password.uppercase) - self.assertTrue(password.symbols) - self.assertTrue(password.numbers) - self.assertEqual(entry.password.length, password.length) - self.assertEqual(entry.password.counter, password.counter) - - def test_create_password_robust(self): - password_info = factories.PasswordInfoFactory(settings='["lowercase", "numbers"]', counter=2, length=14) - entry = factories.EntryFactory(site='migration.com', login='contact@migration.com', - user=self.user, password=password_info) - - create_password_with(entry) - - password = models.Password.objects.get(id=entry.id) - self.assertEqual(self.user, password.user) - self.assertEqual('contact@migration.com', password.login) - self.assertEqual('migration.com', password.site) - self.assertTrue(password.lowercase) - self.assertFalse(password.uppercase) - self.assertFalse(password.symbols) - self.assertTrue(password.numbers) - self.assertEqual(14, password.length) - self.assertEqual(2, password.counter) diff --git a/api/tests/tests_entries.py b/api/tests/tests_entries.py deleted file mode 100644 index 87fbe7a..0000000 --- a/api/tests/tests_entries.py +++ /dev/null @@ -1,102 +0,0 @@ -import json - -from rest_framework.test import APITestCase, APIClient - -from api import models -from api.tests import factories - - -class LogoutApiTestCase(APITestCase): - def test_get_entries_401(self): - response = self.client.get('/api/entries/') - self.assertEqual(401, response.status_code) - - -class LoginApiTestCase(APITestCase): - def setUp(self): - self.user = factories.UserFactory() - self.client = APIClient() - self.client.force_authenticate(user=self.user) - - def test_get_empty_entries(self): - request = self.client.get('/api/entries/') - self.assertEqual(0, len(request.data['results'])) - - def test_retrieve_its_own_entries(self): - entry = factories.EntryFactory(user=self.user) - request = self.client.get('/api/entries/') - self.assertEqual(1, len(request.data['results'])) - self.assertEqual(entry.site, request.data['results'][0]['site']) - - def test_cant_retrieve_other_entries(self): - not_my_entry = factories.EntryFactory(user=factories.UserFactory()) - request = self.client.get('/api/entries/%s/' % not_my_entry.id) - self.assertEqual(404, request.status_code) - - def test_delete_its_own_entries(self): - entry = factories.EntryFactory(user=self.user) - self.assertEqual(1, models.Entry.objects.all().count()) - request = self.client.delete('/api/entries/%s/' % entry.id) - self.assertEqual(204, request.status_code) - self.assertEqual(0, models.Entry.objects.all().count()) - - def test_cant_delete_other_entry(self): - not_my_entry = factories.EntryFactory(user=factories.UserFactory()) - self.assertEqual(1, models.Entry.objects.all().count()) - request = self.client.delete('/api/entries/%s/' % not_my_entry.id) - self.assertEqual(404, request.status_code) - self.assertEqual(1, models.Entry.objects.all().count()) - - def test_create_entry(self): - entry = { - "site": "twitter", - "login": "guillaume@oslab.fr", - "password": { - "counter": 1, - "settings": [ - "lowercase", - "uppercase", - "numbers", - "symbols" - ], - "length": 12 - }, - } - self.assertEqual(0, models.Entry.objects.count()) - self.assertEqual(0, models.PasswordInfo.objects.count()) - self.client.post('/api/entries/', entry) - self.assertEqual(1, models.Entry.objects.count()) - self.assertEqual(1, models.PasswordInfo.objects.count()) - - def test_update_entry(self): - entry = factories.EntryFactory(user=self.user) - self.assertNotEqual('facebook', entry.site) - new_entry = { - "site": "facebook", - "login": "", - "password": { - "counter": 1, - "settings": [ - "lowercase", - "uppercase", - "numbers" - ], - "length": 12 - }, - } - request = self.client.put('/api/entries/%s/' % entry.id, new_entry) - self.assertEqual(200, request.status_code, request.content.decode('utf-8')) - entry_updated = models.Entry.objects.get(id=entry.id) - self.assertEqual('facebook', entry_updated.site) - self.assertEqual(3, len(json.loads(entry_updated.password.settings))) - - def test_cant_update_other_entry(self): - not_my_entry = factories.EntryFactory(user=factories.UserFactory()) - self.assertEqual('twitter', not_my_entry.site) - new_entry = { - "site": "facebook", - "password": {"settings": []} - } - request = self.client.put('/api/entries/%s/' % not_my_entry.id, new_entry) - self.assertEqual(404, request.status_code) - self.assertEqual(1, models.Entry.objects.all().count()) diff --git a/api/urls.py b/api/urls.py index 35452c5..647cd02 100644 --- a/api/urls.py +++ b/api/urls.py @@ -5,7 +5,6 @@ from rest_framework.routers import DefaultRouter from api import views router = DefaultRouter() -router.register(r'entries', views.EntryViewSet, base_name='entries') router.register(r'passwords', views.PasswordViewSet, base_name='passwords') urlpatterns = [ diff --git a/api/views.py b/api/views.py index 4c60094..eb758b6 100644 --- a/api/views.py +++ b/api/views.py @@ -1,42 +1,7 @@ from api import models, serializers from api.permissions import IsOwner -from django.contrib.auth import login, authenticate -from rest_framework import status, permissions, viewsets -from rest_framework.response import Response - - -class AuthViewSet(viewsets.ViewSet): - permission_classes = (permissions.AllowAny,) - - @staticmethod - def list(request, format=None): - if request.user.is_authenticated(): - user = { - 'id': request.user.id, - 'email': request.user.email, - 'is_admin': request.user.is_staff, - 'is_authenticated': True - } - else: - user = { - 'id': None, - 'email': None, - 'is_admin': False, - 'is_authenticated': False - } - - return Response({ - 'user': user - }) - - @staticmethod - def post(request): - user = authenticate(username=request.data.get('username'), password=request.data.get('password')) - if user and user.is_active: - login(request, user) - return Response(status=status.HTTP_201_CREATED) - return Response(status=status.HTTP_401_UNAUTHORIZED) +from rest_framework import permissions, viewsets class PasswordViewSet(viewsets.ModelViewSet): @@ -47,13 +12,3 @@ class PasswordViewSet(viewsets.ModelViewSet): def get_queryset(self): return models.Password.objects.filter(user=self.request.user) - - -class EntryViewSet(viewsets.ModelViewSet): - serializer_class = serializers.EntrySerializer - permission_classes = (permissions.IsAuthenticated, IsOwner,) - search_fields = ('site', 'email',) - ordering_fields = ('site', 'email', 'created') - - def get_queryset(self): - return models.Entry.objects.filter(user=self.request.user) From a380582677fa98ad0e563cc39b854312f7f09d12 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 25 Oct 2016 17:53:04 +0200 Subject: [PATCH 73/93] update readme --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f901c03..92b88a8 100644 --- a/readme.md +++ b/readme.md @@ -21,4 +21,6 @@ api server with django rest framework for LessPass password manager MIT © [Guillaume Vincent](http://guillaumevincent.com) -## [LessPass project](https://github.com/lesspass/lesspass) \ No newline at end of file +## Issues + +report issues on [LessPass project](https://github.com/lesspass/lesspass/issues) \ No newline at end of file From b4f557ddd5b502d7f7370e327ed3efe1b520ffbf Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 29 Oct 2016 19:00:25 +0200 Subject: [PATCH 74/93] change license from MIT to GNU GPLv3 --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ license | 21 -- readme.md | 2 +- 3 files changed, 675 insertions(+), 22 deletions(-) create mode 100644 LICENSE delete mode 100644 license diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/license b/license deleted file mode 100644 index 6a8501b..0000000 --- a/license +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) Guillaume Vincent (guillaumevincent.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/readme.md b/readme.md index 92b88a8..140a4c2 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ api server with django rest framework for LessPass password manager ## License -MIT © [Guillaume Vincent](http://guillaumevincent.com) +This project is licensed under the terms of the GNU GPLv3. ## Issues From 3648bfdd6836a5762a23ea01a21b36c52d3fdfda Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 4 Nov 2016 19:20:17 +0100 Subject: [PATCH 75/93] update requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index c33f6a1..d9a2b58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -Django==1.10.1 +Django==1.10.3 django-cors-middleware==1.3.1 -djangorestframework==3.4.7 +djangorestframework==3.5.2 djangorestframework-jwt==1.8.0 psycopg2==2.6.2 gunicorn==19.6.0 From ac2a9aa3b0e4fe36a1c3ac24d1f291d900b00932 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 7 Nov 2016 14:58:10 +0100 Subject: [PATCH 76/93] remove useless ISSUE_TEMPLATE --- ISSUE_TEMPLATE | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 ISSUE_TEMPLATE diff --git a/ISSUE_TEMPLATE b/ISSUE_TEMPLATE deleted file mode 100644 index f6acdd8..0000000 --- a/ISSUE_TEMPLATE +++ /dev/null @@ -1,11 +0,0 @@ - - -**Thank you for taking your time to fill out an issue.** - -To make it easier to manage, can you put this issue in LessPass super project ? - -https://github.com/lesspass/lesspass/issues - -:heart: - -Thanks \ No newline at end of file From 3e307df93500f8f9d5426ec068c99eee5a412bb5 Mon Sep 17 00:00:00 2001 From: Bran Sorem Date: Mon, 14 Nov 2016 01:19:27 -0800 Subject: [PATCH 77/93] Update badge location (#2) --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 140a4c2..26903b4 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/lesspass/api.svg?branch=master)](https://travis-ci.org/lesspass/api) +[![Build Status](https://travis-ci.org/lesspass/backend.svg?branch=master)](https://travis-ci.org/lesspass/backend) # LessPass Backend @@ -23,4 +23,4 @@ This project is licensed under the terms of the GNU GPLv3. ## Issues -report issues on [LessPass project](https://github.com/lesspass/lesspass/issues) \ No newline at end of file +report issues on [LessPass project](https://github.com/lesspass/lesspass/issues) From 198513bf68a04d5bbc671b4d819e3d8a1d37f301 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 21 Nov 2016 14:31:15 +0100 Subject: [PATCH 78/93] add version field in password profile model --- api/migrations/0005_password_version.py | 20 ++++++++++++++++++++ api/models.py | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 api/migrations/0005_password_version.py diff --git a/api/migrations/0005_password_version.py b/api/migrations/0005_password_version.py new file mode 100644 index 0000000..385d709 --- /dev/null +++ b/api/migrations/0005_password_version.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-21 13:30 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0004_remove_entries_password_info_models'), + ] + + operations = [ + migrations.AddField( + model_name='password', + name='version', + field=models.IntegerField(default=1), + ), + ] diff --git a/api/models.py b/api/models.py index 3e7601b..649b02c 100644 --- a/api/models.py +++ b/api/models.py @@ -83,5 +83,8 @@ class Password(DateMixin): length = models.IntegerField(default=12) counter = models.IntegerField(default=1) + version = models.IntegerField(default=1) + def __str__(self): return str(self.id) + From ae404bf9880d40bb576232dd8a33f6bb5ec9550b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 22 Nov 2016 22:24:05 +0100 Subject: [PATCH 79/93] add version field in password profile --- api/serializers.py | 2 +- api/tests/tests_passwords.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index 0b79438..95570b5 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -6,7 +6,7 @@ class PasswordSerializer(serializers.ModelSerializer): class Meta: model = models.Password fields = ('id', 'login', 'site', 'lowercase', 'uppercase', 'symbols', 'numbers', 'counter', 'length', - 'created', 'modified') + 'version', 'created', 'modified') read_only_fields = ('created', 'modified') def create(self, validated_data): diff --git a/api/tests/tests_passwords.py b/api/tests/tests_passwords.py index c70c8bb..8e0e133 100644 --- a/api/tests/tests_passwords.py +++ b/api/tests/tests_passwords.py @@ -60,6 +60,21 @@ class LoginApiTestCase(APITestCase): self.client.post('/api/passwords/', password) self.assertEqual(1, models.Password.objects.count()) + def test_create_password_v2(self): + password = { + "site": "lesspass.com", + "login": "test@oslab.fr", + "lowercase": True, + "uppercase": True, + "number": True, + "symbol": True, + "counter": 1, + "length": 12, + "version": 2 + } + self.client.post('/api/passwords/', password) + self.assertEqual(2, models.Password.objects.first().version) + def test_update_password(self): password = factories.PasswordFactory(user=self.user) self.assertNotEqual('facebook.com', password.site) From 46b1ea1f63b40e0c0cd48e84b722d26ed1b262c8 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 25 Nov 2016 15:06:55 +0100 Subject: [PATCH 80/93] raise to 60 minutes validity for JWT --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 1207653..ed6de9b 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -121,7 +121,7 @@ LOGGING = { AUTH_USER_MODEL = 'api.LessPassUser' JWT_AUTH = { - 'JWT_EXPIRATION_DELTA': datetime.timedelta(minutes=15), + 'JWT_EXPIRATION_DELTA': datetime.timedelta(minutes=60), 'JWT_ALLOW_REFRESH': True, } From e79aa7733992de1ba81f71055e21b0e5377051da Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Wed, 21 Dec 2016 17:27:16 +0100 Subject: [PATCH 81/93] Update requirements.txt --- requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index d9a2b58..1fa6cb0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -Django==1.10.3 +Django==1.10.4 django-cors-middleware==1.3.1 -djangorestframework==3.5.2 -djangorestframework-jwt==1.8.0 +djangorestframework==3.5.3 +djangorestframework-jwt==1.9.0 psycopg2==2.6.2 gunicorn==19.6.0 djoser==0.5.1 envparse==0.2.0 # tests -factory-boy==2.7.0 +factory-boy==2.8.1 From 4f5d2214b33aecbdf5725796b1b39d2db6d85401 Mon Sep 17 00:00:00 2001 From: philip-ulrich Date: Sun, 8 Jan 2017 02:38:54 -0600 Subject: [PATCH 82/93] changing delta to 7 days lesspass/lesspass#94 (#3) --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index ed6de9b..ab13251 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -121,7 +121,7 @@ LOGGING = { AUTH_USER_MODEL = 'api.LessPassUser' JWT_AUTH = { - 'JWT_EXPIRATION_DELTA': datetime.timedelta(minutes=60), + 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7), 'JWT_ALLOW_REFRESH': True, } From 24a9f1d1501290a4841d31c0a143c92271ca3d79 Mon Sep 17 00:00:00 2001 From: "P@nther" Date: Thu, 16 Feb 2017 15:38:55 +0100 Subject: [PATCH 83/93] Update settings.py ... (#5) fix https://github.com/lesspass/lesspass/issues/149 --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index ab13251..0d1ee82 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -130,7 +130,7 @@ REST_FRAMEWORK = { 'rest_framework.permissions.IsAuthenticated', ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', - 'PAGE_SIZE': 50, + 'PAGE_SIZE': 1000, 'DEFAULT_FILTER_BACKENDS': ( 'rest_framework.filters.OrderingFilter', 'rest_framework.filters.SearchFilter', From f315e8f085b0e37c76de5d03fb8875805cb646c3 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Wed, 1 Mar 2017 16:58:30 +0100 Subject: [PATCH 84/93] fix admin config in settings --- lesspass/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index 0d1ee82..ec3320c 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -20,7 +20,7 @@ DEBUG = env.bool('DJANGO_DEBUG', default=False) ALLOWED_HOSTS = env('ALLOWED_HOSTS', cast=list, default=['localhost', '127.0.0.1', '.lesspass.com']) -ADMIN = [('Guillaume Vincent', 'guillaume@oslab.fr'), ] +ADMINS = (('Guillaume Vincent', 'guillaume@oslab.fr'), ) INSTALLED_APPS = [ 'django.contrib.admin', From 4e1635f80e48f4c4bfc9765d043b6e443a82b0e2 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sun, 5 Mar 2017 14:37:29 +0100 Subject: [PATCH 85/93] update pip packages --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1fa6cb0..71cac78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -Django==1.10.4 +Django==1.10.6 django-cors-middleware==1.3.1 -djangorestframework==3.5.3 +djangorestframework==3.5.4 djangorestframework-jwt==1.9.0 -psycopg2==2.6.2 -gunicorn==19.6.0 -djoser==0.5.1 +psycopg2==2.7 +gunicorn==19.7.0 +djoser==0.5.4 envparse==0.2.0 # tests factory-boy==2.8.1 From 128812b85ad48d36b4ca1fb39b987e6903e4432b Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 13 Mar 2017 14:36:09 +0100 Subject: [PATCH 86/93] add .editorconfig and auto format --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c193ae0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.py] +indent_size = 4 From 2b3841033751d586f6180b1b0ff4ea574a0737c4 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 14 Mar 2017 16:10:45 +0100 Subject: [PATCH 87/93] update travis configuration --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e332ccd..17f5242 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ +dist: trusty +sudo: required language: python python: - - 3.4 - 3.5 addons: - postgresql: "9.4" + postgresql: "9.5" services: - postgresql env: From a6c056112e933a349287e1a152cc757d2b6a1885 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 14 Apr 2017 09:13:21 +0200 Subject: [PATCH 88/93] update python requirements --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 71cac78..51df6d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -Django==1.10.6 +Django==1.11 django-cors-middleware==1.3.1 -djangorestframework==3.5.4 -djangorestframework-jwt==1.9.0 -psycopg2==2.7 -gunicorn==19.7.0 +djangorestframework==3.6.2 +djangorestframework-jwt==1.10.0 +psycopg2==2.7.1 +gunicorn==19.7.1 djoser==0.5.4 envparse==0.2.0 # tests From 376e7634d905b8080e6f1df44e86d88ca53d6306 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 14 Apr 2017 21:09:09 +0200 Subject: [PATCH 89/93] fix tests error with DisableMigrations class --- lesspass/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lesspass/settings.py b/lesspass/settings.py index ec3320c..60e2f43 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -20,7 +20,7 @@ DEBUG = env.bool('DJANGO_DEBUG', default=False) ALLOWED_HOSTS = env('ALLOWED_HOSTS', cast=list, default=['localhost', '127.0.0.1', '.lesspass.com']) -ADMINS = (('Guillaume Vincent', 'guillaume@oslab.fr'), ) +ADMINS = (('Guillaume Vincent', 'guillaume@oslab.fr'),) INSTALLED_APPS = [ 'django.contrib.admin', @@ -155,7 +155,7 @@ class DisableMigrations(object): return True def __getitem__(self, item): - return "notmigrations" + return None TESTS_IN_PROGRESS = False From f853a465b0f2e51d5af26cb4fde28a9ba6016711 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 19 May 2017 20:05:32 +0200 Subject: [PATCH 90/93] Change default password profile in model to version 2 --- .../0006_change_default_password_profile.py | 25 ++++++++++++++++++++++ api/models.py | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 api/migrations/0006_change_default_password_profile.py diff --git a/api/migrations/0006_change_default_password_profile.py b/api/migrations/0006_change_default_password_profile.py new file mode 100644 index 0000000..dc62ee2 --- /dev/null +++ b/api/migrations/0006_change_default_password_profile.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-05-19 18:03 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0005_password_version'), + ] + + operations = [ + migrations.AlterField( + model_name='password', + name='length', + field=models.IntegerField(default=16), + ), + migrations.AlterField( + model_name='password', + name='version', + field=models.IntegerField(default=2), + ), + ] diff --git a/api/models.py b/api/models.py index 649b02c..e0604d2 100644 --- a/api/models.py +++ b/api/models.py @@ -80,10 +80,10 @@ class Password(DateMixin): symbols = models.BooleanField(default=True) numbers = models.BooleanField(default=True) - length = models.IntegerField(default=12) + length = models.IntegerField(default=16) counter = models.IntegerField(default=1) - version = models.IntegerField(default=1) + version = models.IntegerField(default=2) def __str__(self): return str(self.id) From f49e6e4d2d1267914bae7fe004c321ff06629b73 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 30 Jun 2017 10:29:17 +0200 Subject: [PATCH 91/93] Add basic authentication for LessPass Move --- lesspass/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lesspass/settings.py b/lesspass/settings.py index 60e2f43..5fbedab 100644 --- a/lesspass/settings.py +++ b/lesspass/settings.py @@ -137,6 +137,7 @@ REST_FRAMEWORK = { ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', + 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_RENDERER_CLASSES': ( From 670e4b39c06416a1f3946a7d97074dc6f42751b7 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 14 Sep 2017 08:47:56 +0200 Subject: [PATCH 92/93] Update README.md --- README.md | 24 ++++++++++++++++++++++++ readme.md | 26 -------------------------- 2 files changed, 24 insertions(+), 26 deletions(-) create mode 100644 README.md delete mode 100644 readme.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..965d580 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# LessPass backend + +REST API used by [lesspass-pure](https://github.com/lesspass/pure) to store password profiles + + * python 3 + * django rest framework + * django rest framework jwt + * djoser + * postgresql + * gunicorn + +## Tests + + pip install -r requirements.txt + python manage.py test + +## License + +This project is licensed under the terms of the GNU GPLv3. + + +## Issues + +report issues on [LessPass project](https://github.com/lesspass/lesspass/issues) diff --git a/readme.md b/readme.md deleted file mode 100644 index 26903b4..0000000 --- a/readme.md +++ /dev/null @@ -1,26 +0,0 @@ -[![Build Status](https://travis-ci.org/lesspass/backend.svg?branch=master)](https://travis-ci.org/lesspass/backend) - -# LessPass Backend - -api server with django rest framework for LessPass password manager - - - python 3 - - django rest framework - - django rest framework jwt - - djoser - - postgresql - - gunicorn - -## Tests - - pip install -r requirements.txt - python manage.py test - -## License - -This project is licensed under the terms of the GNU GPLv3. - - -## Issues - -report issues on [LessPass project](https://github.com/lesspass/lesspass/issues) From 6f4890f52f6c394dfc95d8db4ee1a9a71092a63f Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 2 Jan 2018 17:50:43 +0100 Subject: [PATCH 93/93] Update python requirements --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 51df6d5..1e1ed27 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -Django==1.11 +Django==1.11.9 django-cors-middleware==1.3.1 -djangorestframework==3.6.2 -djangorestframework-jwt==1.10.0 -psycopg2==2.7.1 +djangorestframework==3.7.7 +djangorestframework-jwt==1.11.0 +psycopg2==2.7.3.2 gunicorn==19.7.1 djoser==0.5.4 envparse==0.2.0 # tests -factory-boy==2.8.1 +factory-boy==2.9.2