Skip to content

Commit 4935c66

Browse files
author
Hans Hörberg
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # setup.py # src/saml2/server.py
2 parents 361b29f + 2ce425c commit 4935c66

25 files changed

+500
-326
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ language: python
33
sudo: false
44

55
env:
6-
- TOX_ENV=py27
7-
- TOX_ENV=py34
6+
- TOXENV=py27
7+
- TOXENV=py34
88

99
addons:
1010
apt:
@@ -14,5 +14,8 @@ addons:
1414
services:
1515
- mongodb
1616

17+
install:
18+
- pip install -U tox
19+
1720
script:
18-
- ./setup.py test
21+
- tox

example/idp2/idp.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,19 @@ def operation(self, saml_msg, binding):
143143
return resp(self.environ, self.start_response)
144144
else:
145145
kwargs = {}
146+
146147
try:
147-
_encrypt_cert = encrypt_cert_from_item(
148+
kwargs['encrypt_cert'] = encrypt_cert_from_item(
148149
saml_msg["req_info"].message)
149-
return self.do(saml_msg["SAMLRequest"], binding,
150-
saml_msg["RelayState"],
151-
encrypt_cert=_encrypt_cert, **kwargs)
152150
except KeyError:
153-
# Can live with no relay state
154-
return self.do(saml_msg["SAMLRequest"], binding,
155-
saml_msg["RelayState"], **kwargs)
151+
pass
152+
153+
try:
154+
kwargs['relay_state'] = saml_msg['RelayState']
155+
except KeyError:
156+
pass
157+
158+
return self.do(saml_msg["SAMLRequest"], binding, **kwargs)
156159

157160
def artifact_operation(self, saml_msg):
158161
if not saml_msg:

example/idp2/idp_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"ou": "IT",
6969
"initials": "P",
7070
#"schacHomeOrganization": "example.com",
71-
"email": "[email protected]",
71+
"mail": "[email protected]",
7272
"displayName": "P. Roland Hedberg",
7373
"labeledURL": "http://www.example.com/rohe My homepage",
7474
"norEduPersonNIN": "SE197001012222"

example/sp-wsgi/sp.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from saml2.response import StatusError
3939
from saml2.response import VerificationError
4040
from saml2.s_utils import UnknownPrincipal
41+
from saml2.s_utils import decode_base64_and_inflate
4142
from saml2.s_utils import UnsupportedBinding
4243
from saml2.s_utils import sid
4344
from saml2.s_utils import rndstr
@@ -634,8 +635,18 @@ def __init__(self, sp, environ, start_response, cache=None):
634635
self.sp = sp
635636
self.cache = cache
636637

637-
def do(self, response, binding, relay_state="", mtype="response"):
638-
req_info = self.sp.parse_logout_request_response(response, binding)
638+
def do(self, message, binding, relay_state="", mtype="response"):
639+
try:
640+
txt = decode_base64_and_inflate(message)
641+
is_logout_request = 'LogoutRequest' in txt.split('>', 1)[0]
642+
except: # TODO: parse the XML correctly
643+
is_logout_request = False
644+
645+
if is_logout_request:
646+
self.sp.parse_logout_request(message, binding)
647+
else:
648+
self.sp.parse_logout_request_response(message, binding)
649+
639650
return finish_logout(self.environ, self.start_response)
640651

641652
# ----------------------------------------------------------------------------

setup.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@
66
from setuptools import setup
77
from setuptools.command.test import test as TestCommand
88

9-
10-
class PyTest(TestCommand):
11-
12-
def finalize_options(self):
13-
TestCommand.finalize_options(self)
14-
self.test_args = []
15-
self.test_suite = True
16-
17-
def run_tests(self):
18-
#import here, cause outside the eggs aren't loaded
19-
import pytest
20-
errno = pytest.main(self.test_args)
21-
sys.exit(errno)
22-
23-
249
install_requires = [
2510
# core dependencies
2611
'decorator',
@@ -35,18 +20,6 @@ def run_tests(self):
3520
'six'
3621
]
3722

38-
tests_require = [
39-
'mongodict',
40-
'pyasn1',
41-
'pymongo==3.0.1',
42-
'python-memcached >= 1.51',
43-
'pytest',
44-
'mako',
45-
'webob',
46-
'mock'
47-
#'pytest-coverage',
48-
]
49-
5023
version = ''
5124
with open('src/saml2/__init__.py', 'r') as fd:
5225
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
@@ -79,13 +52,6 @@ def run_tests(self):
7952

8053
scripts=["tools/parse_xsd2.py", "tools/make_metadata.py",
8154
"tools/mdexport.py", "tools/merge_metadata.py"],
82-
83-
tests_require=tests_require,
84-
extras_require={
85-
'testing': tests_require,
86-
},
8755
install_requires=install_requires,
8856
zip_safe=False,
89-
test_suite='tests',
90-
cmdclass={'test': PyTest},
9157
)

src/saml2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def extension_elements_to_elements(extension_elements, schemas):
979979
if isinstance(schemas, list):
980980
pass
981981
elif isinstance(schemas, dict):
982-
schemas = schemas.values()
982+
schemas = list(schemas.values())
983983
else:
984984
return res
985985

src/saml2/attribute_converter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,19 @@ def to_format(self, attr):
425425
:return: An Attribute instance
426426
"""
427427
try:
428+
_attr = self._to[attr]
429+
except KeyError:
430+
try:
431+
_attr = self._to[attr.lower()]
432+
except:
433+
_attr = ''
434+
435+
if _attr:
428436
return factory(saml.Attribute,
429-
name=self._to[attr],
437+
name=_attr,
430438
name_format=self.name_format,
431439
friendly_name=attr)
432-
except KeyError:
440+
else:
433441
return factory(saml.Attribute, name=attr)
434442

435443
def from_format(self, attr):

src/saml2/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def prepare_for_authenticate(
5656
successfull log in.
5757
:param binding: Which binding to use for sending the request
5858
:param vorg: The entity_id of the virtual organization I'm a member of
59+
:param nameid_format:
5960
:param scoping: For which IdPs this query are aimed.
6061
:param consent: Whether the principal have given her consent
6162
:param extensions: Possible extensions
@@ -95,6 +96,7 @@ def prepare_for_negotiated_authenticate(
9596
successfull log in.
9697
:param binding: Which binding to use for sending the request
9798
:param vorg: The entity_id of the virtual organization I'm a member of
99+
:param nameid_format:
98100
:param scoping: For which IdPs this query are aimed.
99101
:param consent: Whether the principal have given her consent
100102
:param extensions: Possible extensions

src/saml2/client_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def _sso_location(self, entityid=None, binding=BINDING_HTTP_REDIRECT):
155155
except IndexError:
156156
raise IdpUnspecified("No IdP to send to given the premises")
157157

158+
def sso_location(self, entityid=None, binding=BINDING_HTTP_REDIRECT):
159+
return self._sso_location(entityid, binding)
160+
158161
def _my_name(self):
159162
return self.config.name
160163

src/saml2/entity.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,16 @@ def apply_binding(self, binding, msg_str, destination="", relay_state="",
215215

216216
if binding == BINDING_HTTP_POST:
217217
logger.info("HTTP POST")
218+
# if self.entity_type == 'sp':
219+
# info = self.use_http_post(msg_str, destination, relay_state,
220+
# typ)
221+
# info["url"] = destination
222+
# info["method"] = "POST"
223+
# else:
218224
info = self.use_http_form_post(msg_str, destination,
219225
relay_state, typ)
220226
info["url"] = destination
221-
info["method"] = "GET"
227+
info["method"] = "POST"
222228
elif binding == BINDING_HTTP_REDIRECT:
223229
logger.info("HTTP REDIRECT")
224230
info = self.use_http_get(msg_str, destination, relay_state, typ,

0 commit comments

Comments
 (0)