@@ -3,9 +3,6 @@ package main
33import (
44 "crypto"
55 "encoding/base64"
6− "github.com/18F/hmacauth"
7− "github.com/bitly/oauth2_proxy/providers"
8− "github.com/bmizerany/assert"
96 "io"
107 "io/ioutil"
118 "log"
@@ -17,6 +14,10 @@ import (
1714 "strings"
1815 "testing"
1916 "time"
17+
18+ "github.com/18F/hmacauth"
19+ "github.com/bitly/oauth2_proxy/providers"
20+ "github.com/bmizerany/assert"
2021)
2122
2223func init() {
@@ -359,26 +360,30 @@ func TestDoNotForwardAccessTokenUpstream(t *testing.T) {
359360}
360361
361362type SignInPageTest struct {
362− opts *Options
363− proxy *OAuthProxy
364− sign_in_regexp *regexp.Regexp
363+ opts *Options
364+ proxy *OAuthProxy
365+ sign_in_regexp *regexp.Regexp
366+ sign_in_provider_regexp *regexp.Regexp
365367}
366368
367369const signInRedirectPattern = `<input type="hidden" name="rd" value="(.*)">`
370+const signInSkipProvider = `>Found<`
368371
369−func NewSignInPageTest() *SignInPageTest {
372+func NewSignInPageTest(skipProvider bool) *SignInPageTest {
370373 var sip_test SignInPageTest
371374
372375 sip_test.opts = NewOptions()
373376 sip_test.opts.CookieSecret = "foobar"
374377 sip_test.opts.ClientID = "bazquux"
375378 sip_test.opts.ClientSecret = "xyzzyplugh"
379+ sip_test.opts.SkipProviderButton = skipProvider
376380 sip_test.opts.Validate()
377381
378382 sip_test.proxy = NewOAuthProxy(sip_test.opts, func(email string) bool {
379383 return true
380384 })
381385 sip_test.sign_in_regexp = regexp.MustCompile(signInRedirectPattern)
386+ sip_test.sign_in_provider_regexp = regexp.MustCompile(signInSkipProvider)
382387
383388 return &sip_test
384389}
@@ -391,7 +396,7 @@ func (sip_test *SignInPageTest) GetEndpoint(endpoint string) (int, string) {
391396}
392397
393398func TestSignInPageIncludesTargetRedirect(t *testing.T) {
394− sip_test := NewSignInPageTest()
399+ sip_test := NewSignInPageTest(false)
395400 const endpoint = "/some/random/endpoint"
396401
397402 code, body := sip_test.GetEndpoint(endpoint)
@@ -409,7 +414,7 @@ func TestSignInPageIncludesTargetRedirect(t *testing.T) {
409414}
410415
411416func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) {
412− sip_test := NewSignInPageTest()
417+ sip_test := NewSignInPageTest(false)
413418 code, body := sip_test.GetEndpoint("/oauth2/sign_in")
414419 assert.Equal(t, 200, code)
415420
@@ -423,6 +428,34 @@ func TestSignInPageDirectAccessRedirectsToRoot(t *testing.T) {
423428 }
424429}
425430
431+func TestSignInPageSkipProvider(t *testing.T) {
432+ sip_test := NewSignInPageTest(true)
433+ const endpoint = "/some/random/endpoint"
434+
435+ code, body := sip_test.GetEndpoint(endpoint)
436+ assert.Equal(t, 302, code)
437+
438+ match := sip_test.sign_in_provider_regexp.FindStringSubmatch(body)
439+ if match == nil {
440+ t.Fatal("Did not find pattern in body: " +
441+ signInSkipProvider + "\nBody:\n" + body)
442+ }
443+}
444+
445+func TestSignInPageSkipProviderDirect(t *testing.T) {
446+ sip_test := NewSignInPageTest(true)
447+ const endpoint = "/sign_in"
448+
449+ code, body := sip_test.GetEndpoint(endpoint)
450+ assert.Equal(t, 302, code)
451+
452+ match := sip_test.sign_in_provider_regexp.FindStringSubmatch(body)
453+ if match == nil {
454+ t.Fatal("Did not find pattern in body: " +
455+ signInSkipProvider + "\nBody:\n" + body)
456+ }
457+}
458+
426459type ProcessCookieTest struct {
427460 opts *Options
428461 proxy *OAuthProxy