|
|
Mads Kiilerich
|
5e46f73f0d1c
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
b095e2fbba44
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
6fbbbd9a627a
|
5 years ago
|
|
db: move URL_SEP constant from db to top level kallithea module
URL_SEP is used in several places - having it in the db module is too high level.
__init__ might not be the best place for this, but it does no harm to the dependencies graph to place constants there.
|
|
|
Thomas De Schampheleire
|
3e9d079fcf91
|
5 years ago
|
|
|
|
|
Thomas De Schampheleire
|
d727e81e0097
|
5 years ago
|
|
vcs: fix cloning remote repository with HTTP authentication (Issue #379) Using a remote clone URI of http://user:pass@host/... triggered an exception: ... E File ".../kallithea/lib/utils.py", line 256, in is_valid_repo_uri E GitRepository._check_url(url) E File ".../kallithea/lib/vcs/backends/git/repository.py", line 183, in _check_url E passmgr.add_password(*authinfo) E File "/usr/lib/python3.7/urllib/request.py", line 848, in add_password E self.reduce_uri(u, default_port) for u in uri) E File "/usr/lib/python3.7/urllib/request.py", line 848, in <genexpr> E self.reduce_uri(u, default_port) for u in uri) E File "/usr/lib/python3.7/urllib/request.py", line 875, in reduce_uri E host, port = splitport(authority) E File "/usr/lib/python3.7/urllib/parse.py", line 1022, in splitport E match = _portprog.fullmatch(host) E TypeError: cannot use a string pattern on a bytes-like object The authinfo tuple is obtained via mercurial.util.url, which unfortunately returns a tuple of bytes whereas urllib expects strings. It seems that mercurial internally has some more hacking around urllib as urllibcompat.py, which we don't use. Therefore, transform the bytes into strings before passing authinfo to urllib. As the realm can be None, we need to check it specifically otherwise safe_str would return a string 'None'. A basic test that catches the mentioned problem is added, even though it does not actually test that cloning with auth info will actually work (it only tests that it fails cleanly if the URI is not reachable). Additionally, one use of 'test_uri' in hg/repository.py still needed to be transformed from bytes to string. For git this was already ok.
|
|
|
Mads Kiilerich
|
1de3e5d104bf
|
5 years ago
|
|
tests: consistent use of more helpful raise_exception "fixture"
"Total Crash" was too misleading when debugging problems.
|
|
|
Mads Kiilerich
|
2045d30919e6
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
6484a0fc0e0b
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e63bcce18fef
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e51ad2cd400e
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e35373106528
|
6 years ago
|
|
py3: remove safe_unicode in places where it no longer is needed because all strings (except bytes) already *are* unicode strings
(The remaining safe_unicode calls are still needed and can't just be removed, generally because we in these cases still have to convert from bytes to unicode strings.)
|
|
|
Mads Kiilerich
|
22b40db44a41
|
6 years ago
|
|
py3: migrate from urllib2 to urllib
Based on 2to3 urllib, but with unnecessary imports removed.
|
|
|
Mads Kiilerich
|
e527cc2ce8dc
|
6 years ago
|
|
cleanup: get rid of most "import *"
Apply script generated with the following hack: ( hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u ) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
|
|
|
Mads Kiilerich
|
fe4086096758
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
0a277465fddf
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
09100b3b8f42
|
6 years ago
|
|
|
|
|
Lars Kruse
|
48a00daba2f2
|
8 years ago
|
|
codingstyle: replace comparison for equality against None with "is" expression
Both style and correctness.
Reported by flake8.
|
|
|
Lars Kruse
|
7691290837d2
|
8 years ago
|
|
codingstyle: trivial whitespace fixes
Reported by flake8.
|
|
|
domruf
|
865c1f65244c
|
9 years ago
|
|
repositories: make sure repositories not only differ in casing
Repositories only differing in case cause problems: * it can't be stored on case insensitive filesystems (Windows and MacOS) * some databases can't easily handle case sensitive queries * users will most certainly be confused by names that only differ in case
We will keep trying to be case sensitive on systems that can ... but on some systems wrong casings might work. We don't care.
The validators are changed to prevent mixed case repo and repo group names.
Repository sensitivity tests are removed, and insensitivity tests are added instead.
|
|
|
Søren Løvborg
|
a918c4c5a841
|
9 years ago
|
|
tests: fix test_permanent_url_protocol_access instability
Since the test repositories are created in the database by scanning the file system, their IDs depends on the (non-deterministic) order in which files are listed by the file system.
The solution, of course, is to ask the database for the ID instead of assuming it will be ID 1.
|
|
|
Mads Kiilerich
|
aaacb075c3f3
|
9 years ago
|
|
hg: return 400 Bad Request for hg commands that not are commands
Avoid throwing bare Exceptions which requires framework specific testing. Instead, return a reasonable http error code and make the test more framework independent.
The "helpful" message will just be a description of the http exception and not sent to the client.
|
|
|
Søren Løvborg
|
cd6176c0634a
|
9 years ago
|
|
db: PullRequest/Repository/RepoGroup/UserGroup: change 'user' to 'owner'
Rename the 'user' and 'user_id' fields on the four classes to something more informative. The database column names remain unchanged for now; a later Alembic script can fix the name of these and other columns to match their Python name.
This might break rcextensions, though, and external scripts that use the HTML form interface.
|
|
|
Søren Løvborg
|
4136526cce20
|
9 years ago
|
|
db: remove superfluous Session.add calls
Don't re-add objects to the SQLAlchemy Session just because they were modified. Session.add is only for freshly constructed objects that SQLAlchemy doesn't know about yet.
The rules are quite simple:
When creating a database object by calling the constructor directly, it must explicitly be added to the session.
When creating an object using a factory function (like "create_repo"), the returned object has already (by convention) been added to the session, and should not be added again.
When getting an object from the session (via Session.query or any of the utility functions that look up objects in the database), it's already added, and should not be added again. SQLAlchemy notices attribute modifications automatically for all objects it knows about.
|
|
|
Thomas De Schampheleire
|
8d98924c58b1
|
9 years ago
|
|
tests: add as little code as possible in __init__.py
kallithea/tests/__init__.py contained quite a lot of code, including the test base class TestController. This in itself may be considered bad practice.
Specifically, this poses a problem when using pytest 3.0+, in which asserts in some files are not automatically rewritten to give improved assert output. That problem can be fixed by explicitly registering such files for assertion rewriting, but that register call should be executed _before_ said files are imported. I.e. if the register call is in kallithea/tests/__init__.py, assert calls in __init__.py itself can not be rewritten.
Since the TestController base class does effectively contain asserts, and we do not want to execute the register call from somewhere outside the kallithea/tests directory, we need to move the TestController class to another file (kallithea/tests/base.py) so we can have a register call in __init__.py before loading base.py.
While not strictly necessary to fix the mentioned pytest problem, we take the opportunity to fully clean __init__.py and move everything to the new kallithea/tests/base.py. While doing so, unnecessary imports are removed, and imports are ordered alphabetically. Explicit imports of symbols from modules that were already imported as a whole, are removed in favor of fully qualifying the references (e.g. tempfile._RandomNameSequence).
|
|
|
Mads Kiilerich
|
caf71e50a070
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
062aa22363a1
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
ad41c9a72a88
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
02cfb2197c63
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
110dcae69d7d
|
9 years ago
|
|
protocols: fix assertion error when accessing repositories with "permanent" urls (Issue #202)
I am not aware of any good way to test this, so it is tested with a Mercurial only hack.
|
|
|
Thomas De Schampheleire
|
7f2aa3ec2931
|
10 years ago
|
|
pytest migration: rename TestControllerPytest back to TestController
The name TestControllerPytest was introduced to allow a temporary situation where nose/unittest and pytest-based tests could coexist. This situation is now over, so the base test class can be renamed again.
|
|
|
Thomas De Schampheleire
|
be1d366f461c
|
10 years ago
|
|
pytest migration: functional: switch to standard assert statements
Use unittest2pytest to replace unittest-style assert statements (e.g. assertEqual) with standard Python assert statements to benefit from pytest's improved reporting on assert failures.
The conversion by unittest2pytest was correct, except for line wrapping problems.
|
|
|
Thomas De Schampheleire
|
1173317b4f1a
|
10 years ago
|
|
pytest migration: simplify hg+git test class hierarchies
No need to use multiple inheritance when single inheritance can do it just as well. Let the git/hg test cases just derive from _BaseTestCase which in turn derives from TestControllerPytest.
Also remove empty setup_class/teardown_class methods.
|
|
|
Thomas De Schampheleire
|
15c40f8a3510
|
10 years ago
|
|
pytest migration: convert functional tests with setup/teardown methods
pytest also supports setup/teardown methods like unittest (even though pytest fixtures are more powerful and should be the end goal). Only difference is the naming and signature of setUp (setup_method) and tearDown (teardown_method).
|
|
|
domruf
|
8568a1d4f100
|
10 years ago
|
|
tests: don't use the TESTS_TMP_PATH string
it differs each time you run the test and therefore doesn't work if you use a separat kallithea test instance (KALLITHEA_NO_TMP_PATH=1)
instead get the 'real' path from the DB
FIXME: breaks kallithea/tests/functional/test_admin_repos.py
|
|
|
domruf
|
1883a4e4c390
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
bd4840ad72d3
|
10 years ago
|
|
tests: more consistently use unicode where unicode is expected
Nothing but extra u annotation to turn str constants into unicode.
This has been verified by hacking sqlalchemy to fail if wrong string types are passed.
|
|
|
Mads Kiilerich
|
b326cfed4486
|
10 years ago
|
|
tests: cleanup of unicode in test_create_non_ascii repository test
Repository names are generally conceptually unicode. Prepare for future changes by explicitly encoding repo_name as utf8 before appending a utf8 string.
Drop test_create_non_ascii - test_delete_non_ascii contains exactly the same test.
|
|
|
Mads Kiilerich
|
f2cda217fbc2
|
10 years ago
|
|
tests: always convert unicode paths to str before passing to vcs layer
Repo names are generally unicode. Don't rely on implicit conversion.
|
|
|
Mads Kiilerich
|
edb24bc0f71a
|
10 years ago
|
|
|
|
|
Søren Løvborg
|
a041321d2aa1
|
10 years ago
|
|
security: apply CSRF check to all non-GET requests
The automatic CSRF protection was broken for POST requests with no request payload parameters (but possibly containing request URI parameters); a security hole was narrowly avoided because the code base quite consistently checks the request method in the same way, and because of browser protection against PUT/DELETE CSRF attacks.
Since explicit is better than implicit, the better way of checking the HTTP request method is to simply check request.method, instead of checking if request.POST is non-empty, which is subtly different (it doesn't catch POST requests if all parameters are in the query string) and non-obvious (because it also applies to PUT requests).
The commit also fixes some tests which relied on the CSRF protection being broken. It does not fix all the controllers that still does the misleading request.POST check, but since the CSRF check has now been tightened, those are no longer a potential security issue.
|
|
|
Søren Løvborg
|
aaa2478f9d60
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
ab5c4d84f99c
|
10 years ago
|
|
repos: fix abuse of dead 'repo' routing
The repo "show" controller didn't do anything and was unused. There was a routing GET entry for it but it was only used for generating URLs for DELETE and PUT operations that have separate controllers that happen to have the same URL.
Use the right routing entries when generating URLs and drop the dead code.
|
|
|
Mads Kiilerich
|
cb362e3439dd
|
10 years ago
|
|
repos: refactor repo group handling - extract generic functionality that can be used consistently
By using the right repo group list in the form, it is no longer possible for users to pick wrong repo creation locations ... and doing so anyway will be caught earlier on with a more generic error message at the specific place.
|
|
|
Thomas De Schampheleire
|
aacc82d4a967
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
221d6a002601
|
10 years ago
|
|
|
|
|
Marc Abramowitz
|
12ae08b2fe3f
|
11 years ago
|
|
tests: avoid executing tests in base classes
Fixes lots of failures with pytest by making sure base test classes don't inherit from unittest.TestCase or by prefacing name with an underscore so tests don't get executed by pytest.
|
|
|
Mads Kiilerich
|
0efca3ad8467
|
11 years ago
|
|
tests: provide _authentication_token when POSTing
So far not used, just preparing for the the time when the actual checking is introduced ...
This change is very verbose. self.app.post should perhaps just at this value automagically ...
|
|
|
Thomas De Schampheleire
|
53d766fc9782
|
11 years ago
|
|
spelling: consistent capitalization of URL
Change Url / url into URL. Additionally, convert the sole use of 'Uri' to URL.
|
|
|
Mads Kiilerich
|
cc1ab5ef6686
|
11 years ago
|
|
cleanup: avoid some 'except Exception' catching - catch specific exceptions or log it and show what happened
This has a risk of introducing regressions ... but we want to get rid of all exception muting and make the whole system less fragile and easier to debug.
|
|
|
Mads Kiilerich
|
d51a6f5e57d1
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
d1addaf7a91e
|
11 years ago
|
|
Second step in two-part process to rename directories. This is the actual directory rename.
|