Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Commit

Permalink
Test IsValidRedirect method
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Oct 2, 2017
1 parent 2839a5f commit e9c9e0a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions oauthproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ func TestRobotsTxt(t *testing.T) {
assert.Equal(t, "User-agent: *\nDisallow: /", rw.Body.String())
}

func TestIsValidRedirect(t *testing.T) {
opts := NewOptions()
opts.ClientID = "bazquux"
opts.ClientSecret = "foobar"
opts.CookieSecret = "xyzzyplugh"
opts.WhitelistDomains = []string{"foo.bar"}
opts.Validate()

proxy := NewOAuthProxy(opts, func(string) bool { return true })

noRD := proxy.IsValidRedirect("")
assert.Equal(t, false, noRD)

singleSlash := proxy.IsValidRedirect("/redirect")
assert.Equal(t, true, singleSlash)

doubleSlash := proxy.IsValidRedirect("//redirect")
assert.Equal(t, false, doubleSlash)

validHttp := proxy.IsValidRedirect("http://baz.foo.bar/redirect")
assert.Equal(t, true, validHttp)

validHttps := proxy.IsValidRedirect("https://baz.foo.bar/redirect")
assert.Equal(t, true, validHttps)

invalidHttp1 := proxy.IsValidRedirect("http://foo.bar.evil.corp/redirect")
assert.Equal(t, false, invalidHttp1)

invalidHttps1 := proxy.IsValidRedirect("https://foo.bar.evil.corp/redirect")
assert.Equal(t, false, invalidHttps1)

invalidHttp2 := proxy.IsValidRedirect("http://evil.corp/redirect?rd=foo.bar")
assert.Equal(t, false, invalidHttp2)

invalidHttps2 := proxy.IsValidRedirect("https://evil.corp/redirect?rd=foo.bar")
assert.Equal(t, false, invalidHttps2)
}

type TestProvider struct {
*providers.ProviderData
EmailAddress string
Expand Down

0 comments on commit e9c9e0a

Please sign in to comment.