From c7fa5ecce6a4b4766a956d46dea64f5a194ec4df Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 28 Dec 2007 03:46:05 -0800 Subject: Allow some slashes, to provide support for git+ssh:// URLs that always have a leading slash. --- gitosis/serve.py | 12 ++++++++++++ gitosis/test/test_serve.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/gitosis/serve.py b/gitosis/serve.py index 9718758..2d45f58 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -66,6 +66,18 @@ def serve(cfg, user, command): and verb not in COMMANDS_READONLY): raise UnknownCommandError() + if args.startswith("'/") and args.endswith("'"): + args = args[1:-1] + repos = util.getRepositoryDir(cfg) + reposreal = os.path.realpath(repos) + if args.startswith(repos): + args = os.path.realpath(args)[len(repos)+1:] + elif args.startswith(reposreal): + args = os.path.realpath(args)[len(reposreal)+1:] + else: + args = args[1:] + args = "'%s'" % (args, ) + match = ALLOW_RE.match(args) if match is None: raise UnsafeArgumentsError() diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py index f5785f5..deb9637 100644 --- a/gitosis/test/test_serve.py +++ b/gitosis/test/test_serve.py @@ -117,6 +117,39 @@ def test_simple_read(): ) eq(got, "git-upload-pack '%s/foo.git'" % tmp) +def test_simple_read_absolute(): + tmp = util.maketemp() + full_path = os.path.join(tmp, 'foo.git') + repository.init(full_path) + 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 '%s'" % (full_path, ), + ) + eq(got, "git-upload-pack '%s/foo.git'" % tmp) + +def test_simple_read_leading_slash(): + 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) + def test_simple_write(): tmp = util.maketemp() repository.init(os.path.join(tmp, 'foo.git')) -- cgit v1.2.3