Exemplo n.º 1
0
    def test_real_logout(self):
        user = User.create('foo', 'foo_id', auth_remember=True)
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            store.login_with_auth_id('foo_id', remember=False)

            response = Response()
            request.session_store.save(response)

        with self.get_app().get_test_context(
                '/',
                headers={
                    'Cookie':
                    '\n'.join(response.headers.getlist('Set-Cookie')),
                }) as request:
            store = MultiAuthStore(request)
            self.assertNotEqual(store.user, None)
            self.assertEqual(store.user.username, 'foo')
            store.logout()

            response = Response()
            request.session_store.save(response)

        with self.get_app().get_test_context(
                '/',
                headers={
                    'Cookie':
                    '\n'.join(response.headers.getlist('Set-Cookie')),
                }) as request:
            store = MultiAuthStore(request)
            self.assertEqual(store.session, None)
Exemplo n.º 2
0
    def test_login_with_auth_id(self):
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            store.login_with_auth_id("foo_id", remember=False)

            user = User.create("foo", "foo_id", password="******")
            app = self.get_app()
            store.login_with_auth_id("foo_id", remember=True)
Exemplo n.º 3
0
    def test_login_with_form(self):
        user = User.create('foo', 'foo_id', password='******')
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            res = store.login_with_form('foo', 'bar', remember=True)
            self.assertEqual(res, True)

            res = store.login_with_form('foo', 'bar', remember=False)
            self.assertEqual(res, True)
Exemplo n.º 4
0
    def test_login_with_form_invalid(self):
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        res = store.login_with_form('foo', 'bar', remember=True)

        self.assertEqual(res, False)
Exemplo n.º 5
0
    def test_login_with_form(self):
        user = User.create("foo", "foo_id", password="******")
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            res = store.login_with_form("foo", "bar", remember=True)
            self.assertEqual(res, True)

            res = store.login_with_form("foo", "bar", remember=False)
            self.assertEqual(res, True)
Exemplo n.º 6
0
    def test_login_with_auth_id(self):
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        store.login_with_auth_id('foo_id', remember=False)

        user = User.create('foo', 'foo_id', password='******')
        app = self.get_app()
        store.login_with_auth_id('foo_id', remember=True)
Exemplo n.º 7
0
    def test_login_with_form(self):
        user = User.create('foo', 'foo_id', password='******')
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        res = store.login_with_form('foo', 'bar', remember=True)
        self.assertEqual(res, True)

        res = store.login_with_form('foo', 'bar', remember=False)
        self.assertEqual(res, True)
Exemplo n.º 8
0
    def test_real_login_no_user(self):
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            user = store.create_user("foo", "foo_id")
            store.login_with_auth_id("foo_id", remember=False)

            response = Response()
            request.session_store.save(response)
            user.delete()

        with self.get_app().get_test_context(
            "/", headers={"Cookie": "\n".join(response.headers.getlist("Set-Cookie"))}
        ) as request:
            store = MultiAuthStore(request)
            self.assertEqual(store.session["id"], "foo_id")
            self.assertEqual(store.user, None)
Exemplo n.º 9
0
    def test_real_login(self):
        user = User.create("foo", "foo_id", auth_remember=True)
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            store.login_with_auth_id("foo_id", remember=False)

            response = Response()
            request.session_store.save(response)

        with self.get_app().get_test_context(
            "/", headers={"Cookie": "\n".join(response.headers.getlist("Set-Cookie"))}
        ) as request:
            store = MultiAuthStore(request)
            self.assertNotEqual(store.user, None)
            self.assertEqual(store.user.username, "foo")
            self.assertEqual(store.user.auth_id, "foo_id")
Exemplo n.º 10
0
    def test_real_logout(self):
        user = User.create('foo', 'foo_id', auth_remember=True)
        app = self.get_app()
        request = Request.from_values('/')
        local.current_handler = RequestHandler(app, request)

        store = MultiAuthStore(local.current_handler)
        store.login_with_auth_id('foo_id', remember=False)

        response = Response()
        local.current_handler.session_store.save(response)

        request = Request.from_values('/', headers={
            'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')),
        })
        local.current_handler = RequestHandler(app, request)
        store = MultiAuthStore(local.current_handler)
        self.assertNotEqual(store.user, None)
        self.assertEqual(store.user.username, 'foo')
        store.logout()

        response = Response()
        local.current_handler.session_store.save(response)

        request = Request.from_values('/', headers={
            'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')),
        })
        local.current_handler = RequestHandler(app, request)
        store = MultiAuthStore(local.current_handler)

        #self.assertEqual(store.user, None)
        self.assertEqual(store.session, None)
Exemplo n.º 11
0
    def test_real_login_no_user(self):
        app = self.get_app()
        store = MultiAuthStore(local.current_handler)
        user = store.create_user('foo', 'foo_id')
        store.login_with_auth_id('foo_id', remember=False)

        response = Response()
        local.current_handler.session_store.save(response)

        user.delete()

        request = Request.from_values('/', headers={
            'Cookie': '\n'.join(response.headers.getlist('Set-Cookie')),
        })
        local.current_handler = RequestHandler(app, request)
        store = MultiAuthStore(local.current_handler)
        self.assertEqual(store.session['id'], 'foo_id')
        self.assertEqual(store.user, None)
Exemplo n.º 12
0
    def test_login_with_auth_id(self):
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            store.login_with_auth_id('foo_id', remember=False)

            user = User.create('foo', 'foo_id', password='******')
            app = self.get_app()
            store.login_with_auth_id('foo_id', remember=True)
Exemplo n.º 13
0
    def test_real_login_no_user(self):
        with self.get_app().get_test_context() as request:
            store = MultiAuthStore(request)
            user = store.create_user('foo', 'foo_id')
            store.login_with_auth_id('foo_id', remember=False)

            response = Response()
            request.session_store.save(response)
            user.delete()

        with self.get_app().get_test_context(
                '/',
                headers={
                    'Cookie':
                    '\n'.join(response.headers.getlist('Set-Cookie')),
                }) as request:
            store = MultiAuthStore(request)
            self.assertEqual(store.session['id'], 'foo_id')
            self.assertEqual(store.user, None)
Exemplo n.º 14
0
 def test_login_with_form_invalid(self):
     with self.get_app().get_test_context() as request:
         store = MultiAuthStore(request)
         res = store.login_with_form('foo', 'bar', remember=True)
         self.assertEqual(res, False)
Exemplo n.º 15
0
 def test_real_login_invalid(self):
     with self.get_app().get_test_context() as request:
         store = MultiAuthStore(request)
         self.assertEqual(store.user, None)
         self.assertEqual(store.session, None)
Exemplo n.º 16
0
 def get(self):
     a = MultiAuthStore(self.request)
     u = a.create_user('admin','own|admin', password='******')
     return self.redirect('/')
Exemplo n.º 17
0
 def test_login_with_form_invalid(self):
     with self.get_app().get_test_context() as request:
         store = MultiAuthStore(request)
         res = store.login_with_form("foo", "bar", remember=True)
         self.assertEqual(res, False)