1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 check "gopkg.in/check.v1"
14 var _ = check.Suite(&GitSuite{})
17 spectatorToken = "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu"
18 activeToken = "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi"
19 anonymousToken = "4kg6k6lzmp9kj4cpkcoxie964cmvjahbt4fod9zru44k4jqdmi"
20 expiredToken = "2ym314ysp27sk7h943q6vtc378srb06se3pq6ghurylyf3pdmx"
23 type GitSuite struct {
27 func (s *GitSuite) TestPathVariants(c *check.C) {
29 for _, repo := range []string{"active/foo.git", "active/foo/.git", "arvados.git", "arvados/.git"} {
30 err := s.RunGit(c, spectatorToken, "fetch", repo, "refs/heads/main")
31 c.Assert(err, check.Equals, nil)
35 func (s *GitSuite) TestReadonly(c *check.C) {
36 err := s.RunGit(c, spectatorToken, "fetch", "active/foo.git", "refs/heads/main")
37 c.Assert(err, check.Equals, nil)
38 err = s.RunGit(c, spectatorToken, "push", "active/foo.git", "main:newbranchfail")
39 c.Assert(err, check.ErrorMatches, `.*HTTP (code = )?403.*`)
40 _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranchfail")
41 c.Assert(err, check.FitsTypeOf, &os.PathError{})
44 func (s *GitSuite) TestReadwrite(c *check.C) {
45 err := s.RunGit(c, activeToken, "fetch", "active/foo.git", "refs/heads/main")
46 c.Assert(err, check.Equals, nil)
47 err = s.RunGit(c, activeToken, "push", "active/foo.git", "main:newbranch")
48 c.Assert(err, check.Equals, nil)
49 _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranch")
50 c.Assert(err, check.Equals, nil)
53 func (s *GitSuite) TestNonexistent(c *check.C) {
54 err := s.RunGit(c, spectatorToken, "fetch", "thisrepodoesnotexist.git", "refs/heads/main")
55 c.Assert(err, check.ErrorMatches, `.* not found.*`)
58 func (s *GitSuite) TestMissingGitdirReadableRepository(c *check.C) {
59 err := s.RunGit(c, activeToken, "fetch", "active/foo2.git", "refs/heads/main")
60 c.Assert(err, check.ErrorMatches, `.* not found.*`)
63 func (s *GitSuite) TestNoPermission(c *check.C) {
64 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
65 err := s.RunGit(c, anonymousToken, "fetch", repo, "refs/heads/main")
66 c.Assert(err, check.ErrorMatches, `.* not found.*`)
70 func (s *GitSuite) TestExpiredToken(c *check.C) {
71 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
72 err := s.RunGit(c, expiredToken, "fetch", repo, "refs/heads/main")
73 c.Assert(err, check.ErrorMatches, `.* (500 while accessing|requested URL returned error: 500).*`)
77 func (s *GitSuite) TestInvalidToken(c *check.C) {
78 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
79 err := s.RunGit(c, "s3cr3tp@ssw0rd", "fetch", repo, "refs/heads/main")
80 c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
84 func (s *GitSuite) TestShortToken(c *check.C) {
85 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
86 err := s.RunGit(c, "s3cr3t", "fetch", repo, "refs/heads/main")
87 c.Assert(err, check.ErrorMatches, `.* (500 while accessing|requested URL returned error: 500).*`)
91 func (s *GitSuite) TestShortTokenBadReq(c *check.C) {
92 for _, repo := range []string{"bogus"} {
93 err := s.RunGit(c, "s3cr3t", "fetch", repo, "refs/heads/main")
94 c.Assert(err, check.ErrorMatches, `.*not found.*`)
98 // Make a bare arvados repo at {tmpRepoRoot}/arvados.git
99 func (s *GitSuite) makeArvadosRepo(c *check.C) {
100 msg, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").CombinedOutput()
102 c.Assert(err, check.Equals, nil)
103 msg, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git", "fetch", "../../.git", "HEAD:main").CombinedOutput()
105 c.Assert(err, check.Equals, nil)