git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #198 from steakunderscore/switch_to_golangci-lint

Switch linter to golangci-lint

commit85c5cef78322dbe561f2d363da0ba27700fbf299 authorJoel Speed <Joel.speed@hotmail.co.uk> dateMon 1 Jul 2019, 16:37 (7 years ago) parent317f09fce7e384
12 files changed+76−56
.golangci.yml+13 .travis.yml+1−2 CHANGELOG.md+1 Dockerfile+1 Dockerfile.arm64+1 Dockerfile.armv6+1 Makefile+1−11 configure+2−2 http_test.go+15−12 oauthproxy.go+14−3 oauthproxy_test.go+25−25 options.go+1−1
.golangci.ymlnew file+13
@@ -0,0 +1,13 @@
1+run:
2+ deadline: 120s
3+linters:
4+ enable:
5+ - govet
6+ - golint
7+ - ineffassign
8+ - goconst
9+ - deadcode
10+ - gofmt
11+ - goimports
12+ enable-all: false
13+ disable-all: true
.travis.yml+1−2
@@ -6,8 +6,7 @@ install:
66 - wget -O dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
77 - chmod +x dep
88 - mv dep $GOPATH/bin/dep
9− - go get github.com/alecthomas/gometalinter
10− - gometalinter --install
9+ - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.17.1
1110script:
1211 - ./configure && make test
1312sudo: false
CHANGELOG.md+1
@@ -62,6 +62,7 @@
6262- [#185](https://github.com/pusher/oauth2_proxy/pull/185) Fix an unsupported protocol scheme error during token validation when using the Azure provider (@jonas)
6363- [#141](https://github.com/pusher/oauth2_proxy/pull/141) Check google group membership based on email address (@bchess)
6464 - Google Group membership is additionally checked via email address, allowing users outside a GSuite domain to be authorized.
65+- [#198](https://github.com/pusher/outh2_proxy/pull/198) Switch from gometalinter to golangci-lint (@steakunderscore)
6566
6667# v3.2.0
6768
Dockerfile+1
@@ -3,6 +3,7 @@ FROM golang:1.12-stretch AS builder
33# Download tools
44RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
55RUN chmod +x $GOPATH/bin/dep
6+RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
67
78# Copy sources
89WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy
Dockerfile.arm64+1
@@ -3,6 +3,7 @@ FROM golang:1.12-stretch AS builder
33# Download tools
44RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
55RUN chmod +x $GOPATH/bin/dep
6+RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
67
78# Copy sources
89WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy
Dockerfile.armv6+1
@@ -3,6 +3,7 @@ FROM golang:1.12-stretch AS builder
33# Download tools
44RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64
55RUN chmod +x $GOPATH/bin/dep
6+RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
67
78# Copy sources
89WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy
Makefile+1−11
@@ -17,17 +17,7 @@ distclean: clean
1717
1818.PHONY: lint
1919lint:
20− $(GOMETALINTER) --vendor --disable-all \
21− --enable=vet \
22− --enable=vetshadow \
23− --enable=golint \
24− --enable=ineffassign \
25− --enable=goconst \
26− --enable=deadcode \
27− --enable=gofmt \
28− --enable=goimports \
29− --deadline=120s \
30− --tests ./...
20+ $(GOLANGCILINT) run
3121
3222.PHONY: dep
3323dep:
configure+2−2
@@ -126,7 +126,7 @@ check_for go
126126check_go_version
127127check_go_env
128128check_for dep
129−check_for gometalinter
129+check_for golangci-lint
130130
131131echo
132132
@@ -135,7 +135,7 @@ cat <<- EOF > .env
135135 GO := "${tools[go]}"
136136 GO_VERSION := ${tools[go_version]}
137137 DEP := "${tools[dep]}"
138− GOMETALINTER := "${tools[gometalinter]}"
138+ GOLANGCILINT := "${tools[golangci-lint]}"
139139EOF
140140
141141echo "Environment configuration written to .env"
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