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

A2 hash should use the request's method (closes #13) #14

Merged
merged 2 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *AuthenticationService) SetDigestAuth(username, password string) {
// returns 401 Unauthorized and authType was set to authTypeDigest. The
// resulting string is used to set the Authorization header before retrying
// the request.
func (s *AuthenticationService) digestAuthHeader(response *http.Response) (string, error) {
func (s *AuthenticationService) digestAuthHeader(method string, response *http.Response) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response object contains the original request.
So you dont have to pass themethodhere. I thinkresponse.Request.Method` should work here.
See https://golang.org/pkg/net/http/#Response

What do you think?

Copy link
Contributor Author

@opalmer opalmer Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and good point. We're already using response.Request elsewhere in that same function too...not sure why I missed it.

authenticateHeader := response.Header.Get("WWW-Authenticate")
if authenticateHeader == "" {
return "", fmt.Errorf("WWW-Authenticate header is missing")
Expand Down Expand Up @@ -112,7 +112,7 @@ func (s *AuthenticationService) digestAuthHeader(response *http.Response) (strin

// A2
h = md5.New()
A2 := fmt.Sprintf("GET:%s", uriHeader)
A2 := fmt.Sprintf("%s:%s", method, uriHeader)
io.WriteString(h, A2)
HA2 := fmt.Sprintf("%x", h.Sum(nil))

Expand Down
2 changes: 1 addition & 1 deletion gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (c *Client) addAuthentication(req *http.Request) error {
defer response.Body.Close()

if response.StatusCode == http.StatusUnauthorized {
authorization, err := c.Authentication.digestAuthHeader(response)
authorization, err := c.Authentication.digestAuthHeader(req.Method, response)

if err != nil {
return err
Expand Down