Skip to content

Commit

Permalink
Fix oauth_callback_confirmed comparison when server returns extra whi…
Browse files Browse the repository at this point in the history
…tespace
  • Loading branch information
pscohn committed Jan 28, 2022
1 parent 54bbea8 commit 39f1d89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -89,7 +90,7 @@ func (c *Config) RequestToken() (requestToken, requestSecret string, err error)
}

// ParseQuery to decode URL-encoded application/x-www-form-urlencoded body
values, err := url.ParseQuery(string(body))
values, err := url.ParseQuery(strings.TrimSpace(string(body)))
if err != nil {
return "", "", err
}
Expand Down
7 changes: 4 additions & 3 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func newRequestTokenServer(t *testing.T, data url.Values) *httptest.Server {
assert.Equal(t, "POST", req.Method)
assert.NotEmpty(t, req.Header.Get("Authorization"))
w.Header().Set(contentType, formContentType)
w.Write([]byte(data.Encode()))
// Add a newline to ensure parsing works for servers that return extra whitespace
w.Write([]byte(data.Encode() + "\n"))
})
}

Expand Down Expand Up @@ -91,7 +92,7 @@ func newUnparseableBodyServer() *httptest.Server {
}

func TestConfigRequestToken(t *testing.T) {
expectedToken := "reqest_token"
expectedToken := "request_token"
expectedSecret := "request_secret"
data := url.Values{}
data.Add("oauth_token", expectedToken)
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestConfigRequestToken_InvalidRequestTokenURL(t *testing.T) {
}

func TestConfigRequestToken_CallbackNotConfirmed(t *testing.T) {
const expectedToken = "reqest_token"
const expectedToken = "request_token"
const expectedSecret = "request_secret"
data := url.Values{}
data.Add("oauth_token", expectedToken)
Expand Down

0 comments on commit 39f1d89

Please sign in to comment.