예제 #1
0
def test_error(devops_wapp):
	wapp = devops_wapp('auth')
	with wapp.mock() as ctx:
		wa = auth.WebappAuth(ctx.config)
		with raises(bottle.HTTPResponse) as exc:
			wa.error()
		wapp.checkRedirect(exc, 302, view.url('user.login'))
예제 #2
0
파일: auth.py 프로젝트: jrmsdev/pysadm
def loginPost(auth=None):
    log.debug('login post')
    req = bottle.request
    if auth is None:  # pragma: no cover
        auth = WebappAuth(cfg.config)
    sessid = session.cookie(req)
    if not sessid:
        log.error('session cookie not found')
        bottle.redirect(view.url('user.login'))
    try:
        auth.login(req, sessid)
        log.debug('login done')
    except AuthError as err:
        log.error("login: %s" % err)
        return bottle.HTTPError(401, str(err))
    log.debug('redirect')
    bottle.redirect(view.url('index'))
예제 #3
0
def test_login_post_no_session_cookie(devops_wapp):
	wapp = devops_wapp()
	with mock_session(wapp) as ctx:
		ctx.session.cookie.return_value = None
		with raises(bottle.HTTPResponse) as resp:
			auth.loginPost(auth = ctx.auth)
		req = bottle.request
		ctx.session.cookie.assert_called_with(req)
		wapp.checkRedirect(resp, 302, view.url('user.login'))
예제 #4
0
def test_login_post(devops_wapp):
	wapp = devops_wapp()
	with mock_session(wapp) as ctx:
		with raises(bottle.HTTPResponse) as resp:
			auth.loginPost(auth = ctx.auth)
		req = bottle.request
		ctx.session.cookie.assert_called_with(req)
		ctx.auth.login.assert_called_with(req, '01234567')
		wapp.checkRedirect(resp, 302, view.url('index'))
예제 #5
0
def test_auth_check(devops_wapp):
	wapp = devops_wapp()
	with mock_session(wapp) as ctx:
		with raises(bottle.HTTPResponse) as resp:
			auth.login(auth = ctx.auth)
		wapp.checkRedirect(resp, 302, view.url('index'))
		req = bottle.request
		resp = bottle.response
		ctx.auth.check.assert_called_with(req)
		assert ctx.tpl.parse.mock_calls == []
		ctx.session.cookie.assert_called_with(req)
		assert ctx.session.new.mock_calls == []
def test_auth_error(devops_wapp):
    wapp = devops_wapp('session')
    with wapp.mock() as ctx:
        p = auth.AuthPlugin(ctx.config)
        p.setup(ctx.wapp)
        rtrn = object()
        ctx.callback = ctx.mock.callback
        ctx.callback.return_value = rtrn
        p.auth.check = Mock()
        p.auth.check.side_effect = AuthError('testing.autherror')
        with raises(bottle.HTTPResponse) as exc:
            p.apply(ctx.callback, ctx.mock.ctx)()
        wapp.checkRedirect(exc, 302, view.url('user.login'))
예제 #7
0
파일: auth.py 프로젝트: jrmsdev/pysadm
def login(auth=None):
    log.debug('login')
    req = bottle.request
    resp = bottle.response
    if auth is None:  # pragma: no cover
        auth = WebappAuth(cfg.config)
    sessid = session.cookie(req)
    if not sessid:
        session.new(resp)
    else:
        try:
            auth.check(req)
            bottle.redirect(view.url('index'))
        except AuthError as err:
            # if there was an auth error we show the login form
            log.debug("auth error: %s" % err)
    return tpl.parse('user/login', auth=auth)
예제 #8
0
파일: auth.py 프로젝트: jrmsdev/pysadm
 def error(self):
     log.info('login error, redirect to user login page')
     bottle.redirect(view.url('user.login'))
예제 #9
0
파일: tpl.py 프로젝트: jrmsdev/pysadm
 def url(self, name, **kw):
     return view.url(name, **kw)