コード例 #1
0
ファイル: test_gitdaemon.py プロジェクト: handmoney/gitosis
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)
コード例 #2
0
ファイル: test_ssh.py プロジェクト: emillan/gitosis
    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))
コード例 #3
0
ファイル: test_ssh.py プロジェクト: emillan/gitosis
 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__)
コード例 #4
0
ファイル: test_gitdaemon.py プロジェクト: handmoney/gitosis
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)
コード例 #5
0
ファイル: test_ssh.py プロジェクト: elmer/smart-gitosis
 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)
コード例 #6
0
ファイル: test_repository.py プロジェクト: taladar/gitosis
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)
コード例 #7
0
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)
コード例 #8
0
ファイル: test_repository.py プロジェクト: taladar/gitosis
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)
コード例 #9
0
ファイル: test_ssh.py プロジェクト: handmoney/gitosis
 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)
コード例 #10
0
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)
コード例 #11
0
ファイル: test_ssh.py プロジェクト: emillan/gitosis
    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__)
コード例 #12
0
ファイル: test_ssh.py プロジェクト: elmer/smart-gitosis
    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)
コード例 #13
0
ファイル: test_ssh.py プロジェクト: emillan/gitosis
    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([]))
コード例 #14
0
ファイル: test_ssh.py プロジェクト: handmoney/gitosis
    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)
コード例 #15
0
ファイル: test_ssh.py プロジェクト: handmoney/gitosis
    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([]))
コード例 #16
0
ファイル: test_htaccess.py プロジェクト: PhilMiller/gitosis
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, '')
コード例 #17
0
ファイル: test_ssh.py プロジェクト: handmoney/gitosis
    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)]))
コード例 #18
0
ファイル: test_gitdaemon.py プロジェクト: handmoney/gitosis
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)
コード例 #19
0
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)
コード例 #20
0
ファイル: test_ssh.py プロジェクト: superbobry/gitosis
    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)
コード例 #21
0
ファイル: test_htaccess.py プロジェクト: PhilMiller/gitosis
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)
コード例 #22
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
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")
コード例 #23
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
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")
コード例 #24
0
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)
コード例 #25
0
ファイル: test_gitdaemon.py プロジェクト: handmoney/gitosis
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)
コード例 #26
0
ファイル: test_ssh.py プロジェクト: elmer/smart-gitosis
    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),
            ]))
コード例 #27
0
ファイル: test_ssh.py プロジェクト: emillan/gitosis
    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),
        ]))
コード例 #28
0
ファイル: test_repository.py プロジェクト: voretaq7/gitosis
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),
    )
コード例 #29
0
ファイル: test_ssh.py プロジェクト: superbobry/gitosis
    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),
            ]))
コード例 #30
0
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')
コード例 #31
0
ファイル: test_repository.py プロジェクト: taladar/gitosis
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),
    )
コード例 #32
0
ファイル: test_repository.py プロジェクト: Dawnflying/gitosis
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),
        )
コード例 #33
0
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')
コード例 #34
0
ファイル: test_htaccess.py プロジェクト: PhilMiller/gitosis
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
''')
コード例 #35
0
ファイル: test_repository.py プロジェクト: voretaq7/gitosis
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)
コード例 #36
0
ファイル: test_gitweb.py プロジェクト: PhilMiller/gitosis
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')
コード例 #37
0
ファイル: test_repository.py プロジェクト: Dawnflying/gitosis
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)
コード例 #38
0
ファイル: test_gitweb.py プロジェクト: PhilMiller/gitosis
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')
コード例 #39
0
ファイル: test_repository.py プロジェクト: voretaq7/gitosis
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)
コード例 #40
0
ファイル: test_ssh.py プロジェクト: handmoney/gitosis
    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),
        )
コード例 #41
0
ファイル: test_repository.py プロジェクト: Dawnflying/gitosis
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)
コード例 #42
0
ファイル: test_ssh.py プロジェクト: superbobry/gitosis
    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))