|
|
|
@ -24,6 +24,9 @@ func TestGetSessionCookieMissingCookie(t *testing.T) {
|
|
|
|
|
if c.Value != sessionKey {
|
|
|
|
|
t.Errorf("Wrong sessionKey %q != %q", c.Value, sessionKey)
|
|
|
|
|
}
|
|
|
|
|
if c.Path != "/" {
|
|
|
|
|
t.Errorf("Wrong cookiepath %q != %q", c.Path, "/")
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -33,7 +36,38 @@ func TestGetSessionCookieCookieSet(t *testing.T) {
|
|
|
|
|
mySessionKey := "12341234"
|
|
|
|
|
|
|
|
|
|
r, _ := http.NewRequest("GET", "/", nil)
|
|
|
|
|
cookie := &http.Cookie{Name: "session", Value: mySessionKey}
|
|
|
|
|
cookie := &http.Cookie{Name: "session", Value: mySessionKey, Path: r.URL.Path}
|
|
|
|
|
r.AddCookie(cookie)
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
sessionKey, err := getSessionCookie(w, r)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("err != nil in getSessionCookie")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if mySessionKey != sessionKey {
|
|
|
|
|
t.Errorf("getSessionKey didn't fetch sessionKey from \"session\" cookie")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cookies := w.Result().Cookies()
|
|
|
|
|
for _, c := range cookies {
|
|
|
|
|
if c.Name == "session" {
|
|
|
|
|
if c.Value != sessionKey {
|
|
|
|
|
t.Errorf("Wrong sessionKey %q != %q", c.Value, sessionKey)
|
|
|
|
|
}
|
|
|
|
|
if c.Path != "" {
|
|
|
|
|
t.Errorf("Wrong cookiepath %q != %q", c.Path, "")
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetSessionCookieCookieSetAuth(t *testing.T) {
|
|
|
|
|
mySessionKey := "12341234"
|
|
|
|
|
|
|
|
|
|
r, _ := http.NewRequest("GET", "/auth/", nil)
|
|
|
|
|
cookie := &http.Cookie{Name: "session", Value: mySessionKey, Path: r.URL.Path}
|
|
|
|
|
r.AddCookie(cookie)
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
@ -45,4 +79,17 @@ func TestGetSessionCookieCookieSet(t *testing.T) {
|
|
|
|
|
if mySessionKey != sessionKey {
|
|
|
|
|
t.Errorf("getSessionKey didn't fetch sessionKey from \"session\" cookie")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cookies := w.Result().Cookies()
|
|
|
|
|
for _, c := range cookies {
|
|
|
|
|
if c.Name == "session" {
|
|
|
|
|
if c.Value != sessionKey {
|
|
|
|
|
t.Errorf("Wrong sessionKey %q != %q", c.Value, sessionKey)
|
|
|
|
|
}
|
|
|
|
|
if c.Path != "" {
|
|
|
|
|
t.Errorf("Wrong cookiepath %q != %q", c.Path, "")
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|