Changeset - efe23d6c178c
[Not reviewed]
Marcin Kuzminski - 13 years ago 2013-01-21 00:49:59
marcin@python-works.com
merged with beta
2 files changed with 34 insertions and 25 deletions:
0 comments (0 inline, 0 general)
rhodecode/tests/scripts/test_vcs_operations.py
Show inline comments
 
@@ -20,32 +20,33 @@
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import os
 
import tempfile
 
import unittest
 
import time
 
from os.path import join as jn
 
from os.path import dirname as dn
 

	
 
from tempfile import _RandomNameSequence
 
from subprocess import Popen, PIPE
 

	
 
from rhodecode.tests import *
 
from rhodecode.model.db import User, Repository, UserLog
 
from rhodecode.model.db import User, Repository, UserLog, UserIpMap
 
from rhodecode.model.meta import Session
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.model.user import UserModel
 

	
 
DEBUG = True
 
HOST = '127.0.0.1:5000'  # test host
 

	
 

	
 
class Command(object):
 

	
 
    def __init__(self, cwd):
 
        self.cwd = cwd
 
@@ -415,47 +416,55 @@ class TestVCSOperations(unittest.TestCas
 
#        assert r.locked[0] == User.get_by_username(TEST_USER_ADMIN_LOGIN).user_id
 
#
 
#        #push is ok and repo is now unlocked
 
#        stdout, stderr = _add_files_and_push('git', DEST)
 
#        #assert ('remote: Released lock on repo `%s`' % GIT_REPO) in stdout
 
#        #we need to cleanup the Session Here !
 
#        Session.remove()
 
#        r = Repository.get_by_repo_name(GIT_REPO)
 
#        assert r.locked == [None, None]
 

	
 
    def test_ip_restriction_hg(self):
 
        user_model = UserModel()
 
        new_ip = user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
 
        Session().commit()
 
        try:
 
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
 
            Session().commit()
 
            clone_url = _construct_url(HG_REPO)
 
            stdout, stderr = Command('/tmp').execute('hg clone', clone_url)
 
            assert 'abort: HTTP Error 403: Forbidden' in stderr
 
        finally:
 
            #release IP restrictions
 
            for ip in UserIpMap.getAll():
 
                UserIpMap.delete(ip.ip_id)
 
            Session().commit()
 

	
 
        time.sleep(2)
 
        clone_url = _construct_url(HG_REPO)
 
        stdout, stderr = Command('/tmp').execute('hg clone', clone_url)
 
        assert 'abort: HTTP Error 403: Forbidden' in stderr
 

	
 
        #release IP restrictions
 
        clone_url = _construct_url(HG_REPO)
 
        user_model.delete_extra_ip(TEST_USER_ADMIN_LOGIN, new_ip.ip_id)
 
        Session().commit()
 
        stdout, stderr = Command('/tmp').execute('hg clone', clone_url)
 

	
 
        assert 'requesting all changes' in stdout
 
        assert 'adding changesets' in stdout
 
        assert 'adding manifests' in stdout
 
        assert 'adding file changes' in stdout
 

	
 
        assert stderr == ''
 

	
 
    def test_ip_restriction_git(self):
 
        user_model = UserModel()
 
        new_ip = user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
 
        Session().commit()
 
        try:
 
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
 
            Session().commit()
 
            clone_url = _construct_url(GIT_REPO)
 
            stdout, stderr = Command('/tmp').execute('git clone', clone_url)
 
            assert 'error: The requested URL returned error: 403 Forbidden' in stderr
 
        finally:
 
            #release IP restrictions
 
            for ip in UserIpMap.getAll():
 
                UserIpMap.delete(ip.ip_id)
 
            Session().commit()
 

	
 
        time.sleep(2)
 
        clone_url = _construct_url(GIT_REPO)
 
        stdout, stderr = Command('/tmp').execute('git clone', clone_url)
 
        assert 'error: The requested URL returned error: 403 Forbidden' in stderr
 

	
 
        #release IP restrictions
 
        clone_url = _construct_url(GIT_REPO)
 
        user_model.delete_extra_ip(TEST_USER_ADMIN_LOGIN, new_ip.ip_id)
 
        Session().commit()
 
        stdout, stderr = Command('/tmp').execute('git clone', clone_url)
 

	
 
        assert 'Cloning into' in stdout
 
        assert stderr == ''
test.ini
Show inline comments
 
@@ -21,34 +21,34 @@ pdebug = false
 

	
 
#smtp_server = mail.server.com
 
#smtp_username = 
 
#smtp_password = 
 
#smtp_port = 
 
#smtp_use_tls = false
 
#smtp_use_ssl = true
 
# Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
 
#smtp_auth = 
 

	
 
[server:main]
 
##nr of threads to spawn
 
#threadpool_workers = 5
 
threadpool_workers = 5
 

	
 
##max request before thread respawn
 
#threadpool_max_requests = 2
 
threadpool_max_requests = 2
 

	
 
##option to use threads of process
 
#use_threadpool = true
 
use_threadpool = true
 

	
 
#use = egg:Paste#http
 
use = egg:waitress#main
 
use = egg:Paste#http
 
#use = egg:waitress#main
 
host = 127.0.0.1
 
port = 5000
 

	
 
[app:main]
 
use = egg:rhodecode
 
full_stack = true
 
static_files = true
 
lang=en
 
cache_dir = /tmp/rc/data
 
index_dir = /tmp/rc/index
 
app_instance_uuid = develop-test
 
cut_off_limit = 256000
 
@@ -286,13 +286,13 @@ formatter = generic
 

	
 
################
 
## FORMATTERS ##
 
################
 

	
 
[formatter_generic]
 
format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
 
datefmt = %Y-%m-%d %H:%M:%S
 

	
 
[formatter_color_formatter]
 
class=rhodecode.lib.colored_formatter.ColorFormatter
 
format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
 
datefmt = %Y-%m-%d %H:%M:%S
 
\ No newline at end of file
 
datefmt = %Y-%m-%d %H:%M:%S
0 comments (0 inline, 0 general)