Language correction.
Deal with case where people want to JSON serialize session information. Carry over more parameters in create_attribute_response.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import shelve
|
import shelve
|
||||||
|
import six
|
||||||
from saml2.ident import code, decode
|
from saml2.ident import code, decode
|
||||||
from saml2 import time_util, SAMLError
|
from saml2 import time_util, SAMLError
|
||||||
import logging
|
import logging
|
||||||
@@ -98,6 +99,8 @@ class Cache(object):
|
|||||||
if check_not_on_or_after and time_util.after(timestamp):
|
if check_not_on_or_after and time_util.after(timestamp):
|
||||||
raise ToOld("past %s" % str(timestamp))
|
raise ToOld("past %s" % str(timestamp))
|
||||||
|
|
||||||
|
if 'name_id' in info and isinstance(info['name_id'], six.string_types):
|
||||||
|
info['name_id'] = decode(info['name_id'])
|
||||||
return info or None
|
return info or None
|
||||||
|
|
||||||
def set(self, name_id, entity_id, info, not_on_or_after=0):
|
def set(self, name_id, entity_id, info, not_on_or_after=0):
|
||||||
|
@@ -29,8 +29,8 @@ class Unknown(SAMLError):
|
|||||||
def code(item):
|
def code(item):
|
||||||
"""
|
"""
|
||||||
Turn a NameID class instance into a quoted string of comma separated
|
Turn a NameID class instance into a quoted string of comma separated
|
||||||
attribute,value pairs. The attribute name is replaced with a digits.
|
attribute,value pairs. The attribute names are replaced with digits.
|
||||||
Depends on knowledge on the specific order of the attributes for that
|
Depends on knowledge on the specific order of the attributes for the
|
||||||
class that is used.
|
class that is used.
|
||||||
|
|
||||||
:param item: The class instance
|
:param item: The class instance
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from saml2.cache import Cache
|
|
||||||
import six
|
import six
|
||||||
|
from saml2.cache import Cache
|
||||||
|
from saml2.ident import code
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@ class Population(object):
|
|||||||
this function will overwrite that information"""
|
this function will overwrite that information"""
|
||||||
|
|
||||||
name_id = session_info["name_id"]
|
name_id = session_info["name_id"]
|
||||||
|
# make friendly to (JSON) serialization
|
||||||
|
session_info['name_id'] = code(name_id)
|
||||||
issuer = session_info["issuer"]
|
issuer = session_info["issuer"]
|
||||||
del session_info["issuer"]
|
del session_info["issuer"]
|
||||||
self.cache.set(name_id, issuer, session_info,
|
self.cache.set(name_id, issuer, session_info,
|
||||||
|
@@ -480,7 +480,7 @@ class Server(Entity):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
to_sign = []
|
to_sign = []
|
||||||
args = {}
|
|
||||||
if identity:
|
if identity:
|
||||||
_issuer = self._issuer(issuer)
|
_issuer = self._issuer(issuer)
|
||||||
ast = Assertion(identity)
|
ast = Assertion(identity)
|
||||||
@@ -505,12 +505,16 @@ class Server(Entity):
|
|||||||
digest_alg=digest_alg)
|
digest_alg=digest_alg)
|
||||||
# Just the assertion or the response and the assertion ?
|
# Just the assertion or the response and the assertion ?
|
||||||
to_sign = [(class_name(assertion), assertion.id)]
|
to_sign = [(class_name(assertion), assertion.id)]
|
||||||
|
kwargs['sign_assertion'] = True
|
||||||
|
|
||||||
args["assertion"] = assertion
|
kwargs["assertion"] = assertion
|
||||||
|
|
||||||
|
if sp_entity_id:
|
||||||
|
kwargs['sp_entity_id'] = sp_entity_id
|
||||||
|
|
||||||
return self._response(in_response_to, destination, status, issuer,
|
return self._response(in_response_to, destination, status, issuer,
|
||||||
sign_response, to_sign, sign_alg=sign_alg,
|
sign_response, to_sign, sign_alg=sign_alg,
|
||||||
digest_alg=digest_alg, **args)
|
digest_alg=digest_alg, **kwargs)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -7,30 +7,32 @@ from saml2.cache import Cache
|
|||||||
from saml2.time_util import in_a_while, str_to_time
|
from saml2.time_util import in_a_while, str_to_time
|
||||||
from saml2.ident import code
|
from saml2.ident import code
|
||||||
|
|
||||||
SESSION_INFO_PATTERN = {"ava":{}, "came from":"", "not_on_or_after":0,
|
SESSION_INFO_PATTERN = {"ava": {}, "came from": "", "not_on_or_after": 0,
|
||||||
"issuer":"", "session_id":-1}
|
"issuer": "", "session_id": -1}
|
||||||
|
|
||||||
|
|
||||||
def _eq(l1,l2):
|
def _eq(l1, l2):
|
||||||
return set(l1) == set(l2)
|
return set(l1) == set(l2)
|
||||||
|
|
||||||
|
|
||||||
def nid_eq(l1, l2):
|
def nid_eq(l1, l2):
|
||||||
return _eq([code(c) for c in l1], [code(c) for c in l2])
|
return _eq([code(c) for c in l1], [code(c) for c in l2])
|
||||||
|
|
||||||
|
|
||||||
nid = [
|
nid = [
|
||||||
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="1234"),
|
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="1234"),
|
||||||
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="9876"),
|
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="9876"),
|
||||||
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="1000")]
|
NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT, text="1000")]
|
||||||
|
|
||||||
|
|
||||||
class TestClass:
|
class TestClass:
|
||||||
def setup_class(self):
|
def setup_class(self):
|
||||||
self.cache = Cache()
|
self.cache = Cache()
|
||||||
|
|
||||||
|
|
||||||
def test_set(self):
|
def test_set(self):
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
not_on_or_after = str_to_time(in_a_while(days=1))
|
||||||
session_info = SESSION_INFO_PATTERN.copy()
|
session_info = SESSION_INFO_PATTERN.copy()
|
||||||
session_info["ava"] = {"givenName":["Derek"]}
|
session_info["ava"] = {"givenName": ["Derek"]}
|
||||||
self.cache.set(nid[0], "abcd", session_info, not_on_or_after)
|
self.cache.set(nid[0], "abcd", session_info, not_on_or_after)
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity(nid[0])
|
(ava, inactive) = self.cache.get_identity(nid[0])
|
||||||
@@ -41,12 +43,12 @@ class TestClass:
|
|||||||
def test_add_ava_info(self):
|
def test_add_ava_info(self):
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
not_on_or_after = str_to_time(in_a_while(days=1))
|
||||||
session_info = SESSION_INFO_PATTERN.copy()
|
session_info = SESSION_INFO_PATTERN.copy()
|
||||||
session_info["ava"] = {"surName":["Jeter"]}
|
session_info["ava"] = {"surName": ["Jeter"]}
|
||||||
self.cache.set(nid[0], "bcde", session_info, not_on_or_after)
|
self.cache.set(nid[0], "bcde", session_info, not_on_or_after)
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity(nid[0])
|
(ava, inactive) = self.cache.get_identity(nid[0])
|
||||||
assert inactive == []
|
assert inactive == []
|
||||||
assert _eq(ava.keys(), ["givenName","surName"])
|
assert _eq(ava.keys(), ["givenName", "surName"])
|
||||||
assert ava["givenName"] == ["Derek"]
|
assert ava["givenName"] == ["Derek"]
|
||||||
assert ava["surName"] == ["Jeter"]
|
assert ava["surName"] == ["Jeter"]
|
||||||
|
|
||||||
@@ -84,14 +86,14 @@ class TestClass:
|
|||||||
def test_second_subject(self):
|
def test_second_subject(self):
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
not_on_or_after = str_to_time(in_a_while(days=1))
|
||||||
session_info = SESSION_INFO_PATTERN.copy()
|
session_info = SESSION_INFO_PATTERN.copy()
|
||||||
session_info["ava"] = {"givenName":["Ichiro"],
|
session_info["ava"] = {"givenName": ["Ichiro"],
|
||||||
"surName":["Suzuki"]}
|
"surName": ["Suzuki"]}
|
||||||
self.cache.set(nid[1], "abcd", session_info,
|
self.cache.set(nid[1], "abcd", session_info,
|
||||||
not_on_or_after)
|
not_on_or_after)
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity(nid[1])
|
(ava, inactive) = self.cache.get_identity(nid[1])
|
||||||
assert inactive == []
|
assert inactive == []
|
||||||
assert _eq(ava.keys(), ["givenName","surName"])
|
assert _eq(ava.keys(), ["givenName", "surName"])
|
||||||
assert ava["givenName"] == ["Ichiro"]
|
assert ava["givenName"] == ["Ichiro"]
|
||||||
assert ava["surName"] == ["Suzuki"]
|
assert ava["surName"] == ["Suzuki"]
|
||||||
assert nid_eq(self.cache.subjects(), [nid[0], nid[1]])
|
assert nid_eq(self.cache.subjects(), [nid[0], nid[1]])
|
||||||
@@ -101,10 +103,10 @@ class TestClass:
|
|||||||
|
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
not_on_or_after = str_to_time(in_a_while(days=1))
|
||||||
session_info = SESSION_INFO_PATTERN.copy()
|
session_info = SESSION_INFO_PATTERN.copy()
|
||||||
session_info["ava"] = {"givenName":["Ichiro"],
|
session_info["ava"] = {"givenName": ["Ichiro"],
|
||||||
"surName":["Suzuki"]}
|
"surName": ["Suzuki"]}
|
||||||
self.cache.set(nid[1], "bcde", session_info,
|
self.cache.set(nid[1], "bcde", session_info,
|
||||||
not_on_or_after)
|
not_on_or_after)
|
||||||
|
|
||||||
assert _eq(self.cache.receivers(nid[1]), ["abcd", "bcde"])
|
assert _eq(self.cache.receivers(nid[1]), ["abcd", "bcde"])
|
||||||
assert nid_eq(self.cache.subjects(), nid[0:2])
|
assert nid_eq(self.cache.subjects(), nid[0:2])
|
||||||
@@ -112,13 +114,12 @@ class TestClass:
|
|||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
not_on_or_after = str_to_time(in_a_while(seconds=1))
|
not_on_or_after = str_to_time(in_a_while(seconds=1))
|
||||||
session_info = SESSION_INFO_PATTERN.copy()
|
session_info = SESSION_INFO_PATTERN.copy()
|
||||||
session_info["ava"] = {"givenName":["Alex"],
|
session_info["ava"] = {"givenName": ["Alex"],
|
||||||
"surName":["Rodriguez"]}
|
"surName": ["Rodriguez"]}
|
||||||
self.cache.set(nid[2], "bcde", session_info,
|
self.cache.set(nid[2], "bcde", session_info,
|
||||||
not_on_or_after)
|
not_on_or_after)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
(ava, inactive) = self.cache.get_identity(nid[2])
|
(ava, inactive) = self.cache.get_identity(nid[2])
|
||||||
assert inactive == ["bcde"]
|
assert inactive == ["bcde"]
|
||||||
assert ava == {}
|
assert ava == {}
|
||||||
|
|
||||||
|
@@ -10,8 +10,9 @@ IDP_OTHER = "urn:mace:example.com:saml:other:idp"
|
|||||||
|
|
||||||
nid = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
|
nid = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
|
||||||
text="123456")
|
text="123456")
|
||||||
|
|
||||||
nida = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
|
nida = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
|
||||||
text="abcdef")
|
text="abcdef")
|
||||||
|
|
||||||
cnid = code(nid)
|
cnid = code(nid)
|
||||||
cnida = code(nida)
|
cnida = code(nida)
|
||||||
|
@@ -1204,7 +1204,7 @@ class TestServer2():
|
|||||||
print(aa_policy.__dict__)
|
print(aa_policy.__dict__)
|
||||||
response = self.server.create_attribute_response(
|
response = self.server.create_attribute_response(
|
||||||
IDENTITY.copy(), "aaa", "http://example.com/sp/",
|
IDENTITY.copy(), "aaa", "http://example.com/sp/",
|
||||||
"urn:mace:example.com:sp:1")
|
"http://www.example.com/roland/sp")
|
||||||
|
|
||||||
assert response is not None
|
assert response is not None
|
||||||
assert response.destination == "http://example.com/sp/"
|
assert response.destination == "http://example.com/sp/"
|
||||||
|
Reference in New Issue
Block a user