7 check "gopkg.in/check.v1"
10 var _ = check.Suite(&GitSuite{})
13 spectatorToken = "zw2f4gwx8hw8cjre7yp6v1zylhrhn3m5gvjq73rtpwhmknrybu"
14 activeToken = "3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi"
15 anonymousToken = "4kg6k6lzmp9kj4cpkcoxie964cmvjahbt4fod9zru44k4jqdmi"
16 expiredToken = "2ym314ysp27sk7h943q6vtc378srb06se3pq6ghurylyf3pdmx"
19 type GitSuite struct {
23 func (s *GitSuite) TestPathVariants(c *check.C) {
25 for _, repo := range []string{"active/foo.git", "active/foo/.git", "arvados.git", "arvados/.git"} {
26 err := s.RunGit(c, spectatorToken, "fetch", repo)
27 c.Assert(err, check.Equals, nil)
31 func (s *GitSuite) TestReadonly(c *check.C) {
32 err := s.RunGit(c, spectatorToken, "fetch", "active/foo.git")
33 c.Assert(err, check.Equals, nil)
34 err = s.RunGit(c, spectatorToken, "push", "active/foo.git", "master:newbranchfail")
35 c.Assert(err, check.ErrorMatches, `.*HTTP code = 403.*`)
36 _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranchfail")
37 c.Assert(err, check.FitsTypeOf, &os.PathError{})
40 func (s *GitSuite) TestReadwrite(c *check.C) {
41 err := s.RunGit(c, activeToken, "fetch", "active/foo.git")
42 c.Assert(err, check.Equals, nil)
43 err = s.RunGit(c, activeToken, "push", "active/foo.git", "master:newbranch")
44 c.Assert(err, check.Equals, nil)
45 _, err = os.Stat(s.tmpRepoRoot + "/zzzzz-s0uqq-382brsig8rp3666.git/refs/heads/newbranch")
46 c.Assert(err, check.Equals, nil)
49 func (s *GitSuite) TestNonexistent(c *check.C) {
50 err := s.RunGit(c, spectatorToken, "fetch", "thisrepodoesnotexist.git")
51 c.Assert(err, check.ErrorMatches, `.* not found.*`)
54 func (s *GitSuite) TestMissingGitdirReadableRepository(c *check.C) {
55 err := s.RunGit(c, activeToken, "fetch", "active/foo2.git")
56 c.Assert(err, check.ErrorMatches, `.* not found.*`)
59 func (s *GitSuite) TestNoPermission(c *check.C) {
60 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
61 err := s.RunGit(c, anonymousToken, "fetch", repo)
62 c.Assert(err, check.ErrorMatches, `.* not found.*`)
66 func (s *GitSuite) TestExpiredToken(c *check.C) {
67 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
68 err := s.RunGit(c, expiredToken, "fetch", repo)
69 c.Assert(err, check.ErrorMatches, `.* (500 while accessing|requested URL returned error: 500).*`)
73 func (s *GitSuite) TestInvalidToken(c *check.C) {
74 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
75 err := s.RunGit(c, "s3cr3tp@ssw0rd", "fetch", repo)
76 c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
80 func (s *GitSuite) TestShortToken(c *check.C) {
81 for _, repo := range []string{"active/foo.git", "active/foo/.git"} {
82 err := s.RunGit(c, "s3cr3t", "fetch", repo)
83 c.Assert(err, check.ErrorMatches, `.* (500 while accessing|requested URL returned error: 500).*`)
87 func (s *GitSuite) TestShortTokenBadReq(c *check.C) {
88 for _, repo := range []string{"bogus"} {
89 err := s.RunGit(c, "s3cr3t", "fetch", repo)
90 c.Assert(err, check.ErrorMatches, `.* requested URL returned error.*`)
94 // Make a bare arvados repo at {tmpRepoRoot}/arvados.git
95 func (s *GitSuite) makeArvadosRepo(c *check.C) {
96 msg, err := exec.Command("git", "init", "--bare", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git").CombinedOutput()
98 c.Assert(err, check.Equals, nil)
99 msg, err = exec.Command("git", "--git-dir", s.tmpRepoRoot+"/zzzzz-s0uqq-arvadosrepo0123.git", "fetch", "../../.git", "HEAD:master").CombinedOutput()
101 c.Assert(err, check.Equals, nil)