Show More
@@ -102,3 +102,5 b' class Command(BasePasterCommand):' | |||||
102 | dbmanage.create_permissions() |
|
102 | dbmanage.create_permissions() | |
103 | dbmanage.populate_default_permissions() |
|
103 | dbmanage.populate_default_permissions() | |
104 | Session().commit() |
|
104 | Session().commit() | |
|
105 | ||||
|
106 | print 'Database set up successfully.' |
@@ -587,8 +587,30 b' class GitRepository(BaseRepository):' | |||||
587 | :param ignore_whitespace: If set to ``True``, would not show whitespace |
|
587 | :param ignore_whitespace: If set to ``True``, would not show whitespace | |
588 | changes. Defaults to ``False``. |
|
588 | changes. Defaults to ``False``. | |
589 | :param context: How many lines before/after changed lines should be |
|
589 | :param context: How many lines before/after changed lines should be | |
590 | shown. Defaults to ``3``. |
|
590 | shown. Defaults to ``3``. Due to limitations in Git, if | |
|
591 | value passed-in is greater than ``2**31-1`` | |||
|
592 | (``2147483647``), it will be set to ``2147483647`` | |||
|
593 | instead. If negative value is passed-in, it will be set to | |||
|
594 | ``0`` instead. | |||
591 | """ |
|
595 | """ | |
|
596 | ||||
|
597 | # Git internally uses a signed long int for storing context | |||
|
598 | # size (number of lines to show before and after the | |||
|
599 | # differences). This can result in integer overflow, so we | |||
|
600 | # ensure the requested context is smaller by one than the | |||
|
601 | # number that would cause the overflow. It is highly unlikely | |||
|
602 | # that a single file will contain that many lines, so this | |||
|
603 | # kind of change should not cause any realistic consequences. | |||
|
604 | overflowed_long_int = 2**31 | |||
|
605 | ||||
|
606 | if context >= overflowed_long_int: | |||
|
607 | context = overflowed_long_int - 1 | |||
|
608 | ||||
|
609 | # Negative context values make no sense, and will result in | |||
|
610 | # errors. Ensure this does not happen. | |||
|
611 | if context < 0: | |||
|
612 | context = 0 | |||
|
613 | ||||
592 | flags = ['-U%s' % context, '--full-index', '--binary', '-p', '-M', '--abbrev=40'] |
|
614 | flags = ['-U%s' % context, '--full-index', '--binary', '-p', '-M', '--abbrev=40'] | |
593 | if ignore_whitespace: |
|
615 | if ignore_whitespace: | |
594 | flags.append('-w') |
|
616 | flags.append('-w') |
@@ -243,8 +243,15 b' class MercurialRepository(BaseRepository' | |||||
243 | :param ignore_whitespace: If set to ``True``, would not show whitespace |
|
243 | :param ignore_whitespace: If set to ``True``, would not show whitespace | |
244 | changes. Defaults to ``False``. |
|
244 | changes. Defaults to ``False``. | |
245 | :param context: How many lines before/after changed lines should be |
|
245 | :param context: How many lines before/after changed lines should be | |
246 | shown. Defaults to ``3``. |
|
246 | shown. Defaults to ``3``. If negative value is passed-in, it will be | |
|
247 | set to ``0`` instead. | |||
247 | """ |
|
248 | """ | |
|
249 | ||||
|
250 | # Negative context values make no sense, and will result in | |||
|
251 | # errors. Ensure this does not happen. | |||
|
252 | if context < 0: | |||
|
253 | context = 0 | |||
|
254 | ||||
248 | if hasattr(rev1, 'raw_id'): |
|
255 | if hasattr(rev1, 'raw_id'): | |
249 | rev1 = getattr(rev1, 'raw_id') |
|
256 | rev1 = getattr(rev1, 'raw_id') | |
250 |
|
257 |
@@ -15,4 +15,4 b'' | |||||
15 | "theme_color": "#ffffff", |
|
15 | "theme_color": "#ffffff", | |
16 | "background_color": "#ffffff", |
|
16 | "background_color": "#ffffff", | |
17 | "display": "standalone" |
|
17 | "display": "standalone" | |
18 | } No newline at end of file |
|
18 | } |
@@ -144,6 +144,13 b' class TestLoginController(TestController' | |||||
144 |
|
144 | |||
145 | response.mustcontain('Invalid username or password') |
|
145 | response.mustcontain('Invalid username or password') | |
146 |
|
146 | |||
|
147 | def test_login_non_ascii(self): | |||
|
148 | response = self.app.post(url(controller='login', action='index'), | |||
|
149 | {'username': TEST_USER_REGULAR_LOGIN, | |||
|
150 | 'password': 'blΓ₯bΓ¦rgrΓΈd'}) | |||
|
151 | ||||
|
152 | response.mustcontain('>Invalid username or password<') | |||
|
153 | ||||
147 | # verify that get arguments are correctly passed along login redirection |
|
154 | # verify that get arguments are correctly passed along login redirection | |
148 |
|
155 | |||
149 | @parametrize('args,args_encoded', [ |
|
156 | @parametrize('args,args_encoded', [ |
@@ -709,6 +709,46 b' class TestGitSpecificWithRepo(_BackendTe' | |||||
709 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
709 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
710 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
710 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) | |
711 |
|
711 | |||
|
712 | def test_get_diff_does_not_sanitize_valid_context(self): | |||
|
713 | almost_overflowed_long_int = 2**31-1 | |||
|
714 | ||||
|
715 | self.repo.run_git_command = mock.Mock(return_value=['', '']) | |||
|
716 | self.repo.get_diff(0, 1, 'foo', context=almost_overflowed_long_int) | |||
|
717 | self.repo.run_git_command.assert_called_once_with( | |||
|
718 | ['diff', '-U' + str(almost_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |||
|
719 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) | |||
|
720 | ||||
|
721 | def test_get_diff_sanitizes_overflowing_context(self): | |||
|
722 | overflowed_long_int = 2**31 | |||
|
723 | sanitized_overflowed_long_int = overflowed_long_int-1 | |||
|
724 | ||||
|
725 | self.repo.run_git_command = mock.Mock(return_value=['', '']) | |||
|
726 | self.repo.get_diff(0, 1, 'foo', context=overflowed_long_int) | |||
|
727 | ||||
|
728 | self.repo.run_git_command.assert_called_once_with( | |||
|
729 | ['diff', '-U' + str(sanitized_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |||
|
730 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) | |||
|
731 | ||||
|
732 | def test_get_diff_does_not_sanitize_zero_context(self): | |||
|
733 | zero_context = 0 | |||
|
734 | ||||
|
735 | self.repo.run_git_command = mock.Mock(return_value=['', '']) | |||
|
736 | self.repo.get_diff(0, 1, 'foo', context=zero_context) | |||
|
737 | ||||
|
738 | self.repo.run_git_command.assert_called_once_with( | |||
|
739 | ['diff', '-U' + str(zero_context), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |||
|
740 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) | |||
|
741 | ||||
|
742 | def test_get_diff_sanitizes_negative_context(self): | |||
|
743 | negative_context = -10 | |||
|
744 | ||||
|
745 | self.repo.run_git_command = mock.Mock(return_value=['', '']) | |||
|
746 | self.repo.get_diff(0, 1, 'foo', context=negative_context) | |||
|
747 | ||||
|
748 | self.repo.run_git_command.assert_called_once_with( | |||
|
749 | ['diff', '-U0', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |||
|
750 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) | |||
|
751 | ||||
712 |
|
752 | |||
713 | class TestGitRegression(_BackendTestMixin): |
|
753 | class TestGitRegression(_BackendTestMixin): | |
714 | backend_alias = 'git' |
|
754 | backend_alias = 'git' |
@@ -1,6 +1,7 b'' | |||||
1 | import os |
|
1 | import os | |
2 |
|
2 | |||
3 | import pytest |
|
3 | import pytest | |
|
4 | import mock | |||
4 |
|
5 | |||
5 | from kallithea.lib.utils2 import safe_str |
|
6 | from kallithea.lib.utils2 import safe_str | |
6 | from kallithea.lib.vcs.backends.hg import MercurialRepository, MercurialChangeset |
|
7 | from kallithea.lib.vcs.backends.hg import MercurialRepository, MercurialChangeset | |
@@ -236,6 +237,23 b' TODO: To be written...' | |||||
236 | assert node.kind == NodeKind.FILE |
|
237 | assert node.kind == NodeKind.FILE | |
237 | assert node.content == readme |
|
238 | assert node.content == readme | |
238 |
|
239 | |||
|
240 | @mock.patch('kallithea.lib.vcs.backends.hg.repository.diffopts') | |||
|
241 | def test_get_diff_does_not_sanitize_zero_context(self, mock_diffopts): | |||
|
242 | zero_context = 0 | |||
|
243 | ||||
|
244 | self.repo.get_diff(0, 1, 'foo', context=zero_context) | |||
|
245 | ||||
|
246 | mock_diffopts.assert_called_once_with(git=True, showfunc=True, ignorews=False, context=zero_context) | |||
|
247 | ||||
|
248 | @mock.patch('kallithea.lib.vcs.backends.hg.repository.diffopts') | |||
|
249 | def test_get_diff_sanitizes_negative_context(self, mock_diffopts): | |||
|
250 | negative_context = -10 | |||
|
251 | zero_context = 0 | |||
|
252 | ||||
|
253 | self.repo.get_diff(0, 1, 'foo', context=negative_context) | |||
|
254 | ||||
|
255 | mock_diffopts.assert_called_once_with(git=True, showfunc=True, ignorews=False, context=zero_context) | |||
|
256 | ||||
239 |
|
257 | |||
240 | class TestMercurialChangeset(object): |
|
258 | class TestMercurialChangeset(object): | |
241 |
|
259 |
General Comments 0
You need to be logged in to leave comments.
Login now