mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-01 20:27:36 +03:00
refactor(gofumpt): run gofumpt over the code
This commit is contained in:
parent
32b75262ad
commit
b8d8ca6301
30 changed files with 52 additions and 61 deletions
|
@ -82,7 +82,7 @@ func LogOutputOption(args []string) (log.Output, error) {
|
|||
// keep the absolute path for reinitialization.
|
||||
args[i] = absPath
|
||||
|
||||
w, err := os.OpenFile(absPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||
w, err := os.OpenFile(absPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o666)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create log file: %v", err)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func addrFuncTest(t *testing.T, f func(string) (string, error)) func(in string, wantOut string, fail bool) {
|
||||
func addrFuncTest(t *testing.T, f func(string) (string, error)) func(in, wantOut string, fail bool) {
|
||||
return func(in, wantOut string, fail bool) {
|
||||
t.Helper()
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@ import (
|
|||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")
|
||||
)
|
||||
var ErrUnicodeMailbox = errors.New("address: cannot convert the Unicode local-part to the ACE form")
|
||||
|
||||
// ToASCII converts the domain part of the email address to the A-label form and
|
||||
// fails with ErrUnicodeMailbox if the local-part contains non-ASCII characters.
|
||||
|
|
|
@ -80,7 +80,7 @@ func validateNodeName(s string) error {
|
|||
return errors.New("directive name cannot start with a digit")
|
||||
}
|
||||
|
||||
var allowedPunct = map[rune]bool{'.': true, '-': true, '_': true}
|
||||
allowedPunct := map[rune]bool{'.': true, '-': true, '_': true}
|
||||
|
||||
for _, ch := range s {
|
||||
if !unicode.IsLetter(ch) &&
|
||||
|
|
|
@ -80,7 +80,7 @@ func (m *Map) AllowUnknown() {
|
|||
// slice. At least one argument should be present.
|
||||
//
|
||||
// See Map.Custom for description of inheritGlobal and required.
|
||||
func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed []string, defaultVal []string, store *[]string) {
|
||||
func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed, defaultVal []string, store *[]string) {
|
||||
m.Custom(name, inheritGlobal, required, func() (interface{}, error) {
|
||||
return defaultVal, nil
|
||||
}, func(_ *Map, node Node) (interface{}, error) {
|
||||
|
|
|
@ -40,9 +40,9 @@ import (
|
|||
)
|
||||
|
||||
// createInlineModule is a helper function for config matchers that can create inline modules.
|
||||
func createInlineModule(preferredNamespace string, modName string, args []string) (module.Module, error) {
|
||||
func createInlineModule(preferredNamespace, modName string, args []string) (module.Module, error) {
|
||||
var newMod module.FuncNewModule
|
||||
var originalModName = modName
|
||||
originalModName := modName
|
||||
|
||||
// First try to extend the name with preferred namespace unless the name
|
||||
// already contains it.
|
||||
|
|
|
@ -130,7 +130,7 @@ func TestExtResolver_AuthLookupIPAddr(t *testing.T) {
|
|||
// Silence log messages about disregarded I/O errors.
|
||||
log.DefaultLogger.Out = nil
|
||||
|
||||
test := func(aAct, aaaaAct TestSrvAction, aAD, aaaaAD bool, ad bool, addrs []net.IP, err bool) {
|
||||
test := func(aAct, aaaaAct TestSrvAction, aAD, aaaaAD, ad bool, addrs []net.IP, err bool) {
|
||||
t.Helper()
|
||||
t.Run(fmt.Sprintln(aAct, aaaaAct, aAD, aaaaAD), func(t *testing.T) {
|
||||
t.Helper()
|
||||
|
|
|
@ -24,9 +24,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
overrideServ string
|
||||
)
|
||||
var overrideServ string
|
||||
|
||||
// override globally overrides the used DNS server address with one provided.
|
||||
// This function is meant only for testing. It should be called before any modules are
|
||||
|
|
|
@ -50,19 +50,19 @@ func TestParse(t *testing.T) {
|
|||
}
|
||||
|
||||
test("2006-01-02T15:04:05.000Z module: hello\t", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Module: "module",
|
||||
Message: "hello",
|
||||
Context: map[string]interface{}{},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z module: hello: whatever\t", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Module: "module",
|
||||
Message: "hello: whatever",
|
||||
Context: map[string]interface{}{},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z module: hello: whatever\t{\"a\":1}", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Module: "module",
|
||||
Message: "hello: whatever",
|
||||
Context: map[string]interface{}{
|
||||
|
@ -70,7 +70,7 @@ func TestParse(t *testing.T) {
|
|||
},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z module: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Module: "module",
|
||||
Message: "hello: whatever",
|
||||
Context: map[string]interface{}{
|
||||
|
@ -79,7 +79,7 @@ func TestParse(t *testing.T) {
|
|||
},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z [debug] module: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Debug: true,
|
||||
Module: "module",
|
||||
Message: "hello: whatever",
|
||||
|
@ -89,7 +89,7 @@ func TestParse(t *testing.T) {
|
|||
},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z [debug] oink oink: hello: whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Debug: true,
|
||||
Message: "oink oink: hello: whatever",
|
||||
Context: map[string]interface{}{
|
||||
|
@ -98,7 +98,7 @@ func TestParse(t *testing.T) {
|
|||
},
|
||||
}, "")
|
||||
test("2006-01-02T15:04:05.000Z [debug] whatever\t{\"a\":1,\"b\":\"bbb\"}", Msg{
|
||||
Stamp: time.Date(2006, time.January, 02, 15, 04, 05, 0, time.UTC),
|
||||
Stamp: time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC),
|
||||
Debug: true,
|
||||
Message: "whatever",
|
||||
Context: map[string]interface{}{
|
||||
|
|
|
@ -20,12 +20,10 @@ package module
|
|||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrUnknownCredentials should be returned by auth. provider if supplied
|
||||
// credentials are valid for it but are not recognized (e.g. not found in
|
||||
// used DB).
|
||||
ErrUnknownCredentials = errors.New("unknown credentials")
|
||||
)
|
||||
// ErrUnknownCredentials should be returned by auth. provider if supplied
|
||||
// credentials are valid for it but are not recognized (e.g. not found in
|
||||
// used DB).
|
||||
var ErrUnknownCredentials = errors.New("unknown credentials")
|
||||
|
||||
// PlainAuth is the interface implemented by modules providing authentication using
|
||||
// username:password pairs.
|
||||
|
|
|
@ -28,6 +28,7 @@ package pam
|
|||
#include "pam.h"
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
|
@ -27,8 +27,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ErrNoSuchUser = errors.New("shadow: user entry is not present in database")
|
||||
var ErrWrongPassword = errors.New("shadow: wrong password")
|
||||
var (
|
||||
ErrNoSuchUser = errors.New("shadow: user entry is not present in database")
|
||||
ErrWrongPassword = errors.New("shadow: wrong password")
|
||||
)
|
||||
|
||||
// Read reads system shadow passwords database and returns all entires in it.
|
||||
func Read() ([]Entry, error) {
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
)
|
||||
|
||||
func TestRequireMatchingRDNS(t *testing.T) {
|
||||
test := func(rdns string, srcHost string, fail bool) {
|
||||
test := func(rdns, srcHost string, fail bool) {
|
||||
rdnsFut := future.New()
|
||||
var ptr []string
|
||||
if rdns != "" {
|
||||
|
|
|
@ -60,7 +60,7 @@ type Verifier struct {
|
|||
// TODO(GH #206): DMARC reporting
|
||||
// FailureReportFunc is the callback that is called when a failure report
|
||||
// is generated. If it is nil - failure reports generation is disabled.
|
||||
//FailureReportFunc func(textproto.Header, io.Reader)
|
||||
// FailureReportFunc func(textproto.Header, io.Reader)
|
||||
}
|
||||
|
||||
func NewVerifier(r Resolver) *Verifier {
|
||||
|
|
|
@ -190,7 +190,7 @@ func bufferModeDirective(_ *config.Map, node config.Node) (interface{}, error) {
|
|||
return buffer.BufferInMemory, nil
|
||||
case "fs":
|
||||
path := filepath.Join(config.StateDirectory, "buffer")
|
||||
if err := os.MkdirAll(path, 0700); err != nil {
|
||||
if err := os.MkdirAll(path, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(node.Args) {
|
||||
|
@ -206,7 +206,7 @@ func bufferModeDirective(_ *config.Map, node config.Node) (interface{}, error) {
|
|||
}
|
||||
case "auto":
|
||||
path := filepath.Join(config.StateDirectory, "buffer")
|
||||
if err := os.MkdirAll(path, 0700); err != nil {
|
||||
if err := os.MkdirAll(path, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ func (endp *Endpoint) setConfig(cfg *config.Map) error {
|
|||
cfg.Int("max_received", false, false, 50, &endp.maxReceived)
|
||||
cfg.Custom("buffer", false, false, func() (interface{}, error) {
|
||||
path := filepath.Join(config.StateDirectory, "buffer")
|
||||
if err := os.MkdirAll(path, 0700); err != nil {
|
||||
if err := os.MkdirAll(path, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return autoBufferMode(1*1024*1024 /* 1 MiB */, path), nil
|
||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
|||
}
|
||||
|
||||
func TestSubmissionPrepare(t *testing.T) {
|
||||
test := func(hdrMap map[string][]string, expectedMap map[string][]string) {
|
||||
test := func(hdrMap, expectedMap map[string][]string) {
|
||||
t.Helper()
|
||||
|
||||
hdr := textproto.Header{}
|
||||
|
|
|
@ -24,9 +24,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrClosed = errors.New("limiters: Rate bucket is closed")
|
||||
)
|
||||
var ErrClosed = errors.New("limiters: Rate bucket is closed")
|
||||
|
||||
// Rate structure implements a basic rate-limiter for requests using the token
|
||||
// bucket approach.
|
||||
|
|
|
@ -127,7 +127,7 @@ func (m *Modifier) generateAndWrite(keyPath, newKeyAlgo string) (crypto.Signer,
|
|||
|
||||
// 0777 because we have public keys in here too and they don't
|
||||
// need protection. Individual private key files have 0600 perms.
|
||||
if err := os.MkdirAll(filepath.Dir(keyPath), 0777); err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(keyPath), 0o777); err != nil {
|
||||
return nil, wrapErr(err)
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func (m *Modifier) generateAndWrite(keyPath, newKeyAlgo string) (crypto.Signer,
|
|||
return nil, wrapErr(err)
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
f, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)
|
||||
if err != nil {
|
||||
return nil, wrapErr(err)
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestKeyLoad_existing_pkcs8(t *testing.T) {
|
|||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyEd25519), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyEd25519), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ func TestKeyLoad_existing_pkcs1(t *testing.T) {
|
|||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyRSA), 0600); err != nil {
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, "testkey.key"), []byte(pkeyRSA), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ func (dd *msgpipelineDelivery) initRunGlobalModifiers(ctx context.Context, msgMe
|
|||
}
|
||||
|
||||
func (dd *msgpipelineDelivery) srcBlockForAddr(ctx context.Context, mailFrom string) (sourceBlock, error) {
|
||||
var cleanFrom = mailFrom
|
||||
cleanFrom := mailFrom
|
||||
if mailFrom != "" {
|
||||
var err error
|
||||
cleanFrom, err = address.ForLookup(mailFrom)
|
||||
|
|
|
@ -329,7 +329,8 @@ func TestMsgPipeline_PerSourceAddrAndDomainSplit(t *testing.T) {
|
|||
targets: []module.DeliveryTarget{&target1},
|
||||
},
|
||||
},
|
||||
"example.com": {perRcpt: map[string]*rcptBlock{},
|
||||
"example.com": {
|
||||
perRcpt: map[string]*rcptBlock{},
|
||||
defaultRcpt: &rcptBlock{
|
||||
targets: []module.DeliveryTarget{&target2},
|
||||
},
|
||||
|
@ -365,7 +366,8 @@ func TestMsgPipeline_PerSourceReject(t *testing.T) {
|
|||
targets: []module.DeliveryTarget{&target},
|
||||
},
|
||||
},
|
||||
"example.com": {perRcpt: map[string]*rcptBlock{},
|
||||
"example.com": {
|
||||
perRcpt: map[string]*rcptBlock{},
|
||||
rejectErr: errors.New("go away"),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -88,7 +88,7 @@ func isVerifyError(err error) bool {
|
|||
// Return values:
|
||||
// - tlsLevel TLS security level that was estabilished.
|
||||
// - tlsErr Error that prevented TLS from working if tlsLevel != TLSAuthenticated
|
||||
func (rd *remoteDelivery) connect(ctx context.Context, conn mxConn, host string, tlsCfg *tls.Config) (tlsLevel module.TLSLevel, tlsErr error, err error) {
|
||||
func (rd *remoteDelivery) connect(ctx context.Context, conn mxConn, host string, tlsCfg *tls.Config) (tlsLevel module.TLSLevel, tlsErr, err error) {
|
||||
tlsLevel = module.TLSAuthenticated
|
||||
if rd.rt.tlsConfig != nil {
|
||||
tlsCfg = rd.rt.tlsConfig.Clone()
|
||||
|
|
|
@ -253,7 +253,6 @@ func (d *delivery) connect(ctx context.Context) error {
|
|||
|
||||
func (d *delivery) AddRcpt(ctx context.Context, rcptTo string) error {
|
||||
err := d.conn.Rcpt(ctx, rcptTo)
|
||||
|
||||
if err != nil {
|
||||
return d.u.moduleError(err)
|
||||
}
|
||||
|
|
|
@ -185,11 +185,9 @@ func (s *session) LMTPData(r io.Reader, status smtp.StatusCollector) error {
|
|||
|
||||
type SMTPServerConfigureFunc func(*smtp.Server)
|
||||
|
||||
var (
|
||||
AuthDisabled = func(s *smtp.Server) {
|
||||
s.AuthDisabled = true
|
||||
}
|
||||
)
|
||||
var AuthDisabled = func(s *smtp.Server) {
|
||||
s.AuthDisabled = true
|
||||
}
|
||||
|
||||
func SMTPServer(t *testing.T, addr string, fn ...SMTPServerConfigureFunc) (*SMTPBackend, *smtp.Server) {
|
||||
t.Helper()
|
||||
|
@ -383,7 +381,7 @@ func CheckSMTPConnLeak(t *testing.T, srv *smtp.Server) {
|
|||
// wait a bit for handleQuit in go-smtp to do its work.
|
||||
for i := 0; i < 10; i++ {
|
||||
found := false
|
||||
srv.ForEachConn(func(c *smtp.Conn) {
|
||||
srv.ForEachConn(func(_ *smtp.Conn) {
|
||||
found = true
|
||||
})
|
||||
if !found {
|
||||
|
|
2
maddy.go
2
maddy.go
|
@ -232,7 +232,7 @@ func InitDirs() error {
|
|||
}
|
||||
|
||||
func ensureDirectoryWritable(path string) error {
|
||||
if err := os.MkdirAll(path, 0700); err != nil {
|
||||
if err := os.MkdirAll(path, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,7 @@ const (
|
|||
SDStopping = "STOPPING=1"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoNotifySock = errors.New("no systemd socket")
|
||||
)
|
||||
var ErrNoNotifySock = errors.New("no systemd socket")
|
||||
|
||||
func sdNotifySock() (*net.UnixConn, error) {
|
||||
sockAddr := os.Getenv("NOTIFY_SOCKET")
|
||||
|
|
|
@ -103,5 +103,4 @@ func TestPerIPConcurrency(tt *testing.T) {
|
|||
c1.Writeln("MAIL FROM:<testing@maddy.test")
|
||||
// Temporary error due to lock timeout.
|
||||
c1.ExpectPattern("451 *")
|
||||
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ func TestReplaceAddr_Rcpt(tt *testing.T) {
|
|||
}`)
|
||||
|
||||
// FIXME: Not implemented
|
||||
//test("external", `
|
||||
// test("external", `
|
||||
// hostname mx.maddy.test
|
||||
// tls off
|
||||
|
||||
|
@ -212,7 +212,7 @@ func TestReplaceAddr_Sender(tt *testing.T) {
|
|||
}
|
||||
}`)
|
||||
// FIXME: Not implemented
|
||||
//test("external", `
|
||||
// test("external", `
|
||||
// hostname mx.maddy.test
|
||||
// tls off
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ func TestSPF_DMARCDefer(tt *testing.T) {
|
|||
defer conn.Close()
|
||||
conn.SMTPNegotation("localhost", nil, nil)
|
||||
|
||||
msg := func(fromEnv, fromHdr string, bodyRespPattern string) {
|
||||
msg := func(fromEnv, fromHdr, bodyRespPattern string) {
|
||||
tt.Helper()
|
||||
|
||||
conn.Writeln("MAIL FROM:<" + fromEnv + ">")
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
"github.com/foxcpp/maddy/tests"
|
||||
)
|
||||
|
||||
func floodSmtp(c *tests.Conn, commands []string, expectedPatterns []string, iterations int) {
|
||||
func floodSmtp(c *tests.Conn, commands, expectedPatterns []string, iterations int) {
|
||||
for i := 0; i < iterations; i++ {
|
||||
for i, cmd := range commands {
|
||||
c.Writeln(cmd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue