Skip to content

Commit

Permalink
Fix lint issues, add test for panic()
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby committed Dec 15, 2024
1 parent e977d53 commit d668fa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func listenConfigDefault(config ...ListenConfig) ListenConfig {
}

if cfg.TLSMinVersion != tls.VersionTLS12 && cfg.TLSMinVersion != tls.VersionTLS13 {
panic("Supported TLS versions: 1.2, 1.3")
panic("unsupported TLS version, please use tls.VersionTLS12 or tls.VersionTLS13")
}

return cfg
Expand All @@ -183,7 +183,7 @@ func (app *App) Listen(addr string, config ...ListenConfig) error {
}

tlsHandler := &TLSHandler{}
tlsConfig = &tls.Config{
tlsConfig = &tls.Config{ //nolint:gosec // This is a user input
MinVersion: cfg.TLSMinVersion,
Certificates: []tls.Certificate{
cert,
Expand All @@ -207,7 +207,7 @@ func (app *App) Listen(addr string, config ...ListenConfig) error {
// Attach the tlsHandler to the config
app.SetTLSHandler(tlsHandler)
} else if cfg.AutoCertManager != nil {
tlsConfig = &tls.Config{
tlsConfig = &tls.Config{ //nolint:gosec // This is a user input
MinVersion: cfg.TLSMinVersion,

Check warning on line 211 in listen.go

View check run for this annotation

Codecov / codecov/patch

listen.go#L210-L211

Added lines #L210 - L211 were not covered by tests
GetCertificate: cfg.AutoCertManager.GetCertificate,
NextProtos: []string{"http/1.1", "acme-tls/1"},
Expand Down
20 changes: 20 additions & 0 deletions listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ func Test_Listen_Prefork(t *testing.T) {

app := New()

require.Panics(t, func() {
_ = app.Listen(":443", ListenConfig{TLSMinVersion: tls.VersionTLS10}) //nolint:errcheck // ignore error
})
require.Panics(t, func() {
_ = app.Listen(":443", ListenConfig{TLSMinVersion: tls.VersionTLS11}) //nolint:errcheck // ignore error
})

require.Panics(t, func() {
_ = app.Listen(":443", ListenConfig{DisableStartupMessage: true, EnablePrefork: true, TLSMinVersion: tls.VersionTLS10}) //nolint:errcheck // ignore error
})
require.Panics(t, func() {
_ = app.Listen(":443", ListenConfig{DisableStartupMessage: true, EnablePrefork: true, TLSMinVersion: tls.VersionTLS11}) //nolint:errcheck // ignore error
})
}

// go test -run Test_Listen_TLSMinVersion
func Test_Listen_TLSMinVersion(t *testing.T) {
testPreforkMaster = true

app := New()
require.NoError(t, app.Listen(":99999", ListenConfig{DisableStartupMessage: true, EnablePrefork: true}))
}

Expand Down

0 comments on commit d668fa8

Please sign in to comment.