|
8 | 8 | "net"
|
9 | 9 | "net/http"
|
10 | 10 | "net/http/cgi"
|
| 11 | + "net/url" |
11 | 12 | "os"
|
12 | 13 | "os/exec"
|
13 | 14 | "path/filepath"
|
@@ -119,6 +120,42 @@ func (s *ClientSuite) TestSetAuthWrongType(c *C) {
|
119 | 120 | c.Assert(err, Equals, transport.ErrInvalidAuthMethod)
|
120 | 121 | }
|
121 | 122 |
|
| 123 | +func (s *ClientSuite) TestModifyEndpointIfRedirect(c *C) { |
| 124 | + sess := &session{endpoint: nil} |
| 125 | + u, _ := url.Parse("https://example.com/info/refs") |
| 126 | + res := &http.Response{Request: &http.Request{URL: u}} |
| 127 | + c.Assert(func() { |
| 128 | + sess.ModifyEndpointIfRedirect(res) |
| 129 | + }, PanicMatches, ".*nil pointer dereference.*") |
| 130 | + |
| 131 | + sess = &session{endpoint: nil} |
| 132 | + // no-op - should return and not panic |
| 133 | + sess.ModifyEndpointIfRedirect(&http.Response{}) |
| 134 | + |
| 135 | + data := []struct { |
| 136 | + url string |
| 137 | + endpoint *transport.Endpoint |
| 138 | + expected *transport.Endpoint |
| 139 | + }{ |
| 140 | + {"https://example.com/foo/bar", nil, nil}, |
| 141 | + {"https://example.com/foo.git/info/refs", |
| 142 | + &transport.Endpoint{}, |
| 143 | + &transport.Endpoint{Protocol: "https", Host: "example.com", Path: "/foo.git"}}, |
| 144 | + {"https://example.com:8080/foo.git/info/refs", |
| 145 | + &transport.Endpoint{}, |
| 146 | + &transport.Endpoint{Protocol: "https", Host: "example.com", Port: 8080, Path: "/foo.git"}}, |
| 147 | + } |
| 148 | + |
| 149 | + for _, d := range data { |
| 150 | + u, _ := url.Parse(d.url) |
| 151 | + sess := &session{endpoint: d.endpoint} |
| 152 | + sess.ModifyEndpointIfRedirect(&http.Response{ |
| 153 | + Request: &http.Request{URL: u}, |
| 154 | + }) |
| 155 | + c.Assert(d.endpoint, DeepEquals, d.expected) |
| 156 | + } |
| 157 | +} |
| 158 | + |
122 | 159 | type BaseSuite struct {
|
123 | 160 | fixtures.Suite
|
124 | 161 |
|
|
0 commit comments