aboutsummaryrefslogtreecommitdiff
path: root/gitosis/test
diff options
context:
space:
mode:
Diffstat (limited to 'gitosis/test')
-rw-r--r--gitosis/test/test_gitweb.py20
-rw-r--r--gitosis/test/test_init.py88
-rw-r--r--gitosis/test/test_repository.py7
-rw-r--r--gitosis/test/test_run_hook.py34
-rw-r--r--gitosis/test/test_serve.py50
-rw-r--r--gitosis/test/test_ssh.py31
-rw-r--r--gitosis/test/test_sshkey.py99
-rw-r--r--gitosis/test/test_util.py65
-rw-r--r--gitosis/test/test_zzz_app.py108
9 files changed, 380 insertions, 122 deletions
diff --git a/gitosis/test/test_gitweb.py b/gitosis/test/test_gitweb.py
index 635e555..e538ec7 100644
--- a/gitosis/test/test_gitweb.py
+++ b/gitosis/test/test_gitweb.py
@@ -222,3 +222,23 @@ def test_description_again():
)
got = readFile(os.path.join(path, 'description'))
eq(got, 'foodesc\n')
+
+def test_escape_filename_normal():
+ i = 'abc'
+ eq(gitweb._escape_filename(i), 'abc')
+
+def test_escape_filename_slashone():
+ i = 'ab\\c'
+ eq(gitweb._escape_filename(i), 'ab\\\\c')
+
+def test_escape_filename_slashtwo():
+ i = 'ab\\\\c'
+ eq(gitweb._escape_filename(i), 'ab\\\\\\\\c')
+
+def test_escape_filename_dollar():
+ i = 'abc$'
+ eq(gitweb._escape_filename(i), 'abc\\$')
+
+def test_escape_filename_quote():
+ i = 'abc"'
+ eq(gitweb._escape_filename(i), 'abc\\"')
diff --git a/gitosis/test/test_init.py b/gitosis/test/test_init.py
index fb6b286..dcfa3bf 100644
--- a/gitosis/test/test_init.py
+++ b/gitosis/test/test_init.py
@@ -2,95 +2,13 @@ from nose.tools import eq_ as eq
from gitosis.test.util import assert_raises, maketemp
import os
-from ConfigParser import RawConfigParser
from gitosis import init
from gitosis import repository
+from gitosis.configutil import GitosisRawConfigParser
from gitosis.test import util
-def test_ssh_extract_user_simple():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
- eq(got, 'fakeuser@fakehost')
-
-def test_ssh_extract_user_domain():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost.example.com')
- eq(got, 'fakeuser@fakehost.example.com')
-
-def test_ssh_extract_user_domain_dashes():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@ridiculously-long.example.com')
- eq(got, 'fakeuser@ridiculously-long.example.com')
-
-def test_ssh_extract_user_underscore():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake_user@example.com')
- eq(got, 'fake_user@example.com')
-
-def test_ssh_extract_user_dot():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake.u.ser@example.com')
- eq(got, 'fake.u.ser@example.com')
-
-def test_ssh_extract_user_dash():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake.u-ser@example.com')
- eq(got, 'fake.u-ser@example.com')
-
-def test_ssh_extract_user_no_at():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser')
- eq(got, 'fakeuser')
-
-def test_ssh_extract_user_caps():
- got = init.ssh_extract_user(
- 'ssh-somealgo '
- +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Fake.User@Domain.Example.Com')
- eq(got, 'Fake.User@Domain.Example.Com')
-
-def test_ssh_extract_user_bad():
- e = assert_raises(
- init.InsecureSSHKeyUsername,
- init.ssh_extract_user,
- 'ssh-somealgo AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
- +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= ER3%#@e%')
- eq(str(e), "Username contains not allowed characters: 'ER3%#@e%'")
-
def test_init_admin_repository():
tmp = maketemp()
admin_repository = os.path.join(tmp, 'admin.git')
@@ -101,10 +19,12 @@ def test_init_admin_repository():
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
user = 'jdoe'
+ cfg = GitosisRawConfigParser()
init.init_admin_repository(
git_dir=admin_repository,
pubkey=pubkey,
user=user,
+ config=cfg,
)
eq(os.listdir(tmp), ['admin.git'])
hook = os.path.join(
@@ -129,9 +49,9 @@ def test_init_admin_repository():
# the only thing guaranteed of initial config file ordering is
# that [gitosis] is first
got = util.readFile(os.path.join(export_dir, 'gitosis.conf'))
+ # We can't gaurentee this anymore
got = got.splitlines()[0]
eq(got, '[gitosis]')
- cfg = RawConfigParser()
cfg.read(os.path.join(export_dir, 'gitosis.conf'))
eq(sorted(cfg.sections()),
sorted([
diff --git a/gitosis/test/test_repository.py b/gitosis/test/test_repository.py
index 6ce4129..6bc9e76 100644
--- a/gitosis/test/test_repository.py
+++ b/gitosis/test/test_repository.py
@@ -36,6 +36,13 @@ def test_init_exist_dir():
check_mode(path, 0710, is_dir=True)
check_bare(path)
+def test_init_custom_perm():
+ tmp = maketemp()
+ path = os.path.join(tmp, 'repo.git')
+ repository.init(path, mode=0711)
+ check_mode(path, 0711, is_dir=True)
+ check_bare(path)
+
def test_init_exist_git():
tmp = maketemp()
path = os.path.join(tmp, 'repo.git')
diff --git a/gitosis/test/test_run_hook.py b/gitosis/test/test_run_hook.py
index db01e0c..f935375 100644
--- a/gitosis/test/test_run_hook.py
+++ b/gitosis/test/test_run_hook.py
@@ -13,16 +13,31 @@ def test_post_update_simple():
os.mkdir(repos)
admin_repository = os.path.join(repos, 'gitosis-admin.git')
pubkey = (
- 'ssh-somealgo '
+ 'ssh-rsa '
+'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
user = 'theadmin'
+ 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'),
+ )
+
init.init_admin_repository(
git_dir=admin_repository,
pubkey=pubkey,
user=user,
+ config=cfg,
)
repository.init(path=os.path.join(repos, 'forweb.git'))
repository.init(path=os.path.join(repos, 'fordaemon.git'))
@@ -50,26 +65,13 @@ owner = John Doe
description = blah blah
"""),
('keydir/jdoe.pub',
- 'ssh-somealgo '
+ 'ssh-rsa '
+'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,
@@ -91,5 +93,5 @@ forweb.git John+Doe
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, \
+ assert 'command="gitosis-serve jdoe",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa 0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= jdoe@host.example.com\n' in got, \
"SSH authorized_keys line for jdoe not found: %r" % got
diff --git a/gitosis/test/test_serve.py b/gitosis/test/test_serve.py
index f1c1930..4b414c4 100644
--- a/gitosis/test/test_serve.py
+++ b/gitosis/test/test_serve.py
@@ -199,7 +199,24 @@ def test_simple_read_dash():
)
eq(got, "git-upload-pack '%s/foo.git'" % tmp)
-def test_simple_read_space():
+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()
@@ -211,11 +228,11 @@ def test_simple_read_space():
got = serve.serve(
cfg=cfg,
user='jdoe',
- command="git upload-pack 'foo'",
+ command="git-upload-pack '/foo'",
)
- eq(got, "git upload-pack '%s/foo.git'" % tmp)
+ eq(got, "git-upload-pack '%s/foo.git'" % tmp)
-def test_simple_write_dash():
+def test_simple_write():
tmp = util.maketemp()
repository.init(os.path.join(tmp, 'foo.git'))
cfg = RawConfigParser()
@@ -317,6 +334,31 @@ def test_push_inits_subdir_parent_missing():
eq(os.listdir(foo), ['bar.git'])
assert os.path.isfile(os.path.join(repositories, 'foo', 'bar.git', 'HEAD'))
+def test_push_inits_subdir_parent_missing_custom_perms():
+ tmp = util.maketemp()
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ repositories = os.path.join(tmp, 'repositories')
+ os.mkdir(repositories)
+ cfg.set('gitosis', 'repositories', repositories)
+ cfg.set('gitosis', 'dirmode', '0711')
+ generated = os.path.join(tmp, 'generated')
+ os.mkdir(generated)
+ cfg.set('gitosis', 'generate-files-in', generated)
+ cfg.add_section('group foo')
+ cfg.set('group foo', 'members', 'jdoe')
+ cfg.set('group foo', 'writable', 'foo/bar')
+ serve.serve(
+ cfg=cfg,
+ user='jdoe',
+ command="git-receive-pack 'foo/bar.git'",
+ )
+ eq(os.listdir(repositories), ['foo'])
+ foo = os.path.join(repositories, 'foo')
+ util.check_mode(foo, 0711, is_dir=True)
+ eq(os.listdir(foo), ['bar.git'])
+ assert os.path.isfile(os.path.join(repositories, 'foo', 'bar.git', 'HEAD'))
+
def test_push_inits_subdir_parent_exists():
tmp = util.maketemp()
cfg = RawConfigParser()
diff --git a/gitosis/test/test_ssh.py b/gitosis/test/test_ssh.py
index fc6ecbc..75effd5 100644
--- a/gitosis/test/test_ssh.py
+++ b/gitosis/test/test_ssh.py
@@ -1,9 +1,10 @@
-from nose.tools import eq_ as eq, assert_raises
+from nose.tools import eq_ as eq, assert_raises, raises
import os
from cStringIO import StringIO
from gitosis import ssh
+from gitosis import sshkey
from gitosis.test.util import mkdir, maketemp, writeFile, readFile
def _key(s):
@@ -13,15 +14,13 @@ KEY_1 = _key("""
ssh-rsa +v5XLsUrLsHOKy7Stob1lHZM17YCCNXplcKfbpIztS2PujyixOaBev1ku6H6ny
gUXfuYVzY+PmfTLviSwD3UETxEkR/jlBURACDQARJdUxpgt9XG2Lbs8bhOjonAPapxrH0o
9O8R0Y6Pm1Vh+H2U0B4UBhPgEframpeJYedijBxBV5aq3yUvHkXpcjM/P0gsKqr036k= j
-unk@gunk
-""")
+unk@gunk""")
KEY_2 = _key("""
ssh-rsa 4BX2TxZoD3Og2zNjHwaMhVEa5/NLnPcw+Z02TDR0IGJrrqXk7YlfR3oz+Wb/Eb
Ctli20SoWY0Ur8kBEF/xR4hRslZ2U8t0PAJhr8cq5mifhok/gAdckmSzjD67QJ68uZbga8
ZwIAo7y/BU7cD3Y9UdVZykG34NiijHZLlCBo/TnobXjFIPXvFbfgQ3y8g+akwocFVcQ= f
-roop@snoop
-""")
+roop@snoop""")
class ReadKeys_Test(object):
def test_empty(self):
@@ -54,7 +53,9 @@ class ReadKeys_Test(object):
writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1+'\n')
gen = ssh.readKeys(keydir=keydir)
- eq(gen.next(), ('jdoe', KEY_1))
+ (who, key) = gen.next()
+ eq(who, 'jdoe')
+ eq(key.full_key, KEY_1)
assert_raises(StopIteration, gen.next)
def test_two(self):
@@ -65,7 +66,7 @@ class ReadKeys_Test(object):
writeFile(os.path.join(keydir, 'wsmith.pub'), KEY_2+'\n')
gen = ssh.readKeys(keydir=keydir)
- got = frozenset(gen)
+ got = frozenset( (i, j.full_key) for (i, j) in gen)
eq(got,
frozenset([
@@ -90,7 +91,7 @@ class ReadKeys_Test(object):
writeFile(os.path.join(keydir, 'jdoe.pub'), KEY_1+'\n'+KEY_2+'\n')
gen = ssh.readKeys(keydir=keydir)
- got = frozenset(gen)
+ got = frozenset( (i, j.full_key) for (i, j) in gen)
eq(got,
frozenset([
@@ -101,8 +102,8 @@ class ReadKeys_Test(object):
class GenerateAuthorizedKeys_Test(object):
def test_simple(self):
def k():
- yield ('jdoe', KEY_1)
- yield ('wsmith', KEY_2)
+ yield ('jdoe', sshkey.get_ssh_pubkey(KEY_1))
+ yield ('wsmith', sshkey.get_ssh_pubkey(KEY_2))
gen = ssh.generateAuthorizedKeys(k())
eq(gen.next(), ssh.COMMENT)
eq(gen.next(), (
@@ -191,11 +192,5 @@ baz
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))
+ 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))
+
diff --git a/gitosis/test/test_sshkey.py b/gitosis/test/test_sshkey.py
new file mode 100644
index 0000000..09863fa
--- /dev/null
+++ b/gitosis/test/test_sshkey.py
@@ -0,0 +1,99 @@
+from nose.tools import eq_ as eq, assert_raises, raises
+
+from gitosis import sshkey
+
+def test_sshkey_username_simple():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
+ got = _.username
+ eq(got, 'fakeuser@fakehost')
+
+def test_sshkey_username_domain():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost.example.com')
+ got = _.username
+ eq(got, 'fakeuser@fakehost.example.com')
+
+def test_sshkey_username_domain_dashes():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= '
+ +'fakeuser@ridiculously-long.example.com')
+ got = _.username
+ eq(got, 'fakeuser@ridiculously-long.example.com')
+
+def test_sshkey_username_underscore():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake_user@example.com')
+ got = _.username
+ eq(got, 'fake_user@example.com')
+
+def test_sshkey_username_dot():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake.u.ser@example.com')
+ got = _.username
+ eq(got, 'fake.u.ser@example.com')
+
+def test_sshkey_username_dash():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fake.u-ser@example.com')
+ got = _.username
+ eq(got, 'fake.u-ser@example.com')
+
+def test_sshkey_username_no_at():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser')
+ got = _.username
+ eq(got, 'fakeuser')
+
+def test_sshkey_username_caps():
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa '
+ +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Fake.User@Domain.Example.Com')
+ got = _.username
+ eq(got, 'Fake.User@Domain.Example.Com')
+
+@raises(sshkey.InsecureSSHKeyUsername)
+def test_sshkey_username_bad():
+ # The '#' and characters after it are part of an actual comment in the file
+ # and are ignored.
+ try:
+ _ = sshkey.get_ssh_pubkey(
+ 'ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
+ +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= ER3%#@e%')
+ got = _.username
+ except sshkey.InsecureSSHKeyUsername, e:
+ eq(str(e), "Username contains not allowed characters: 'ER3%'")
+ raise e
diff --git a/gitosis/test/test_util.py b/gitosis/test/test_util.py
new file mode 100644
index 0000000..c53f76c
--- /dev/null
+++ b/gitosis/test/test_util.py
@@ -0,0 +1,65 @@
+from nose.tools import eq_ as eq, assert_raises
+
+import os
+import errno
+
+from ConfigParser import RawConfigParser
+
+from gitosis import util
+
+# Nose interferes with this test case, and 'except' block inside _sysfunc does
+# not recieve the error.
+#def test_sysfunc_raise_ignore():
+# def foo():
+# os.mkdir('/does/not/exist/anywhere')
+# util._sysfunc(foo, [errno.EEXIST])
+
+def test_sysfunc_raise_catch():
+ def foo():
+ raise OSError(errno.EEXIST)
+ assert_raises(OSError, util._sysfunc, foo, [errno.ENOENT])
+
+def test_getRepositoryDir_cfg_missing():
+ cfg = RawConfigParser()
+ d = util.getRepositoryDir(cfg)
+ eq(d, os.path.expanduser('~/repositories'))
+
+def test_getRepositoryDir_cfg_empty():
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'repositories', '')
+ d = util.getRepositoryDir(cfg)
+ eq(d, os.path.expanduser('~/'))
+
+def test_getRepositoryDir_cfg_relative():
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'repositories', 'foobar')
+ d = util.getRepositoryDir(cfg)
+ eq(d, os.path.expanduser('~/foobar'))
+
+def test_getRepositoryDir_cfg_absolute():
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'repositories', '/var/gitroot')
+ d = util.getRepositoryDir(cfg)
+ eq(d, '/var/gitroot')
+
+def test_getGeneratedFilesDir_cfg_missing():
+ cfg = RawConfigParser()
+ d = util.getGeneratedFilesDir(cfg)
+ eq(d, os.path.expanduser('~/gitosis'))
+
+def test_getGeneratedFilesDir_cfg_empty():
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'generate-files-in', '')
+ d = util.getGeneratedFilesDir(cfg)
+ eq(d, '')
+
+def test_getGeneratedFilesDir_cfg_set():
+ cfg = RawConfigParser()
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'generate-files-in', 'foobar')
+ d = util.getGeneratedFilesDir(cfg)
+ eq(d, 'foobar')
diff --git a/gitosis/test/test_zzz_app.py b/gitosis/test/test_zzz_app.py
new file mode 100644
index 0000000..27ba697
--- /dev/null
+++ b/gitosis/test/test_zzz_app.py
@@ -0,0 +1,108 @@
+from nose.tools import eq_ as eq, assert_raises
+
+from gitosis import app
+from gitosis import init
+from gitosis import run_hook
+from gitosis import serve
+import sys
+import os
+
+class TestMain(app.App):
+ def handle_args(self, parser, cfg, options, args):
+ """Parse the input for this program."""
+ pass
+
+def test_app_setup_basic_logging():
+ main = TestMain()
+ main.setup_basic_logging()
+
+def test_app_create_parser():
+ main = TestMain()
+ parser = main.create_parser()
+
+def test_app_create_parser_parse_none():
+ main = TestMain()
+ parser = main.create_parser()
+ (options, args) = parser.parse_args([])
+ print '%r' % (options, )
+ eq(args, [])
+ eq(options, {'config': os.path.expanduser('~/.gitosis.conf')})
+
+def test_app_create_parser_parse_config():
+ main = TestMain()
+ parser = main.create_parser()
+ (options, args) = parser.parse_args(['--config=/dev/null'])
+ eq(args, [])
+ eq(options, {'config': '/dev/null'})
+
+def test_app_create_config():
+ main = TestMain()
+ cfg = main.create_config(None)
+
+def test_app_read_config_empty():
+ main = TestMain()
+ cfg = main.create_config(None)
+ parser = main.create_parser()
+ (options, args) = parser.parse_args(['--config=/dev/null'])
+ main.read_config(options, cfg)
+
+def test_app_read_config_does_not_exist():
+ main = TestMain()
+ cfg = main.create_config(None)
+ parser = main.create_parser()
+ (options, args) = parser.parse_args(['--config=/does/not/exist'])
+ assert_raises(app.ConfigFileDoesNotExistError, main.read_config, options, cfg)
+
+
+def test_app_setup_logging_default():
+ main = TestMain()
+ cfg = main.create_config(None)
+ main.setup_logging(cfg)
+
+def test_app_setup_logging_goodname():
+ main = TestMain()
+ cfg = main.create_config(None)
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'loglevel', 'WARN')
+ main.setup_logging(cfg)
+
+def test_app_setup_logging_badname():
+ main = TestMain()
+ cfg = main.create_config(None)
+ cfg.add_section('gitosis')
+ cfg.set('gitosis', 'loglevel', 'FOOBAR')
+ main.setup_logging(cfg)
+
+def test_appinit_create_parser():
+ main = init.Main()
+ parser = main.create_parser()
+
+def test_appinit_read_config():
+ main = init.Main()
+ cfg = main.create_config(None)
+ parser = main.create_parser()
+ (options, args) = parser.parse_args(['--config=/does/not/exist'])
+ main.read_config(options, cfg)
+
+def test_apprunhook_create_parser():
+ main = run_hook.Main()
+ parser = main.create_parser()
+
+def test_appserve_create_parser():
+ main = serve.Main()
+ parser = main.create_parser()
+
+# We must call this test last
+def test_zzz_app_main():
+ class Main(TestMain):
+ def read_config(self, options, cfg):
+ """Ignore errors that result from non-existent config file."""
+ pass
+ oldargv = sys.argv
+ sys.argv = []
+ main = Main()
+ main.run()
+ #parser = self.create_parser()
+ #(options, args) = parser.parse_args()
+ #cfg = self.create_config(options)
+ sys.argv = oldargv