當前位置: 首頁>>代碼示例>>Python>>正文


Python application.Application類代碼示例

本文整理匯總了Python中stormpath.resources.application.Application的典型用法代碼示例。如果您正苦於以下問題:Python Application類的具體用法?Python Application怎麽用?Python Application使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Application類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: IDSiteCallbackTest

class IDSiteCallbackTest(IDSiteBuildURITest):

    def setUp(self):
        super(IDSiteCallbackTest, self).setUp()
        self.store = MagicMock()
        self.store.get_resource.return_value = {'href': 'acchref', 'sp_http_status': 200}
        self.store._cache_get.return_value = False # ignore nonce

        self.client.data_store = self.store

        self.app = Application(
                client=self.client,
                properties={'href': 'apphref', 'accounts': {'href': 'acchref'}})

        self.acc = MagicMock(href='acchref')
        now = datetime.datetime.utcnow()

        try:
            irt = uuid4().get_hex()
        except AttributeError:
            irt = uuid4().hex

        fake_jwt_data = {
                'exp': now + datetime.timedelta(seconds=3600),
                'aud': self.app._client.auth.id,
                'irt': irt,
                'iss': 'Stormpath',
                'sub': self.acc.href,
                'isNewSub': False,
                'state': None,
        }

        self.fake_jwt = to_unicode(jwt.encode(
            fake_jwt_data,
            self.app._client.auth.secret,
            'HS256'), 'UTF-8')

    def test_id_site_callback_handler(self):
        fake_jwt_response = 'http://localhost/?jwtResponse=%s' % self.fake_jwt
        ret = self.app.handle_id_site_callback(fake_jwt_response)
        self.assertIsNotNone(ret)
        self.assertEqual(ret.account.href, self.acc.href)
        self.assertIsNone(ret.state)

    def test_id_site_callback_handler_jwt_already_used(self):
        self.store._cache_get.return_value = True # Fake Nonce already used

        fake_jwt_response = 'http://localhost/?jwtResponse=%s' % self.fake_jwt
        self.assertRaises(ValueError, self.app.handle_id_site_callback, fake_jwt_response)

    def test_id_site_callback_handler_invalid_jwt(self):
        fake_jwt_response = 'http://localhost/?jwtResponse=%s' % 'INVALID_JWT'
        ret = self.app.handle_id_site_callback(fake_jwt_response)
        self.assertIsNone(ret)

    def test_id_site_callback_handler_invalid_url_response(self):
        fake_jwt_response = 'invalid_url_response'
        ret = self.app.handle_id_site_callback(fake_jwt_response)
        self.assertIsNone(ret)
開發者ID:kkinder,項目名稱:stormpath-sdk-python,代碼行數:59,代碼來源:test_id_site.py

示例2: test_building_saml_redirect_uri

    def test_building_saml_redirect_uri(self):
        try:
            from urlparse import urlparse
        except ImportError:
            from urllib.parse import urlparse

        app = Application(client=self.client, properties={'href': 'apphref'})

        ret = app.build_saml_idp_redirect_url(
            'http://localhost/', 'apphref/saml/sso/idpRedirect')
        try:
            jwt_response = urlparse(ret).query.split('=')[1]
        except:
            self.fail("Failed to parse ID site redirect uri")

        try:
            decoded_data = jwt.decode(
                jwt_response, verify=False, algorithms=['HS256'])
        except jwt.DecodeError:
            self.fail("Invaid JWT generated.")

        self.assertIsNotNone(decoded_data.get('iat'))
        self.assertIsNotNone(decoded_data.get('jti'))
        self.assertIsNotNone(decoded_data.get('iss'))
        self.assertIsNotNone(decoded_data.get('sub'))
        self.assertIsNotNone(decoded_data.get('cb_uri'))
        self.assertEqual(decoded_data.get('cb_uri'), 'http://localhost/')
        self.assertIsNone(decoded_data.get('path'))
        self.assertIsNone(decoded_data.get('state'))

        ret = app.build_saml_idp_redirect_url(
                'http://testserver/',
                'apphref/saml/sso/idpRedirect',
                path='/#/register',
                state='test')
        try:
            jwt_response = urlparse(ret).query.split('=')[1]
        except:
            self.fail("Failed to parse SAML redirect uri")

        try:
            decoded_data = jwt.decode(
                jwt_response, verify=False, algorithms=['HS256'])
        except jwt.DecodeError:
            self.fail("Invaid JWT generated.")

        self.assertEqual(decoded_data.get('path'), '/#/register')
        self.assertEqual(decoded_data.get('state'), 'test')
開發者ID:RepositPower,項目名稱:stormpath-sdk-python,代碼行數:48,代碼來源:test_saml.py

示例3: setUp

    def setUp(self):
        super(IDSiteCallbackTest, self).setUp()
        self.store = MagicMock()
        self.store.get_resource.return_value = {'href': 'acchref', 'sp_http_status': 200}
        self.store._cache_get.return_value = False # ignore nonce

        self.client.data_store = self.store

        self.app = Application(
                client=self.client,
                properties={'href': 'apphref', 'accounts': {'href': 'acchref'}})

        self.acc = MagicMock(href='acchref')
        now = datetime.datetime.utcnow()

        try:
            irt = uuid4().get_hex()
        except AttributeError:
            irt = uuid4().hex

        fake_jwt_data = {
                'exp': now + datetime.timedelta(seconds=3600),
                'aud': self.app._client.auth.id,
                'irt': irt,
                'iss': 'Stormpath',
                'sub': self.acc.href,
                'isNewSub': False,
                'state': None,
        }

        self.fake_jwt = to_unicode(jwt.encode(
            fake_jwt_data,
            self.app._client.auth.secret,
            'HS256'), 'UTF-8')
開發者ID:kkinder,項目名稱:stormpath-sdk-python,代碼行數:34,代碼來源:test_id_site.py

示例4: SamlCallbackTest

class SamlCallbackTest(SamlBuildURITest):

    def setUp(self):
        super(SamlCallbackTest, self).setUp()
        self.store = MagicMock()
        self.store.get_resource.return_value = {
            'href': 'acchref',
            'sp_http_status': 200,
            'applications': ApplicationList(
                client=self.client,
                properties={
                    'href': 'apps',
                    'items': [{'href': 'apphref'}],
                    'offset': 0,
                    'limit': 25
                })
        }
        self.store._cache_get.return_value = False # ignore nonce

        self.client.data_store = self.store

        self.app = Application(
                client=self.client,
                properties={'href': 'apphref', 'accounts': {'href': 'acchref'}})

        self.acc = MagicMock(href='acchref')
        now = datetime.datetime.utcnow()

        try:
            irt = uuid4().get_hex()
        except AttributeError:
            irt = uuid4().hex

        fake_jwt_data = {
                'exp': now + datetime.timedelta(seconds=3600),
                'aud': self.app._client.auth.id,
                'irt': irt,
                'iss': 'Stormpath',
                'sub': self.acc.href,
                'isNewSub': False,
                'state': None,
        }

        self.fake_jwt = to_unicode(jwt.encode(
            fake_jwt_data,
            self.app._client.auth.secret,
            'HS256'), 'UTF-8')

    def test_saml_callback_handler(self):
        fake_jwt_response = 'http://localhost/?jwtResponse=%s' % self.fake_jwt

        with patch.object(Application, 'has_account') as mock_has_account:
            mock_has_account.return_value = True
            ret = self.app.handle_stormpath_callback(fake_jwt_response)

        self.assertIsNotNone(ret)
        self.assertIsInstance(ret, StormpathCallbackResult)
        self.assertEqual(ret.account.href, self.acc.href)
        self.assertIsNone(ret.state)
開發者ID:RepositPower,項目名稱:stormpath-sdk-python,代碼行數:59,代碼來源:test_saml.py

示例5: test_app_get_provider_acc_does_create_w_provider_data

    def test_app_get_provider_acc_does_create_w_provider_data(self):
        ds = MagicMock()
        ds.get_resource.return_value = {}
        client = MagicMock(data_store=ds, BASE_URL='http://example.com')

        app = Application(client=client, properties={
            'href': 'test/app',
            'accounts': {'href': '/test/app/accounts'}
        })

        app.get_provider_account('myprovider', access_token='foo')

        ds.create_resource.assert_called_once_with(
            'http://example.com/test/app/accounts', {
                'providerData': {
                    'providerId': 'myprovider',
                    'accessToken': 'foo'
                }
            }, params={})
開發者ID:denibertovic,項目名稱:stormpath-sdk-python,代碼行數:19,代碼來源:test_provider.py

示例6: test_building_id_site_redirect_uri

    def test_building_id_site_redirect_uri(self):

        app = Application(client=self.client, properties={'href': 'apphref'})
        ret = app.build_id_site_redirect_url('http://localhost/')
        decoded_data = self.decode_jwt(ret)
        self.assertIsNotNone(decoded_data.get('iat'))
        self.assertIsNotNone(decoded_data.get('jti'))
        self.assertIsNotNone(decoded_data.get('iss'))
        self.assertIsNotNone(decoded_data.get('sub'))
        self.assertIsNotNone(decoded_data.get('cb_uri'))
        self.assertEqual(decoded_data.get('cb_uri'), 'http://localhost/')
        self.assertIsNone(decoded_data.get('path'))
        self.assertIsNone(decoded_data.get('state'))
        self.assertNotEqual(decoded_data.get('sof'), True)
        self.assertIsNone(decoded_data.get('onk'))
        self.assertIsNone(decoded_data.get('sp_token'))

        ret = app.build_id_site_redirect_url(
                'http://testserver/',
                path='/#/register',
                state='test')
        decoded_data = self.decode_jwt(ret)
        self.assertEqual(decoded_data.get('path'), '/#/register')
        self.assertEqual(decoded_data.get('state'), 'test')

        sp_token = '{"test":"test"}'
        ret = app.build_id_site_redirect_url(
            'http://localhost/', show_organization_field=True, sp_token=sp_token)
        decoded_data = self.decode_jwt(ret)
        self.assertEqual(decoded_data["sof"], True)
        self.assertEqual(decoded_data["sp_token"], sp_token)
        self.assertIsNone(decoded_data.get('onk'))

        ret = app.build_id_site_redirect_url(
            'http://localhost/', organization_name_key="testorg")
        decoded_data = self.decode_jwt(ret)
        self.assertEqual(decoded_data["onk"], "testorg")
        self.assertNotEqual(decoded_data.get('sof'), True)
開發者ID:RepositPower,項目名稱:stormpath-sdk-python,代碼行數:38,代碼來源:test_id_site.py

示例7: test_iter_method_on_dict_mixin

 def test_iter_method_on_dict_mixin(self):
     r = Application(MagicMock(), properties={'name': 'some app'})
     self.assertEqual(['name'], list(r.__iter__()))
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:3,代碼來源:test_resource.py

示例8: test_getting_items_from_dict_mixing

 def test_getting_items_from_dict_mixing(self):
     r = Application(MagicMock(), properties={'name': 'some app'})
     self.assertEqual([('name', 'some app')], r.items())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:3,代碼來源:test_resource.py

示例9: test_checking_if_status_disabled

 def test_checking_if_status_disabled(self):
     r = Application(
             MagicMock(),
             properties={})
     self.assertTrue(r.is_disabled())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_resource.py

示例10: test_checking_if_status_enabled

 def test_checking_if_status_enabled(self):
     r = Application(
             MagicMock(),
             properties={'status': Application.STATUS_ENABLED})
     self.assertTrue(r.is_enabled())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_resource.py

示例11: test_getting_resource_status

 def test_getting_resource_status(self):
     r = Application(
             MagicMock(),
             properties={'status': Application.STATUS_ENABLED})
     self.assertEqual(r.STATUS_ENABLED, r.get_status())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_resource.py

示例12: test_resource_status_is_disabled_if_not_specified

 def test_resource_status_is_disabled_if_not_specified(self):
     r = Application(
             MagicMock(),
             properties={})
     self.assertEqual(r.STATUS_DISABLED, r.get_status())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_resource.py

示例13: test_deleting_new_resource

 def test_deleting_new_resource(self):
     r = Application(
             MagicMock(),
             properties={})
     self.assertIsNone(r.delete())
開發者ID:nkwood,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_resource.py

示例14: test_building_id_site_redirect_uri_with_usd

 def test_building_id_site_redirect_uri_with_usd(self):
     app = Application(client=self.client, properties={'href': 'apphref'})
     ret = app.build_id_site_redirect_url('http://localhost/', use_subdomain=True)
     decoded_data = self.decode_jwt(ret)
     self.assertEqual(decoded_data.get('usd'), True)
開發者ID:stormpath,項目名稱:stormpath-sdk-python,代碼行數:5,代碼來源:test_id_site.py


注:本文中的stormpath.resources.application.Application類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。