diff --git a/rhodecode/tests/vcs_operations/__init__.py b/rhodecode/tests/vcs_operations/__init__.py --- a/rhodecode/tests/vcs_operations/__init__.py +++ b/rhodecode/tests/vcs_operations/__init__.py @@ -158,8 +158,14 @@ def _add_files_and_push(vcs, dest, clone f'{git_ident} && git push --verbose --tags {clone_url} {target_branch}' ) elif vcs == 'svn': + username = kwargs.pop('username', '') + password = kwargs.pop('password', '') + auth = '' + if username and password: + auth = f'--username {username} --password {password}' + stdout, stderr = Command(cwd).execute( - f'svn ci -m "pushing to {target_branch}"' + f'svn commit --no-auth-cache --non-interactive {auth} -m "pushing to {target_branch}"' ) return stdout, stderr diff --git a/rhodecode/tests/vcs_operations/test_vcs_operations_svn.py b/rhodecode/tests/vcs_operations/test_vcs_operations_svn.py --- a/rhodecode/tests/vcs_operations/test_vcs_operations_svn.py +++ b/rhodecode/tests/vcs_operations/test_vcs_operations_svn.py @@ -41,6 +41,14 @@ from rhodecode.tests.vcs_operations impo _add_files_and_push, SVN_REPO_WITH_GROUP) +def get_cli_flags(username, password): + flags = '--no-auth-cache --non-interactive' + auth = '' + if username and password: + auth = f'--username {username} --password {password}' + return flags, auth + + @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") class TestVCSOperations(object): @@ -50,8 +58,11 @@ class TestVCSOperations(object): cmd = Command('/tmp') - auth = f'--non-interactive --username={username} --password={password}' - stdout, stderr = cmd.execute(f'svn checkout {auth}', clone_url, tmpdir.strpath) + flags, auth = get_cli_flags(username, password) + + stdout, stderr = Command('/tmp').execute( + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) + _check_proper_clone(stdout, stderr, 'svn') cmd.assert_returncode_success() @@ -61,8 +72,12 @@ class TestVCSOperations(object): clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) cmd = Command('/tmp') - auth = f'--non-interactive --username={username} --password={password}' - stdout, stderr = cmd.execute(f'svn checkout {auth}', clone_url, tmpdir.strpath) + + flags, auth = get_cli_flags(username, password) + + stdout, stderr = Command('/tmp').execute( + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) + _check_proper_clone(stdout, stderr, 'svn') cmd.assert_returncode_success() @@ -70,9 +85,11 @@ class TestVCSOperations(object): clone_url = rc_web_server.repo_clone_url(SVN_REPO_WITH_GROUP) username, password = rc_web_server.repo_clone_credentials() - cmd = Command('/tmp') - auth = f'--non-interactive --username={username} --password={password}' - stdout, stderr = cmd.execute(f'svn checkout {auth}', clone_url, tmpdir.strpath) + flags, auth = get_cli_flags(username, password) + + stdout, stderr = Command('/tmp').execute( + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) + _check_proper_clone(stdout, stderr, 'svn') cmd.assert_returncode_success() @@ -81,14 +98,20 @@ class TestVCSOperations(object): username, password = rc_web_server.repo_clone_credentials() password = 'bad-password' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) + stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) assert 'fatal: Authentication failed' in stderr def test_clone_svn_with_slashes(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url('//' + SVN_REPO) - stdout, stderr = Command('/tmp').execute('svn checkout', clone_url) + username, password = '', '' + flags, auth = get_cli_flags(username, password) + + stdout, stderr = Command('/tmp').execute( + f'svn checkout {flags} {auth}', clone_url) + assert 'not found' in stderr def test_clone_existing_path_svn_not_in_database( @@ -96,10 +119,10 @@ class TestVCSOperations(object): db_name = fs_repo_only('not-in-db-git', repo_type='git') clone_url = rc_web_server.repo_clone_url(db_name) username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) assert 'not found' in stderr def test_clone_existing_path_svn_not_in_database_different_scm( @@ -108,9 +131,10 @@ class TestVCSOperations(object): clone_url = rc_web_server.repo_clone_url(db_name) username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) + stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) assert 'not found' in stderr def test_clone_non_existing_store_path_svn(self, rc_web_server, tmpdir, user_util): @@ -121,57 +145,60 @@ class TestVCSOperations(object): RepoModel()._delete_filesystem_repo(repo) username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) + stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) assert 'not found' in stderr def test_push_new_file_svn(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(SVN_REPO) username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) # commit some stuff into this repo stdout, stderr = _add_files_and_push( - 'svn', tmpdir.strpath, clone_url=clone_url) + 'svn', tmpdir.strpath, clone_url=clone_url, username=username, password=password) _check_proper_svn_push(stdout, stderr) def test_push_wrong_credentials_svn(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(SVN_REPO) - username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + username, password = rc_web_server.repo_clone_credentials() + flags, auth = get_cli_flags(username, password) + stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) push_url = rc_web_server.repo_clone_url( SVN_REPO, user='bad', passwd='name') stdout, stderr = _add_files_and_push( - 'svn', tmpdir.strpath, clone_url=push_url) + 'svn', tmpdir.strpath, clone_url=push_url, username=username, password=password) assert 'fatal: Authentication failed' in stderr def test_push_back_to_wrong_url_svn(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(SVN_REPO) username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' - Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + flags, auth = get_cli_flags(username, password) + + stdout, stderr = Command('/tmp').execute( + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) stdout, stderr = _add_files_and_push( 'svn', tmpdir.strpath, - clone_url=rc_web_server.repo_clone_url('not-existing')) + clone_url=rc_web_server.repo_clone_url('not-existing'), username=username, password=password) assert 'not found' in stderr def test_ip_restriction_svn(self, rc_web_server, tmpdir): user_model = UserModel() username, password = '', '' - auth = f'--non-interactive --username={username} --password={password}' + flags, auth = get_cli_flags(username, password) try: user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') @@ -180,7 +207,7 @@ class TestVCSOperations(object): clone_url = rc_web_server.repo_clone_url(SVN_REPO) stdout, stderr = Command('/tmp').execute( - f'svn checkout {auth}', clone_url, tmpdir.strpath) + f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) msg = "The requested URL returned error: 403" assert msg in stderr finally: @@ -192,6 +219,6 @@ class TestVCSOperations(object): time.sleep(2) cmd = Command('/tmp') - stdout, stderr = cmd.execute(f'svn checkout {auth}', clone_url, tmpdir.strpath) + stdout, stderr = cmd.execute(f'svn checkout {flags} {auth}', clone_url, tmpdir.strpath) cmd.assert_returncode_success() _check_proper_clone(stdout, stderr, 'svn')