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

« back to all changes in this revision

Viewing changes to tests/test_62_vo.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
from saml2.saml import NameID
 
2
from saml2.saml import NAMEID_FORMAT_TRANSIENT
 
3
 
 
4
__author__ = 'rolandh'
 
5
 
 
6
from saml2 import config
 
7
from saml2.client import Saml2Client
 
8
from saml2.time_util import str_to_time, in_a_while
 
9
 
 
10
SESSION_INFO_PATTERN = {"ava": {}, "came from": "", "not_on_or_after": 0,
 
11
                        "issuer": "", "session_id": -1}
 
12
 
 
13
nid = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
 
14
             text="abcdefgh")
 
15
nid0 = NameID(name_qualifier="foo", format=NAMEID_FORMAT_TRANSIENT,
 
16
              text="01234567")
 
17
 
 
18
 
 
19
def add_derek_info(sp):
 
20
    not_on_or_after = str_to_time(in_a_while(days=1))
 
21
    session_info = SESSION_INFO_PATTERN.copy()
 
22
    session_info["ava"] = {"givenName": ["Derek"], "umuselin": ["deje0001"]}
 
23
    session_info["issuer"] = "urn:mace:example.com:saml:idp"
 
24
    session_info["name_id"] = nid
 
25
    session_info["not_on_or_after"] = not_on_or_after
 
26
    # subject_id, entity_id, info, timestamp
 
27
    sp.users.add_information_about_person(session_info)
 
28
 
 
29
 
 
30
class TestVirtualOrg():
 
31
    def setup_class(self):
 
32
        conf = config.SPConfig()
 
33
        conf.load_file("server_conf")
 
34
        self.sp = Saml2Client(conf)
 
35
 
 
36
        vo_name = conf.vorg.keys()[0]
 
37
        self.vo = conf.vorg[vo_name]
 
38
        add_derek_info(self.sp)
 
39
 
 
40
    def test_mta(self):
 
41
        aas = self.vo.members_to_ask(nid)
 
42
        print aas
 
43
        assert len(aas) == 1
 
44
        assert 'urn:mace:example.com:saml:aa' in aas
 
45
 
 
46
    def test_unknown_subject(self):
 
47
        aas = self.vo.members_to_ask(nid0)
 
48
        print aas
 
49
        assert len(aas) == 2
 
50
 
 
51
    def test_id(self):
 
52
        cid = self.vo.get_common_identifier(nid)
 
53
        print cid
 
54
        assert cid == "deje0001"
 
55
 
 
56
    def test_id_unknown(self):
 
57
        cid = self.vo.get_common_identifier(nid0)
 
58
        assert cid is None
 
59
 
 
60
 
 
61
class TestVirtualOrg_2():
 
62
    def setup_class(self):
 
63
        conf = config.SPConfig()
 
64
        conf.load_file("server_conf")
 
65
        vo_name = conf.vorg.keys()[0]
 
66
        self.sp = Saml2Client(conf, virtual_organization=vo_name)
 
67
        add_derek_info(self.sp)
 
68
 
 
69
    def test_mta(self):
 
70
        aas = self.sp.vorg.members_to_ask(nid)
 
71
        print aas
 
72
        assert len(aas) == 1
 
73
        assert 'urn:mace:example.com:saml:aa' in aas
 
74
 
 
75
    def test_unknown_subject(self):
 
76
        aas = self.sp.vorg.members_to_ask(nid0)
 
77
        print aas
 
78
        assert len(aas) == 2
 
79
 
 
80
    def test_id(self):
 
81
        cid = self.sp.vorg.get_common_identifier(nid)
 
82
        print cid
 
83
        assert cid == "deje0001"
 
84
 
 
85
    def test_id_unknown(self):
 
86
        cid = self.sp.vorg.get_common_identifier(nid0)
 
87
        assert cid is None