forked from bitly/oauth2_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike Bland
committed
May 8, 2015
1 parent
f554f99
commit 5cbdb74
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,3 +305,56 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) { | |
t.Fatal(`expected redirect to "/", but was "` + match[1] + `"`) | ||
} | ||
} | ||
|
||
type ProcessCookieTest struct { | ||
opts *Options | ||
proxy *OauthProxy | ||
rw *httptest.ResponseRecorder | ||
req *http.Request | ||
} | ||
|
||
func NewProcessCookieTest() *ProcessCookieTest { | ||
var pc_test ProcessCookieTest | ||
|
||
pc_test.opts = NewOptions() | ||
pc_test.opts.Upstreams = append(pc_test.opts.Upstreams, "unused") | ||
pc_test.opts.CookieSecret = "foobar" | ||
pc_test.opts.ClientID = "bazquux" | ||
pc_test.opts.ClientSecret = "xyzzyplugh" | ||
pc_test.opts.Validate() | ||
|
||
pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool { | ||
return true | ||
}) | ||
|
||
pc_test.rw = httptest.NewRecorder() | ||
pc_test.req, _ = http.NewRequest("GET", "/", strings.NewReader("")) | ||
return &pc_test | ||
} | ||
|
||
func (p *ProcessCookieTest) MakeCookie(value string) *http.Cookie { | ||
return p.proxy.MakeCookie(p.req, value, p.opts.CookieExpire) | ||
} | ||
|
||
func (p *ProcessCookieTest) AddCookie(value string) { | ||
p.req.AddCookie(p.MakeCookie(value)) | ||
} | ||
|
||
func (p *ProcessCookieTest) ProcessCookie() (email, user, access_token string, ok bool) { | ||
return p.proxy.ProcessCookie(p.rw, p.req) | ||
} | ||
|
||
func TestProcessCookie(t *testing.T) { | ||
pc_test := NewProcessCookieTest() | ||
pc_test.AddCookie("[email protected]") | ||
email, user, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, true, ok) | ||
assert.Equal(t, "[email protected]", email) | ||
assert.Equal(t, "michael.bland", user) | ||
} | ||
|
||
func TestProcessCookieError(t *testing.T) { | ||
pc_test := NewProcessCookieTest() | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, false, ok) | ||
} |