~corey.bryant/ubuntu/wily/python-pysaml2/3.0.0

« back to all changes in this revision

Viewing changes to tests/test_76_metadata_in_mdb.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-08 16:11:53 UTC
  • Revision ID: package-import@ubuntu.com-20140908161153-vms9r4gu0oz4v4ai
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
__author__ = 'rolandh'
 
4
 
 
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
 
12
 
 
13
from saml2 import saml
 
14
from saml2 import md
 
15
from saml2 import config
 
16
 
 
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
 
22
import xmldsig
 
23
import xmlenc
 
24
 
 
25
from pathutils import full_path
 
26
 
 
27
ONTS = {
 
28
    saml.NAMESPACE: saml,
 
29
    mdui.NAMESPACE: mdui,
 
30
    mdattr.NAMESPACE: mdattr,
 
31
    dri.NAMESPACE: dri,
 
32
    ui.NAMESPACE: ui,
 
33
    idpdisc.NAMESPACE: idpdisc,
 
34
    md.NAMESPACE: md,
 
35
    xmldsig.NAMESPACE: xmldsig,
 
36
    xmlenc.NAMESPACE: xmlenc
 
37
}
 
38
 
 
39
ATTRCONV = ac_factory(full_path("attributemaps"))
 
40
 
 
41
 
 
42
def _eq(l1, l2):
 
43
    return set(l1) == set(l2)
 
44
 
 
45
 
 
46
def test_metadata():
 
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)
 
53
 
 
54
    # Import metadata from local file.
 
55
    mds.imp({"local": [full_path("swamid-2.0.xml")]})
 
56
    assert len(mds) == 1  # One source
 
57
 
 
58
    export_mdstore_to_mongo_db(mds, "metadata", "test")
 
59
 
 
60
    mdmdb = MetadataMDB(ONTS, ATTRCONV, "metadata", "test")
 
61
    # replace all metadata instances with this one
 
62
    mds.metadata = {"mongo_db": mdmdb}
 
63
 
 
64
    idps = mds.with_descriptor("idpsso")
 
65
    assert idps.keys()
 
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']
 
70
 
 
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
 
75
 
 
76
    sps = mds.with_descriptor("spsso")
 
77
    assert len(sps) == 417
 
78
 
 
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'])
 
84
 
 
85
    wants = mds.attribute_requirement(
 
86
        "https://gidp.geant.net/sp/module.php/saml/sp/metadata.php/default-sp")
 
87
    # Optional
 
88
    lnamn = [d_to_local_name(mds.attrc, attr) for attr in wants["optional"]]
 
89
    assert _eq(lnamn, ['displayName', 'commonName', 'schacHomeOrganization',
 
90
                       'eduPersonAffiliation', 'schacHomeOrganizationType'])
 
91
    # Required
 
92
    lnamn = [d_to_local_name(mds.attrc, attr) for attr in wants["required"]]
 
93
    assert _eq(lnamn, ['eduPersonTargetedID', 'mail',
 
94
                       'eduPersonScopedAffiliation'])
 
95
 
 
96
if __name__ == "__main__":
 
97
    test_metadata()