Commit 65d66138 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

fix test when running from outside the test directory (as done by eg apycot)

parent 457250cfcb04
# copyright 2010-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# copyright 2010-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
......@@ -20,6 +20,17 @@ from cubicweb import ConfigurationError
CONFENTRY = 'trustedauth-secret-key-file'
def set_secret(config, secretfile):
try:
secret = open(secretfile).read().strip()
except IOError:
config.error("Cannot open secret key file. Check your configuration file!")
return
if not secret or len(secret) > 32:
config.error('secret key must me a string 0 < len(key) <= 32')
return
config._secret = secret.ljust(32, '#')
# the presence of this registration callback here is a small hack to
# make sure the secret key file is loaded on both sides of cw (repo
# and web)
......@@ -29,13 +40,4 @@ def registration_callback(vreg):
vreg.config.warning("Configuration '%s' is missing or empty. "
"Please check your configuration file!" % CONFENTRY)
return
try:
secret = open(secretfile).read().strip()
except IOError:
vreg.config.error("Cannot open secret key file. Check your configuration file!")
return
if not secret or len(secret) > 32:
vreg.config.error('secret key must me a string 0 < len(key) <= 32')
return
vreg.config._secret = secret.ljust(32, '#')
vreg.debug('loaded secret key')
set_secret(vreg.config, secretfile)
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
......@@ -15,40 +15,22 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""unit tests for trustedauth cube"""
"""unit tests for cubicweb.web.application"""
import base64, Cookie
import os
import sys
import logging
import tempfile
from logilab.common.testlib import TestCase, unittest_main
from logilab.common.decorators import clear_cache, classproperty
from cubicweb import AuthenticationError, Unauthorized
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.devtools.fake import FakeRequest
from cubicweb.web import LogOut, Redirect, INTERNAL_FIELD_VALUE
from cubicweb.web.views.basecontrollers import ViewController
CONFIG = u'''trustedauth-secret-key-file=%s'''
secretfile = None
from cubicweb.web import LogOut
def setUpModule():
global secretfile
config = TrustAuthTC.config
home = config.apphome
# print home
from cubes.trustedauth.entities import set_secret
class TrustAuthTC(CubicWebTC):
class TrustedAuthTC(CubicWebTC):
## def setup_database(self):
## for log in 'cubicweb', 'cubicweb.cubes', 'cubicweb.twisted':
## logger = logging.getLogger(log)
## logger.handlers = [logging.StreamHandler(sys.stdout)]
## logger.setLevel(logging.DEBUG)
@classmethod
def init_config(cls, config):
super(TrustedAuthTC, cls).init_config(config)
# XXX secret file in data/allinone.conf is a relative path, so test may
# fail depending on the CWD when starting them. Recall set_secret to fix
# this
set_secret(config, cls.datapath('secretfile'))
def test_login(self):
req, origsession = self.init_authentication('http')
......@@ -67,4 +49,5 @@ class TrustAuthTC(CubicWebTC):
self.assertEqual(len(self.open_sessions), 0)
if __name__ == "__main__":
from logilab.common.testlib import unittest_main
unittest_main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment