예제 #1
0
    def test_anonym_unauth(self):
        'Anonym and unathorized access'

        def anonym(r):
            self.assert_(r.vals.user is None)

        auth = CookieAuth(user_by_credential, user_by_id)
        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler,
            auth.logout_handler,
            auth | Map(
                match('/', 'index') | anonym,
            )
        )

        rctx = RequestContext.blank('/')
        rctx = app(rctx)

        def view(r):
            r.response.write('aaaa')

        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler,
            auth.logout_handler,
            auth | auth.login_required | Map(
                match('/', 'index') | view
            )
        )
        rctx = RequestContext.blank('/')
        self.assertRaises(HttpException, lambda: app(rctx))
        try:
            app(rctx)
        except HttpException, e:
            self.assertEqual(str(e.url), '/login?next=/')
예제 #2
0
    def test_anonym_unauth(self):
        'Anonym and unathorized access'

        def anonym(r):
            self.assert_(r.vals.user is None)

        auth = CookieAuth(user_by_credential, user_by_id)
        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler, auth.logout_handler,
            auth | Map(match('/', 'index') | anonym, ))

        rctx = RequestContext.blank('/')
        rctx = app(rctx)

        def view(r):
            r.response.write('aaaa')

        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler, auth.logout_handler,
            auth | auth.login_required | Map(match('/', 'index') | view))
        rctx = RequestContext.blank('/')
        self.assertRaises(HttpException, lambda: app(rctx))
        try:
            app(rctx)
        except HttpException, e:
            self.assertEqual(str(e.url), '/login?next=/')
예제 #3
0
    def test_login_logout(self):
        'Login and Logout process'
        auth = CookieAuth(user_by_credential, user_by_id)

        def logout(r):
            self.assertEqual(len(r.vals.session_storage.cache), 0)

        def login(r):
            self.assertEqual(len(r.vals.session_storage.cache), 1)

        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler | login,
            auth.logout_handler | logout,
            auth | Map(
                match('/', 'index')
            )
        )
        rctx = RequestContext.blank('/login', login='******', password='******')
        self.assertRaises(HttpException, lambda: app(rctx))

        self.assert_(rctx.response.headers.get('Set-Cookie'))

        try:
            app(rctx)
        except HttpException, e:
            self.assertEqual(e.status, 303)
예제 #4
0
    def test_auth(self):
        'Authorized access'
        auth = CookieAuth(user_by_credential, user_by_id)
        def user(r):
            self.assertEqual(r.vals.user.name, 'user name')
        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler,
            auth.logout_handler,
            auth | auth.login_required | Map(
                match('/', 'index') | user
            )
        )

        try:
            rctx = RequestContext.blank('/login', login='******', password='******')
            app(rctx)
        except HttpException:
            pass
        r = RequestContext.blank('/')
        r.request.headers['Cookie'] = rctx.response.headers['Set-Cookie']
        self.assertEqual(app(r).response.status_int, 200)
예제 #5
0
    def test_auth(self):
        'Authorized access'
        auth = CookieAuth(user_by_credential, user_by_id)

        def user(r):
            self.assertEqual(r.vals.user.name, 'user name')

        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler, auth.logout_handler,
            auth | auth.login_required | Map(match('/', 'index') | user))

        try:
            rctx = RequestContext.blank('/login',
                                        login='******',
                                        password='******')
            app(rctx)
        except HttpException:
            pass
        r = RequestContext.blank('/')
        r.request.headers['Cookie'] = rctx.response.headers['Set-Cookie']
        self.assertEqual(app(r).response.status_int, 200)
예제 #6
0
    def test_login_logout(self):
        'Login and Logout process'
        auth = CookieAuth(user_by_credential, user_by_id)

        def logout(r):
            self.assertEqual(len(r.vals.session_storage.cache), 0)

        def login(r):
            self.assertEqual(len(r.vals.session_storage.cache), 1)

        app = local_cache_env() | jinja_env() | Map(
            auth.login_handler | login, auth.logout_handler | logout,
            auth | Map(match('/', 'index')))
        rctx = RequestContext.blank('/login',
                                    login='******',
                                    password='******')
        self.assertRaises(HttpException, lambda: app(rctx))

        self.assert_(rctx.response.headers.get('Set-Cookie'))

        try:
            app(rctx)
        except HttpException, e:
            self.assertEqual(e.status, 303)
예제 #7
0
from insanities.web.filters import *
from insanities.web.wrappers import *

from insanities.ext.jinja2 import render_to, jinja_env
from insanities.ext.cache import local_cache_env
from insanities.utils import conf_to_dict


import cfg
import handlers as h

static = static_files(cfg.STATIC)
media = static_files(cfg.MEDIA, '/media/')

env = (Conf(**conf_to_dict(cfg)) | 
       jinja_env(extensions=['jinja2.ext.i18n'], autoescape=True) |
       local_cache_env())

# should be added only in local app, but for simplicity added immediatelly
env = env | static.add_reverse

app = env | Map(
    static, media,
    match('/', 'files') | Map(
        # Playing REST ;)
        method('GET') | h.list_files | render_to('index.html'),
        method('POST') | h.post_file | render_to('index.html'),
        #method('DELETE') | h.delete_files,
    ),
)
예제 #8
0
from insanities.web import *
from insanities.web.filters import *
from insanities.web.wrappers import *

from insanities.ext.jinja2 import render_to, jinja_env
from insanities.ext.cache import local_cache_env
from insanities.utils import conf_to_dict

import cfg
import handlers as h

static = static_files(cfg.STATIC)
media = static_files(cfg.MEDIA, '/media/')

env = (Conf(**conf_to_dict(cfg))
       | jinja_env(extensions=['jinja2.ext.i18n'], autoescape=True)
       | local_cache_env())

# should be added only in local app, but for simplicity added immediatelly
env = env | static.add_reverse

app = env | Map(
    static,
    media,
    match('/', 'files') | Map(
        # Playing REST ;)
        method('GET') | h.list_files | render_to('index.html'),
        method('POST') | h.post_file | render_to('index.html'),
        #method('DELETE') | h.delete_files,
    ),
)