示例#1
0
class ProxyTest(helper.CPWebCase):
    def setUp(self):
        self.sp = FakeSP('tests.configurations.sp_conf')
        self.idp = FakeIdP(USERS)

    @staticmethod
    def setup_server():
        app = WsgiApplication('tests.configurations.proxy_conf',
                              'http://example.com/unittest_idp.xml')

        cherrypy.tree.graft(app.run_server, '/')

    def test_flow(self):
        url = self.sp.make_auth_req()
        status, headers, _ = self.getPage(url)
        assert status == '303 See Other'

        url = self.get_redirect_location(headers)
        req = parse_qs(urlsplit(url).query)
        assert 'SAMLRequest' in req
        assert 'RelayState' in req

        action, body = self.idp.handle_auth_req(req['SAMLRequest'][0],
                                                req['RelayState'][0],
                                                BINDING_HTTP_REDIRECT,
                                                'test1')
        status, headers, body = self.getPage(action, method='POST',
                                             body=urlencode(body))
        assert status == '302 Found'

        url = self.get_redirect_location(headers)
        req = parse_qs(urlsplit(url).query)
        assert 'SAMLResponse' in req
        assert 'RelayState' in req
        resp = self.sp.parse_authn_request_response(req['SAMLResponse'][0],
                                                    BINDING_HTTP_REDIRECT)
        identity = resp.ava
        assert identity["displayName"][0] == "Test1"
        assert identity["sn"][0] == "test1@valueA"
        assert identity['o'][0] == "Small university"

    def get_redirect_location(self, headers):
        for header, value in headers:
            if header.lower() == 'location':
                return value
示例#2
0
class ProxyTest(helper.CPWebCase):
    def setUp(self):
        self.sp = FakeSP('tests.configurations.sp_conf')
        self.idp = FakeIdP(USERS)

    @staticmethod
    def setup_server():
        app = WsgiApplication('tests.configurations.proxy_conf',
                              'http://example.com/unittest_idp.xml')

        cherrypy.tree.graft(app.run_server, '/')

    def test_flow(self):
        url = self.sp.make_auth_req()
        status, headers, _ = self.getPage(url)
        assert status == '303 See Other'

        url = self.get_redirect_location(headers)
        req = parse_qs(urlsplit(url).query)
        assert 'SAMLRequest' in req
        assert 'RelayState' in req

        action, body = self.idp.handle_auth_req(req['SAMLRequest'][0],
                                                req['RelayState'][0],
                                                BINDING_HTTP_REDIRECT, 'test1')
        status, headers, body = self.getPage(action,
                                             method='POST',
                                             body=urlencode(body))
        assert status == '302 Found'

        url = self.get_redirect_location(headers)
        req = parse_qs(urlsplit(url).query)
        assert 'SAMLResponse' in req
        assert 'RelayState' in req
        resp = self.sp.parse_authn_request_response(req['SAMLResponse'][0],
                                                    BINDING_HTTP_REDIRECT)
        identity = resp.ava
        assert identity["displayName"][0] == "Test1"
        assert identity["sn"][0] == "test1@valueA"
        assert identity['o'][0] == "Small university"

    def get_redirect_location(self, headers):
        for header, value in headers:
            if header.lower() == 'location':
                return value
示例#3
0
 def setUp(self):
     self.sp = FakeSP('tests.configurations.sp_conf')
     self.idp = FakeIdP(USERS)
示例#4
0
 def setUp(self):
     self.sp = FakeSP('tests.configurations.sp_conf')
     self.idp = FakeIdP(USERS)