aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2008-03-19 21:49:47 +0200
committerTommi Virtanen <tv@eagain.net>2008-03-19 21:55:19 +0200
commit4d8ba7788d10e62928404b0272de241580e00e92 (patch)
tree7f03923a420c81c8a78930d574cc8a7283248dae
parentMake serve acceptable path unit tests more careful. (diff)
downloadgitosis-gentoo-4d8ba7788d10e62928404b0272de241580e00e92.zip
gitosis-gentoo-4d8ba7788d10e62928404b0272de241580e00e92.tar.gz
gitosis-gentoo-4d8ba7788d10e62928404b0272de241580e00e92.tar.bz2
Allow absolute paths in repo paths, treat them as relative.
As the only convenient way to use non-standard SSH ports with git is via the ssh://user@host:port/path syntax, and that syntax forces absolute urls, just force convert absolute paths to relative paths; you'll never really want absolute paths via gitosis, anyway.
-rw-r--r--gitosis/serve.py2
-rw-r--r--gitosis/test/test_serve.py32
2 files changed, 21 insertions, 13 deletions
diff --git a/gitosis/serve.py b/gitosis/serve.py
index 0f9cb5c..37ad97f 100644
--- a/gitosis/serve.py
+++ b/gitosis/serve.py
@@ -15,7 +15,7 @@ from gitosis import gitdaemon
from gitosis import app
from gitosis import util
-ALLOW_RE = re.compile("^'(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)'$")
+ALLOW_RE = re.compile("^'/*(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)'$")
COMMANDS_READONLY = [
'git-upload-pack',
diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py
index 23b6a6f..a223c43 100644
--- a/gitosis/test/test_serve.py
+++ b/gitosis/test/test_serve.py
@@ -57,18 +57,6 @@ def test_bad_unsafeArguments_notQuoted():
eq(str(e), 'Arguments to command look dangerous')
assert isinstance(e, serve.ServingError)
-def test_bad_unsafeArguments_absolute():
- cfg = RawConfigParser()
- e = assert_raises(
- serve.UnsafeArgumentsError,
- serve.serve,
- cfg=cfg,
- user='jdoe',
- command="git-upload-pack '/evil/attack'",
- )
- eq(str(e), 'Arguments to command look dangerous')
- assert isinstance(e, serve.ServingError)
-
def test_bad_unsafeArguments_badCharacters():
cfg = RawConfigParser()
e = assert_raises(
@@ -402,3 +390,23 @@ def test_push_inits_sets_export_ok():
path = os.path.join(repositories, 'foo.git', 'git-daemon-export-ok')
assert os.path.exists(path)
+def test_absolute():
+ # as the only convenient way to use non-standard SSH ports with
+ # git is via the ssh://user@host:port/path syntax, and that syntax
+ # forces absolute urls, just force convert absolute paths to
+ # relative paths; you'll never really want absolute paths via
+ # gitosis, anyway.
+ tmp = util.maketemp()
+ repository.init(os.path.join(tmp, 'foo.git'))
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'repositories', tmp)
+ cfg.add_section('group foo')
+ cfg.set('group foo', 'members', 'jdoe')
+ cfg.set('group foo', 'readonly', 'foo')
+ got = serve.serve(
+ cfg=cfg,
+ user='jdoe',
+ command="git-upload-pack '/foo'",
+ )
+ eq(got, "git-upload-pack '%s/foo.git'" % tmp)