Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oauth_callback_confirmed comparison when server returns extra whitespace #56

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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