コード例 #1
0
    def test_auth_provider_pyramid(self):
        import ptah

        class Provider(object):
            def authenticate(self, creds):
                if creds['login'] == 'user':
                    return Principal('1', 'user', 'user')

        config = testing.setUp()
        config.include('ptah')

        self.assertTrue(getattr(config, 'ptah_auth_provider'))

        config.ptah_auth_provider('test-provider', Provider())
        config.commit()

        info = ptah.auth_service.authenticate(
            {'login': '******', 'password': '******'})

        self.assertTrue(info.status)
        self.assertEqual(info.__uri__, '1')
コード例 #2
0
    def test_auth_checker_pyramid(self):
        import ptah

        principal = Principal('1', 'user', 'user')

        class Provider(object):
            def authenticate(self, creds):
                if creds['login'] == 'user':
                    return Principal('1', 'user', 'user')

        config = testing.setUp()
        config.include('ptah')

        def checker(info):
            info.message = 'Suspended'
            info.arguments['additional'] = 'test'
            return False

        config.ptah_auth_checker(checker)
        config.ptah_auth_provider('test-provider', Provider())

        info = ptah.auth_service.authenticate(
            {'login': '******', 'password': '******'})

        self.assertFalse(info.status)
        self.assertEqual(info.__uri__, '1')
        self.assertEqual(info.message, 'Suspended')
        self.assertEqual(info.arguments, {'additional': 'test'})

        principal = Principal('1', 'user', 'user')

        info = ptah.auth_service.authenticate_principal(principal)
        self.assertFalse(info.status)
        self.assertEqual(info.__uri__, '1')
        self.assertEqual(info.message, 'Suspended')
        self.assertEqual(info.arguments, {'additional': 'test'})