fix(nano): say that [server] listen is ignored instead of defaulting it
LoadNano filled in [server] listen = "0.0.0.0:8080" when it was unset, and a test pinned that value, but felis nano never reads it: it binds the -listen flag, which the installer sets from FELIS_NANO_LISTEN. An operator moving nano off loopback by writing [server] listen in its config got connection refused from the proxy and no hint that the key did nothing. LoadNano no longer sets the default, and nano prints a line naming the ignored value and the address it actually binds whenever the key is set. It is a warning rather than a load error so a full felis.toml copied onto a nano host keeps starting. The assertion that pinned the unused default is removed along with it. The new test runs cmdNano against a config that sets [server] listen and one that does not, with an unbindable -listen so it returns after loading. The first must warn and the second must not; with the old default restored, the second prints a warning about 0.0.0.0:8080.
This commit is contained in:
4 files changed
+34
-7
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -14,6 +16,32 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// [server] listen in a nano config reads like the bind address but is not one; nano must
|
||||
// say so. The -listen value cannot be bound, so cmdNano returns right after loading.
|
||||
func TestNanoWarnsThatServerListenIsIgnored(t *testing.T) {
|
||||
cfg := filepath.Join(t.TempDir(), "felis.toml")
|
||||
if err := os.WriteFile(cfg, []byte("[server]\nlisten = \"0.0.0.0:9999\"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stderr bytes.Buffer
|
||||
if rc := cmdNano([]string{"-config", cfg, "-listen", "127.0.0.1:-1"}, io.Discard, &stderr); rc != 1 {
|
||||
t.Fatalf("cmdNano = %d, want 1 from the unbindable -listen", rc)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), `listen = "0.0.0.0:9999" is ignored`) {
|
||||
t.Fatalf("stderr %q should say the configured listen is ignored", stderr.String())
|
||||
}
|
||||
|
||||
// With no [server] table at all there is nothing to warn about.
|
||||
if err := os.WriteFile(cfg, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stderr.Reset()
|
||||
_ = cmdNano([]string{"-config", cfg, "-listen", "127.0.0.1:-1"}, io.Discard, &stderr)
|
||||
if strings.Contains(stderr.String(), "is ignored") {
|
||||
t.Fatalf("stderr %q warns about a listen the operator never set", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
// A stop signal that lands while a login is waiting on an upstream must let that login
|
||||
// finish: the request is answered, and serveNano returns only afterwards.
|
||||
func TestNanoDrainsInFlightLoginOnShutdown(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user