From 13c89cdb7d493c43659c7f202c6cc3f81ea4c1e8 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Sat, 17 Nov 2007 16:27:21 +0200 Subject: Manage git-daemon-export-ok flags from gitosis config. --- gitosis/test/test_gitdaemon.py | 155 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 gitosis/test/test_gitdaemon.py (limited to 'gitosis/test/test_gitdaemon.py') diff --git a/gitosis/test/test_gitdaemon.py b/gitosis/test/test_gitdaemon.py new file mode 100644 index 0000000..94475ac --- /dev/null +++ b/gitosis/test/test_gitdaemon.py @@ -0,0 +1,155 @@ +from nose.tools import eq_ as eq + +import os +from ConfigParser import RawConfigParser + +from gitosis import gitdaemon +from gitosis.test.util import maketemp, writeFile + +def exported(path): + assert os.path.isdir(path) + p = gitdaemon.export_ok_path(path) + return os.path.exists(p) + +def test_git_daemon_export_ok_repo_missing(): + # configured but not created yet; before first push + tmp = maketemp() + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'daemon', 'yes') + gitdaemon.set_export_ok(config=cfg) + assert not os.path.exists(os.path.join(tmp, 'foo')) + assert not os.path.exists(os.path.join(tmp, 'foo.git')) + +def test_git_daemon_export_ok_repo_missing_parent(): + # configured but not created yet; before first push + tmp = maketemp() + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo/bar') + cfg.set('repo foo/bar', 'daemon', 'yes') + gitdaemon.set_export_ok(config=cfg) + assert not os.path.exists(os.path.join(tmp, 'foo')) + +def test_git_daemon_export_ok_allowed(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'daemon', 'yes') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), True) + +def test_git_daemon_export_ok_allowed_already(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + writeFile(gitdaemon.export_ok_path(path), '') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'daemon', 'yes') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), True) + +def test_git_daemon_export_ok_denied(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + writeFile(gitdaemon.export_ok_path(path), '') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'daemon', 'no') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), False) + +def test_git_daemon_export_ok_denied_already(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'daemon', 'no') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), False) + +def test_git_daemon_export_ok_subdirs(): + tmp = maketemp() + foo = os.path.join(tmp, 'foo') + os.mkdir(foo) + path = os.path.join(foo, 'bar.git') + os.mkdir(path) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo/bar') + cfg.set('repo foo/bar', 'daemon', 'yes') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), True) + +def test_git_daemon_export_ok_denied_default(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + writeFile(gitdaemon.export_ok_path(path), '') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), False) + +def test_git_daemon_export_ok_denied_even_not_configured(): + # repositories not mentioned in config also get touched; this is + # to avoid security trouble, otherwise we might expose (or + # continue to expose) old repositories removed from config + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + os.mkdir(path) + writeFile(gitdaemon.export_ok_path(path), '') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + gitdaemon.set_export_ok(config=cfg) + eq(exported(path), False) + +def test_git_daemon_export_ok_allowed_global(): + tmp = maketemp() + + for repo in [ + 'foo.git', + 'quux.git', + 'thud.git', + ]: + path = os.path.join(tmp, repo) + os.mkdir(path) + + # try to provoke an invalid allow + writeFile(gitdaemon.export_ok_path(os.path.join(tmp, 'thud.git')), '') + + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.set('gitosis', 'daemon', 'yes') + cfg.add_section('repo foo') + cfg.add_section('repo quux') + # same as default, no effect + cfg.set('repo quux', 'daemon', 'yes') + cfg.add_section('repo thud') + # this is still hidden + cfg.set('repo thud', 'daemon', 'no') + gitdaemon.set_export_ok(config=cfg) + eq(exported(os.path.join(tmp, 'foo.git')), True) + eq(exported(os.path.join(tmp, 'quux.git')), True) + eq(exported(os.path.join(tmp, 'thud.git')), False) -- cgit v1.2.3