Handled changes in config classes, return format on global_logout method and more
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from saml2 import BINDING_HTTP_REDIRECT
|
||||
from saml2.config import Config
|
||||
from saml2.config import SPConfig, IDPConfig
|
||||
from saml2.metadata import MetaData
|
||||
from py.test import raises
|
||||
|
||||
@@ -105,7 +105,7 @@ def _eq(l1,l2):
|
||||
return set(l1) == set(l2)
|
||||
|
||||
def test_1():
|
||||
c = Config().load(sp1)
|
||||
c = SPConfig().load(sp1)
|
||||
|
||||
print c
|
||||
service = c["service"]
|
||||
@@ -120,7 +120,7 @@ def test_1():
|
||||
assert sp["idp"].values() == [{'single_sign_on_service': {'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect':'http://localhost:8088/sso/'}}]
|
||||
|
||||
def test_2():
|
||||
c = Config().load(sp2)
|
||||
c = SPConfig().load(sp2)
|
||||
|
||||
print c
|
||||
service = c["service"]
|
||||
@@ -164,7 +164,7 @@ def test_missing_must():
|
||||
},
|
||||
}
|
||||
|
||||
c = Config()
|
||||
c = SPConfig()
|
||||
raises(AssertionError, "c.load(no_service)")
|
||||
raises(AssertionError, "c.load(no_entity_id)")
|
||||
raises(AssertionError, "c.load(no_xmlsec)")
|
||||
@@ -186,12 +186,12 @@ def test_minimum():
|
||||
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
|
||||
}
|
||||
|
||||
c = Config().load(minimum)
|
||||
c = SPConfig().load(minimum)
|
||||
|
||||
assert c != None
|
||||
|
||||
def test_idp_1():
|
||||
c = Config().load(IDP1)
|
||||
c = IDPConfig().load(IDP1)
|
||||
|
||||
print c
|
||||
assert c.services() == ["idp"]
|
||||
@@ -201,7 +201,7 @@ def test_idp_1():
|
||||
assert attribute_restrictions["eduPersonAffiliation"][0].match("staff")
|
||||
|
||||
def test_idp_2():
|
||||
c = Config().load(IDP2)
|
||||
c = IDPConfig().load(IDP2)
|
||||
|
||||
print c
|
||||
assert c.services() == ["idp"]
|
||||
@@ -212,7 +212,7 @@ def test_idp_2():
|
||||
assert attribute_restrictions["eduPersonAffiliation"][0].match("staff")
|
||||
|
||||
def test_wayf():
|
||||
c = Config().load_file("server.config")
|
||||
c = SPConfig().load_file("server.config")
|
||||
|
||||
idps = c.get_available_idps()
|
||||
assert idps == [('urn:mace:example.com:saml:roland:idp', 'Exempel AB')]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from saml2 import samlp
|
||||
from saml2.saml import NAMEID_FORMAT_PERSISTENT, NAMEID_FORMAT_TRANSIENT
|
||||
from saml2.config import Config
|
||||
from saml2.config import IDPConfig
|
||||
from saml2.server import Identifier
|
||||
from saml2.assertion import Policy
|
||||
|
||||
@@ -10,7 +10,7 @@ from saml2.assertion import Policy
|
||||
def _eq(l1,l2):
|
||||
return set(l1) == set(l2)
|
||||
|
||||
CONFIG = Config().load({
|
||||
CONFIG = IDPConfig().load({
|
||||
"entityid" : "urn:mace:example.com:idp:2",
|
||||
"service": {
|
||||
"idp": {
|
||||
|
||||
@@ -51,10 +51,8 @@ class TestResponse:
|
||||
name_id = name_id,
|
||||
authn=(saml.AUTHN_PASSWORD, "http://www.example.com/login")
|
||||
)
|
||||
|
||||
self._logout_resp = server.logout_response("id12")
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
try:
|
||||
conf.load_file("tests/server.config")
|
||||
except IOError:
|
||||
@@ -84,15 +82,15 @@ class TestResponse:
|
||||
assert isinstance(resp, StatusResponse)
|
||||
assert isinstance(resp, AuthnResponse)
|
||||
|
||||
def test_3(self):
|
||||
xml_response = ("%s" % (self._logout_resp,)).split("\n")[1]
|
||||
sec = security_context(self.conf)
|
||||
resp = response_factory(xml_response, self.conf,
|
||||
entity_id="urn:mace:example.com:saml:roland:sp",
|
||||
return_addr="http://lingon.catalogix.se:8087/",
|
||||
outstanding_queries={"id12": "http://localhost:8088/sso"},
|
||||
timeslack=10000, decode=False)
|
||||
|
||||
assert isinstance(resp, StatusResponse)
|
||||
assert isinstance(resp, LogoutResponse)
|
||||
# def test_3(self):
|
||||
# xml_response = ("%s" % (self._logout_resp,)).split("\n")[1]
|
||||
# sec = security_context(self.conf)
|
||||
# resp = response_factory(xml_response, self.conf,
|
||||
# entity_id="urn:mace:example.com:saml:roland:sp",
|
||||
# return_addr="http://lingon.catalogix.se:8087/",
|
||||
# outstanding_queries={"id12": "http://localhost:8088/sso"},
|
||||
# timeslack=10000, decode=False)
|
||||
#
|
||||
# assert isinstance(resp, StatusResponse)
|
||||
# assert isinstance(resp, LogoutResponse)
|
||||
|
||||
@@ -46,9 +46,7 @@ class TestAuthnResponse:
|
||||
authn=(saml.AUTHN_PASSWORD, "http://www.example.com/login")
|
||||
)
|
||||
|
||||
self._logout_resp = server.logout_response("id12")
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
try:
|
||||
conf.load_file("tests/server.config")
|
||||
except IOError:
|
||||
|
||||
@@ -9,7 +9,7 @@ from saml2 import time_util
|
||||
from saml2.s_utils import OtherError
|
||||
from saml2.s_utils import do_attribute_statement, factory
|
||||
from saml2.soap import make_soap_enveloped_saml_thingy
|
||||
from saml2 import BINDING_HTTP_POST
|
||||
from saml2 import BINDING_HTTP_POST, BINDING_HTTP_REDIRECT, BINDING_SOAP
|
||||
|
||||
from py.test import raises
|
||||
import shelve
|
||||
@@ -60,7 +60,7 @@ class TestServer1():
|
||||
def setup_class(self):
|
||||
self.server = Server("idp.config")
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
try:
|
||||
conf.load_file("tests/server.config")
|
||||
except IOError:
|
||||
@@ -372,7 +372,7 @@ class TestServer1():
|
||||
"surName": "Laport",
|
||||
}
|
||||
}
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
conf.load_file("server2.config")
|
||||
sp = client.Saml2Client(conf)
|
||||
|
||||
@@ -424,4 +424,40 @@ class TestServer2():
|
||||
assert subject.subject_confirmation
|
||||
subject_confirmation = subject.subject_confirmation
|
||||
assert subject_confirmation.subject_confirmation_data.in_response_to == "aaa"
|
||||
|
||||
|
||||
def _logout_request(conf_file):
|
||||
conf = config.SPConfig()
|
||||
conf.load_file(conf_file)
|
||||
sp = client.Saml2Client(conf)
|
||||
|
||||
soon = time_util.in_a_while(days=1)
|
||||
sinfo = {
|
||||
"name_id": "foba0001",
|
||||
"issuer": "urn:mace:example.com:saml:roland:idp",
|
||||
"not_on_or_after" : soon,
|
||||
"user": {
|
||||
"givenName": "Leo",
|
||||
"surName": "Laport",
|
||||
}
|
||||
}
|
||||
sp.users.add_information_about_person(sinfo)
|
||||
|
||||
return sp.logout_requests(
|
||||
subject_id = "foba0001",
|
||||
destination = "http://localhost:8088/slo",
|
||||
entity_id = "urn:mace:example.com:saml:roland:idp",
|
||||
reason = "I'm tired of this")
|
||||
|
||||
class TestServerLogout():
|
||||
|
||||
def test_1(self):
|
||||
server = Server("idp_slo_redirect.conf")
|
||||
request = _logout_request("sp_slo_redirect.conf")
|
||||
print request
|
||||
bindings = [BINDING_HTTP_REDIRECT]
|
||||
(resp, headers, message) = server.logout_response(request, bindings)
|
||||
assert resp == '302 Found'
|
||||
assert len(headers) == 1
|
||||
assert headers[0][0] == "Location"
|
||||
assert message == ['']
|
||||
|
||||
@@ -55,7 +55,7 @@ class TestClient:
|
||||
def setup_class(self):
|
||||
self.server = Server("idp.config")
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
try:
|
||||
conf.load_file("tests/server.config")
|
||||
except IOError:
|
||||
@@ -385,9 +385,10 @@ class TestClient:
|
||||
print resp
|
||||
assert resp
|
||||
assert resp[0] # a session_id
|
||||
assert resp[1] == [('Content-type', 'text/html')]
|
||||
assert resp[2][0] == '<head>'
|
||||
assert resp[2][1] == '<title>SAML 2.0 POST</title>'
|
||||
assert resp[1] == '200 OK'
|
||||
assert resp[2] == [('Content-type', 'text/html')]
|
||||
assert resp[3][0] == '<head>'
|
||||
assert resp[3][1] == '<title>SAML 2.0 POST</title>'
|
||||
session_info = self.client.state[resp[0]]
|
||||
print session_info
|
||||
assert session_info["entity_id"] == entity_ids[0]
|
||||
@@ -400,7 +401,7 @@ class TestClient:
|
||||
def test_logout_2(self):
|
||||
""" one IdP/AA with BINDING_SOAP, can't actually send something"""
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
conf.load_file("server2.config")
|
||||
client = Saml2Client(conf)
|
||||
|
||||
@@ -428,7 +429,7 @@ class TestClient:
|
||||
def test_logout_3(self):
|
||||
""" two or more IdP/AA with BINDING_HTTP_REDIRECT"""
|
||||
|
||||
conf = config.Config()
|
||||
conf = config.SPConfig()
|
||||
conf.load_file("server3.config")
|
||||
client = Saml2Client(conf)
|
||||
|
||||
@@ -460,10 +461,11 @@ class TestClient:
|
||||
print resp
|
||||
assert resp
|
||||
assert resp[0] # a session_id
|
||||
assert resp[1] == '200 OK'
|
||||
# HTTP POST
|
||||
assert resp[1] == [('Content-type', 'text/html')]
|
||||
assert resp[2][0] == '<head>'
|
||||
assert resp[2][1] == '<title>SAML 2.0 POST</title>'
|
||||
assert resp[2] == [('Content-type', 'text/html')]
|
||||
assert resp[3][0] == '<head>'
|
||||
assert resp[3][1] == '<title>SAML 2.0 POST</title>'
|
||||
|
||||
state_info = client.state[resp[0]]
|
||||
print state_info
|
||||
|
||||
Reference in New Issue
Block a user