Show More
@@ -242,7 +242,7 b' def RepoForm(edit=False, old_data=None, ' | |||||
242 | allow_extra_fields = True |
|
242 | allow_extra_fields = True | |
243 | filter_extra_fields = False |
|
243 | filter_extra_fields = False | |
244 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
244 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), | |
245 | v.SlugifyName()) |
|
245 | v.SlugifyName(), v.CannotHaveGitSuffix()) | |
246 | repo_group = All(v.CanWriteGroup(old_data), |
|
246 | repo_group = All(v.CanWriteGroup(old_data), | |
247 | v.OneOf(repo_groups, hideList=True)) |
|
247 | v.OneOf(repo_groups, hideList=True)) | |
248 | repo_type = v.OneOf(supported_backends, required=False, |
|
248 | repo_type = v.OneOf(supported_backends, required=False, |
@@ -191,7 +191,12 b' def deferred_unique_name_validator(node,' | |||||
191 |
|
191 | |||
192 | @colander.deferred |
|
192 | @colander.deferred | |
193 | def deferred_repo_name_validator(node, kw): |
|
193 | def deferred_repo_name_validator(node, kw): | |
194 | return validators.valid_name_validator |
|
194 | def no_git_suffix_validator(node, value): | |
|
195 | if value.endswith('.git'): | |||
|
196 | msg = _('Repository name cannot end with .git') | |||
|
197 | raise colander.Invalid(node, msg) | |||
|
198 | return colander.All( | |||
|
199 | no_git_suffix_validator, validators.valid_name_validator) | |||
195 |
|
200 | |||
196 |
|
201 | |||
197 | class GroupType(colander.Mapping): |
|
202 | class GroupType(colander.Mapping): |
@@ -574,6 +574,26 b' def SlugifyName():' | |||||
574 | return _validator |
|
574 | return _validator | |
575 |
|
575 | |||
576 |
|
576 | |||
|
577 | def CannotHaveGitSuffix(): | |||
|
578 | class _validator(formencode.validators.FancyValidator): | |||
|
579 | messages = { | |||
|
580 | 'has_git_suffix': | |||
|
581 | _(u'Repository name cannot end with .git'), | |||
|
582 | } | |||
|
583 | ||||
|
584 | def _to_python(self, value, state): | |||
|
585 | return value | |||
|
586 | ||||
|
587 | def validate_python(self, value, state): | |||
|
588 | if value and value.endswith('.git'): | |||
|
589 | msg = M( | |||
|
590 | self, 'has_git_suffix', state) | |||
|
591 | raise formencode.Invalid( | |||
|
592 | msg, value, state, error_dict={'repo_name': msg}) | |||
|
593 | ||||
|
594 | return _validator | |||
|
595 | ||||
|
596 | ||||
577 | def ValidCloneUri(): |
|
597 | def ValidCloneUri(): | |
578 | class InvalidCloneUrl(Exception): |
|
598 | class InvalidCloneUrl(Exception): | |
579 | allowed_prefixes = () |
|
599 | allowed_prefixes = () |
@@ -24,7 +24,7 b' import mock' | |||||
24 | import pytest |
|
24 | import pytest | |
25 |
|
25 | |||
26 | from rhodecode.lib import auth |
|
26 | from rhodecode.lib import auth | |
27 | from rhodecode.lib.utils2 import safe_str, str2bool |
|
27 | from rhodecode.lib.utils2 import safe_str, str2bool, safe_unicode | |
28 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError |
|
28 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError | |
29 | from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\ |
|
29 | from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\ | |
30 | Permission |
|
30 | Permission | |
@@ -44,7 +44,7 b' fixture = Fixture()' | |||||
44 |
|
44 | |||
45 |
|
45 | |||
46 | @pytest.mark.usefixtures("app") |
|
46 | @pytest.mark.usefixtures("app") | |
47 | class TestAdminRepos: |
|
47 | class TestAdminRepos(object): | |
48 |
|
48 | |||
49 | def test_index(self): |
|
49 | def test_index(self): | |
50 | self.app.get(url('repos')) |
|
50 | self.app.get(url('repos')) | |
@@ -63,13 +63,14 b' class TestAdminRepos:' | |||||
63 | assert_response.element_contains('#repo_type', 'svn') |
|
63 | assert_response.element_contains('#repo_type', 'svn') | |
64 | assert_response.element_contains('#repo_type', 'hg') |
|
64 | assert_response.element_contains('#repo_type', 'hg') | |
65 |
|
65 | |||
66 |
@pytest.mark.parametrize("suffix", |
|
66 | @pytest.mark.parametrize("suffix", | |
|
67 | [u'', u'xxa'], ids=['', 'non-ascii']) | |||
67 | def test_create(self, autologin_user, backend, suffix, csrf_token): |
|
68 | def test_create(self, autologin_user, backend, suffix, csrf_token): | |
68 | repo_name_unicode = backend.new_repo_name(suffix=suffix) |
|
69 | repo_name_unicode = backend.new_repo_name(suffix=suffix) | |
69 | repo_name = repo_name_unicode.encode('utf8') |
|
70 | repo_name = repo_name_unicode.encode('utf8') | |
70 | description_unicode = u'description for newly created repo' + suffix |
|
71 | description_unicode = u'description for newly created repo' + suffix | |
71 | description = description_unicode.encode('utf8') |
|
72 | description = description_unicode.encode('utf8') | |
72 | self.app.post( |
|
73 | response = self.app.post( | |
73 | url('repos'), |
|
74 | url('repos'), | |
74 | fixture._get_repo_create_params( |
|
75 | fixture._get_repo_create_params( | |
75 | repo_private=False, |
|
76 | repo_private=False, | |
@@ -77,8 +78,7 b' class TestAdminRepos:' | |||||
77 | repo_type=backend.alias, |
|
78 | repo_type=backend.alias, | |
78 | repo_description=description, |
|
79 | repo_description=description, | |
79 | csrf_token=csrf_token), |
|
80 | csrf_token=csrf_token), | |
80 | status=302 |
|
81 | status=302) | |
81 | ) |
|
|||
82 |
|
82 | |||
83 | self.assert_repository_is_created_correctly( |
|
83 | self.assert_repository_is_created_correctly( | |
84 | repo_name, description, backend) |
|
84 | repo_name, description, backend) | |
@@ -368,6 +368,20 b' class TestAdminRepos:' | |||||
368 | csrf_token=csrf_token)) |
|
368 | csrf_token=csrf_token)) | |
369 | response.mustcontain('invalid clone url') |
|
369 | response.mustcontain('invalid clone url') | |
370 |
|
370 | |||
|
371 | def test_create_with_git_suffix( | |||
|
372 | self, autologin_user, backend, csrf_token): | |||
|
373 | repo_name = backend.new_repo_name() + ".git" | |||
|
374 | description = 'description for newly created repo' | |||
|
375 | response = self.app.post( | |||
|
376 | url('repos'), | |||
|
377 | fixture._get_repo_create_params( | |||
|
378 | repo_private=False, | |||
|
379 | repo_name=repo_name, | |||
|
380 | repo_type=backend.alias, | |||
|
381 | repo_description=description, | |||
|
382 | csrf_token=csrf_token)) | |||
|
383 | response.mustcontain('Repository name cannot end with .git') | |||
|
384 | ||||
371 | @pytest.mark.parametrize("suffix", [u'', u'ąęł'], ids=['', 'non-ascii']) |
|
385 | @pytest.mark.parametrize("suffix", [u'', u'ąęł'], ids=['', 'non-ascii']) | |
372 | def test_delete(self, autologin_user, backend, suffix, csrf_token): |
|
386 | def test_delete(self, autologin_user, backend, suffix, csrf_token): | |
373 | repo = backend.create_repo(name_suffix=suffix) |
|
387 | repo = backend.create_repo(name_suffix=suffix) | |
@@ -596,15 +610,15 b' class TestAdminRepos:' | |||||
596 |
|
610 | |||
597 | def assert_repository_is_created_correctly( |
|
611 | def assert_repository_is_created_correctly( | |
598 | self, repo_name, description, backend): |
|
612 | self, repo_name, description, backend): | |
599 |
repo_name_utf8 = repo_name |
|
613 | repo_name_utf8 = safe_str(repo_name) | |
600 |
|
614 | |||
601 | # run the check page that triggers the flash message |
|
615 | # run the check page that triggers the flash message | |
602 | response = self.app.get(url('repo_check_home', repo_name=repo_name)) |
|
616 | response = self.app.get(url('repo_check_home', repo_name=repo_name)) | |
603 | assert response.json == {u'result': True} |
|
617 | assert response.json == {u'result': True} | |
604 | assert_session_flash( |
|
618 | ||
605 | response, |
|
619 | flash_msg = u'Created repository <a href="/{}">{}</a>'.format( | |
606 | u'Created repository <a href="/%s">%s</a>' |
|
620 | urllib.quote(repo_name_utf8), repo_name) | |
607 | % (urllib.quote(repo_name_utf8), repo_name)) |
|
621 | assert_session_flash(response, flash_msg) | |
608 |
|
622 | |||
609 | # test if the repo was created in the database |
|
623 | # test if the repo was created in the database | |
610 | new_repo = RepoModel().get_by_repo_name(repo_name) |
|
624 | new_repo = RepoModel().get_by_repo_name(repo_name) |
General Comments 0
You need to be logged in to leave comments.
Login now