From: Radek Czajka Date: Wed, 9 Jan 2019 13:02:23 +0000 (+0100) Subject: Compatibility up to Django 2.1, dropped < 1.8. Removed unused code, fixed tests. X-Git-Tag: 22.4~5 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/fdbd98e576514c2a58183132369dccfb5781804a?ds=inline;hp=--cc Compatibility up to Django 2.1, dropped < 1.8. Removed unused code, fixed tests. --- fdbd98e576514c2a58183132369dccfb5781804a diff --git a/cas_provider/exceptions.py b/cas_provider/exceptions.py deleted file mode 100644 index fdb6251..0000000 --- a/cas_provider/exceptions.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -"""cas_provider.exceptions -- exceptions defined for CAS login workflows -""" -from __future__ import unicode_literals - - -class SameEmailMismatchedPasswords(Exception): pass diff --git a/cas_provider/migrations/0001_initial.py b/cas_provider/migrations/0001_initial.py index 6622ec5..160eab5 100644 --- a/cas_provider/migrations/0001_initial.py +++ b/cas_provider/migrations/0001_initial.py @@ -45,7 +45,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('ticket', models.CharField(max_length=32, verbose_name='ticket')), ('created', models.DateTimeField(auto_now=True, verbose_name='created')), - ('proxyGrantingTicket', models.ForeignKey(verbose_name='Proxy Granting Ticket', to='cas_provider.ProxyGrantingTicket')), + ('proxyGrantingTicket', models.ForeignKey(verbose_name='Proxy Granting Ticket', to='cas_provider.ProxyGrantingTicket', on_delete=models.CASCADE)), ], options={ 'verbose_name': 'Proxy Granting Ticket IOU', @@ -70,8 +70,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='ProxyTicket', fields=[ - ('serviceticket_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cas_provider.ServiceTicket')), - ('proxyGrantingTicket', models.ForeignKey(verbose_name='Proxy Granting Ticket', to='cas_provider.ProxyGrantingTicket')), + ('serviceticket_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='cas_provider.ServiceTicket', on_delete=models.CASCADE)), + ('proxyGrantingTicket', models.ForeignKey(verbose_name='Proxy Granting Ticket', to='cas_provider.ProxyGrantingTicket', on_delete=models.CASCADE)), ], options={ 'verbose_name': 'Proxy Ticket', @@ -82,13 +82,13 @@ class Migration(migrations.Migration): migrations.AddField( model_name='serviceticket', name='user', - field=models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL), + field=models.ForeignKey(verbose_name='user', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( model_name='proxygrantingticket', name='serviceTicket', - field=models.ForeignKey(to='cas_provider.ServiceTicket', null=True), + field=models.ForeignKey(to='cas_provider.ServiceTicket', null=True, on_delete=models.CASCADE), preserve_default=True, ), ] diff --git a/cas_provider/migrations/0002_auto_20140920_1644.py b/cas_provider/migrations/0002_auto_20140920_1644.py index 5948a66..6f3781c 100644 --- a/cas_provider/migrations/0002_auto_20140920_1644.py +++ b/cas_provider/migrations/0002_auto_20140920_1644.py @@ -20,7 +20,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='proxygrantingticket', name='pgt', - field=models.ForeignKey(to='cas_provider.ProxyGrantingTicket', null=True), + field=models.ForeignKey(to='cas_provider.ProxyGrantingTicket', null=True, on_delete=models.CASCADE), preserve_default=True, ), migrations.AddField( @@ -32,7 +32,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='proxygrantingticket', name='user', - field=models.ForeignKey(default=0, verbose_name='user', to=settings.AUTH_USER_MODEL), + field=models.ForeignKey(default=0, verbose_name='user', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE), preserve_default=False, ), ] diff --git a/cas_provider/models.py b/cas_provider/models.py index 36014b5..0dd8b9a 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -35,7 +35,7 @@ class BaseTicket(models.Model): class ServiceTicket(BaseTicket): - user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user')) + user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'), on_delete=models.CASCADE) service = models.URLField(_('service')) prefix = 'ST' @@ -64,9 +64,9 @@ class LoginTicket(BaseTicket): class ProxyGrantingTicket(BaseTicket): - user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user')) + user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'), on_delete=models.CASCADE) service = models.URLField(_('service'), null=True) - pgt = models.ForeignKey('self', null=True) + pgt = models.ForeignKey('self', null=True, on_delete=models.CASCADE) pgtiou = models.CharField(max_length=256, verbose_name=_('PGTiou')) prefix = 'PGT' @@ -81,7 +81,7 @@ class ProxyGrantingTicket(BaseTicket): class ProxyTicket(ServiceTicket): - proxyGrantingTicket = models.ForeignKey(ProxyGrantingTicket, verbose_name=_('Proxy Granting Ticket')) + proxyGrantingTicket = models.ForeignKey(ProxyGrantingTicket, verbose_name=_('Proxy Granting Ticket'), on_delete=models.CASCADE) prefix = 'PT' @@ -91,7 +91,7 @@ class ProxyTicket(ServiceTicket): class ProxyGrantingTicketIOU(BaseTicket): - proxyGrantingTicket = models.ForeignKey(ProxyGrantingTicket, verbose_name=_('Proxy Granting Ticket')) + proxyGrantingTicket = models.ForeignKey(ProxyGrantingTicket, verbose_name=_('Proxy Granting Ticket'), on_delete=models.CASCADE) prefix = 'PGTIOU' diff --git a/cas_provider/south_migrations/0001_initial.py b/cas_provider/south_migrations/0001_initial.py deleted file mode 100644 index 74770af..0000000 --- a/cas_provider/south_migrations/0001_initial.py +++ /dev/null @@ -1,92 +0,0 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Adding model 'ServiceTicket' - db.create_table('cas_provider_serviceticket', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('ticket', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), - ('service', self.gf('django.db.models.fields.URLField')(max_length=200)), - )) - db.send_create_signal('cas_provider', ['ServiceTicket']) - - # Adding model 'LoginTicket' - db.create_table('cas_provider_loginticket', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('ticket', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - )) - db.send_create_signal('cas_provider', ['LoginTicket']) - - - def backwards(self, orm): - - # Deleting model 'ServiceTicket' - db.delete_table('cas_provider_serviceticket') - - # Deleting model 'LoginTicket' - db.delete_table('cas_provider_loginticket') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - 'cas_provider.loginticket': { - 'Meta': {'object_name': 'LoginTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.serviceticket': { - 'Meta': {'object_name': 'ServiceTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'service': ('django.db.models.fields.URLField', [], {'max_length': '200'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['cas_provider'] diff --git a/cas_provider/south_migrations/0002_auto__add_proxygrantingticket__add_proxyticket__add_proxygrantingticke.py b/cas_provider/south_migrations/0002_auto__add_proxygrantingticket__add_proxyticket__add_proxygrantingticke.py deleted file mode 100644 index 46247aa..0000000 --- a/cas_provider/south_migrations/0002_auto__add_proxygrantingticket__add_proxyticket__add_proxygrantingticke.py +++ /dev/null @@ -1,125 +0,0 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Adding model 'ProxyGrantingTicket' - db.create_table('cas_provider_proxygrantingticket', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('ticket', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('serviceTicket', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cas_provider.ServiceTicket'], null=True)), - ('pgtiou', self.gf('django.db.models.fields.CharField')(max_length=256)), - ('targetService', self.gf('django.db.models.fields.URLField')(max_length=200)), - )) - db.send_create_signal('cas_provider', ['ProxyGrantingTicket']) - - # Adding model 'ProxyTicket' - db.create_table('cas_provider_proxyticket', ( - ('serviceticket_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cas_provider.ServiceTicket'], unique=True, primary_key=True)), - ('proxyGrantingTicket', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cas_provider.ProxyGrantingTicket'])), - )) - db.send_create_signal('cas_provider', ['ProxyTicket']) - - # Adding model 'ProxyGrantingTicketIOU' - db.create_table('cas_provider_proxygrantingticketiou', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('ticket', self.gf('django.db.models.fields.CharField')(max_length=32)), - ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('proxyGrantingTicket', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cas_provider.ProxyGrantingTicket'])), - )) - db.send_create_signal('cas_provider', ['ProxyGrantingTicketIOU']) - - - def backwards(self, orm): - - # Deleting model 'ProxyGrantingTicket' - db.delete_table('cas_provider_proxygrantingticket') - - # Deleting model 'ProxyTicket' - db.delete_table('cas_provider_proxyticket') - - # Deleting model 'ProxyGrantingTicketIOU' - db.delete_table('cas_provider_proxygrantingticketiou') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - 'cas_provider.loginticket': { - 'Meta': {'object_name': 'LoginTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxygrantingticket': { - 'Meta': {'object_name': 'ProxyGrantingTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'pgtiou': ('django.db.models.fields.CharField', [], {'max_length': '256'}), - 'serviceTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ServiceTicket']", 'null': 'True'}), - 'targetService': ('django.db.models.fields.URLField', [], {'max_length': '200'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxygrantingticketiou': { - 'Meta': {'object_name': 'ProxyGrantingTicketIOU'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxyticket': { - 'Meta': {'object_name': 'ProxyTicket', '_ormbases': ['cas_provider.ServiceTicket']}, - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'serviceticket_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cas_provider.ServiceTicket']", 'unique': 'True', 'primary_key': 'True'}) - }, - 'cas_provider.serviceticket': { - 'Meta': {'object_name': 'ServiceTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'service': ('django.db.models.fields.URLField', [], {'max_length': '200'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['cas_provider'] diff --git a/cas_provider/south_migrations/0003_auto__del_field_proxygrantingticket_targetService.py b/cas_provider/south_migrations/0003_auto__del_field_proxygrantingticket_targetService.py deleted file mode 100644 index 46b5124..0000000 --- a/cas_provider/south_migrations/0003_auto__del_field_proxygrantingticket_targetService.py +++ /dev/null @@ -1,94 +0,0 @@ -# encoding: utf-8 -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - -class Migration(SchemaMigration): - - def forwards(self, orm): - - # Deleting field 'ProxyGrantingTicket.targetService' - db.delete_column('cas_provider_proxygrantingticket', 'targetService') - - - def backwards(self, orm): - - # Adding field 'ProxyGrantingTicket.targetService' - db.add_column('cas_provider_proxygrantingticket', 'targetService', self.gf('django.db.models.fields.URLField')(default='http://not.used', max_length=200), keep_default=False) - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - 'cas_provider.loginticket': { - 'Meta': {'object_name': 'LoginTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxygrantingticket': { - 'Meta': {'object_name': 'ProxyGrantingTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'pgtiou': ('django.db.models.fields.CharField', [], {'max_length': '256'}), - 'serviceTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ServiceTicket']", 'null': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxygrantingticketiou': { - 'Meta': {'object_name': 'ProxyGrantingTicketIOU'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxyticket': { - 'Meta': {'object_name': 'ProxyTicket', '_ormbases': ['cas_provider.ServiceTicket']}, - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'serviceticket_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cas_provider.ServiceTicket']", 'unique': 'True', 'primary_key': 'True'}) - }, - 'cas_provider.serviceticket': { - 'Meta': {'object_name': 'ServiceTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'service': ('django.db.models.fields.URLField', [], {'max_length': '200'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['cas_provider'] diff --git a/cas_provider/south_migrations/0004_auto__del_field_proxygrantingticket_serviceTicket__add_field_proxygran.py b/cas_provider/south_migrations/0004_auto__del_field_proxygrantingticket_serviceTicket__add_field_proxygran.py deleted file mode 100644 index 33e92cb..0000000 --- a/cas_provider/south_migrations/0004_auto__del_field_proxygrantingticket_serviceTicket__add_field_proxygran.py +++ /dev/null @@ -1,121 +0,0 @@ -# -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Deleting field 'ProxyGrantingTicket.serviceTicket' - db.delete_column('cas_provider_proxygrantingticket', 'serviceTicket_id') - - # Adding field 'ProxyGrantingTicket.user' - db.add_column('cas_provider_proxygrantingticket', 'user', - self.gf('django.db.models.fields.related.ForeignKey')(default=0, to=orm['auth.User']), - keep_default=False) - - # Adding field 'ProxyGrantingTicket.service' - db.add_column('cas_provider_proxygrantingticket', 'service', - self.gf('django.db.models.fields.URLField')(max_length=200, null=True), - keep_default=False) - - # Adding field 'ProxyGrantingTicket.pgt' - db.add_column('cas_provider_proxygrantingticket', 'pgt', - self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cas_provider.ProxyGrantingTicket'], null=True), - keep_default=False) - - - def backwards(self, orm): - # Adding field 'ProxyGrantingTicket.serviceTicket' - db.add_column('cas_provider_proxygrantingticket', 'serviceTicket', - self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cas_provider.ServiceTicket'], null=True), - keep_default=False) - - # Deleting field 'ProxyGrantingTicket.user' - db.delete_column('cas_provider_proxygrantingticket', 'user_id') - - # Deleting field 'ProxyGrantingTicket.service' - db.delete_column('cas_provider_proxygrantingticket', 'service') - - # Deleting field 'ProxyGrantingTicket.pgt' - db.delete_column('cas_provider_proxygrantingticket', 'pgt_id') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), - 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - 'auth.user': { - 'Meta': {'object_name': 'User'}, - 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), - 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), - 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), - 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), - 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - 'cas_provider.loginticket': { - 'Meta': {'object_name': 'LoginTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxygrantingticket': { - 'Meta': {'object_name': 'ProxyGrantingTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'pgt': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']", 'null': 'True'}), - 'pgtiou': ('django.db.models.fields.CharField', [], {'max_length': '256'}), - 'service': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - }, - 'cas_provider.proxygrantingticketiou': { - 'Meta': {'object_name': 'ProxyGrantingTicketIOU'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}) - }, - 'cas_provider.proxyticket': { - 'Meta': {'object_name': 'ProxyTicket', '_ormbases': ['cas_provider.ServiceTicket']}, - 'proxyGrantingTicket': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cas_provider.ProxyGrantingTicket']"}), - 'serviceticket_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cas_provider.ServiceTicket']", 'unique': 'True', 'primary_key': 'True'}) - }, - 'cas_provider.serviceticket': { - 'Meta': {'object_name': 'ServiceTicket'}, - 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'service': ('django.db.models.fields.URLField', [], {'max_length': '200'}), - 'ticket': ('django.db.models.fields.CharField', [], {'max_length': '32'}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) - }, - 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['cas_provider'] diff --git a/cas_provider/south_migrations/__init__.py b/cas_provider/south_migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cas_provider/views.py b/cas_provider/views.py index 0b18b22..ccf84a2 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -13,6 +13,7 @@ except ImportError: from urlparse import parse_qsl, urlparse, urlsplit, urlunsplit from functools import wraps +from django import VERSION from django.utils.decorators import available_attrs from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.cache import cache_control @@ -22,12 +23,11 @@ from django.views.decorators.csrf import csrf_protect from django.http import HttpResponse, HttpResponseRedirect from django.conf import settings from django.contrib.auth import login as auth_login, logout as auth_logout -from django.core.urlresolvers import get_callable + from django.shortcuts import render from django.utils.translation import ugettext as _ from django.template import RequestContext from django.contrib.auth import authenticate -from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ from lxml import etree @@ -39,6 +39,13 @@ from cas_provider.forms import LoginForm, MergeLoginForm from . import signals +if VERSION >= (1, 10): + from django.urls import get_callable, reverse + user_is_authenticated = lambda user: user.is_authenticated +else: + from django.core.urlresolvers import get_callable, reverse + user_is_authenticated = lambda user: user.is_authenticated() + __all__ = ['login', 'validate', 'logout', 'service_validate'] INVALID_TICKET = 'INVALID_TICKET' @@ -143,7 +150,7 @@ def login(request, template_name='cas/login.html', else: form = LoginForm(initial={'service': service}) - if user is not None and user.is_authenticated(): + if user is not None and user_is_authenticated(user): # We have an authenticated user. if not user.is_active: errors.append(_('This account is disabled. Please contact us if you feel it should be enabled again.')) @@ -220,7 +227,7 @@ def validate(request): def logout(request, template_name='cas/logout.html', auto_redirect=settings.CAS_AUTO_REDIRECT_AFTER_LOGOUT): url = request.GET.get('url', None) - if request.user.is_authenticated(): + if user_is_authenticated(request.user): for ticket in ServiceTicket.objects.filter(user=request.user): ticket.delete() auth_logout(request) diff --git a/cas_provider_examples/simple/settings.py b/cas_provider_examples/simple/settings.py index 2d4eda3..6a520b4 100644 --- a/cas_provider_examples/simple/settings.py +++ b/cas_provider_examples/simple/settings.py @@ -5,7 +5,6 @@ from django import VERSION # Django settings for xxx project. DEBUG = True -TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@example.com'), @@ -18,7 +17,7 @@ import os DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(os.path.realpath(__file__), 'db'), + 'NAME': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'db'), } } @@ -54,6 +53,11 @@ MEDIA_ROOT = '' # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '' +# Allow SHA1, because it's used in the fixture. +PASSWORD_HASHERS = [ + 'django.contrib.auth.hashers.SHA1PasswordHasher', +] + # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. @@ -87,14 +91,7 @@ STATICFILES_FINDERS = ( # Make this unique, and don't share it with anybody. SECRET_KEY = 'kv*6pmkq47crqskw%wkst!h7xnisy78zzli@rtklgm#y6o=of!' -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', -) - -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -102,14 +99,32 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', ) +# For Django < 1.10 +MIDDLEWARE_CLASSES = MIDDLEWARE + + ROOT_URLCONF = 'simple.urls' import os PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) -TEMPLATE_DIRS = ( - os.path.join(PROJECT_PATH, 'templates'), -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': [ + os.path.join(PROJECT_PATH, 'templates'), + ], + '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', + ], + }, + } +] INSTALLED_APPS = ( 'django.contrib.admin', @@ -123,9 +138,6 @@ INSTALLED_APPS = ( 'simple', ) -if VERSION < (1, 7): - INSTALLED_APPS += ('south',) - # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error. diff --git a/cas_provider_examples/simple/tests.py b/cas_provider_examples/simple/tests.py index 2d95228..6518bdf 100644 --- a/cas_provider_examples/simple/tests.py +++ b/cas_provider_examples/simple/tests.py @@ -8,9 +8,10 @@ from cas_provider.models import ServiceTicket from cas_provider.signals import cas_collect_custom_attributes from cas_provider.views import _cas2_sucess_response, INVALID_TICKET, _cas2_error_response, generate_proxy_granting_ticket from django.contrib.auth.models import User, UserManager -from django.core.urlresolvers import reverse from django.test import TestCase from django.conf import settings +from django import VERSION + try: from urllib.parse import urlparse, parse_qsl, parse_qs @@ -20,6 +21,12 @@ except: from urllib2 import install_opener +if VERSION >= (1, 10): + from django.urls import reverse + user_is_anonymous = lambda user: user.is_anonymous +else: + from django.core.urlresolvers import reverse + user_is_anonymous = lambda user: user.is_anonymous() class DummyOpener(object): @@ -160,7 +167,7 @@ class ViewsTest(TestCase): response = self.client.get(reverse('cas_login'), follow=False) self.assertEqual(response.status_code, 302) - self.assertTrue(response['location'].startswith('http://testserver/')) + self.assertTrue(response['location'].startswith('http://testserver/' if VERSION < (1, 9) else '/')) response = self.client.get(response['location'], follow=False) self.assertIn(response.status_code, [302, 200]) @@ -183,7 +190,7 @@ class ViewsTest(TestCase): response = self.client.get(reverse('cas_login'), follow=False) self.assertEqual(response.status_code, 200) - self.assertEqual(response.context['user'].is_anonymous(), True) + self.assertEqual(user_is_anonymous(response.context['user']), True) def test_broken_pwd(self): diff --git a/cas_provider_examples/simple/urls.py b/cas_provider_examples/simple/urls.py index f1b5378..62e735d 100644 --- a/cas_provider_examples/simple/urls.py +++ b/cas_provider_examples/simple/urls.py @@ -3,9 +3,13 @@ from __future__ import unicode_literals from django.conf.urls import include, url from django.contrib import admin from django.views.generic import TemplateView +from django import VERSION + +if VERSION >= (2,): + from django.urls import path urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(admin.site.urls)) if VERSION < (2,) else path('admin/', admin.site.urls), url(r'^', include('cas_provider.urls')), url(r'^accounts/profile', TemplateView.as_view(template_name='login-success-redirect-target.html')), ] diff --git a/tox.ini b/tox.ini index 97e9d22..4344927 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,6 @@ [tox] envlist=clear, - d1{5,6}-py{27}, - d{17,18}-py{27,34}, + d18-py{27,34}, d{19,110}-py{27,34,35}, d111-py{27,34,35,36,37}, d20-py{34,35,36,37}, @@ -11,9 +10,6 @@ envlist=clear, [testenv] commands=coverage run --source=cas_provider --append --branch cas_provider_examples/manage.py test simple deps= - d15: Django>=1.5,<1.6 - d16: Django>=1.6,<1.7 - d17: Django>=1.7,<1.8 d18: Django>=1.8,<1.9 d19: Django>=1.9,<1.10 d110: Django>=1.10,<1.11 @@ -22,6 +18,7 @@ deps= d21: Django>=2.1,<2.2 d15,d16: https://bitbucket.org/andrewgodwin/south/get/e2c9102ee033.zip coverage +usedevelop=True [testenv:clear] commands=coverage erase