FIX: Allow unicode in username and groups.
This commit is contained in:
parent
22c3ae4548
commit
319fb64c9a
5
main.go
5
main.go
|
@ -238,6 +238,7 @@ func redirectIfNoCookie(handler http.Handler, r *http.Request, w http.ResponseWr
|
||||||
expiration := time.Now().Add(reauthorizeInterval)
|
expiration := time.Now().Add(reauthorizeInterval)
|
||||||
|
|
||||||
cookieData := strings.Join([]string{username, strings.Join(groups, "|"), user_id}, ",")
|
cookieData := strings.Join([]string{username, strings.Join(groups, "|"), user_id}, ",")
|
||||||
|
cookieData = url.QueryEscape(cookieData)
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: cookieName,
|
Name: cookieName,
|
||||||
Value: signCookie(cookieData, config.CookieSecret),
|
Value: signCookie(cookieData, config.CookieSecret),
|
||||||
|
@ -298,6 +299,10 @@ func parseCookie(data, secret string) (username string, groups string, user_id s
|
||||||
err = fmt.Errorf("Expecting signature to match")
|
err = fmt.Errorf("Expecting signature to match")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
parsed, err = url.QueryUnescape(parsed)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
splitted := strings.Split(parsed, ",")
|
splitted := strings.Split(parsed, ",")
|
||||||
username = splitted[0]
|
username = splitted[0]
|
||||||
groups = splitted[1]
|
groups = splitted[1]
|
||||||
|
|
10
main_test.go
10
main_test.go
|
@ -214,6 +214,16 @@ func TestValidPayloadWithoutUserID(t *testing.T) {
|
||||||
assert.Equal(t, user_id, "")
|
assert.Equal(t, user_id, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidPayloadWithUnicode(t *testing.T) {
|
||||||
|
signed := signCookie("用户名,群组,2", "secretfoo")
|
||||||
|
username, group, user_id, parseError := parseCookie(signed, "secretfoo")
|
||||||
|
|
||||||
|
assert.NoError(t, parseError)
|
||||||
|
assert.Equal(t, username, "用户名")
|
||||||
|
assert.Equal(t, group, "群组")
|
||||||
|
assert.Equal(t, user_id, "2")
|
||||||
|
}
|
||||||
|
|
||||||
func TestNotWhitelistedPath(t *testing.T) {
|
func TestNotWhitelistedPath(t *testing.T) {
|
||||||
c := NewTestConfig()
|
c := NewTestConfig()
|
||||||
c.Whitelist = ""
|
c.Whitelist = ""
|
||||||
|
|
Loading…
Reference in New Issue