git.iko.soy/typeable/oauth2-proxy
on master help sign in
Fix lint errors
commitd24aacdb5c34630a7a8ca3b2f9fe0ef1c093a37d authorHenry Jenkins <henry@henryjenkins.name> dateSun 23 Jun 2019, 20:41 (7 years ago) parent411adf6
4 files changed+55−41
http_test.go+15−12 oauthproxy.go+14−3 oauthproxy_test.go+25−25 options.go+1−1
http_test.go+15−12
@@ -8,6 +8,9 @@ import (
88 "github.com/stretchr/testify/assert"
99)
1010
11+const localhost = "127.0.0.1"
12+const host = "test-server"
13+
1114func TestGCPHealthcheckLiveness(t *testing.T) {
1215 handler := func(w http.ResponseWriter, req *http.Request) {
1316 w.Write([]byte("test"))
@@ -16,8 +19,8 @@ func TestGCPHealthcheckLiveness(t *testing.T) {
1619 h := gcpHealthcheck(http.HandlerFunc(handler))
1720 rw := httptest.NewRecorder()
1821 r, _ := http.NewRequest("GET", "/liveness_check", nil)
19− r.RemoteAddr = "127.0.0.1"
20− r.Host = "test-server"
22+ r.RemoteAddr = localhost
23+ r.Host = host
2124 h.ServeHTTP(rw, r)
2225
2326 assert.Equal(t, 200, rw.Code)
@@ -32,8 +35,8 @@ func TestGCPHealthcheckReadiness(t *testing.T) {
3235 h := gcpHealthcheck(http.HandlerFunc(handler))
3336 rw := httptest.NewRecorder()
3437 r, _ := http.NewRequest("GET", "/readiness_check", nil)
35− r.RemoteAddr = "127.0.0.1"
36− r.Host = "test-server"
38+ r.RemoteAddr = localhost
39+ r.Host = host
3740 h.ServeHTTP(rw, r)
3841
3942 assert.Equal(t, 200, rw.Code)
@@ -48,8 +51,8 @@ func TestGCPHealthcheckNotHealthcheck(t *testing.T) {
4851 h := gcpHealthcheck(http.HandlerFunc(handler))
4952 rw := httptest.NewRecorder()
5053 r, _ := http.NewRequest("GET", "/not_any_check", nil)
51− r.RemoteAddr = "127.0.0.1"
52− r.Host = "test-server"
54+ r.RemoteAddr = localhost
55+ r.Host = host
5356 h.ServeHTTP(rw, r)
5457
5558 assert.Equal(t, "test", rw.Body.String())
@@ -63,8 +66,8 @@ func TestGCPHealthcheckIngress(t *testing.T) {
6366 h := gcpHealthcheck(http.HandlerFunc(handler))
6467 rw := httptest.NewRecorder()
6568 r, _ := http.NewRequest("GET", "/", nil)
66− r.RemoteAddr = "127.0.0.1"
67− r.Host = "test-server"
69+ r.RemoteAddr = localhost
70+ r.Host = host
6871 r.Header.Set(userAgentHeader, googleHealthCheckUserAgent)
6972 h.ServeHTTP(rw, r)
7073
@@ -80,8 +83,8 @@ func TestGCPHealthcheckNotIngress(t *testing.T) {
8083 h := gcpHealthcheck(http.HandlerFunc(handler))
8184 rw := httptest.NewRecorder()
8285 r, _ := http.NewRequest("GET", "/foo", nil)
83− r.RemoteAddr = "127.0.0.1"
84− r.Host = "test-server"
86+ r.RemoteAddr = localhost
87+ r.Host = host
8588 r.Header.Set(userAgentHeader, googleHealthCheckUserAgent)
8689 h.ServeHTTP(rw, r)
8790
@@ -96,8 +99,8 @@ func TestGCPHealthcheckNotIngressPut(t *testing.T) {
9699 h := gcpHealthcheck(http.HandlerFunc(handler))
97100 rw := httptest.NewRecorder()
98101 r, _ := http.NewRequest("PUT", "/", nil)
99− r.RemoteAddr = "127.0.0.1"
100− r.Host = "test-server"
102+ r.RemoteAddr = localhost
103+ r.Host = host
101104 r.Header.Set(userAgentHeader, googleHealthCheckUserAgent)
102105 h.ServeHTTP(rw, r)
103106
oauthproxy.go+14−3
@@ -160,7 +160,7 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
160160}
161161
162162// NewWebSocketOrRestReverseProxy creates a reverse proxy for REST or websocket based on url
163−func NewWebSocketOrRestReverseProxy(u *url.URL, opts *Options, auth hmacauth.HmacAuth) (restProxy http.Handler) {
163+func NewWebSocketOrRestReverseProxy(u *url.URL, opts *Options, auth hmacauth.HmacAuth) http.Handler {
164164 u.Path = ""
165165 proxy := NewReverseProxy(u, opts.FlushInterval)
166166 if !opts.PassHostHeader {
@@ -176,7 +176,12 @@ func NewWebSocketOrRestReverseProxy(u *url.URL, opts *Options, auth hmacauth.Hma
176176 wsURL := &url.URL{Scheme: wsScheme, Host: u.Host}
177177 wsProxy = wsutil.NewSingleHostReverseProxy(wsURL)
178178 }
179− return &UpstreamProxy{u.Host, proxy, wsProxy, auth}
179+ return &UpstreamProxy{
180+ upstream: u.Host,
181+ handler: proxy,
182+ wsHandler: wsProxy,
183+ auth: auth,
184+ }
180185}
181186
182187// NewOAuthProxy creates a new instance of OOuthProxy from the options provided
@@ -201,7 +206,13 @@ func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
201206 }
202207 logger.Printf("mapping path %q => file system %q", path, u.Path)
203208 proxy := NewFileServer(path, u.Path)
204− serveMux.Handle(path, &UpstreamProxy{path, proxy, nil, nil})
209+ uProxy := UpstreamProxy{
210+ upstream: path,
211+ handler: proxy,
212+ wsHandler: nil,
213+ auth: nil,
214+ }
215+ serveMux.Handle(path, &uProxy)
205216 default:
206217 panic(fmt.Sprintf("unknown upstream protocol %s", u.Scheme))
207218 }
oauthproxy_test.go+25−25
@@ -163,9 +163,9 @@ func TestEncodedSlashes(t *testing.T) {
163163
164164func TestRobotsTxt(t *testing.T) {
165165 opts := NewOptions()
166− opts.ClientID = "bazquux"
167− opts.ClientSecret = "foobar"
168− opts.CookieSecret = "xyzzyplugh"
166+ opts.ClientID = "asdlkjx"
167+ opts.ClientSecret = "alkgks"
168+ opts.CookieSecret = "asdkugkj"
169169 opts.Validate()
170170
171171 proxy := NewOAuthProxy(opts, func(string) bool { return true })
@@ -178,9 +178,9 @@ func TestRobotsTxt(t *testing.T) {
178178
179179func TestIsValidRedirect(t *testing.T) {
180180 opts := NewOptions()
181− opts.ClientID = "bazquux"
182− opts.ClientSecret = "foobar"
183− opts.CookieSecret = "xyzzyplugh"
181+ opts.ClientID = "skdlfj"
182+ opts.ClientSecret = "fgkdsgj"
183+ opts.CookieSecret = "ljgiogbj"
184184 // Should match domains that are exactly foo.bar and any subdomain of bar.foo
185185 opts.WhitelistDomains = []string{"foo.bar", ".bar.foo"}
186186 opts.Validate()
@@ -298,8 +298,8 @@ func TestBasicAuthPassword(t *testing.T) {
298298 // The CookieSecret must be 32 bytes in order to create the AES
299299 // cipher.
300300 opts.CookieSecret = "xyzzyplughxyzzyplughxyzzyplughxp"
301− opts.ClientID = "bazquux"
302− opts.ClientSecret = "foobar"
301+ opts.ClientID = "dlgkj"
302+ opts.ClientSecret = "alkgret"
303303 opts.CookieSecure = false
304304 opts.PassBasicAuth = true
305305 opts.PassUserHeaders = true
@@ -392,8 +392,8 @@ func NewPassAccessTokenTest(opts PassAccessTokenTestOptions) *PassAccessTokenTes
392392 // The CookieSecret must be 32 bytes in order to create the AES
393393 // cipher.
394394 t.opts.CookieSecret = "xyzzyplughxyzzyplughxyzzyplughxp"
395− t.opts.ClientID = "bazquux"
396− t.opts.ClientSecret = "foobar"
395+ t.opts.ClientID = "slgkj"
396+ t.opts.ClientSecret = "gfjgojl"
397397 t.opts.CookieSecure = false
398398 t.opts.PassAccessToken = opts.PassAccessToken
399399 t.opts.Validate()
@@ -518,9 +518,9 @@ func NewSignInPageTest(skipProvider bool) *SignInPageTest {
518518 var sipTest SignInPageTest
519519
520520 sipTest.opts = NewOptions()
521− sipTest.opts.CookieSecret = "foobar"
522− sipTest.opts.ClientID = "bazquux"
523− sipTest.opts.ClientSecret = "xyzzyplugh"
521+ sipTest.opts.CookieSecret = "adklsj2"
522+ sipTest.opts.ClientID = "lkdgj"
523+ sipTest.opts.ClientSecret = "sgiufgoi"
524524 sipTest.opts.SkipProviderButton = skipProvider
525525 sipTest.opts.Validate()
526526
@@ -624,8 +624,8 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
624624 for _, modifier := range modifiers {
625625 modifier(pcTest.opts)
626626 }
627− pcTest.opts.ClientID = "bazquux"
628− pcTest.opts.ClientSecret = "xyzzyplugh"
627+ pcTest.opts.ClientID = "asdfljk"
628+ pcTest.opts.ClientSecret = "lkjfdsig"
629629 pcTest.opts.CookieSecret = "0123456789abcdefabcd"
630630 // First, set the CookieRefresh option so proxy.AesCipher is created,
631631 // needed to encrypt the access_token.
@@ -860,9 +860,9 @@ func TestAuthSkippedForPreflightRequests(t *testing.T) {
860860
861861 opts := NewOptions()
862862 opts.Upstreams = append(opts.Upstreams, upstream.URL)
863− opts.ClientID = "bazquux"
864− opts.ClientSecret = "foobar"
865− opts.CookieSecret = "xyzzyplugh"
863+ opts.ClientID = "aljsal"
864+ opts.ClientSecret = "jglkfsdgj"
865+ opts.CookieSecret = "dkfjgdls"
866866 opts.SkipAuthPreflight = true
867867 opts.Validate()
868868
@@ -999,8 +999,8 @@ func TestNoRequestSignature(t *testing.T) {
999999func TestRequestSignatureGetRequest(t *testing.T) {
10001000 st := NewSignatureTest()
10011001 defer st.Close()
1002− st.opts.SignatureKey = "sha1:foobar"
1003− st.MakeRequestWithExpectedKey("GET", "", "foobar")
1002+ st.opts.SignatureKey = "sha1:7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d"
1003+ st.MakeRequestWithExpectedKey("GET", "", "7d9e1aa87a5954e6f9fc59266b3af9d7c35fda2d")
10041004 assert.Equal(t, 200, st.rw.Code)
10051005 assert.Equal(t, st.rw.Body.String(), "signatures match")
10061006}
@@ -1008,9 +1008,9 @@ func TestRequestSignatureGetRequest(t *testing.T) {
10081008func TestRequestSignaturePostRequest(t *testing.T) {
10091009 st := NewSignatureTest()
10101010 defer st.Close()
1011− st.opts.SignatureKey = "sha1:foobar"
1011+ st.opts.SignatureKey = "sha1:d90df39e2d19282840252612dd7c81421a372f61"
10121012 payload := `{ "hello": "world!" }`
1013− st.MakeRequestWithExpectedKey("POST", payload, "foobar")
1013+ st.MakeRequestWithExpectedKey("POST", payload, "d90df39e2d19282840252612dd7c81421a372f61")
10141014 assert.Equal(t, 200, st.rw.Code)
10151015 assert.Equal(t, st.rw.Body.String(), "signatures match")
10161016}
@@ -1056,9 +1056,9 @@ type ajaxRequestTest struct {
10561056func newAjaxRequestTest() *ajaxRequestTest {
10571057 test := &ajaxRequestTest{}
10581058 test.opts = NewOptions()
1059− test.opts.CookieSecret = "foobar"
1060− test.opts.ClientID = "bazquux"
1061− test.opts.ClientSecret = "xyzzyplugh"
1059+ test.opts.CookieSecret = "sdflsw"
1060+ test.opts.ClientID = "gkljfdl"
1061+ test.opts.ClientSecret = "sdflkjs"
10621062 test.opts.Validate()
10631063 test.proxy = NewOAuthProxy(test.opts, func(email string) bool {
10641064 return true
options.go+1−1
@@ -454,7 +454,7 @@ func parseSignatureKey(o *Options, msgs []string) []string {
454454 return append(msgs, "unsupported signature hash algorithm: "+
455455 o.SignatureKey)
456456 }
457− o.signatureData = &SignatureData{hash, secretKey}
457+ o.signatureData = &SignatureData{hash: hash, key: secretKey}
458458 return msgs
459459}
460460