8784: Fix test for latest firefox.
[arvados.git] / services / arv-git-httpd / git_handler_test.go
1 package main
2
3 import (
4         "net/http"
5         "net/http/httptest"
6         "net/url"
7         "regexp"
8
9         check "gopkg.in/check.v1"
10 )
11
12 var _ = check.Suite(&GitHandlerSuite{})
13
14 type GitHandlerSuite struct{}
15
16 func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
17         theConfig = defaultConfig()
18         theConfig.RepoRoot = "/"
19         theConfig.GitoliteHome = "/test/ghh"
20
21         u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
22         c.Check(err, check.Equals, nil)
23         resp := httptest.NewRecorder()
24         req := &http.Request{
25                 Method:     "GET",
26                 URL:        u,
27                 RemoteAddr: "[::1]:12345",
28         }
29         h := newGitHandler()
30         h.(*gitHandler).Path = "/bin/sh"
31         h.(*gitHandler).Args = []string{"-c", "printf 'Content-Type: text/plain\r\n\r\n'; env"}
32
33         h.ServeHTTP(resp, req)
34
35         c.Check(resp.Code, check.Equals, http.StatusOK)
36         body := resp.Body.String()
37         c.Check(body, check.Matches, `(?ms).*^PATH=.*:/test/ghh/bin$.*`)
38         c.Check(body, check.Matches, `(?ms).*^GITOLITE_HTTP_HOME=/test/ghh$.*`)
39         c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=1$.*`)
40         c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
41         c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
42         c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
43 }
44
45 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
46         u, err := url.Parse("git.zzzzz.arvadosapi.com/test")
47         c.Check(err, check.Equals, nil)
48         resp := httptest.NewRecorder()
49         req := &http.Request{
50                 Method:     "GET",
51                 URL:        u,
52                 RemoteAddr: "test.bad.address.missing.port",
53         }
54         h := newGitHandler()
55         h.ServeHTTP(resp, req)
56         c.Check(resp.Code, check.Equals, http.StatusInternalServerError)
57         c.Check(resp.Body.String(), check.Equals, "")
58 }