Ejemplo n.º 1
0
def test_push_inits_default_templates():
    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')
    os.umask(0022)
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    hook_path = os.path.join(tmp, 'repositories', 'foo.git', 'hooks', 'post-receive')
    check_mode(
        hook_path,
        0755,
        is_file=True,
        )
    got = readFile(hook_path)
    eq(got, '#!/bin/sh\nset -e\ngit-update-server-info\ngitosis-run-hook update-mirrors')
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def test_fast_import_parent():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path=path)
    repository.fast_import(
        git_dir=path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    repository.fast_import(
        git_dir=path,
        commit_msg='another',
        committer='Sam One Else <*****@*****.**>',
        parent='refs/heads/master^0',
        files=[
            ('quux', 'thud\n'),
            ],
        )
    export = os.path.join(tmp, 'export')
    repository.export(
        git_dir=path,
        path=export,
        )
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'quux']))
Ejemplo n.º 8
0
def test_has_initial_commit_fail_notAGitDir():
    tmp = maketemp()
    e = assert_raises(
        repository.GitRevParseError,
        repository.has_initial_commit,
        git_dir=tmp)
    eq(str(e), 'rev-parse failed: exit status 128')
Ejemplo n.º 9
0
    def test_simple(self):
        tmp = maketemp()

        authorized_keys = path.join(tmp, 'authorized_keys')

        with open(authorized_keys, 'w') as f:
            f.write('''\
# foo
bar
### autogenerated by gitosis, DO NOT EDIT
command="PATH=/opt/local/bin /foo/bar/baz/gitosis-serve wsmith",no-port-forwarding,\
no-X11-forwarding,no-agent-forwarding,no-pty %s
baz''' % KEY_2)

        keydir = path.join(tmp, 'one')

        mkdir(keydir)

        # okay so we write the key into a file in keyir
        with open(path.join(keydir, 'jdoe.pub'), 'w') as f:
            f.write(KEY_1 + '\n')

        ssh.writeAuthorizedKeys(authorized_keys, keydir)

        got = readFile(authorized_keys)

        eq(got, '''\
# foo
bar
baz
### autogenerated by gitosis, DO NOT EDIT
command="PATH=/opt/local/bin gitosis-serve jdoe",no-port-forwarding,\
no-X11-forwarding,no-agent-forwarding,no-pty %s''' % KEY_1)
Ejemplo n.º 10
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"))
Ejemplo n.º 11
0
def test_dcontrol1():
    tmp = util.maketemp()
    projname = "foo"

    git_dir = os.path.join(tmp, projname + ".git")
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer="John Doe 2 <*****@*****.**>",
        commit_msg="""\
Allow jdoe write access to foo
""",
        files=[("foo", "content"), ("bar/quux", "another")],
    )

    child = subprocess.Popen(
        args=["git", "--git-dir=%s" % git_dir, "cat-file", "commit", "HEAD"],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
    )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError("git exit status %d" % returncode)
    eq(got[0].split(None, 1)[0], "tree")
    eq(got[1].rsplit(None, 2)[0], "author John Doe 2 <*****@*****.**>")
    eq(got[2].rsplit(None, 2)[0], "committer John Doe 2 <*****@*****.**>")
    eq(got[3], "")
    eq(got[4], "Allow jdoe write access to foo")
    eq(got[5:], [])
Ejemplo n.º 12
0
def test_push_inits_sets_export_ok():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    generated = 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')
    cfg.add_section('rsp')
    cfg.set('rsp', 'haveAccessURL', 'example.org')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    eq(os.listdir(repositories), ['foo.git'])
    export = path.join(repositories, 'foo.git', 'git-daemon-export-ok')
    assert path.exists(export)
Ejemplo n.º 13
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 = path.join(tmp, 'repositories')
    os.mkdir(repositories)
    cfg.set('gitosis', 'repositories', repositories)
    generated = 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('rsp')
    cfg.set('rsp', 'haveAccessURL', 'example.org')
    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 path.isfile(path.join(repositories, 'foo.git', 'HEAD'))
Ejemplo n.º 14
0
def test_push_inits_subdir_parent_exists():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    repositories = path.join(tmp, 'repositories')
    os.mkdir(repositories)
    foo = path.join(repositories, 'foo')
    # silly mode on purpose; not to be touched
    os.mkdir(foo, 0751)
    cfg.set('gitosis', 'repositories', repositories)
    generated = 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')
    cfg.add_section('rsp')
    cfg.set('rsp', 'haveAccessURL', 'example.org')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo/bar.git'",
        )
    eq(os.listdir(repositories), ['foo'])
    util.check_mode(foo, 0751, is_dir=True)
    eq(os.listdir(foo), ['bar.git'])
    assert path.isfile(path.join(repositories, 'foo', 'bar.git', 'HEAD'))
Ejemplo n.º 15
0
def test_push_inits_if_needed():
    # a push to a non-existent repository (but where config authorizes
    # you to do that) will create the repository on the fly
    tmp = util.maketemp()

    repositories = path.join(tmp, 'repositories')
    os.mkdir(repositories)

    generated = path.join(tmp, 'generated')
    os.mkdir(generated)

    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis', 'repositories', repositories)
    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('rsp')
    cfg.set('rsp', 'haveAccessURL', 'example.org')

    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )

    eq(os.listdir(repositories), ['foo.git'])
    assert path.isfile(path.join(repositories, 'foo.git', 'HEAD'))
Ejemplo n.º 16
0
def test_init_templates():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    templatedir = os.path.join(
        os.path.dirname(__file__),
        'mocktemplates',
        )
    repository.init(path, template=templatedir)
    repository.init(path)
    got = readFile(os.path.join(path, 'no-confusion'))
    eq(got, 'i should show up\n')
    check_mode(
        os.path.join(path, 'hooks', 'post-update'),
        0755,
        is_file=True,
        )
    got = readFile(os.path.join(path, 'hooks', 'post-update'))
    eq(got, '#!/bin/sh\n# i can override standard templates\n')
    # standard templates are there, too
    assert (
        # compatibility with git <1.6.0
        os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase'))
        # for git >=1.6.0
        or os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase.sample'))
        )
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
def test_push_inits_sets_description():
    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', 'description', 'foodesc')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo'",
        )
    eq(os.listdir(repositories), ['foo.git'])
    path = os.path.join(repositories, 'foo.git', 'description')
    assert os.path.exists(path)
    got = util.readFile(path)
    eq(got, 'foodesc\n')
Ejemplo n.º 19
0
def test_init_exist_git():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path)
    repository.init(path)
    check_mode(path, 0750, is_dir=True)
    check_bare(path)
Ejemplo n.º 20
0
def test_typo_writeable():
    tmp = util.maketemp()
    repository.init(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')
    cfg.add_section('rsp')
    cfg.set('rsp', 'haveAccessURL', 'example.org')
    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\", shou"
        +"ld be \"writable\"\n",
        )
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
def test_init_default_templates():
    tmp = maketemp()
    path = os.path.join(tmp, "repo.git")
    repository.init(path)
    hook_path = os.path.join(path, "hooks", "post-receive")
    check_mode(hook_path, 0755, is_file=True)
    got = readFile(hook_path)
    eq(got, "#!/bin/sh\nset -e\ngit-update-server-info\ngitosis-run-hook update-mirrors")
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
def test_init_exist_dir():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    mkdir(path, 0710)
    check_mode(path, 0710, is_dir=True)
    repository.init(path)
    # my weird access mode is preserved
    check_mode(path, 0710, is_dir=True)
    check_bare(path)
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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([]))
Ejemplo n.º 27
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')
    eq(gitweb.generate_project_list(cfg), ['foo.git'])
Ejemplo n.º 28
0
def test_git_daemon_export_ok_repo_missing_parent():
    # configured but not created yet; before first push
    tmp = maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("repo foo/bar")
    cfg.set("repo foo/bar", "daemon", "yes")
    gitdaemon.set_export_ok(config=cfg)
    assert not os.path.exists(os.path.join(tmp, "foo"))
Ejemplo n.º 29
0
    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)]))
Ejemplo n.º 30
0
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, '')
Ejemplo n.º 31
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')
Ejemplo n.º 32
0
def test_description_repo_missing():
    # configured but not created yet; before first push
    tmp = maketemp()
    path = os.path.join(tmp, 'foo.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'))
    assert not os.path.exists(os.path.join(tmp, 'foo.git'))
Ejemplo n.º 33
0
def test_git_daemon_export_ok_allowed_already():
    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')
    cfg.set('repo foo', 'daemon', 'yes')
    gitdaemon.set_export_ok(config=cfg)
    eq(exported(path), True)
Ejemplo n.º 34
0
def test_git_daemon_export_ok_subdirs():
    tmp = maketemp()
    foo = os.path.join(tmp, 'foo')
    os.mkdir(foo)
    path = os.path.join(foo, 'bar.git')
    os.mkdir(path)
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis', 'repositories', tmp)
    cfg.add_section('repo foo/bar')
    cfg.set('repo foo/bar', 'daemon', 'yes')
    gitdaemon.set_export_ok(config=cfg)
    eq(exported(path), True)
Ejemplo n.º 35
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)
Ejemplo n.º 36
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
''')
Ejemplo n.º 37
0
    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),
        ]))
Ejemplo n.º 38
0
def test_export_simple():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    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')
    repository.export(git_dir=git_dir, path=export)
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'bar']))
    eq(readFile(os.path.join(export, 'foo')), 'content')
    eq(os.listdir(os.path.join(export, 'bar')), ['quux'])
    eq(readFile(os.path.join(export, 'bar', 'quux')), 'another')
    child = subprocess.Popen(
        args=[
            'git',
            '--git-dir=%s' % git_dir,
            'cat-file',
            'commit',
            'HEAD',
            ],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
        )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError('git exit status %d' % returncode)
    eq(got[0].split(None, 1)[0], 'tree')
    eq(got[1].rsplit(None, 2)[0],
       'author John Doe <*****@*****.**>')
    eq(got[2].rsplit(None, 2)[0],
       'committer John Doe <*****@*****.**>')
    eq(got[3], '')
    eq(got[4], 'Reverse the polarity of the neutron flow.')
    eq(got[5], '')
    eq(got[6], 'Frobitz the quux and eschew obfuscation.')
    eq(got[7:], [])
Ejemplo n.º 39
0
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),
    )
Ejemplo n.º 40
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
''')
Ejemplo n.º 41
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)
Ejemplo n.º 42
0
def test_simple_read_archive():
    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-archive 'foo'",
    )
    eq(got, "git upload-archive '%s/foo.git'" % tmp)
Ejemplo n.º 43
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')
Ejemplo n.º 44
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 = '******'
    init.init_admin_repository(
        git_dir=admin_repository,
        pubkey=pubkey,
        user=user,
    )
    eq(os.listdir(tmp), ['admin.git'])
    hook = os.path.join(
        tmp,
        'admin.git',
        'hooks',
        'post-update',
    )
    util.check_mode(hook, 0o755, 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'))
    got = got.splitlines()[0]
    eq(got, '[gitosis]')
    cfg = RawConfigParser()
    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'),
       ]))
Ejemplo n.º 45
0
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)
Ejemplo n.º 46
0
def test_init_templates():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    templatedir = os.path.join(
        os.path.dirname(__file__),
        'mocktemplates',
        )
    os.umask(0022)
    repository.init(path, template=templatedir)
    repository.init(path)
    got = readFile(os.path.join(path, 'no-confusion'))
    eq(got, 'i should show up\n')
    check_mode(
        os.path.join(path, 'hooks', 'post-update'),
        0755,
        is_file=True,
        )
    got = readFile(os.path.join(path, 'hooks', 'post-update'))
    eq(got, '#!/bin/sh\n# i can override standard templates\n')
Ejemplo n.º 47
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)
Ejemplo n.º 48
0
def test_mirror():
    tmp = maketemp()
    main_path = os.path.join(tmp, 'main.git')
    mirror_path = os.path.join(tmp, 'mirror.git')
    repository.init(path=main_path, template=False)
    repository.init(path=mirror_path, template=False)
    repository.fast_import(
        git_dir=main_path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    repository.mirror(main_path, mirror_path)
    export = os.path.join(tmp, 'export')
    repository.export(
        git_dir=mirror_path,
        path=export,
        )
    eq(os.listdir(export),
       ['foo'])
Ejemplo n.º 49
0
def test_push_inits_if_needed_haveExtension():
    # a push to a non-existent repository (but where config authorizes
    # you to do that) will create the repository on the fly
    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')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo.git'",
    )
    eq(os.listdir(repositories), ['foo.git'])
    assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD'))
Ejemplo n.º 50
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')), [])
Ejemplo n.º 51
0
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)
Ejemplo n.º 52
0
def test_push_inits_subdir_parent_missing():
    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/bar')
    serve.serve(
        cfg=cfg,
        user='******',
        command="git-receive-pack 'foo/bar.git'",
    )
    eq(os.listdir(repositories), ['foo'])
    foo = os.path.join(repositories, 'foo')
    util.check_mode(foo, 0o750, is_dir=True)
    eq(os.listdir(foo), ['bar.git'])
    assert os.path.isfile(os.path.join(repositories, 'foo', 'bar.git', 'HEAD'))
Ejemplo n.º 53
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)
Ejemplo n.º 54
0
def test_read_inits_if_needed():
    # a clone of a non-existent repository (but where config
    # authorizes you to do that) will create the repository on the fly
    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', 'readonly', 'foo')
    got = serve.serve(
        cfg=cfg,
        user='******',
        command="git-upload-pack 'foo'",
    )
    eq(got, "git-upload-pack '%s/foo.git'" % repositories)
    eq(os.listdir(repositories), ['foo.git'])
    assert os.path.isfile(os.path.join(repositories, 'foo.git', 'HEAD'))
Ejemplo n.º 55
0
def test_init_templates():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    templatedir = os.path.join(
        os.path.dirname(__file__),
        'mocktemplates',
    )
    repository.init(path, template=templatedir)
    repository.init(path)
    got = readFile(os.path.join(path, 'no-confusion'))
    eq(got, 'i should show up\n')
    check_mode(
        os.path.join(path, 'hooks', 'post-update'),
        0755,
        is_file=True,
    )
    got = readFile(os.path.join(path, 'hooks', 'post-update'))
    eq(got, '#!/bin/sh\n# i can override standard templates\n')
    # standard templates are there, too
    assert (
        # compatibility with git <1.6.0
        os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase'))
        # for git >=1.6.0
        or os.path.isfile(os.path.join(path, 'hooks', 'pre-rebase.sample')))
Ejemplo n.º 56
0
def test_read_inits_if_needed_without_init_permission():
    # a clone of a non-existent repository (but where config
    # authorizes you to do that) will create the repository on the fly
    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', 'readonly', 'foo')
    e = assert_raises(
        serve.InitAccessDenied,
        serve.serve,
        cfg=cfg,
        user='******',
        command="git-upload-pack 'foo'",
    )
    eq(str(e), 'Repository write access denied')
    assert isinstance(e, serve.InitAccessDenied)
Ejemplo n.º 57
0
def test_has_initial_commit_fail_notAGitDir():
    tmp = maketemp()
    e = assert_raises(repository.GitRevParseError,
                      repository.has_initial_commit,
                      git_dir=tmp)
    eq(str(e), 'rev-parse failed: exit status 128')
Ejemplo n.º 58
0
def test_has_initial_commit_no():
    tmp = maketemp()
    repository.init(path=tmp)
    got = repository.has_initial_commit(git_dir=tmp)
    eq(got, False)
def test_post_update_simple():
    tmp = maketemp()
    repos = os.path.join(tmp, 'repositories')
    os.mkdir(repos)
    admin_repository = os.path.join(repos, 'gitosis-admin.git')
    pubkey = (
        'ssh-somealgo '
        +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
    user = '******'
    init.init_admin_repository(
        git_dir=admin_repository,
        pubkey=pubkey,
        user=user,
        )
    repository.init(path=os.path.join(repos, 'forweb.git'))
    repository.init(path=os.path.join(repos, 'fordaemon.git'))
    repository.fast_import(
        git_dir=admin_repository,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
stuff
""",
        parent='refs/heads/master^0',
        files=[
            ('gitosis.conf', """\
[gitosis]

[group gitosis-admin]
members = theadmin
writable = gitosis-admin

[repo fordaemon]
daemon = yes

[repo forweb]
gitweb = yes
owner = John Doe
description = blah blah
"""),
            ('keydir/jdoe.pub',
             'ssh-somealgo '
             +'0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= [email protected]'),
            ],
        )
    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,
        )
    got = readFile(os.path.join(repos, 'forweb.git', 'description'))
    eq(got, 'blah blah\n')
    got = os.listdir(generated)
    eq(got, ['projects.list'])
    got = readFile(os.path.join(generated, 'projects.list'))
    eq(
        got,
        """\
forweb.git John+Doe
""",
        )
    got = os.listdir(os.path.join(repos, 'fordaemon.git'))
    assert 'git-daemon-export-ok' in got, \
        "git-daemon-export-ok not created: %r" % got
    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= [email protected]\n' in got, \
        "SSH authorized_keys line for jdoe not found: %r" % got
Ejemplo n.º 60
0
 def test_empty(self):
     tmp = maketemp()
     empty = os.path.join(tmp, 'empty')
     mkdir(empty)
     gen = ssh.readKeys(keydir=empty)
     assert_raises(StopIteration, gen.__next__)