Upgrade to Go 1.8

The only thing that has substansively changed is that Go 1.8 handles
redirect logic more safely than previous versions. This means we can
drop our special handling to avoid following redirects to other
domains. We were only doing that to protect against the possibility
of leaking auth headers. With Go 1.8, the auth headers are not
forwarded when following a redirect to another domain, so we don't
need our special handling any more.

As long as people are attempting to build with the Makefile, the new
check_go_version script should cause the build to stop if our
collaborators aren't using at least version 1.8 of go.
上级 f4930b52
......@@ -6,7 +6,7 @@ This project adheres to the [Open Code of Conduct][code-of-conduct]. By particip
You will need:
1. Go 1.6+
1. Go 1.8+
1. Ruby 1.9+ with Bundler
2. git 1.8+
3. tmux & zsh (optional) - for running shell completion tests
......
......@@ -71,4 +71,6 @@ install: bin/hub man-pages
clean:
rm -rf bin/hub
rm -rf bin/ronn
rm -rf bin/cucumber
git clean -fdx share/man
......@@ -63,7 +63,7 @@ $ make install prefix=/usr/local
Prerequisites for compilation are:
* `make`
* [Go 1.6+](http://golang.org/doc/install)
* [Go 1.8+](http://golang.org/doc/install)
* Ruby 1.9+ with Bundler - for generating man pages
If you don't have `make`, Ruby, or want to skip man pages (for example, if you
......@@ -100,8 +100,8 @@ eval "$(hub alias -s)"
#### PowerShell
If you're using PowerShell, you can set an alias for `hub` by placing the
following in your PowerShell profile (usually
If you're using PowerShell, you can set an alias for `hub` by placing the
following in your PowerShell profile (usually
`~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1`):
``` sh
......
......@@ -827,22 +827,6 @@ BODY
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
Scenario: Redirect to another host is not followed
Given the "origin" remote has url "https://github.com/mislav/coral.git"
And I am on the "feature" branch pushed to "origin/feature"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
redirect 'https://disney.com/mouse', 307
}
"""
When I run `hub pull-request -m hereyougo`
Then the stderr should contain exactly:
"""
Error creating pull request: Temporary Redirect (HTTP 307)
Refused to follow redirect to https://disney.com/mouse\n
"""
Scenario: Default message with --push
Given the git commit editor is "true"
Given the GitHub API server:
......
......@@ -772,11 +772,6 @@ func FormatError(action string, err error) (ee error) {
}
}
redirectLocation := e.Response.Header.Get("Location")
if statusCode >= 300 && statusCode < 400 && redirectLocation != "" {
errorSentences = append(errorSentences, fmt.Sprintf("Refused to follow redirect to %s", redirectLocation))
}
var errorMessage string
if len(errorSentences) > 0 {
errorMessage = strings.Join(errorSentences, "\n")
......
......@@ -154,20 +154,6 @@ func newHttpClient(testHost string, verbose bool) *http.Client {
return &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if len(via) > 2 {
return fmt.Errorf("too many redirects")
} else {
// replicate rudimentary functionality of copyHeaders from Go 1.8
for key, vals := range via[0].Header {
lkey := strings.ToLower(key)
if !strings.HasPrefix(lkey, "x-original-") && via[0].Host == req.URL.Host || lkey != "authorization" {
req.Header[key] = vals
}
}
return nil
}
},
}
}
......@@ -216,13 +202,13 @@ func (c *simpleClient) performRequest(method, path string, body io.Reader, confi
url, err := url.Parse(path)
if err == nil {
url = c.rootUrl.ResolveReference(url)
return c.performRequestUrl(method, url, body, configure, 2)
return c.performRequestUrl(method, url, body, configure)
} else {
return nil, err
}
}
func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Reader, configure func(*http.Request), redirectsRemaining int) (res *simpleResponse, err error) {
func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Reader, configure func(*http.Request)) (res *simpleResponse, err error) {
req, err := http.NewRequest(method, url.String(), body)
if err != nil {
return
......@@ -247,14 +233,6 @@ func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Re
}
res = &simpleResponse{httpResponse}
// TODO: remove after upgrade to Go 1.8
if res.StatusCode == 307 && redirectsRemaining > 0 {
url, err = url.Parse(res.Header.Get("Location"))
if err != nil || url.Host != req.URL.Host || url.Scheme != req.URL.Scheme {
return
}
res, err = c.performRequestUrl(method, url, bodyBackup, configure, redirectsRemaining-1)
}
return
}
......
#!/usr/bin/env bash
set -e
source script/check_go_version
STATUS=0
if [ -n "$TRAVIS" ] && [ ! -x ~/bin/tmux ]; then
case "$TRAVIS_OS_NAME" in
......@@ -14,12 +17,7 @@ if [ -n "$TRAVIS" ] && [ ! -x ~/bin/tmux ]; then
curl -fsSL "https://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${cache_name}.tgz" | tar -xz -C ~
fi
STATUS=0
if ! go version; then
echo "You need to install Go 1.6 or higher to build hub" >&2
STATUS=1
fi
check_go_version
{ ruby --version
if [ -n "$TRAVIS" ]; then
......
......@@ -8,6 +8,9 @@
# With `test`, runs tests instead.
set -e
source script/check_go_version
check_go_version
windows=
[[ $OS == Windows* ]] && windows=1
......
#!/usr/bin/env bash
# This script is only used by importing into other scripts.
GO_VERSION_REGEX="go(1\.[89]|[2-9]\.[0-9]{1,}|[0-9]{2,}\.[0-9]{1,})(\.[0-9]{1,})?[[:space:]]"
check_go_version() {
if ! go version | grep -E $GO_VERSION_REGEX &> /dev/null; then
echo "You need to install Go 1.8 or higher to build hub" >&2
exit 1
else
go version
fi
}
test_go_version() {
if ! echo $1 | grep -E $GO_VERSION_REGEX &> /dev/null; then
echo "FAIL $1" >&2
else
echo "PASS $1"
fi
}
test_go_versions() {
test_go_version "go version go0.1 darwin/amd64"
test_go_version "go version go0.2 darwin/amd64"
test_go_version "go version go1.6 darwin/amd64"
test_go_version "go version go1.7.8 darwin/amd64"
test_go_version "go version go1.8 darwin/amd64"
test_go_version "go version go1.8.1 darwin/amd64"
test_go_version "go version go1.8.10 darwin/amd64"
test_go_version "go version go1.9 darwin/amd64"
test_go_version "go version go2.0 darwin/amd64"
test_go_version "go version go2.0.1 darwin/amd64"
test_go_version "go version go3.1 darwin/amd64"
test_go_version "go version go4.5 darwin/amd64"
test_go_version "go version go5.6 darwin/amd64"
test_go_version "go version go6.7 darwin/amd64"
test_go_version "go version go10.1 darwin/amd64"
test_go_version "go version go10.1 darwin/amd64"
test_go_version "go version go10.10.10 darwin/amd64"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册