def test_git_daemon_export_ok_allowed_all(): 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-if-all", "yes") cfg.add_section("group all") cfg.set("group all", "readonly", "foo") cfg.add_section("group boo") cfg.set("group boo", "members", "@all") cfg.set("group boo", "readonly", "quux thud") 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)
def test_simple(self): tmp = maketemp() path = os.path.join(tmp, 'authorized_keys') f = file(path, 'w') try: f.write('''\ # foo bar ### autogenerated by gitosis, DO NOT EDIT command="/foo/bar/baz/gitosis-serve wsmith",no-port-forwarding,\ no-X11-forwarding,no-agent-forwarding,no-pty %(key_2)s baz ''' % dict(key_2=KEY_2)) finally: f.close() keydir = os.path.join(tmp, 'one') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1 + '\n') ssh.writeAuthorizedKeys(path=path, keydir=keydir) got = readFile(path) eq( got, '''\ # foo bar baz ### autogenerated by gitosis, DO NOT EDIT command="gitosis-serve jdoe",no-port-forwarding,\ no-X11-forwarding,no-agent-forwarding,no-pty %(key_1)s ''' % dict(key_1=KEY_1))
def test_ignore_nonpub(self): tmp = maketemp() keydir = os.path.join(tmp, 'ignore_dot') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.xub'), KEY_1 + '\n') gen = ssh.readKeys(keydir=keydir) assert_raises(StopIteration, gen.__next__)
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)
def test_ignore_nonpub(self): tmp = maketemp() keydir = path.join(tmp, 'ignore_dot') mkdir(keydir) writeFile(path.join(keydir, 'jdoe.xub'), KEY_1+'\n') gen = ssh.readKeys(keydir=keydir) assert_raises(StopIteration, gen.next)
def test_has_initial_commit_environment(): tmp = maketemp() git_dir = os.path.join(tmp, "repo.git") mockbindir = os.path.join(tmp, "mockbin") os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, "git") writeFile( mockgit, """\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" """, ) os.chmod(mockgit, 0755) repository.init(path=tmp) repository.fast_import(git_dir=tmp, commit_msg="fakecommit", committer="John Doe <*****@*****.**>", files=[]) magic_cookie = "%d" % random.randint(1, 100000) good_path = os.environ["PATH"] try: os.environ["PATH"] = "%s:%s" % (mockbindir, good_path) os.environ["GITOSIS_UNITTEST_COOKIE"] = magic_cookie got = repository.has_initial_commit(git_dir=tmp) finally: os.environ["PATH"] = good_path os.environ.pop("GITOSIS_UNITTEST_COOKIE", None) eq(got, True) got = readFile(os.path.join(tmp, "cookie")) eq(got, magic_cookie)
def test_git_daemon_export_ok_allowed_all(): 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-if-all', 'yes') cfg.add_section('group all') cfg.set('group all', 'readonly', 'foo') cfg.add_section('group boo') cfg.set('group boo', 'members', '@all') cfg.set('group boo', 'readonly', 'quux thud') 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)
def test_init_environment(): tmp = maketemp() path = os.path.join(tmp, "repo.git") mockbindir = os.path.join(tmp, "mockbin") os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, "git") writeFile( mockgit, """\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" """, ) os.chmod(mockgit, 0755) magic_cookie = "%d" % random.randint(1, 100000) good_path = os.environ["PATH"] try: os.environ["PATH"] = "%s:%s" % (mockbindir, good_path) os.environ["GITOSIS_UNITTEST_COOKIE"] = magic_cookie repository.init(path) finally: os.environ["PATH"] = good_path os.environ.pop("GITOSIS_UNITTEST_COOKIE", None) eq(sorted(os.listdir(tmp)), sorted(["mockbin", "cookie", "repo.git"])) got = readFile(os.path.join(tmp, "cookie")) eq(got, magic_cookie)
def test_ignore_nonpub(self): tmp = maketemp() keydir = os.path.join(tmp, "ignore_dot") mkdir(keydir) writeFile(os.path.join(keydir, "jdoe.xub"), KEY_1 + "\n") gen = ssh.readKeys(keydir=keydir) assert_raises(StopIteration, gen.next)
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)
def test_one(self): tmp = maketemp() keydir = os.path.join(tmp, 'one') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1 + '\n') gen = ssh.readKeys(keydir=keydir) eq(next(gen), ('jdoe', KEY_1)) assert_raises(StopIteration, gen.__next__)
def test_one(self): tmp = maketemp() keydir = path.join(tmp, 'one') mkdir(keydir) writeFile(path.join(keydir, 'jdoe.pub'), KEY_1+'\n') gen = ssh.readKeys(keydir=keydir) eq(gen.next(), ('jdoe', KEY_1)) assert_raises(StopIteration, gen.next)
def test_multiple_lines(self): tmp = maketemp() keydir = os.path.join(tmp, 'keys') mkdir(keydir) writeFile(os.path.join(keydir, 'jd"oe.pub'), KEY_1 + '\n') gen = ssh.readKeys(keydir=keydir) got = frozenset(gen) eq(got, frozenset([]))
def test_one(self): tmp = maketemp() keydir = os.path.join(tmp, "one") mkdir(keydir) writeFile(os.path.join(keydir, "jdoe.pub"), KEY_1 + "\n") gen = ssh.readKeys(keydir=keydir) eq(gen.next(), ("jdoe", KEY_1)) assert_raises(StopIteration, gen.next)
def test_multiple_lines(self): tmp = maketemp() keydir = os.path.join(tmp, "keys") mkdir(keydir) writeFile(os.path.join(keydir, 'jd"oe.pub'), KEY_1 + "\n") gen = ssh.readKeys(keydir=keydir) got = frozenset(gen) eq(got, frozenset([]))
def test_htaccess_disabled(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') os.mkdir(path) writeFile(htaccess.htaccess_path(path), '') cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) eq(htaccess.gen_htaccess_if_enabled(config=cfg),False) exported(path, '')
def test_bad_filename(self): tmp = maketemp() keydir = os.path.join(tmp, "two") mkdir(keydir) writeFile(os.path.join(keydir, "jdoe.pub"), KEY_1 + "\n" + KEY_2 + "\n") gen = ssh.readKeys(keydir=keydir) got = frozenset(gen) eq(got, frozenset([("jdoe", KEY_1), ("jdoe", KEY_2)]))
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_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_one(self): tmp = maketemp() keydir = os.path.join(tmp, 'one') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1+'\n') gen = ssh.readKeys(keydir=keydir) (who, key) = gen.next() eq(who, 'jdoe') eq(key.full_key, KEY_1) assert_raises(StopIteration, gen.next)
def test_htaccess_export_ok_all(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') os.mkdir(path) writeFile(htaccess.htaccess_path(path), '') cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) cfg.add_section('group all') cfg.set('group all', 'readonly', 'foo') htaccess.gen_htaccess(config=cfg) exported(path, None)
def test_description_not_set(): tmp = maketemp() path = os.path.join(tmp, "foo.git") mkdir(path) writeFile(os.path.join(path, "description"), "i was here first\n") cfg = RawConfigParser() cfg.add_section("gitosis") cfg.set("gitosis", "repositories", tmp) cfg.add_section("repo foo") gitweb.set_descriptions(config=cfg) got = readFile(os.path.join(path, "description")) eq(got, "i was here first\n")
def test_description_default(): tmp = maketemp() path = os.path.join(tmp, "foo.git") mkdir(path) writeFile(os.path.join(path, "description"), "Unnamed repository; edit this file to name it for gitweb.\n") cfg = RawConfigParser() cfg.add_section("gitosis") cfg.set("gitosis", "repositories", tmp) cfg.add_section("repo foo") cfg.set("repo foo", "description", "foodesc") gitweb.set_descriptions(config=cfg) got = readFile(os.path.join(path, "description")) eq(got, "foodesc\n")
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_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_bad_filename(self): tmp = maketemp() keydir = path.join(tmp, 'two') mkdir(keydir) writeFile(path.join(keydir, 'jdoe.pub'), KEY_1+'\n'+KEY_2+'\n') gen = ssh.readKeys(keydir=keydir) got = frozenset(gen) eq(got, frozenset([ ('jdoe', KEY_1), ('jdoe', KEY_2), ]))
def test_bad_filename(self): tmp = maketemp() keydir = os.path.join(tmp, 'two') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1 + '\n' + KEY_2 + '\n') gen = ssh.readKeys(keydir=keydir) got = frozenset(gen) eq(got, frozenset([ ('jdoe', KEY_1), ('jdoe', KEY_2), ]))
def test_export_environment(): tmp = maketemp() git_dir = os.path.join(tmp, 'repo.git') mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile( mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0o755) repository.init(path=git_dir) repository.fast_import( git_dir=git_dir, committer='John Doe <*****@*****.**>', commit_msg="""\ Reverse the polarity of the neutron flow. Frobitz the quux and eschew obfuscation. """, files=[ ('foo', 'content'), ('bar/quux', 'another'), ], ) export = os.path.join(tmp, 'export') magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie repository.export(git_dir=git_dir, path=export) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) got = readFile(os.path.join(tmp, 'cookie')) eq( got, # export runs git twice '%s\n%s\n' % (magic_cookie, magic_cookie), )
def test_two(self): tmp = maketemp() keydir = os.path.join(tmp, 'two') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1+'\n') writeFile(os.path.join(keydir, 'wsmith.pub'), KEY_2+'\n') gen = ssh.readKeys(keydir=keydir) got = frozenset( (i, j.full_key) for (i, j) in gen) eq(got, frozenset([ ('jdoe', KEY_1), ('wsmith', KEY_2), ]))
def test_description_not_set(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') mkdir(path) writeFile( os.path.join(path, 'description'), 'i was here first\n', ) cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) cfg.add_section('repo foo') gitweb.set_descriptions(config=cfg, ) got = readFile(os.path.join(path, 'description')) eq(got, 'i was here first\n')
def test_export_environment(): tmp = maketemp() git_dir = os.path.join(tmp, "repo.git") mockbindir = os.path.join(tmp, "mockbin") os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, "git") writeFile( mockgit, """\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" """, ) os.chmod(mockgit, 0755) repository.init(path=git_dir) repository.fast_import( git_dir=git_dir, committer="John Doe <*****@*****.**>", commit_msg="""\ Reverse the polarity of the neutron flow. Frobitz the quux and eschew obfuscation. """, files=[("foo", "content"), ("bar/quux", "another")], ) export = os.path.join(tmp, "export") magic_cookie = "%d" % random.randint(1, 100000) good_path = os.environ["PATH"] try: os.environ["PATH"] = "%s:%s" % (mockbindir, good_path) os.environ["GITOSIS_UNITTEST_COOKIE"] = magic_cookie repository.export(git_dir=git_dir, path=export) finally: os.environ["PATH"] = good_path os.environ.pop("GITOSIS_UNITTEST_COOKIE", None) got = readFile(os.path.join(tmp, "cookie")) eq( got, # export runs git twice "%s\n%s\n" % (magic_cookie, magic_cookie), )
def test_export_environment(): tmp = maketemp() git_dir = os.path.join(tmp, 'repo.git') mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile(mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0755) repository.init(path=git_dir) repository.fast_import( git_dir=git_dir, committer='John Doe <*****@*****.**>', commit_msg="""\ Reverse the polarity of the neutron flow. Frobitz the quux and eschew obfuscation. """, files=[ ('foo', 'content'), ('bar/quux', 'another'), ], ) export = os.path.join(tmp, 'export') magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie repository.export(git_dir=git_dir, path=export) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) got = readFile(os.path.join(tmp, 'cookie')) eq( got, # export runs git twice '%s\n%s\n' % (magic_cookie, magic_cookie), )
def test_description_default(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') mkdir(path) writeFile( os.path.join(path, 'description'), 'Unnamed repository; edit this file to name it for gitweb.\n', ) cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) cfg.add_section('repo foo') cfg.set('repo foo', 'description', 'foodesc') gitweb.set_descriptions(config=cfg, ) got = readFile(os.path.join(path, 'description')) eq(got, 'foodesc\n')
def test_htaccess_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(htaccess.htaccess_path(path), '') cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) htaccess.gen_htaccess(config=cfg) exported(path, '''\ Order allow,deny Deny from all ''')
def test_fast_import_environment(): tmp = maketemp() path = os.path.join(tmp, 'repo.git') repository.init(path=path) mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile( mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0o755) magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie repository.fast_import( git_dir=path, commit_msg='foo initial bar', committer='Mr. Unit Test <*****@*****.**>', files=[ ('foo', 'bar\n'), ], ) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) eq( sorted(os.listdir(tmp)), sorted([ 'mockbin', 'cookie', 'repo.git', ]), ) got = readFile(os.path.join(tmp, 'cookie')) eq(got, magic_cookie)
def test_description_not_set(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') mkdir(path) writeFile( os.path.join(path, 'description'), 'i was here first\n', ) cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) cfg.add_section('repo foo') gitweb.set_descriptions( config=cfg, ) got = readFile(os.path.join(path, 'description')) eq(got, 'i was here first\n')
def test_fast_import_environment(): tmp = maketemp() path = os.path.join(tmp, 'repo.git') repository.init(path=path) mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile(mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0755) magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie repository.fast_import( git_dir=path, commit_msg='foo initial bar', committer='Mr. Unit Test <*****@*****.**>', files=[ ('foo', 'bar\n'), ], ) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) eq( sorted(os.listdir(tmp)), sorted([ 'mockbin', 'cookie', 'repo.git', ]), ) got = readFile(os.path.join(tmp, 'cookie')) eq(got, magic_cookie)
def test_description_default(): tmp = maketemp() path = os.path.join(tmp, 'foo.git') mkdir(path) writeFile( os.path.join(path, 'description'), 'Unnamed repository; edit this file to name it for gitweb.\n', ) cfg = RawConfigParser() cfg.add_section('gitosis') cfg.set('gitosis', 'repositories', tmp) cfg.add_section('repo foo') cfg.set('repo foo', 'description', 'foodesc') gitweb.set_descriptions( config=cfg, ) got = readFile(os.path.join(path, 'description')) eq(got, 'foodesc\n')
def test_has_initial_commit_environment(): tmp = maketemp() git_dir = os.path.join(tmp, 'repo.git') mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile( mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0o755) repository.init(path=tmp) repository.fast_import( git_dir=tmp, commit_msg='fakecommit', committer='John Doe <*****@*****.**>', files=[], ) magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie got = repository.has_initial_commit(git_dir=tmp) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) eq(got, True) got = readFile(os.path.join(tmp, 'cookie')) eq(got, magic_cookie)
def test_simple(self): tmp = maketemp() path = os.path.join(tmp, "authorized_keys") f = file(path, "w") try: f.write( """\ # foo bar ### autogenerated by gitosis, DO NOT EDIT command="/foo/bar/baz/gitosis-serve wsmith",no-port-forwarding,\ no-X11-forwarding,no-agent-forwarding,no-pty %(key_2)s baz """ % dict(key_2=KEY_2) ) finally: f.close() keydir = os.path.join(tmp, "one") mkdir(keydir) writeFile(os.path.join(keydir, "jdoe.pub"), KEY_1 + "\n") ssh.writeAuthorizedKeys(path=path, keydir=keydir) got = readFile(path) eq( got, """\ # foo bar baz ### autogenerated by gitosis, DO NOT EDIT command="gitosis-serve jdoe",no-port-forwarding,\ no-X11-forwarding,no-agent-forwarding,no-pty %(key_1)s """ % dict(key_1=KEY_1), )
def test_has_initial_commit_environment(): tmp = maketemp() git_dir = os.path.join(tmp, 'repo.git') mockbindir = os.path.join(tmp, 'mockbin') os.mkdir(mockbindir) mockgit = os.path.join(mockbindir, 'git') writeFile(mockgit, '''\ #!/bin/sh set -e # git wrapper for gitosis unit tests printf '%s' "$GITOSIS_UNITTEST_COOKIE" >"$(dirname "$0")/../cookie" # strip away my special PATH insert so system git will be found PATH="${PATH#*:}" exec git "$@" ''') os.chmod(mockgit, 0755) repository.init(path=tmp) repository.fast_import( git_dir=tmp, commit_msg='fakecommit', committer='John Doe <*****@*****.**>', files=[], ) magic_cookie = '%d' % random.randint(1, 100000) good_path = os.environ['PATH'] try: os.environ['PATH'] = '%s:%s' % (mockbindir, good_path) os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie got = repository.has_initial_commit(git_dir=tmp) finally: os.environ['PATH'] = good_path os.environ.pop('GITOSIS_UNITTEST_COOKIE', None) eq(got, True) got = readFile(os.path.join(tmp, 'cookie')) eq(got, magic_cookie)
def test_simple(self): tmp = maketemp() path = os.path.join(tmp, 'authorized_keys') f = file(path, 'w') try: f.write('''\ # foo bar ### autogenerated by gitosis, DO NOT EDIT command="/foo/bar/baz/gitosis-serve wsmith",no-port-forwarding,\ no-X11-forwarding,no-agent-forwarding,no-pty %(key_2)s baz ''' % dict(key_2=KEY_2)) finally: f.close() keydir = os.path.join(tmp, 'one') mkdir(keydir) writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1+'\n') ssh.writeAuthorizedKeys( path=path, keydir=keydir) got = readFile(path) eq(got, '''# foo\nbar\nbaz\n### autogenerated by gitosis, DO NOT EDIT\ncommand="gitosis-serve jdoe",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %(key_1)s\n''' % dict(key_1=KEY_1))