Skip to content
Snippets Groups Projects
Commit 56247c8b authored by ale's avatar ale
Browse files

More py3 fixes

parent 8a4c673f
No related branches found
No related tags found
1 merge request!4Drop Python 2 support
#!/usr/bin/python
import Cookie
import httplib
import os
import re
import subprocess
import sys
import time
import unittest
import urllib
import urlparse
from http.client import HTTPConnection
from http.cookies import SimpleCookie
from urllib.parse import urlencode, urlsplit, parse_qsl
sys.path.append("../../python")
import sso
......@@ -93,7 +92,7 @@ def _stop_httpd(httpd):
def _query(url, host=None, cookie=None):
"""Make a simple request to url using httplib."""
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
headers = {"Host": host or "localhost"}
if cookie:
headers["Cookie"] = cookie
......@@ -268,10 +267,10 @@ class HttpdIntegrationTestBase(unittest.TestCase):
if not sso_login_url:
sso_login_url = '/%s/sso_login' % sso_service.split('/', 1)[1]
cookies = Cookie.SimpleCookie()
cookies = SimpleCookie()
# Make a request to a protected URL.
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
conn.request("GET", url, headers={'Host': host_header})
resp = conn.getresponse()
self.assertEquals(302, resp.status)
......@@ -279,16 +278,16 @@ class HttpdIntegrationTestBase(unittest.TestCase):
self.assertTrue(set_cookie_hdr)
cookies.load(set_cookie_hdr)
location = resp.getheader("Location")
location_u = urlparse.urlsplit(location)
location_args = dict(urlparse.parse_qsl(location_u.query))
location_u = urlsplit(location)
location_args = dict(parse_qsl(location_u.query))
nonce = location_args.get('n')
self.assertTrue(nonce)
conn.close()
# Now call the /sso_login endpoint.
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
tkt = self._ticket(nonce=nonce, service=sso_service)
conn.request("GET", sso_login_url + "?" + urllib.urlencode(
conn.request("GET", sso_login_url + "?" + urlencode(
{"t": tkt, "d": "https://" + host_header + url}), headers={
"Cookie": cookies.output(attrs=[], header='', sep='; '),
"Host": host_header,
......@@ -302,7 +301,7 @@ class HttpdIntegrationTestBase(unittest.TestCase):
conn.close()
# Make the original request again.
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
conn.request("GET", url, headers={
"Cookie": cookies.output(attrs=[], header='', sep='; '),
'Host': host_header,
......@@ -345,10 +344,10 @@ class HttpdIntegrationTest(HttpdIntegrationTestBase):
def test_sso_login(self):
# Call the /sso_login endpoint, verify that it sets the local
# SSO cookie to whatever the 't' parameter says.
cookies = Cookie.SimpleCookie()
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
cookies = SimpleCookie()
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
tkt = self._ticket()
conn.request("GET", "/sso_login?%s" % urllib.urlencode(
conn.request("GET", "/sso_login?%s" % urlencode(
{"t": tkt, "d": "https://service.example.com/index.html"}))
resp = conn.getresponse()
self.assertEquals(302, resp.status)
......@@ -360,7 +359,7 @@ class HttpdIntegrationTest(HttpdIntegrationTestBase):
def test_sso_logout(self):
# test the /sso_logout endpoint
conn = httplib.HTTPConnection("127.0.0.1", APACHE_PORT)
conn = HTTPConnection("127.0.0.1", APACHE_PORT)
conn.request("GET", "/sso_logout", headers={
"Cookie": mkcookie(self._ticket())})
resp = conn.getresponse()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment