Make post-update hook reload config after writing it out.

Without this, any changes to repository settings would only be
applied after one extra (non-empty) push.

Add unit test coverage for the post-update hook.

Make SSH authorized_keys path configurable, mostly for unit tests.
This commit is contained in:
Tommi Virtanen 2007-12-31 21:11:22 +02:00
parent 895fd8b7ad
commit e495c9a66e
3 changed files with 106 additions and 1 deletions

View file

@ -29,6 +29,8 @@ def post_update(cfg, git_dir):
os.path.join(export, 'gitosis.conf'),
os.path.join(export, '..', 'gitosis.conf'),
)
# re-read config to get up-to-date settings
cfg.read(os.path.join(export, '..', 'gitosis.conf'))
gitweb.set_descriptions(
config=cfg,
)
@ -40,8 +42,9 @@ def post_update(cfg, git_dir):
gitdaemon.set_export_ok(
config=cfg,
)
authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg)
ssh.writeAuthorizedKeys(
path=os.path.expanduser('~/.ssh/authorized_keys'),
path=authorized_keys,
keydir=os.path.join(export, 'keydir'),
)

View file

@ -0,0 +1,95 @@
from nose.tools import eq_ as eq
import os
from ConfigParser import RawConfigParser
from cStringIO import StringIO
from gitosis import init, repository, run_hook
from gitosis.test.util import maketemp, readFile
def test_post_update_simple():
tmp = maketemp()
repos = os.path.join(tmp, 'repositories')
os.mkdir(repos)
admin_repository = os.path.join(repos, 'gitosis-admin.git')
pubkey = (
'ssh-somealgo '
+'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
user = 'theadmin'
init.init_admin_repository(
git_dir=admin_repository,
pubkey=pubkey,
user=user,
)
repository.init(path=os.path.join(repos, 'forweb.git'))
repository.init(path=os.path.join(repos, 'fordaemon.git'))
repository.fast_import(
git_dir=admin_repository,
committer='John Doe <jdoe@example.com>',
commit_msg="""\
stuff
""",
parent='refs/heads/master^0',
files=[
('gitosis.conf', """\
[gitosis]
[group gitosis-admin]
members = theadmin
writable = gitosis-admin
[repo fordaemon]
daemon = yes
[repo forweb]
gitweb = yes
owner = John Doe
description = blah blah
"""),
('keydir/jdoe.pub',
'ssh-somealgo '
+'0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
+'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
+'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
+'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= jdoe@host.example.com'),
],
)
cfg = RawConfigParser()
cfg.add_section('gitosis')
cfg.set('gitosis', 'repositories', repos)
generated = os.path.join(tmp, 'generated')
os.mkdir(generated)
cfg.set('gitosis', 'generate-files-in', generated)
ssh = os.path.join(tmp, 'ssh')
os.mkdir(ssh)
cfg.set(
'gitosis',
'ssh-authorized-keys-path',
os.path.join(ssh, 'authorized_keys'),
)
run_hook.post_update(
cfg=cfg,
git_dir=admin_repository,
)
got = readFile(os.path.join(repos, 'forweb.git', 'description'))
eq(got, 'blah blah\n')
got = os.listdir(generated)
eq(got, ['projects.list'])
got = readFile(os.path.join(generated, 'projects.list'))
eq(
got,
"""\
forweb.git John+Doe
""",
)
got = os.listdir(os.path.join(repos, 'fordaemon.git'))
assert 'git-daemon-export-ok' in got, \
"git-daemon-export-ok not created: %r" % got
got = os.listdir(ssh)
eq(got, ['authorized_keys'])
got = readFile(os.path.join(ssh, 'authorized_keys')).splitlines(True)
assert 'command="gitosis-serve jdoe",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-somealgo 0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= jdoe@host.example.com\n' in got, \
"SSH authorized_keys line for jdoe not found: %r" % got

View file

@ -27,3 +27,10 @@ def getGeneratedFilesDir(config):
except (NoSectionError, NoOptionError):
generated = os.path.expanduser('~/gitosis')
return generated
def getSSHAuthorizedKeysPath(config):
try:
path = config.get('gitosis', 'ssh-authorized-keys-path')
except (NoSectionError, NoOptionError):
path = os.path.expanduser('~/.ssh/authorized_keys'),
return path