This commit is contained in:
Valentin Samir 2016-06-26 16:02:25 +02:00
parent 8303f816df
commit 164e2f5c28
3 changed files with 33 additions and 33 deletions

View file

@ -10,25 +10,25 @@ from cas_server import utils
def get_login_page_params(): def get_login_page_params():
client = Client() client = Client()
response = client.get('/login') response = client.get('/login')
form = response.context["form"] form = response.context["form"]
params = {} params = {}
for field in form: for field in form:
if field.value(): if field.value():
params[field.name] = field.value() params[field.name] = field.value()
else: else:
params[field.name] = "" params[field.name] = ""
return client, params return client, params
def get_auth_client(): def get_auth_client():
client, params = get_login_page_params() client, params = get_login_page_params()
params["username"] = settings.CAS_TEST_USER params["username"] = settings.CAS_TEST_USER
params["password"] = settings.CAS_TEST_PASSWORD params["password"] = settings.CAS_TEST_PASSWORD
client.post('/login', params) client.post('/login', params)
return client return client
def get_user_ticket_request(service): def get_user_ticket_request(service):

View file

@ -30,7 +30,7 @@ def context(params):
return params return params
def JsonResponse(request, data): def json_response(request, data):
data["messages"] = [] data["messages"] = []
for msg in messages.get_messages(request): for msg in messages.get_messages(request):
data["messages"].append({'message': msg.message, 'level': msg.level_tag}) data["messages"].append({'message': msg.message, 'level': msg.level_tag})
@ -146,16 +146,16 @@ def gen_saml_id():
class PGTUrlHandler(BaseHTTPServer.BaseHTTPRequestHandler): class PGTUrlHandler(BaseHTTPServer.BaseHTTPRequestHandler):
PARAMS = {} PARAMS = {}
def do_GET(s): def do_GET(self):
s.send_response(200) self.send_response(200)
s.send_header(b"Content-type", "text/plain") self.send_header(b"Content-type", "text/plain")
s.end_headers() self.end_headers()
s.wfile.write(b"ok") self.wfile.write(b"ok")
url = urlparse(s.path) url = urlparse(self.path)
params = dict(parse_qsl(url.query)) params = dict(parse_qsl(url.query))
PGTUrlHandler.PARAMS.update(params) PGTUrlHandler.PARAMS.update(params)
def log_message(self, template, *args): def log_message(self, *args):
return return
@staticmethod @staticmethod

View file

@ -35,7 +35,7 @@ import cas_server.utils as utils
import cas_server.forms as forms import cas_server.forms as forms
import cas_server.models as models import cas_server.models as models
from .utils import JsonResponse from .utils import json_response
from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket from .models import ServiceTicket, ProxyTicket, ProxyGrantingTicket
from .models import ServicePattern from .models import ServicePattern
@ -154,13 +154,13 @@ class LogoutView(View, LogoutMixin):
'url': url, 'url': url,
'session_nb': session_nb 'session_nb': session_nb
} }
return JsonResponse(request, data) return json_response(request, data)
else: else:
return redirect("cas_server:login") return redirect("cas_server:login")
else: else:
if self.ajax: if self.ajax:
data = {'status': 'success', 'detail': 'logout', 'session_nb': session_nb} data = {'status': 'success', 'detail': 'logout', 'session_nb': session_nb}
return JsonResponse(request, data) return json_response(request, data)
else: else:
return render( return render(
request, request,
@ -253,7 +253,7 @@ class LoginView(View, LogoutMixin):
raise EnvironmentError("invalid output for LoginView.process_post") raise EnvironmentError("invalid output for LoginView.process_post")
return self.common() return self.common()
def process_post(self, pytest=False): def process_post(self):
if not self.check_lt(): if not self.check_lt():
values = self.request.POST.copy() values = self.request.POST.copy()
# if not set a new LT and fail # if not set a new LT and fail
@ -330,7 +330,7 @@ class LoginView(View, LogoutMixin):
) )
if self.ajax: if self.ajax:
data = {"status": "error", "detail": "confirmation needed"} data = {"status": "error", "detail": "confirmation needed"}
return JsonResponse(self.request, data) return json_response(self.request, data)
else: else:
warn_form = forms.WarnForm(initial={ warn_form = forms.WarnForm(initial={
'service': self.service, 'service': self.service,
@ -357,7 +357,7 @@ class LoginView(View, LogoutMixin):
return HttpResponseRedirect(redirect_url) return HttpResponseRedirect(redirect_url)
else: else:
data = {"status": "success", "detail": "auth", "url": redirect_url} data = {"status": "success", "detail": "auth", "url": redirect_url}
return JsonResponse(self.request, data) return json_response(self.request, data)
except ServicePattern.DoesNotExist: except ServicePattern.DoesNotExist:
error = 1 error = 1
messages.add_message( messages.add_message(
@ -401,7 +401,7 @@ class LoginView(View, LogoutMixin):
) )
else: else:
data = {"status": "error", "detail": "auth", "code": error} data = {"status": "error", "detail": "auth", "code": error}
return JsonResponse(self.request, data) return json_response(self.request, data)
def authenticated(self): def authenticated(self):
"""Processing authenticated users""" """Processing authenticated users"""
@ -423,7 +423,7 @@ class LoginView(View, LogoutMixin):
"detail": "login required", "detail": "login required",
"url": utils.reverse_params("cas_server:login", params=self.request.GET) "url": utils.reverse_params("cas_server:login", params=self.request.GET)
} }
return JsonResponse(self.request, data) return json_response(self.request, data)
else: else:
return utils.redirect_params("cas_server:login", params=self.request.GET) return utils.redirect_params("cas_server:login", params=self.request.GET)
@ -433,7 +433,7 @@ class LoginView(View, LogoutMixin):
else: else:
if self.ajax: if self.ajax:
data = {"status": "success", "detail": "logged"} data = {"status": "success", "detail": "logged"}
return JsonResponse(self.request, data) return json_response(self.request, data)
else: else:
return render( return render(
self.request, self.request,
@ -476,7 +476,7 @@ class LoginView(View, LogoutMixin):
"detail": "login required", "detail": "login required",
"url": utils.reverse_params("cas_server:login", params=self.request.GET) "url": utils.reverse_params("cas_server:login", params=self.request.GET)
} }
return JsonResponse(self.request, data) return json_response(self.request, data)
else: else:
return render( return render(
self.request, self.request,