Understand the popular gitosis.conf typo "writeable".
Log a warning still, don't want that to get too common.
This commit is contained in:
parent
a938dccf82
commit
38561aa6a5
3 changed files with 55 additions and 6 deletions
|
@ -15,6 +15,8 @@ from gitosis import gitdaemon
|
|||
from gitosis import app
|
||||
from gitosis import util
|
||||
|
||||
log = logging.getLogger('gitosis.serve')
|
||||
|
||||
ALLOW_RE = re.compile("^'/*(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)'$")
|
||||
|
||||
COMMANDS_READONLY = [
|
||||
|
@ -80,6 +82,21 @@ def serve(
|
|||
mode='writable',
|
||||
path=path)
|
||||
|
||||
if newpath is None:
|
||||
# didn't have write access; try once more with the popular
|
||||
# misspelling
|
||||
newpath = access.haveAccess(
|
||||
config=cfg,
|
||||
user=user,
|
||||
mode='writeable',
|
||||
path=path)
|
||||
if newpath is not None:
|
||||
log.warning(
|
||||
'Repository %r config has typo "writeable", '
|
||||
+'should be "writable"',
|
||||
path,
|
||||
)
|
||||
|
||||
if newpath is None:
|
||||
# didn't have write access
|
||||
|
||||
|
@ -147,15 +164,15 @@ class Main(app.App):
|
|||
except ValueError:
|
||||
parser.error('Missing argument USER.')
|
||||
|
||||
log = logging.getLogger('gitosis.serve.main')
|
||||
main_log = logging.getLogger('gitosis.serve.main')
|
||||
os.umask(0022)
|
||||
|
||||
cmd = os.environ.get('SSH_ORIGINAL_COMMAND', None)
|
||||
if cmd is None:
|
||||
log.error('Need SSH_ORIGINAL_COMMAND in environment.')
|
||||
main_log.error('Need SSH_ORIGINAL_COMMAND in environment.')
|
||||
sys.exit(1)
|
||||
|
||||
log.debug('Got command %(cmd)r' % dict(
|
||||
main_log.debug('Got command %(cmd)r' % dict(
|
||||
cmd=cmd,
|
||||
))
|
||||
|
||||
|
@ -168,10 +185,10 @@ class Main(app.App):
|
|||
command=cmd,
|
||||
)
|
||||
except ServingError, e:
|
||||
log.error('%s', e)
|
||||
main_log.error('%s', e)
|
||||
sys.exit(1)
|
||||
|
||||
log.debug('Serving %s', newcmd)
|
||||
main_log.debug('Serving %s', newcmd)
|
||||
os.execvp('git-shell', ['git-shell', '-c', newcmd])
|
||||
log.error('Cannot execute git-shell.')
|
||||
main_log.error('Cannot execute git-shell.')
|
||||
sys.exit(1)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from nose.tools import eq_ as eq
|
||||
|
||||
import logging
|
||||
from ConfigParser import RawConfigParser
|
||||
|
||||
from gitosis import access
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from nose.tools import eq_ as eq
|
||||
from gitosis.test.util import assert_raises
|
||||
|
||||
import logging
|
||||
import os
|
||||
from cStringIO import StringIO
|
||||
from ConfigParser import RawConfigParser
|
||||
|
||||
from gitosis import serve
|
||||
|
@ -410,3 +412,32 @@ def test_absolute():
|
|||
command="git-upload-pack '/foo'",
|
||||
)
|
||||
eq(got, "git-upload-pack '%s/foo.git'" % tmp)
|
||||
|
||||
def test_typo_writeable():
|
||||
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', 'writeable', 'foo')
|
||||
log = logging.getLogger('gitosis.serve')
|
||||
buf = StringIO()
|
||||
handler = logging.StreamHandler(buf)
|
||||
log.addHandler(handler)
|
||||
try:
|
||||
got = serve.serve(
|
||||
cfg=cfg,
|
||||
user='jdoe',
|
||||
command="git-receive-pack 'foo'",
|
||||
)
|
||||
finally:
|
||||
log.removeHandler(handler)
|
||||
eq(got, "git-receive-pack '%s/foo.git'" % tmp)
|
||||
handler.flush()
|
||||
eq(
|
||||
buf.getvalue(),
|
||||
"Repository 'foo' config has typo \"writeable\", shou"
|
||||
+"ld be \"writable\"\n",
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue