Example #1
0
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)
Example #2
0
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(),
        """\
""",
    )
Example #3
0
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")
Example #4
0
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
""",
    )
Example #5
0
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)
Example #6
0
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")
Example #7
0
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")
Example #8
0
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)
Example #9
0
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"))
Example #10
0
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)
Example #11
0
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")
Example #12
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")
Example #13
0
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
Example #14
0
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")
Example #15
0
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
Example #16
0
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)
Example #17
0
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)
Example #18
0
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")
Example #19
0
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")
Example #20
0
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
""",
    )
Example #21
0
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
""",
    )
Example #22
0
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)
Example #23
0
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'),
        ]))
Example #24
0
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')), [])
Example #25
0
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'))
Example #26
0
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
""",
    )
Example #27
0
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
""",
    )
Example #28
0
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')
Example #29
0
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)
Example #30
0
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"
""")