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.
This commit is contained in:
Clint Byrum
2015-05-26 11:11:18 -07:00
parent 2a9e2804b9
commit 994d11b358
3 changed files with 18 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ import copy
import re import re
import urllib import urllib
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse
from six.moves.urllib.parse import urlencode
import requests import requests
import time import time
from six.moves.http_cookies import SimpleCookie from six.moves.http_cookies import SimpleCookie
@@ -269,10 +270,10 @@ class HTTPBase(object):
@staticmethod @staticmethod
def use_http_artifact(message, destination="", relay_state=""): def use_http_artifact(message, destination="", relay_state=""):
if relay_state: if relay_state:
query = urllib.urlencode({"SAMLart": message, query = urlencode({"SAMLart": message,
"RelayState": relay_state}) "RelayState": relay_state})
else: else:
query = urllib.urlencode({"SAMLart": message}) query = urlencode({"SAMLart": message})
info = { info = {
"data": "", "data": "",
"url": "%s?%s" % (destination, query) "url": "%s?%s" % (destination, query)
@@ -281,9 +282,13 @@ class HTTPBase(object):
@staticmethod @staticmethod
def use_http_uri(message, typ, destination="", relay_state=""): def use_http_uri(message, typ, destination="", relay_state=""):
if "\n" in message:
data = message.split("\n")[1]
else:
data = message.strip()
if typ == "SAMLResponse": if typ == "SAMLResponse":
info = { info = {
"data": message.split("\n")[1], "data": data,
"headers": [ "headers": [
("Content-Type", "application/samlassertion+xml"), ("Content-Type", "application/samlassertion+xml"),
("Cache-Control", "no-cache, no-store"), ("Cache-Control", "no-cache, no-store"),
@@ -293,10 +298,10 @@ class HTTPBase(object):
elif typ == "SAMLRequest": elif typ == "SAMLRequest":
# msg should be an identifier # msg should be an identifier
if relay_state: if relay_state:
query = urllib.urlencode({"ID": message, query = urlencode({"ID": message,
"RelayState": relay_state}) "RelayState": relay_state})
else: else:
query = urllib.urlencode({"ID": message}) query = urlencode({"ID": message})
info = { info = {
"data": "", "data": "",
"url": "%s?%s" % (destination, query) "url": "%s?%s" % (destination, query)

View File

@@ -59,12 +59,15 @@ def http_form_post_message(message, location, relay_state="",
response = ["<head>", """<title>SAML 2.0 POST</title>""", "</head><body>"] response = ["<head>", """<title>SAML 2.0 POST</title>""", "</head><body>"]
if not isinstance(message, six.string_types): if not isinstance(message, six.string_types):
message = "%s" % (message,) message = str(message)
if not isinstance(message, six.binary_type):
message = message.encode('utf-8')
if typ == "SAMLRequest" or typ == "SAMLResponse": if typ == "SAMLRequest" or typ == "SAMLResponse":
_msg = base64.b64encode(message) _msg = base64.b64encode(message)
else: else:
_msg = message _msg = message
_msg = _msg.decode('ascii')
response.append(FORM_SPEC % (location, typ, _msg, relay_state)) response.append(FORM_SPEC % (location, typ, _msg, relay_state))

View File

@@ -1,6 +1,6 @@
from contextlib import closing from contextlib import closing
from urlparse import parse_qs from six.moves.urllib.parse import parse_qs
from urlparse import urlparse from six.moves.urllib.parse import urlparse
from saml2.authn_context import INTERNETPROTOCOLPASSWORD from saml2.authn_context import INTERNETPROTOCOLPASSWORD
from saml2.samlp import AuthnRequest from saml2.samlp import AuthnRequest
from saml2.samlp import NameIDPolicy from saml2.samlp import NameIDPolicy