Beispiel #1
0
    def test_rest_api_auth(self):
        from ptah.rest import Api, Login
        from ptah import authentication
        self._init_ptah()

        config.get_cfg_storage(
            authentication.AUTH_PROVIDER_ID)['test'] = Provider()

        request = DummyRequest(params = {'login': '******', 'password': '******'})

        login = Login(request)
        info = simplejson.loads(login.render())

        request = DummyRequest(environ = {'HTTP_X_AUTH_TOKEN': 'unknown'})
        request.matchdict = {'service': 'cms', 'subpath': ()}

        api = Api(request)
        api.render()
        self.assertEqual(ptah.authService.get_userid(), None)

        token = info['auth-token']

        request = DummyRequest(environ = {'HTTP_X_AUTH_TOKEN': token})
        request.matchdict = {'service': 'cms', 'subpath': ()}

        api = Api(request)
        api.render()
        self.assertEqual(ptah.authService.get_userid(), 'testprincipal:1')
Beispiel #2
0
    def test_rest_login(self):
        from ptah.rest import Login

        request = DummyRequest()
        login = Login(request)

        self.assertIn('authentication failed', login.render())
        self.assertEqual(request.response.status, '403 Forbidden')
Beispiel #3
0
    def test_rest_login_success(self):
        from ptah.rest import Login
        from ptah import authentication
        self._init_ptah()

        config.get_cfg_storage(
            authentication.AUTH_PROVIDER_ID)['test'] = Provider()
        request = DummyRequest(params = {'login': '******', 'password': '******'})

        login = Login(request)
        info = simplejson.loads(login.render())

        self.assertIn('auth-token', info)
        self.assertEqual(request.response.status, '200 OK')