Skip to content

Commit 994d11b

Browse files
committed
Fix assertion ID tests for python3
Fixing basic renames reveals that some assumptions about the XML produced by etree need fixing, and there is a need to coerce some strings into bytes before base64.
1 parent 2a9e280 commit 994d11b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/saml2/httpbase.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import urllib
77
from six.moves.urllib.parse import urlparse
8+
from six.moves.urllib.parse import urlencode
89
import requests
910
import time
1011
from six.moves.http_cookies import SimpleCookie
@@ -269,10 +270,10 @@ def use_http_form_post(message, destination, relay_state,
269270
@staticmethod
270271
def use_http_artifact(message, destination="", relay_state=""):
271272
if relay_state:
272-
query = urllib.urlencode({"SAMLart": message,
273-
"RelayState": relay_state})
273+
query = urlencode({"SAMLart": message,
274+
"RelayState": relay_state})
274275
else:
275-
query = urllib.urlencode({"SAMLart": message})
276+
query = urlencode({"SAMLart": message})
276277
info = {
277278
"data": "",
278279
"url": "%s?%s" % (destination, query)
@@ -281,9 +282,13 @@ def use_http_artifact(message, destination="", relay_state=""):
281282

282283
@staticmethod
283284
def use_http_uri(message, typ, destination="", relay_state=""):
285+
if "\n" in message:
286+
data = message.split("\n")[1]
287+
else:
288+
data = message.strip()
284289
if typ == "SAMLResponse":
285290
info = {
286-
"data": message.split("\n")[1],
291+
"data": data,
287292
"headers": [
288293
("Content-Type", "application/samlassertion+xml"),
289294
("Cache-Control", "no-cache, no-store"),
@@ -293,10 +298,10 @@ def use_http_uri(message, typ, destination="", relay_state=""):
293298
elif typ == "SAMLRequest":
294299
# msg should be an identifier
295300
if relay_state:
296-
query = urllib.urlencode({"ID": message,
297-
"RelayState": relay_state})
301+
query = urlencode({"ID": message,
302+
"RelayState": relay_state})
298303
else:
299-
query = urllib.urlencode({"ID": message})
304+
query = urlencode({"ID": message})
300305
info = {
301306
"data": "",
302307
"url": "%s?%s" % (destination, query)

src/saml2/pack.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ def http_form_post_message(message, location, relay_state="",
5959
response = ["<head>", """<title>SAML 2.0 POST</title>""", "</head><body>"]
6060

6161
if not isinstance(message, six.string_types):
62-
message = "%s" % (message,)
62+
message = str(message)
63+
if not isinstance(message, six.binary_type):
64+
message = message.encode('utf-8')
6365

6466
if typ == "SAMLRequest" or typ == "SAMLResponse":
6567
_msg = base64.b64encode(message)
6668
else:
6769
_msg = message
70+
_msg = _msg.decode('ascii')
6871

6972
response.append(FORM_SPEC % (location, typ, _msg, relay_state))
7073

tests/test_68_assertion_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from contextlib import closing
2-
from urlparse import parse_qs
3-
from urlparse import urlparse
2+
from six.moves.urllib.parse import parse_qs
3+
from six.moves.urllib.parse import urlparse
44
from saml2.authn_context import INTERNETPROTOCOLPASSWORD
55
from saml2.samlp import AuthnRequest
66
from saml2.samlp import NameIDPolicy

0 commit comments

Comments
 (0)