python3 compatibility

This commit is contained in:
Valentin Samir 2016-06-24 23:37:24 +02:00
parent 0776e371e8
commit 4bb886f083
3 changed files with 35 additions and 41 deletions

View File

@ -5,8 +5,8 @@ from django.test import Client
from lxml import etree from lxml import etree
import models from cas_server import models
import utils from cas_server import utils
def get_login_page_params(): def get_login_page_params():
@ -79,8 +79,8 @@ class LoginTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue( self.assertTrue(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -100,11 +100,11 @@ class LoginTestCase(TestCase):
response = client.post('/login', params) response = client.post('/login', params)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue("Invalid login ticket" in response.content) self.assertTrue(b"Invalid login ticket" in response.content)
self.assertFalse( self.assertFalse(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -117,14 +117,14 @@ class LoginTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue( self.assertTrue(
( (
"The credentials you provided cannot be " b"The credentials you provided cannot be "
"determined to be authentic" b"determined to be authentic"
) in response.content ) in response.content
) )
self.assertFalse( self.assertFalse(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -155,7 +155,7 @@ class LoginTestCase(TestCase):
client = get_auth_client() client = get_auth_client()
response = client.get("/login?service=https://www.example.org") response = client.get("/login?service=https://www.example.org")
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue("Service https://www.example.org non allowed" in response.content) self.assertTrue(b"Service https://www.example.org non allowed" in response.content)
class LogoutTestCase(TestCase): class LogoutTestCase(TestCase):
@ -170,8 +170,8 @@ class LogoutTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue( self.assertTrue(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -179,8 +179,8 @@ class LogoutTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue( self.assertTrue(
( (
"You have successfully logged out from " b"You have successfully logged out from "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -188,8 +188,8 @@ class LogoutTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFalse( self.assertFalse(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -205,8 +205,8 @@ class LogoutTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFalse( self.assertFalse(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -222,8 +222,8 @@ class LogoutTestCase(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFalse( self.assertFalse(
( (
"You have successfully logged into " b"You have successfully logged into "
"the Central Authentication Service" b"the Central Authentication Service"
) in response.content ) in response.content
) )
@ -251,7 +251,7 @@ class AuthTestCase(TestCase):
} }
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'yes\n') self.assertEqual(response.content, b'yes\n')
def test_auth_view_badpass(self): def test_auth_view_badpass(self):
settings.CAS_AUTH_SHARED_SECRET = 'test' settings.CAS_AUTH_SHARED_SECRET = 'test'
@ -266,7 +266,7 @@ class AuthTestCase(TestCase):
} }
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'no\n') self.assertEqual(response.content, b'no\n')
def test_auth_view_badservice(self): def test_auth_view_badservice(self):
settings.CAS_AUTH_SHARED_SECRET = 'test' settings.CAS_AUTH_SHARED_SECRET = 'test'
@ -281,7 +281,7 @@ class AuthTestCase(TestCase):
} }
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'no\n') self.assertEqual(response.content, b'no\n')
def test_auth_view_badsecret(self): def test_auth_view_badsecret(self):
settings.CAS_AUTH_SHARED_SECRET = 'test' settings.CAS_AUTH_SHARED_SECRET = 'test'
@ -296,7 +296,7 @@ class AuthTestCase(TestCase):
} }
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'no\n') self.assertEqual(response.content, b'no\n')
def test_auth_view_badsettings(self): def test_auth_view_badsettings(self):
settings.CAS_AUTH_SHARED_SECRET = None settings.CAS_AUTH_SHARED_SECRET = None
@ -311,7 +311,7 @@ class AuthTestCase(TestCase):
} }
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, "no\nplease set CAS_AUTH_SHARED_SECRET") self.assertEqual(response.content, b"no\nplease set CAS_AUTH_SHARED_SECRET")
class ValidateTestCase(TestCase): class ValidateTestCase(TestCase):
@ -331,7 +331,7 @@ class ValidateTestCase(TestCase):
client = Client() client = Client()
response = client.get('/validate', {'ticket': ticket.value, 'service': self.service}) response = client.get('/validate', {'ticket': ticket.value, 'service': self.service})
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'yes\ntest\n') self.assertEqual(response.content, b'yes\ntest\n')
def test_validate_view_badservice(self): def test_validate_view_badservice(self):
(user, ticket) = get_user_ticket_request(self.service) (user, ticket) = get_user_ticket_request(self.service)
@ -342,7 +342,7 @@ class ValidateTestCase(TestCase):
{'ticket': ticket.value, 'service': "https://www.example.org"} {'ticket': ticket.value, 'service': "https://www.example.org"}
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'no\n') self.assertEqual(response.content, b'no\n')
def test_validate_view_badticket(self): def test_validate_view_badticket(self):
(user, ticket) = get_user_ticket_request(self.service) (user, ticket) = get_user_ticket_request(self.service)
@ -353,7 +353,7 @@ class ValidateTestCase(TestCase):
{'ticket': "%s-RANDOM" % settings.CAS_SERVICE_TICKET_PREFIX, 'service': self.service} {'ticket': "%s-RANDOM" % settings.CAS_SERVICE_TICKET_PREFIX, 'service': self.service}
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'no\n') self.assertEqual(response.content, b'no\n')
class ValidateServiceTestCase(TestCase): class ValidateServiceTestCase(TestCase):

View File

@ -14,7 +14,7 @@ from django.conf.urls import patterns, url
from django.views.generic import RedirectView from django.views.generic import RedirectView
from django.views.decorators.debug import sensitive_post_parameters, sensitive_variables from django.views.decorators.debug import sensitive_post_parameters, sensitive_variables
import views from cas_server import views
urlpatterns = patterns( urlpatterns = patterns(
'', '',

View File

@ -19,15 +19,10 @@ from django.contrib import messages
import random import random
import string import string
import json import json
import BaseHTTPServer
from threading import Thread from threading import Thread
from importlib import import_module from importlib import import_module
from six.moves import BaseHTTPServer
try: from six.moves.urllib.parse import urlparse, urlunparse, parse_qsl, urlencode
from urlparse import urlparse, urlunparse, parse_qsl
from urllib import urlencode
except ImportError:
from urllib.parse import urlparse, urlunparse, parse_qsl, urlencode
def context(params): def context(params):
@ -153,13 +148,12 @@ class PGTUrlHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s): def do_GET(s):
s.send_response(200) s.send_response(200)
s.send_header("Content-type", "text/plain") s.send_header(b"Content-type", "text/plain")
s.end_headers() s.end_headers()
s.wfile.write("ok") s.wfile.write(b"ok")
url = urlparse(s.path) url = urlparse(s.path)
params = dict(parse_qsl(url.query)) params = dict(parse_qsl(url.query))
PGTUrlHandler.PARAMS.update(params) PGTUrlHandler.PARAMS.update(params)
s.wfile.write("%s" % params)
def log_message(self, format, *args): def log_message(self, format, *args):
return return