Skip to content

Commit f20ac82

Browse files
author
OpenShift Bot
authored
Merge pull request #12068 from liggitt/oauth-fragment-encoding
Merged by openshift-bot
2 parents 4c59faf + 97d6cb2 commit f20ac82

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

Godeps/Godeps.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/godep-restore.sh

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ preload-remote "github.com/emicklei" "go-restful" "github.com/openshift" "go-res
7474
preload-remote "github.com/golang" "glog" "github.com/openshift" "glog"
7575
preload-remote "github.com/cloudflare" "cfssl" "github.com/openshift" "cfssl"
7676
preload-remote "github.com/google" "certificate-transparency" "github.com/openshift" "certificate-transparency"
77-
preload-remote "github.com/RangelReale" "osin" "github.com/openshift" "osin"
7877
preload-remote "github.com/google" "cadvisor" "github.com/openshift" "cadvisor"
7978

8079
# preload any odd-ball commits

pkg/cmd/util/tokencmd/request_token.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ func oauthAuthorizeResult(location string) (string, error) {
191191
return "", errors.New(errorCode + " " + errorDescription)
192192
}
193193

194-
fragmentValues, err := url.ParseQuery(u.Fragment)
194+
// Grab the raw fragment ourselves, since the stdlib URL parsing decodes parts of it
195+
fragment := ""
196+
if parts := strings.SplitN(location, "#", 2); len(parts) == 2 {
197+
fragment = parts[1]
198+
}
199+
fragmentValues, err := url.ParseQuery(fragment)
195200
if err != nil {
196201
return "", err
197202
}

test/integration/oauth_request_header_test.go

+24-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/http/httptest"
99
"net/url"
1010
"os"
11-
"regexp"
11+
"strings"
1212
"testing"
1313

1414
"k8s.io/kubernetes/pkg/client/restclient"
@@ -153,8 +153,11 @@ func TestOAuthRequestHeader(t *testing.T) {
153153
t.Fatalf("unexpected error: %v", err)
154154
}
155155

156-
authorizeURL := clientConfig.Host + "/oauth/authorize?client_id=openshift-challenging-client&response_type=token"
157-
proxyURL := proxyServer.URL + "/oauth/authorize?client_id=openshift-challenging-client&response_type=token"
156+
state := `{"then": "/index.html?a=1&b=2&c=%2F"}`
157+
encodedState := (url.Values{"state": []string{state}}).Encode()
158+
159+
authorizeURL := clientConfig.Host + "/oauth/authorize?client_id=openshift-challenging-client&response_type=token&" + encodedState
160+
proxyURL := proxyServer.URL + "/oauth/authorize?client_id=openshift-challenging-client&response_type=token&" + encodedState
158161

159162
testcases := map[string]struct {
160163
transport http.RoundTripper
@@ -245,14 +248,25 @@ func TestOAuthRequestHeader(t *testing.T) {
245248
continue
246249
}
247250

248-
// Extract the access_token
249-
250-
// group #0 is everything. #1 #2 #3
251-
accessTokenRedirectRegex := regexp.MustCompile(`(^|&)access_token=([^&]+)($|&)`)
252-
accessToken := ""
253-
if matches := accessTokenRedirectRegex.FindStringSubmatch(tokenRedirect.Fragment); matches != nil {
254-
accessToken = matches[2]
251+
// Grab the raw fragment ourselves, since the stdlib URL parsing decodes parts of it
252+
fragment := ""
253+
if parts := strings.SplitN(authenticatedProxyResponse.Header.Get("Location"), "#", 2); len(parts) == 2 {
254+
fragment = parts[1]
255+
}
256+
// Extract query-encoded values from the fragment
257+
fragmentValues, err := url.ParseQuery(fragment)
258+
if err != nil {
259+
t.Errorf("%s: %v", k, err)
260+
continue
261+
}
262+
// Ensure the state was retrieved correctly
263+
returnedState := fragmentValues.Get("state")
264+
if returnedState != state {
265+
t.Errorf("%s: Expected state\n\t%v\ngot\n\t%v", k, state, returnedState)
266+
continue
255267
}
268+
// Ensure the access_token was retrieved correctly
269+
accessToken := fragmentValues.Get("access_token")
256270
if accessToken == "" {
257271
t.Errorf("%s: Expected access token, got %s", k, tokenRedirect.String())
258272
continue

vendor/github.com/RangelReale/osin/response.go

+19-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)