author | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-03-02 16:15:15 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2018-03-02 19:37:37 UTC |
parent | 0611b7a7fc3200983dd747e900d2676f5a120158 |
internal/smtpsrv/server.go | +10 | -1 |
test/t-13-reload/.gitignore | +1 | -0 |
test/t-13-reload/config/chasquid.conf | +9 | -0 |
test/t-13-reload/content | +4 | -0 |
test/t-13-reload/hosts | +1 | -0 |
test/t-13-reload/msmtprc | +14 | -0 |
test/t-13-reload/run.sh | +33 | -0 |
diff --git a/internal/smtpsrv/server.go b/internal/smtpsrv/server.go index 777159c..640a17e 100644 --- a/internal/smtpsrv/server.go +++ b/internal/smtpsrv/server.go @@ -3,6 +3,7 @@ package smtpsrv import ( "crypto/tls" + "flag" "net" "net/http" "net/textproto" @@ -19,6 +20,14 @@ import ( "blitiri.com.ar/go/log" ) +var ( + // Reload frequency. + // We should consider making this a proper option if there's interest in + // changing it, but until then, it's a test-only flag for simplicity. + reloadEvery = flag.Duration("testing__reload_every", 30*time.Second, + "how often to reload, ONLY FOR TESTING") +) + type Server struct { // Main hostname, used for display only. Hostname string @@ -145,7 +154,7 @@ func (s *Server) InitQueue(path string, localC, remoteC courier.Courier) { // PeriodicallyReload some of the server's information, such as aliases and // the user databases. func (s *Server) periodicallyReload() { - for range time.Tick(30 * time.Second) { + for range time.Tick(*reloadEvery) { err := s.aliasesR.Reload() if err != nil { log.Errorf("Error reloading aliases: %v", err) diff --git a/test/t-13-reload/.gitignore b/test/t-13-reload/.gitignore new file mode 100644 index 0000000..9dbf0f3 --- /dev/null +++ b/test/t-13-reload/.gitignore @@ -0,0 +1 @@ +config/domains/testserver/aliases diff --git a/test/t-13-reload/config/chasquid.conf b/test/t-13-reload/config/chasquid.conf new file mode 100644 index 0000000..2da8942 --- /dev/null +++ b/test/t-13-reload/config/chasquid.conf @@ -0,0 +1,9 @@ +smtp_address: ":1025" +submission_address: ":1587" +monitoring_address: ":1099" + +mail_delivery_agent_bin: "test-mda" +mail_delivery_agent_args: "%to%" + +data_dir: "../.data" +mail_log_path: "../.logs/mail_log" diff --git a/test/t-13-reload/content b/test/t-13-reload/content new file mode 100644 index 0000000..76a8b16 --- /dev/null +++ b/test/t-13-reload/content @@ -0,0 +1,4 @@ +Subject: Prueba desde el test + +Crece desde el test el futuro +Crece desde el test diff --git a/test/t-13-reload/hosts b/test/t-13-reload/hosts new file mode 100644 index 0000000..2b9b623 --- /dev/null +++ b/test/t-13-reload/hosts @@ -0,0 +1 @@ +testserver localhost diff --git a/test/t-13-reload/msmtprc b/test/t-13-reload/msmtprc new file mode 100644 index 0000000..f5e3076 --- /dev/null +++ b/test/t-13-reload/msmtprc @@ -0,0 +1,14 @@ +account default + +host testserver +port 1587 + +tls on +tls_trust_file config/certs/testserver/fullchain.pem + +from someone@testserver + +auth on +user someone@testserver +password password222 + diff --git a/test/t-13-reload/run.sh b/test/t-13-reload/run.sh new file mode 100755 index 0000000..203aaec --- /dev/null +++ b/test/t-13-reload/run.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e +. $(dirname ${0})/../util/lib.sh + +init + +generate_certs_for testserver + +# Start with the user with the wrong password, and no aliases. +add_user someone@testserver password111 +rm -f config/domains/testserver/aliases + +mkdir -p .logs +chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config \ + --testing__reload_every=50ms & +wait_until_ready 1025 + +# First, check that delivery fails with the "wrong" password. +if run_msmtp someone@testserver < content 2>/dev/null; then + fail "success using the wrong password" +fi + +# Change password, add an alias; then wait a bit more than the reload period +# and try again. +add_user someone@testserver password222 +echo "analias: someone" > config/domains/testserver/aliases +sleep 0.2 + +run_msmtp analias@testserver < content +wait_for_file .mail/someone@testserver + +success