Show More
@@ -61,7 +61,7 b' def load_environment(global_conf, app_co' | |||
|
61 | 61 | from rhodecode.lib.utils import create_test_env, create_test_index |
|
62 | 62 | from rhodecode.tests import TESTS_TMP_PATH |
|
63 | 63 | create_test_env(TESTS_TMP_PATH, config) |
|
64 | create_test_index(TESTS_TMP_PATH, True) | |
|
64 | create_test_index(TESTS_TMP_PATH, config, True) | |
|
65 | 65 | |
|
66 | 66 | #MULTIPLE DB configs |
|
67 | 67 | # Setup the SQLAlchemy database engine |
@@ -38,7 +38,7 b' from vcs.exceptions import RepositoryErr' | |||
|
38 | 38 | from vcs.nodes import FileNode, NodeKind |
|
39 | 39 | from vcs.utils import diffs as differ |
|
40 | 40 | |
|
41 | from rhodecode.lib import convert_line_endings, detect_mode | |
|
41 | from rhodecode.lib import convert_line_endings, detect_mode, safe_str | |
|
42 | 42 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
43 | 43 | from rhodecode.lib.base import BaseRepoController, render |
|
44 | 44 | from rhodecode.lib.utils import EmptyChangeset |
@@ -153,7 +153,7 b' class FilesController(BaseRepoController' | |||
|
153 | 153 | file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path) |
|
154 | 154 | |
|
155 | 155 | response.content_disposition = 'attachment; filename=%s' % \ |
|
156 |
f_path.split(os.sep)[-1] |
|
|
156 | safe_str(f_path.split(os.sep)[-1]) | |
|
157 | 157 | |
|
158 | 158 | response.content_type = file_node.mimetype |
|
159 | 159 | return file_node.content |
@@ -198,7 +198,7 b' class FilesController(BaseRepoController' | |||
|
198 | 198 | |
|
199 | 199 | if dispo == 'attachment': |
|
200 | 200 | dispo = 'attachment; filename=%s' % \ |
|
201 |
f_path.split(os.sep)[-1] |
|
|
201 | safe_str(f_path.split(os.sep)[-1]) | |
|
202 | 202 | |
|
203 | 203 | response.content_disposition = dispo |
|
204 | 204 | response.content_type = mimetype |
@@ -160,7 +160,7 b' def generate_api_key(username, salt=None' | |||
|
160 | 160 | def safe_unicode(_str, from_encoding='utf8'): |
|
161 | 161 | """ |
|
162 | 162 | safe unicode function. In case of UnicodeDecode error we try to return |
|
163 | unicode with errors replace | |
|
163 | unicode with errors replaceed | |
|
164 | 164 | |
|
165 | 165 | :param _str: string to decode |
|
166 | 166 | :rtype: unicode |
@@ -178,6 +178,28 b" def safe_unicode(_str, from_encoding='ut" | |||
|
178 | 178 | return u_str |
|
179 | 179 | |
|
180 | 180 | |
|
181 | def safe_str(_unicode, to_encoding='utf8'): | |
|
182 | """ | |
|
183 | safe str function. In case of UnicodeEncode error we try to return | |
|
184 | str with errors replaceed | |
|
185 | ||
|
186 | :param _unicode: unicode to encode | |
|
187 | :rtype: str | |
|
188 | :returns: str object | |
|
189 | """ | |
|
190 | ||
|
191 | if isinstance(_unicode, str): | |
|
192 | return _unicode | |
|
193 | ||
|
194 | try: | |
|
195 | safe_str = str(_unicode) | |
|
196 | except UnicodeEncodeError: | |
|
197 | safe_str = _unicode.encode(to_encoding, 'replace') | |
|
198 | ||
|
199 | return safe_str | |
|
200 | ||
|
201 | ||
|
202 | ||
|
181 | 203 | def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs): |
|
182 | 204 | """ |
|
183 | 205 | Custom engine_from_config functions that makes sure we use NullPool for |
@@ -37,7 +37,7 b' from string import lower' | |||
|
37 | 37 | from pylons import config |
|
38 | 38 | from pylons.i18n.translation import _ |
|
39 | 39 | |
|
40 | from rhodecode.lib import LANGUAGES_EXTENSIONS_MAP | |
|
40 | from rhodecode.lib import LANGUAGES_EXTENSIONS_MAP, safe_str | |
|
41 | 41 | from rhodecode.lib.celerylib import run_task, locked_task, str2bool, \ |
|
42 | 42 | __get_lockkey, LockHeld, DaemonLock |
|
43 | 43 | from rhodecode.lib.helpers import person |
@@ -66,7 +66,6 b' except ImportError:' | |||
|
66 | 66 | CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
|
67 | 67 | |
|
68 | 68 | |
|
69 | ||
|
70 | 69 | def get_session(): |
|
71 | 70 | if CELERY_ON: |
|
72 | 71 | engine = engine_from_config(config, 'sqlalchemy.db1.') |
@@ -112,8 +111,7 b' def get_commits_stats(repo_name, ts_min_' | |||
|
112 | 111 | co_day_auth_aggr = {} |
|
113 | 112 | commits_by_day_aggregate = {} |
|
114 | 113 | repos_path = get_repos_path() |
|
115 | p = os.path.join(repos_path, repo_name) | |
|
116 | repo = get_repo(p) | |
|
114 | repo = get_repo(safe_str(os.path.join(repos_path, repo_name))) | |
|
117 | 115 | repo_size = len(repo.revisions) |
|
118 | 116 | #return if repo have no revisions |
|
119 | 117 | if repo_size < 1: |
@@ -358,8 +356,7 b' def create_repo_fork(form_data, cur_user' | |||
|
358 | 356 | |
|
359 | 357 | def __get_codes_stats(repo_name): |
|
360 | 358 | repos_path = get_repos_path() |
|
361 | p = os.path.join(repos_path, repo_name) | |
|
362 | repo = get_repo(p) | |
|
359 | repo = get_repo(safe_str(os.path.join(repos_path, repo_name))) | |
|
363 | 360 | tip = repo.get_changeset() |
|
364 | 361 | code_stats = {} |
|
365 | 362 |
@@ -36,7 +36,7 b' from webhelpers.html.tags import _set_in' | |||
|
36 | 36 | |
|
37 | 37 | from vcs.utils.annotate import annotate_highlight |
|
38 | 38 | from rhodecode.lib.utils import repo_name_slug |
|
39 | from rhodecode.lib import str2bool, safe_unicode | |
|
39 | from rhodecode.lib import str2bool, safe_unicode, safe_str | |
|
40 | 40 | |
|
41 | 41 | def _reset(name, value=None, id=NotGiven, type="reset", **attrs): |
|
42 | 42 | """ |
@@ -502,7 +502,7 b' def gravatar_url(email_address, size=30)' | |||
|
502 | 502 | |
|
503 | 503 | if isinstance(email_address, unicode): |
|
504 | 504 | #hashlib crashes on unicode items |
|
505 |
email_address = email_address |
|
|
505 | email_address = safe_str(email_address) | |
|
506 | 506 | # construct the url |
|
507 | 507 | gravatar_url = baseurl + hashlib.md5(email_address.lower()).hexdigest() + "?" |
|
508 | 508 | gravatar_url += urllib.urlencode({'d':default, 's':str(size)}) |
@@ -69,6 +69,7 b' from dulwich.web import HTTPGitApplicati' | |||
|
69 | 69 | from paste.auth.basic import AuthBasicAuthenticator |
|
70 | 70 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
71 | 71 | |
|
72 | from rhodecode.lib import safe_str | |
|
72 | 73 | from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware |
|
73 | 74 | from rhodecode.lib.utils import invalidate_cache, check_repo_fast |
|
74 | 75 | from rhodecode.model.user import UserModel |
@@ -147,8 +148,8 b' class SimpleGit(object):' | |||
|
147 | 148 | #============================================================== |
|
148 | 149 | |
|
149 | 150 | if not REMOTE_USER(environ): |
|
150 |
self.authenticate.realm = |
|
|
151 |
|
|
|
151 | self.authenticate.realm = \ | |
|
152 | safe_str(self.config['rhodecode_realm']) | |
|
152 | 153 | result = self.authenticate(environ) |
|
153 | 154 | if isinstance(result, str): |
|
154 | 155 | AUTH_TYPE.update(environ, 'basic') |
@@ -35,6 +35,7 b' from mercurial.hgweb.request import wsgi' | |||
|
35 | 35 | from paste.auth.basic import AuthBasicAuthenticator |
|
36 | 36 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
37 | 37 | |
|
38 | from rhodecode.lib import safe_str | |
|
38 | 39 | from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware |
|
39 | 40 | from rhodecode.lib.utils import make_ui, invalidate_cache, \ |
|
40 | 41 | check_repo_fast, ui_sections |
@@ -112,8 +113,8 b' class SimpleHg(object):' | |||
|
112 | 113 | #============================================================== |
|
113 | 114 | |
|
114 | 115 | if not REMOTE_USER(environ): |
|
115 |
self.authenticate.realm = |
|
|
116 |
|
|
|
116 | self.authenticate.realm = \ | |
|
117 | safe_str(self.config['rhodecode_realm']) | |
|
117 | 118 | result = self.authenticate(environ) |
|
118 | 119 | if isinstance(result, str): |
|
119 | 120 | AUTH_TYPE.update(environ, 'basic') |
@@ -458,18 +458,22 b' def get_current_revision():' | |||
|
458 | 458 | #============================================================================== |
|
459 | 459 | # TEST FUNCTIONS AND CREATORS |
|
460 | 460 | #============================================================================== |
|
461 | def create_test_index(repo_location, full_index): | |
|
462 | """Makes default test index | |
|
463 | :param repo_location: | |
|
461 | def create_test_index(repo_location, config, full_index): | |
|
462 | """ | |
|
463 | Makes default test index | |
|
464 | ||
|
465 | :param config: test config | |
|
464 | 466 | :param full_index: |
|
465 | 467 | """ |
|
468 | ||
|
466 | 469 | from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon |
|
467 | 470 | from rhodecode.lib.pidlock import DaemonLock, LockHeld |
|
468 | import shutil | |
|
471 | ||
|
472 | repo_location = repo_location | |
|
469 | 473 | |
|
470 |
index_location = os.path.join( |
|
|
471 | if os.path.exists(index_location): | |
|
472 |
s |
|
|
474 | index_location = os.path.join(config['app_conf']['index_dir'], 'index') | |
|
475 | if not os.path.exists(index_location): | |
|
476 | os.makedirs(index_location) | |
|
473 | 477 | |
|
474 | 478 | try: |
|
475 | 479 | l = DaemonLock(file=jn(dn(index_location), 'make_index.lock')) |
@@ -42,7 +42,7 b' from vcs.exceptions import RepositoryErr' | |||
|
42 | 42 | from vcs.utils.lazy import LazyProperty |
|
43 | 43 | from vcs.nodes import FileNode |
|
44 | 44 | |
|
45 | from rhodecode.lib import str2bool, json | |
|
45 | from rhodecode.lib import str2bool, json, safe_str | |
|
46 | 46 | from rhodecode.model.meta import Base, Session |
|
47 | 47 | from rhodecode.model.caching_query import FromCache |
|
48 | 48 | |
@@ -479,7 +479,11 b' class Repository(Base, BaseModel):' | |||
|
479 | 479 | Session.add(inv) |
|
480 | 480 | Session.commit() |
|
481 | 481 | |
|
482 | return _c(self.repo_name) | |
|
482 | # TODO: remove this trick when beaker 1.6 is released | |
|
483 | # and have fixed this issue | |
|
484 | rn = safe_str(self.repo_name) | |
|
485 | ||
|
486 | return _c(rn) | |
|
483 | 487 | |
|
484 | 488 | def __get_instance(self): |
|
485 | 489 | |
@@ -497,7 +501,8 b' class Repository(Base, BaseModel):' | |||
|
497 | 501 | return |
|
498 | 502 | |
|
499 | 503 | if alias == 'hg': |
|
500 | repo = backend(repo_full_path, create=False, | |
|
504 | ||
|
505 | repo = backend(safe_str(repo_full_path), create=False, | |
|
501 | 506 | baseui=self._ui) |
|
502 | 507 | #skip hidden web repository |
|
503 | 508 | if repo._get_hidden(): |
@@ -33,6 +33,8 b' from sqlalchemy.orm import joinedload, m' | |||
|
33 | 33 | from vcs.utils.lazy import LazyProperty |
|
34 | 34 | from vcs.backends import get_backend |
|
35 | 35 | |
|
36 | from rhodecode.lib import safe_str | |
|
37 | ||
|
36 | 38 | from rhodecode.model import BaseModel |
|
37 | 39 | from rhodecode.model.caching_query import FromCache |
|
38 | 40 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ |
@@ -171,13 +173,12 b' class RepoModel(BaseModel):' | |||
|
171 | 173 | |
|
172 | 174 | try: |
|
173 | 175 | if fork: |
|
174 | #force str since hg doesn't go with unicode | |
|
175 |
|
|
|
176 |
org_name = |
|
|
177 | org_full_name = org_name#str(form_data['fork_name_full']) | |
|
176 | repo_name = form_data['fork_name'] | |
|
177 | org_name = form_data['repo_name'] | |
|
178 | org_full_name = org_name | |
|
178 | 179 | |
|
179 | 180 | else: |
|
180 |
org_name = repo_name = |
|
|
181 | org_name = repo_name = form_data['repo_name'] | |
|
181 | 182 | repo_name_full = form_data['repo_name_full'] |
|
182 | 183 | |
|
183 | 184 | new_repo = Repository() |
@@ -302,21 +303,23 b' class RepoModel(BaseModel):' | |||
|
302 | 303 | """ |
|
303 | 304 | from rhodecode.lib.utils import check_repo |
|
304 | 305 | |
|
305 | ||
|
306 | 306 | if new_parent_id: |
|
307 | 307 | paths = Group.get(new_parent_id).full_path.split(Group.url_sep()) |
|
308 | 308 | new_parent_path = os.sep.join(paths) |
|
309 | 309 | else: |
|
310 | 310 | new_parent_path = '' |
|
311 | 311 | |
|
312 | repo_path = os.path.join(self.repos_path, new_parent_path, repo_name) | |
|
312 | repo_path = os.path.join(*map(lambda x:safe_str(x), | |
|
313 | [self.repos_path, new_parent_path, repo_name])) | |
|
313 | 314 | |
|
314 |
if check_repo(repo_ |
|
|
315 | if check_repo(repo_path, self.repos_path): | |
|
315 | 316 | log.info('creating repo %s in %s @ %s', repo_name, repo_path, |
|
316 | clone_uri) | |
|
317 | clone_uri) | |
|
317 | 318 | backend = get_backend(alias) |
|
319 | ||
|
318 | 320 | backend(repo_path, create=True, src_url=clone_uri) |
|
319 | 321 | |
|
322 | ||
|
320 | 323 | def __rename_repo(self, old, new): |
|
321 | 324 | """ |
|
322 | 325 | renames repository on filesystem |
@@ -27,12 +27,7 b' import time' | |||
|
27 | 27 | import traceback |
|
28 | 28 | import logging |
|
29 | 29 | |
|
30 | from mercurial import ui | |
|
31 | ||
|
32 | 30 | from sqlalchemy.exc import DatabaseError |
|
33 | from sqlalchemy.orm import make_transient | |
|
34 | ||
|
35 | from beaker.cache import cache_region, region_invalidate | |
|
36 | 31 | |
|
37 | 32 | from vcs import get_backend |
|
38 | 33 | from vcs.utils.helpers import get_scm |
@@ -42,15 +37,14 b' from vcs.nodes import FileNode' | |||
|
42 | 37 | |
|
43 | 38 | from rhodecode import BACKENDS |
|
44 | 39 | from rhodecode.lib import helpers as h |
|
40 | from rhodecode.lib import safe_str | |
|
45 | 41 | from rhodecode.lib.auth import HasRepoPermissionAny |
|
46 | 42 | from rhodecode.lib.utils import get_repos as get_filesystem_repos, make_ui, \ |
|
47 | 43 | action_logger |
|
48 | 44 | from rhodecode.model import BaseModel |
|
49 | 45 | from rhodecode.model.user import UserModel |
|
50 | from rhodecode.model.repo import RepoModel | |
|
51 | 46 | from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \ |
|
52 | 47 | UserFollowing, UserLog |
|
53 | from rhodecode.model.caching_query import FromCache | |
|
54 | 48 | |
|
55 | 49 | log = logging.getLogger(__name__) |
|
56 | 50 | |
@@ -182,7 +176,10 b' class ScmModel(BaseModel):' | |||
|
182 | 176 | klass = get_backend(path[0]) |
|
183 | 177 | |
|
184 | 178 | if path[0] == 'hg' and path[0] in BACKENDS.keys(): |
|
185 | repos_list[name] = klass(path[1], baseui=baseui) | |
|
179 | ||
|
180 | # for mercurial we need to have an str path | |
|
181 | repos_list[name] = klass(safe_str(path[1]), | |
|
182 | baseui=baseui) | |
|
186 | 183 | |
|
187 | 184 | if path[0] == 'git' and path[0] in BACKENDS.keys(): |
|
188 | 185 | repos_list[name] = klass(path[1]) |
@@ -364,10 +361,10 b' class ScmModel(BaseModel):' | |||
|
364 | 361 | |
|
365 | 362 | # decoding here will force that we have proper encoded values |
|
366 | 363 | # in any other case this will throw exceptions and deny commit |
|
367 |
content = content |
|
|
368 |
message = message |
|
|
369 |
path = f_path |
|
|
370 |
author = author |
|
|
364 | content = safe_str(content) | |
|
365 | message = safe_str(message) | |
|
366 | path = safe_str(f_path) | |
|
367 | author = safe_str(author) | |
|
371 | 368 | m = IMC(repo) |
|
372 | 369 | m.change(FileNode(path, content)) |
|
373 | 370 | tip = m.commit(message=message, |
@@ -7,8 +7,9 b' class TestSearchController(TestControlle' | |||
|
7 | 7 | def test_index(self): |
|
8 | 8 | self.log_user() |
|
9 | 9 | response = self.app.get(url(controller='search', action='index')) |
|
10 | print response.body | |
|
11 |
assert |
|
|
10 | ||
|
11 | self.assertTrue('class="small" id="q" name="q" type="text"' in | |
|
12 | response.body) | |
|
12 | 13 | # Test response... |
|
13 | 14 | |
|
14 | 15 | def test_empty_search(self): |
@@ -16,20 +17,21 b' class TestSearchController(TestControlle' | |||
|
16 | 17 | raise SkipTest('skipped due to existing index') |
|
17 | 18 | else: |
|
18 | 19 | self.log_user() |
|
19 |
response = self.app.get(url(controller='search', action='index'), |
|
|
20 | assert 'There is no index to search in. Please run whoosh indexer' in response.body, 'No error message about empty index' | |
|
20 | response = self.app.get(url(controller='search', action='index'), | |
|
21 | {'q':HG_REPO}) | |
|
22 | self.assertTrue('There is no index to search in. ' | |
|
23 | 'Please run whoosh indexer' in response.body) | |
|
21 | 24 | |
|
22 | 25 | def test_normal_search(self): |
|
23 | 26 | self.log_user() |
|
24 |
response = self.app.get(url(controller='search', action='index'), |
|
|
25 | print response.body | |
|
26 |
assert |
|
|
27 |
assert |
|
|
28 | ||
|
27 | response = self.app.get(url(controller='search', action='index'), | |
|
28 | {'q':'def repo'}) | |
|
29 | self.assertTrue('10 results' in response.body) | |
|
30 | self.assertTrue('Permission denied' not in response.body) | |
|
29 | 31 | |
|
30 | 32 | def test_repo_search(self): |
|
31 | 33 | self.log_user() |
|
32 |
response = self.app.get(url(controller='search', action='index'), |
|
|
33 | print response.body | |
|
34 |
assert |
|
|
35 |
assert |
|
|
34 | response = self.app.get(url(controller='search', action='index'), | |
|
35 | {'q':'repository:%s def test' % HG_REPO}) | |
|
36 | self.assertTrue('4 results' in response.body) | |
|
37 | self.assertTrue('Permission denied' not in response.body) |
General Comments 0
You need to be logged in to leave comments.
Login now