Skip to content

Commit 1b1c685

Browse files
authored
Bump CI versions, fix a few linting errors (#90)
1 parent b5069f3 commit 1b1c685

7 files changed

Lines changed: 16 additions & 7 deletions

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
tests:
1212
strategy:
1313
matrix:
14-
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x]
14+
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
1515
os: [ubuntu-latest]
1616
runs-on: ${{ matrix.os }}
1717
steps:

.golangci.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
run:
2-
timeout: 10m
2+
timeout: 5m
33

44
linters:
55
enable-all: true
@@ -29,8 +29,6 @@ linters:
2929
- nestif
3030
- funlen
3131
- goconst
32-
- nlreturn
33-
- gochecknoglobals
3432
- cyclop
3533
- gocyclo
3634
- gocognit

csp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
)
1212

13-
// cspHandler writes the nonce out as the response body.
13+
//nolint:gochecknoglobals
1414
var cspHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1515
_, _ = w.Write([]byte(CSPNonce(r.Context())))
1616
})

cspbuilder/builder_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestContentSecurityPolicyBuilder_Build_SingleDirective(t *testing.T) {
4545
got, err := builder.Build()
4646
if (err != nil) != tt.wantErr {
4747
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
48+
4849
return
4950
}
5051

@@ -94,6 +95,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
9495
got, err := builder.Build()
9596
if (err != nil) != tt.wantErr {
9697
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
98+
9799
return
98100
}
99101

@@ -102,6 +104,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
102104
for directive := range tt.directives {
103105
if strings.HasPrefix(got, directive) {
104106
startsWithDirective = true
107+
105108
break
106109
}
107110
}

cspbuilder/directive_builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
func buildDirectiveSandbox(sb *strings.Builder, values []string) error {
1010
if len(values) == 0 {
1111
sb.WriteString(Sandbox)
12+
1213
return nil
1314
}
1415

secure.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ type SSLHostFunc func(host string) (newHost string)
3939
// AllowRequestFunc is a custom function type that can be used to dynamically determine if a request should proceed or not.
4040
type AllowRequestFunc func(r *http.Request) bool
4141

42-
func defaultBadHostHandler(w http.ResponseWriter, r *http.Request) {
42+
func defaultBadHostHandler(w http.ResponseWriter, _ *http.Request) {
4343
http.Error(w, "Bad Host", http.StatusInternalServerError)
4444
}
4545

46-
func defaultBadRequestHandler(w http.ResponseWriter, r *http.Request) {
46+
func defaultBadRequestHandler(w http.ResponseWriter, _ *http.Request) {
4747
http.Error(w, "Bad Request", http.StatusBadRequest)
4848
}
4949

@@ -302,6 +302,7 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
302302
for _, header := range s.opt.HostsProxyHeaders {
303303
if h := r.Header.Get(header); h != "" {
304304
host = h
305+
305306
break
306307
}
307308
}
@@ -314,20 +315,23 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
314315
for _, allowedHost := range s.cRegexAllowedHosts {
315316
if match := allowedHost.MatchString(host); match {
316317
isGoodHost = true
318+
317319
break
318320
}
319321
}
320322
} else {
321323
for _, allowedHost := range s.opt.AllowedHosts {
322324
if strings.EqualFold(allowedHost, host) {
323325
isGoodHost = true
326+
324327
break
325328
}
326329
}
327330
}
328331

329332
if !isGoodHost {
330333
s.badHostHandler.ServeHTTP(w, r)
334+
331335
return nil, nil, fmt.Errorf("bad host name: %s", host)
332336
}
333337
}
@@ -389,6 +393,7 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He
389393
// If the AllowRequestFunc is set, call it and exit early if needed.
390394
if s.opt.AllowRequestFunc != nil && !s.opt.AllowRequestFunc(r) {
391395
s.badRequestHandler.ServeHTTP(w, r)
396+
392397
return nil, nil, fmt.Errorf("request not allowed")
393398
}
394399

@@ -487,6 +492,7 @@ func (s *Secure) isSSL(r *http.Request) bool {
487492
for k, v := range s.opt.SSLProxyHeaders {
488493
if r.Header.Get(k) == v {
489494
ssl = true
495+
490496
break
491497
}
492498
}

secure_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
)
1212

13+
//nolint:gochecknoglobals
1314
var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1415
_, _ = w.Write([]byte("bar"))
1516
})

0 commit comments

Comments
 (0)