1
# -*- coding: utf-8 -*-
5
from saml2.attribute_converter import d_to_local_name
6
from saml2.attribute_converter import ac_factory
7
from saml2.mongo_store import export_mdstore_to_mongo_db
8
from saml2.mongo_store import MetadataMDB
9
from saml2.mdstore import MetadataStore
10
from saml2.mdstore import destinations
11
from saml2.mdstore import name
13
from saml2 import saml
15
from saml2 import config
17
from saml2.extension import mdui
18
from saml2.extension import idpdisc
19
from saml2.extension import dri
20
from saml2.extension import mdattr
21
from saml2.extension import ui
25
from pathutils import full_path
30
mdattr.NAMESPACE: mdattr,
33
idpdisc.NAMESPACE: idpdisc,
35
xmldsig.NAMESPACE: xmldsig,
36
xmlenc.NAMESPACE: xmlenc
39
ATTRCONV = ac_factory(full_path("attributemaps"))
43
return set(l1) == set(l2)
47
conf = config.Config()
48
conf.load_file("idp_conf_mdb")
49
UMU_IDP = 'https://idp.umu.se/saml2/idp/metadata.php'
50
# Set up a Metadata store
51
mds = MetadataStore(ONTS.values(), ATTRCONV, conf,
52
disable_ssl_certificate_validation=True)
54
# Import metadata from local file.
55
mds.imp({"local": [full_path("swamid-2.0.xml")]})
56
assert len(mds) == 1 # One source
58
export_mdstore_to_mongo_db(mds, "metadata", "test")
60
mdmdb = MetadataMDB(ONTS, ATTRCONV, "metadata", "test")
61
# replace all metadata instances with this one
62
mds.metadata = {"mongo_db": mdmdb}
64
idps = mds.with_descriptor("idpsso")
66
idpsso = mds.single_sign_on_service(UMU_IDP)
67
assert len(idpsso) == 1
68
assert destinations(idpsso) == [
69
'https://idp.umu.se/saml2/idp/SSOService.php']
71
_name = name(mds[UMU_IDP])
72
assert _name == u'Ume\xe5 University'
73
certs = mds.certs(UMU_IDP, "idpsso", "signing")
74
assert len(certs) == 1
76
sps = mds.with_descriptor("spsso")
77
assert len(sps) == 417
79
wants = mds.attribute_requirement('https://connect.sunet.se/shibboleth')
80
assert wants["optional"] == []
81
lnamn = [d_to_local_name(mds.attrc, attr) for attr in wants["required"]]
82
assert _eq(lnamn, ['eduPersonPrincipalName', 'mail', 'givenName', 'sn',
83
'eduPersonScopedAffiliation', 'eduPersonAffiliation'])
85
wants = mds.attribute_requirement(
86
"https://gidp.geant.net/sp/module.php/saml/sp/metadata.php/default-sp")
88
lnamn = [d_to_local_name(mds.attrc, attr) for attr in wants["optional"]]
89
assert _eq(lnamn, ['displayName', 'commonName', 'schacHomeOrganization',
90
'eduPersonAffiliation', 'schacHomeOrganizationType'])
92
lnamn = [d_to_local_name(mds.attrc, attr) for attr in wants["required"]]
93
assert _eq(lnamn, ['eduPersonTargetedID', 'mail',
94
'eduPersonScopedAffiliation'])
96
if __name__ == "__main__":