Exemplo n.º 1
0
def start_server():
    """Start the server if it's not already started."""
    if not config.get("cp_started"):
        cherrypy.server.start(server_class=None, init_only=True)
        config.update({"cp_started" : True})

    if not config.get("server_started"):
        startup.startTurboGears()
        config.update({"server_started" : True})
Exemplo n.º 2
0
 def test_redirect(self):
     config.update({"server.webpath": "/coolsite/root"})
     startup.startTurboGears()
     testutil.create_request("/coolsite/root/subthing/")
     try:
         redirect("/foo")
         assert False, "redirect exception should have been raised"
     except cherrypy.HTTPRedirect, e:
         assert "http://localhost/coolsite/root/subthing/foo" in e.urls
Exemplo n.º 3
0
 def test_redirect(self):
     config.update({"server.webpath": "/coolsite/root"})
     startup.startTurboGears()
     testutil.create_request("/coolsite/root/subthing/")
     try:
         redirect("/foo")
         assert False, "redirect exception should have been raised"
     except cherrypy.HTTPRedirect, e:
         assert "http://localhost/coolsite/root/subthing/foo" in e.urls
Exemplo n.º 4
0
 def setUp(self):
     self._identity_on = config.get('identity.on', False)
     config.update({'identity.on': False})
     try:
         self._provider = cherrypy.request.identityProvider
     except AttributeError:
         self._provider= None
     cherrypy.request.identityProvider = None
     startup.startTurboGears()
     testutil.DBTest.setUp(self)
Exemplo n.º 5
0
 def setUp(self):
     self._identity_on = config.get('identity.on', False)
     config.update({'identity.on': False})
     try:
         self._provider = cherrypy.request.identityProvider
     except AttributeError:
         self._provider = None
     cherrypy.request.identityProvider = None
     startup.startTurboGears()
     testutil.DBTest.setUp(self)
Exemplo n.º 6
0
 def test_user_password_raw_unicode(self):
     config.update({'identity.soprovider.encryption_algorithm':'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.set_password_raw(u'garçon')
     u.sync()
     self.assertEqual(u.password, u'garçon')
     hub.rollback()
     hub.end()
Exemplo n.º 7
0
 def test_user_password_raw_unicode(self):
     config.update({'identity.soprovider.encryption_algorithm': 'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.set_password_raw(u'garçon')
     u.sync()
     assert u.password == u'garçon'
     hub.rollback()
     hub.end()
Exemplo n.º 8
0
 def test_user_password_hashed_md5_unicode(self):
     """Test if a non-ascii md5 hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e'
     hub.rollback()
     hub.end()
Exemplo n.º 9
0
 def test_user_password_hashed_sha_unicode(self):
     """Test if a non-ascii sha hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == '442edb21c491a6e6f502eb79e98614f3c7edf43e'
     hub.rollback()
     hub.end()
Exemplo n.º 10
0
 def test_user_password_unicode(self):
     """Test if we can set a non-ascii user password (no encryption)."""
     config.update({'identity.soprovider.encryption_algorithm': None})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == u'garçon'
     hub.rollback()
     hub.end()
Exemplo n.º 11
0
 def test_user_password_hashed_sha(self):
     """Test if a sha hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password == '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
     hub.rollback()
     hub.end()
Exemplo n.º 12
0
 def test_user_password_hashed_md5(self):
     "Test if a md5 hashed password is stored in the database."
     config.update({'identity.soprovider.encryption_algorithm':'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password =='5f4dcc3b5aa765d61d8327deb882cf99'
     hub.rollback()
     hub.end()
Exemplo n.º 13
0
 def test_user_password_hashed_sha(self):
     "Test if a sha hashed password is stored in the database."
     config.update({'identity.soprovider.encryption_algorithm':'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password =='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
     hub.rollback()
     hub.end()
Exemplo n.º 14
0
 def test_user_password_raw(self):
     "Test that we can store raw values in the password field (without being hashed)."
     config.update({'identity.soprovider.encryption_algorithm':'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.set_password_raw('password')
     u.sync()
     assert u.password =='password'
     hub.rollback()
     hub.end()
Exemplo n.º 15
0
 def test_user_password_unicode(self):
     """Test if we can set a non-ascii user password (no encryption)."""
     config.update({'identity.soprovider.encryption_algorithm': None})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == u'garçon'
     hub.rollback()
     hub.end()
Exemplo n.º 16
0
 def test_user_password_hashed_md5(self):
     """Test if a md5 hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password == '5f4dcc3b5aa765d61d8327deb882cf99'
     hub.rollback()
     hub.end()
Exemplo n.º 17
0
 def test_user_password_hashed_sha_unicode(self):
     """Test if a non-ascii sha hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == '442edb21c491a6e6f502eb79e98614f3c7edf43e'
     hub.rollback()
     hub.end()
Exemplo n.º 18
0
 def setUp(self):
     # identity requires visit and a failure_url
     test_config = {'visit.on': True, 'identity.on': True,
         'identity.failure_url': '/identity_failed',
         'identity.soprovider.encryption_algorithm': None}
     old_configuration = dict() 
     for key in test_config: 
         old_configuration[key] = config.get(key) 
     self._original_config = old_configuration         
     config.update(test_config)
     cherrypy.root = IdentityRoot()
     startup.startTurboGears()
     self.init_model()
Exemplo n.º 19
0
 def test_user_password_hashed_md5_unicode(self):
     """Test if a non-ascii md5 hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'
     u.sync()
     assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e'
     hub.rollback()
     hub.end()
Exemplo n.º 20
0
 def test_user_password_raw(self):
     """Test that we can store raw values in the password field
     (without being hashed)."""
     config.update({'identity.soprovider.encryption_algorithm': 'sha1'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.set_password_raw('password')
     u.sync()
     assert u.password == 'password'
     hub.rollback()
     hub.end()
Exemplo n.º 21
0
 def test_user_password_hashed_custom(self):
     """Test if a custom hashed password is stored in the database."""
     config.update({'identity.soprovider.encryption_algorithm': 'custom',
         'identity.custom_encryption':
             'identity.tests.test_identity.mycustomencrypt'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password =='password_custom'
     hub.rollback()
     hub.end()
Exemplo n.º 22
0
 def setUp(self):
     # identity requires visit and a failure_url
     test_config = {'global': {
         'visit.on': True, 'identity.on': True,
         'identity.failure_url': '/identity_failed',
         'identity.force_external_redirect': False,
         'identity.soprovider.encryption_algorithm': None}}
     original_config = dict()
     for key in test_config['global']:
         original_config[key] = config.get(key)
     self._original_config = original_config
     config.configure_loggers(test_config)
     config.update(test_config['global'])
     cherrypy.root = IdentityRoot()
     startup.startTurboGears()
     self.init_model()
Exemplo n.º 23
0
 def test_user_password_hashed_md5_utf8string(self):
     """Test if a md5 hashed password with unicode characters is stored in
     the database if the password is entered as str (encoded in UTF-8). This
     test ensures that the encryption algorithm does handle non-unicode
     parameters gracefully."""
     config.update({'identity.soprovider.encryption_algorithm': 'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'.encode('UTF-8')
     u.sync()
     assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e'
     hub.rollback()
     hub.end()
Exemplo n.º 24
0
 def test_user_password_hashed_md5_utf8string(self):
     """Test if a md5 hashed password with unicode characters is stored in 
     the database if the password is entered as str (encoded in UTF-8). This
     test ensures that the encryption algorithm does handle non-unicode
     parameters gracefully."""
     config.update({'identity.soprovider.encryption_algorithm':'md5'})
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = u'garçon'.encode('UTF-8')
     u.sync()
     self.assertEqual(u.password, 'c295c4bb2672ca8c432effc53b40bb1e')
     hub.rollback()
     hub.end()
Exemplo n.º 25
0
 def test_cookie_permanent(self):
     """Check that the visit cookie can be made permanent."""
     permanent = config.get('visit.cookie.permanent', False)
     try:
         # set cookie permanent for this test only (needs restart)
         startup.stopTurboGears()
         config.update({'visit.cookie.permanent': True})
         startup.startTurboGears()
         testutil.create_request('/')
         morsel = cherrypy.response.simple_cookie[self.cookie_name]
     finally:
         config.update({'visit.cookie.permanent': permanent})
     assert morsel['max-age'] == 3000
     expires = time.mktime(time.strptime(morsel['expires'],
         '%a, %d-%b-%Y %H:%M:%S GMT')[:8] + (0,))
     should_expire = time.mktime(time.gmtime()) + morsel['max-age']
     assert abs(should_expire - expires) < 3
Exemplo n.º 26
0
 def test_cookie_permanent(self):
     """Check that the visit cookie can be made permanent."""
     permanent = config.get('visit.cookie.permanent', False)
     try:
         # set cookie permanent for this test only (needs restart)
         startup.stopTurboGears()
         config.update({'visit.cookie.permanent': True})
         startup.startTurboGears()
         testutil.create_request('/')
         morsel = cherrypy.response.simple_cookie[self.cookie_name]
     finally:
         config.update({'visit.cookie.permanent': permanent})
     assert morsel['max-age'] == 3000
     expires = time.mktime(
         time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT')[:8] +
         (0, ))
     should_expire = time.mktime(time.gmtime()) + morsel['max-age']
     assert abs(should_expire - expires) < 3
Exemplo n.º 27
0
 def test_user_password_hashed_custom(self):
     """Test if a custom hashed password is stored in the database."""
     config.update({
         'identity.soprovider.encryption_algorithm':
         'custom',
         'identity.custom_encryption':
         'identity.tests.test_identity.mycustomencrypt'
     })
     # force new config values to load
     startup.startTurboGears()
     testutil.create_request('/')
     hub.begin()
     u = TG_User.by_user_name('samIam')
     u.password = '******'
     u.sync()
     assert u.password == 'password_custom'
     hub.rollback()
     hub.end()
Exemplo n.º 28
0
def create_request(request, method="GET", protocol="HTTP/1.1",
        headers={}, rfile=None, clientAddress="127.0.0.1",
        remoteHost="localhost", scheme="http"):
    start_cp()
    if not rfile:
        rfile = StringIO.StringIO("")
    if type(headers) != dict:
        headerList = headers
    else:
        headerList = [(key, value) for key, value in headers.items()]
    headerList.append(("Host", "localhost"))
    if not hasattr(cherrypy.root, "started"):
        startup.startTurboGears()
        cherrypy.root.started = True
    req = _cphttptools.Request(clientAddress, 80, remoteHost, scheme)
    cherrypy.serving.request = req
    attach_identity(req)
    cherrypy.serving.response = _cphttptools.Response()
    req.run(" ".join((method, request, protocol)), headerList, rfile)
Exemplo n.º 29
0
 def setUp(self):
     # identity requires visit and a failure_url
     test_config = {
         'global': {
             'visit.on': True,
             'identity.on': True,
             'identity.failure_url': '/identity_failed',
             'identity.force_external_redirect': False,
             'identity.soprovider.encryption_algorithm': None
         }
     }
     original_config = dict()
     for key in test_config['global']:
         original_config[key] = config.get(key)
     self._original_config = original_config
     config.configure_loggers(test_config)
     config.update(test_config['global'])
     cherrypy.root = IdentityRoot()
     startup.startTurboGears()
     self.init_model()
Exemplo n.º 30
0
def create_request(request,
                   method="GET",
                   protocol="HTTP/1.1",
                   headers={},
                   rfile=None,
                   clientAddress="127.0.0.1",
                   remoteHost="localhost",
                   scheme="http"):
    start_cp()
    if not rfile:
        rfile = StringIO.StringIO("")
    if type(headers) != dict:
        headerList = headers
    else:
        headerList = [(key, value) for key, value in headers.items()]
    headerList.append(("Host", "localhost"))
    if not hasattr(cherrypy.root, "started"):
        startup.startTurboGears()
        cherrypy.root.started = True
    req = _cphttptools.Request(clientAddress, 80, remoteHost, scheme)
    cherrypy.serving.request = req
    attach_identity(req)
    cherrypy.serving.response = _cphttptools.Response()
    req.run(" ".join((method, request, protocol)), headerList, rfile)
Exemplo n.º 31
0
 def tearDown(self):
     config.update({"server.webpath": ""})
     startup.startTurboGears()
Exemplo n.º 32
0
 def test_approots_with_path(self):
     config.update({"server.webpath": "/coolsite/root"})
     startup.startTurboGears()
     testutil.create_request("/coolsite/root/subthing/")
     assert url("/foo") == "/coolsite/root/subthing/foo"
Exemplo n.º 33
0
 def tearDown(self):
     config.update({"server.webpath": ""})
     startup.startTurboGears()
Exemplo n.º 34
0
 def test_approots_with_path(self):
     config.update({"server.webpath": "/coolsite/root"})
     startup.startTurboGears()
     testutil.create_request("/coolsite/root/subthing/")
     assert url("/foo") == "/coolsite/root/subthing/foo"