コード例 #1
0
ファイル: test_group.py プロジェクト: superbobry/gitosis
def test_no_notListed():
    cfg = RawConfigParser()
    cfg.add_section('group hackers')
    cfg.set('group hackers', 'members', 'wsmith')
    gen = group.getMembership(config=cfg, user='******')
    eq(gen.next(), 'all')
    assert_raises(StopIteration, gen.next)
コード例 #2
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_repoDenied():
    cfg = RawConfigParser()
    cfg.add_section("repo foo/bar")
    got = StringIO()
    gitweb.generate_project_list_fp(config=cfg, fp=got)
    eq(
        got.getvalue(),
        """\
""",
    )
コード例 #3
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_owner_full_access():
    cfg = GitosisRawConfigParser()
    cfg.add_section("repo foo/bar")
    cfg.set("repo foo/bar", "owner", "jdoe")

    assert access.allowed(cfg,
        user="******", mode="writable", path="foo/bar") == ("repositories", "foo/bar")

    assert access.allowed(cfg,
        user="******", mode="readable", path="foo/bar") == ("repositories", "foo/bar")
コード例 #4
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_noOwner():
    cfg = RawConfigParser()
    cfg.add_section("repo foo/bar")
    cfg.set("repo foo/bar", "gitweb", "yes")
    got = StringIO()
    gitweb.generate_project_list_fp(config=cfg, fp=got)
    eq(
        got.getvalue(),
        """\
foo%2Fbar
""",
    )
コード例 #5
0
ファイル: test_group.py プロジェクト: superbobry/gitosis
def test_no_recurse_loop():
    cfg = RawConfigParser()
    cfg.add_section('group hackers')
    cfg.set('group hackers', 'members', '@smackers')
    cfg.add_section('group smackers')
    cfg.set('group smackers', 'members', '@hackers')
    gen = group.getMembership(config=cfg, user='******')
    eq(gen.next(), 'all')
    assert_raises(StopIteration, gen.next)
コード例 #6
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_base_local():
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "repositories", "some/relative/path")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "map writable foo/bar", "baz/quux/thud")

    assert access.allowed(cfg,
        user="******", mode="writable", path="foo/bar") == ("some/relative/path", "baz/quux/thud")
コード例 #7
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_base_global_unset():
    cfg = GitosisRawConfigParser()
    cfg.add_section("gitosis")
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "readonly", "foo xyzzy bar")

    assert access.allowed(cfg,
        user="******", mode="readonly", path="xyzzy") == ("repositories", "xyzzy")
コード例 #8
0
ファイル: test_group.py プロジェクト: superbobry/gitosis
def test_yes_recurse_one_ordering():
    cfg = RawConfigParser()
    cfg.add_section('group smackers')
    cfg.set('group smackers', 'members', 'danny jdoe')
    cfg.add_section('group hackers')
    cfg.set('group hackers', 'members', 'wsmith @smackers')
    gen = group.getMembership(config=cfg, user='******')
    eq(gen.next(), 'smackers')
    eq(gen.next(), 'hackers')
    eq(gen.next(), 'all')
    assert_raises(StopIteration, gen.next)
コード例 #9
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_description_repo_missing_parent():
    # configured but not created yet; before first push
    tmp = maketemp()
    path = os.path.join(tmp, "foo/bar.git")
    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)
    assert not os.path.exists(os.path.join(tmp, "foo"))
コード例 #10
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_bad_forbiddenCommand_write_readAccess_space():
    cfg = RawConfigParser()
    cfg.add_section('group foo')
    cfg.set('group foo', 'members', 'jdoe')
    cfg.set('group foo', 'readonly', 'foo')
    e = assert_raises(
        serve.WriteAccessDenied,
        serve.serve,
        cfg=cfg,
        user='******',
        command="git receive-pack 'foo'",
        )
    eq(str(e), 'Repository write access denied')
    assert isinstance(e, serve.AccessDenied)
    assert isinstance(e, serve.ServingError)
コード例 #11
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_description_none():
    tmp = maketemp()
    path = os.path.join(tmp, "foo.git")
    mkdir(path)
    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")
コード例 #12
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")
コード例 #13
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_write_no_simple_with_readonly():
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "readonly", "foo/bar")

    assert access.allowed(cfg,
        user="******", mode="writable", path="foo/bar") is None
コード例 #14
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_write_yes_map():
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "map writable foo/bar", "quux/thud")

    assert access.allowed(config=cfg,
        user="******", mode="writable", path="foo/bar") == ("repositories", "quux/thud")
コード例 #15
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_read_yes_map_with_writable():
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "map writable foo/bar", "quux/thud")

    assert access.allowed(cfg,
        user="******", mode="readonly", path="foo/bar") is None
コード例 #16
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_simple_write_space():
    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', 'writable', 'foo')
    got = serve.serve(
        cfg=cfg,
        user='******',
        command="git receive-pack 'foo'",
        )
    eq(got, "git receive-pack '%s/foo.git'" % tmp)
コード例 #17
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_simple_read_leading_slash():
    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', 'readonly', 'foo')
    got = serve.serve(
        cfg=cfg,
        user='******',
        command="git-upload-pack '/foo'",
        )
    eq(got, "git-upload-pack '%s/foo.git'" % tmp)
コード例 #18
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_read_yes_all():
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "@all")
    cfg.set("group fooers", "readonly", "foo/bar")

    assert access.allowed(cfg,
        user="******", mode="readonly", path="foo/bar") == ("repositories", "foo/bar")
コード例 #19
0
ファイル: test_access.py プロジェクト: superbobry/gitosis
def test_dotgit():
    # a .git extension is always allowed to be added
    cfg = GitosisRawConfigParser()
    cfg.add_section("group fooers")
    cfg.set("group fooers", "members", "jdoe")
    cfg.set("group fooers", "writable", "foo/bar")

    assert access.allowed(cfg,
        user="******", mode="writable", path="foo/bar.git") == ("repositories", "foo/bar")
コード例 #20
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_reallyEndsWithGit():
    tmp = maketemp()
    path = os.path.join(tmp, "foo.git")
    mkdir(path)
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("repo foo")
    cfg.set("repo foo", "gitweb", "yes")
    got = StringIO()
    gitweb.generate_project_list_fp(config=cfg, fp=got)
    eq(
        got.getvalue(),
        """\
foo.git
""",
    )
コード例 #21
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_path():
    tmp = maketemp()
    path = os.path.join(tmp, "foo.git")
    mkdir(path)
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("repo foo")
    cfg.set("repo foo", "gitweb", "yes")
    projects_list = os.path.join(tmp, "projects.list")
    gitweb.generate_project_list(config=cfg, path=projects_list)
    got = readFile(projects_list)
    eq(
        got,
        """\
foo.git
""",
    )
コード例 #22
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_absolute():
    # as the only convenient way to use non-standard SSH ports with
    # git is via the ssh://user@host:port/path syntax, and that syntax
    # forces absolute urls, just force convert absolute paths to
    # relative paths; you'll never really want absolute paths via
    # gitosis, anyway.
    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', 'readonly', 'foo')
    got = serve.serve(
        cfg=cfg,
        user='******',
        command="git-upload-pack '/foo'",
        )
    eq(got, "git-upload-pack '%s/foo.git'" % tmp)
コード例 #23
0
ファイル: test_init.py プロジェクト: superbobry/gitosis
def test_init_admin_repository():
    tmp = maketemp()
    admin_repository = os.path.join(tmp, 'admin.git')
    pubkey = (
        'ssh-somealgo '
        +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
    user = '******'
    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(
        tmp,
        'admin.git',
        'hooks',
        'post-update',
        )
    util.check_mode(hook, 0755, is_file=True)
    got = util.readFile(hook).splitlines()
    assert 'gitosis-run-hook post-update' in got
    export_dir = os.path.join(tmp, 'export')
    repository.export(git_dir=admin_repository,
                      path=export_dir)
    eq(sorted(os.listdir(export_dir)),
       sorted(['gitosis.conf', 'keydir']))
    eq(os.listdir(os.path.join(export_dir, 'keydir')),
       ['jdoe.pub'])
    got = util.readFile(
        os.path.join(export_dir, 'keydir', 'jdoe.pub'))
    eq(got, pubkey)
    # 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.read(os.path.join(export_dir, 'gitosis.conf'))
    eq(sorted(cfg.sections()),
       sorted([
        'gitosis',
        'group gitosis-admin',
        ]))
    eq(cfg.items('gitosis'), [])
    eq(sorted(cfg.items('group gitosis-admin')),
       sorted([
        ('writable', 'gitosis-admin'),
        ('members', 'jdoe'),
        ]))
コード例 #24
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_push_inits_if_needed_existsWithExtension():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = os.path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    cfg.add_section('group foo')
    cfg.set('group foo', 'members', 'jdoe')
    cfg.set('group foo', 'writable', 'foo')
    os.mkdir(os.path.join(repositories, 'foo.git'))
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    eq(os.listdir(repositories), ['foo.git'])
    # it should *not* have HEAD here as we just mkdirred it and didn't
    # create it properly, and the mock repo didn't have anything in
    # it.. having HEAD implies serve ran git init, which is supposed
    # to be unnecessary here
    eq(os.listdir(os.path.join(repositories, 'foo.git')), [])
コード例 #25
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_push_inits_no_stdout_spam():
    # git init has a tendency to spew to stdout, and that confuses
    # e.g. a git push
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = os.path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    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')
    old_stdout = os.dup(1)
    try:
        new_stdout = os.tmpfile()
        os.dup2(new_stdout.fileno(), 1)
        serve.serve(
            cfg=cfg,
            user='******',
            command="git-receive-pack 'foo'",
            )
    finally:
        os.dup2(old_stdout, 1)
        os.close(old_stdout)
    new_stdout.seek(0)
    got = new_stdout.read()
    new_stdout.close()
    eq(got, '')
    eq(os.listdir(repositories), ['foo.git'])
    assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD'))
コード例 #26
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_multiple_globalGitwebYes():
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "gitweb", "yes")
    cfg.add_section("repo foo/bar")
    cfg.set("repo foo/bar", "owner", "John Doe")
    cfg.add_section("repo quux")
    # same as default, no effect
    cfg.set("repo quux", "gitweb", "yes")
    cfg.add_section("repo thud")
    # this is still hidden
    cfg.set("repo thud", "gitweb", "no")
    got = StringIO()
    gitweb.generate_project_list_fp(config=cfg, fp=got)
    eq(
        got.getvalue(),
        """\
foo%2Fbar John+Doe
quux
""",
    )
コード例 #27
0
ファイル: test_gitweb.py プロジェクト: superbobry/gitosis
def test_projectsList_multiple():
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.add_section("repo foo/bar")
    cfg.set("repo foo/bar", "owner", "John Doe")
    cfg.set("repo foo/bar", "gitweb", "yes")
    cfg.add_section("repo quux")
    cfg.set("repo quux", "gitweb", "yes")
    got = StringIO()
    gitweb.generate_project_list_fp(config=cfg, fp=got)
    eq(
        got.getvalue(),
        """\
foo%2Fbar John+Doe
quux
""",
    )
コード例 #28
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_push_inits_updates_projects_list():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = os.path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    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')
    cfg.add_section('repo foo')
    cfg.set('repo foo', 'gitweb', 'yes')
    os.mkdir(os.path.join(repositories, 'gitosis-admin.git'))
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    eq(
        sorted(os.listdir(repositories)),
        sorted(['foo.git', 'gitosis-admin.git']),
        )
    path = os.path.join(generated, 'projects.list')
    assert os.path.exists(path)
    got = util.readFile(path)
    eq(got, 'foo.git\n')
コード例 #29
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
def test_push_inits_sets_export_ok():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = os.path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    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')
    cfg.add_section('repo foo')
    cfg.set('repo foo', 'daemon', 'yes')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    eq(os.listdir(repositories), ['foo.git'])
    path = os.path.join(repositories, 'foo.git', 'git-daemon-export-ok')
    assert os.path.exists(path)
コード例 #30
0
ファイル: test_serve.py プロジェクト: superbobry/gitosis
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='******',
            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", should be "writable"
""")