From d577d66fb91caea0bb3ea1d28ee4bc6250216570 Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 28 Sep 2026 13:18:04 +0000 Subject: [PATCH] test: an unknown PIXA_ environment variable aborts startup (closes #133) Tests, written before the change: a PIXA_ variable that is not a setting's variable aborts startup naming it, and PIXA_PORT aborts with a message saying to use PORT. Both fail until the change lands. The test that sets every setting's variable now also sets PIXA_CONFIG_PATH, so it shows that none of those names is rejected. Model: opus-5-5 --- internal/config/env_internal_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/config/env_internal_test.go b/internal/config/env_internal_test.go index ea1e361..11b7d82 100644 --- a/internal/config/env_internal_test.go +++ b/internal/config/env_internal_test.go @@ -49,7 +49,10 @@ func wantStartupError(t *testing.T, err error, wants ...string) { // TestEnvironmentSetsEveryKey sets every key from its environment // variable, with no config file at all: PORT for the port, and PIXA_ // plus the key in upper case, "." written as "_", for every other key. +// It also sets PIXA_CONFIG_PATH, so it shows that none of these PIXA_ +// names is rejected as unknown. func TestEnvironmentSetsEveryKey(t *testing.T) { + t.Setenv("PIXA_CONFIG_PATH", "/etc/pixa/config.yml") t.Setenv("PIXA_DEBUG", "true") t.Setenv("PIXA_MAINTENANCE_MODE", "1") t.Setenv("PORT", "9090") @@ -95,6 +98,26 @@ func TestEnvironmentSetsEveryKey(t *testing.T) { } } +// TestUnknownPixaVariableAbortsStartup checks that a PIXA_ variable that +// is not a setting's variable, such as a misspelled one, aborts startup +// naming it, as an unknown config key does, instead of being ignored. +func TestUnknownPixaVariableAbortsStartup(t *testing.T) { + t.Setenv("PIXA_TRUSTED_PROXY", "192.0.2.0/24") + t.Setenv("PIXA_SIGNINGKEY", validTestSigningKey) + + _, err := configFromYAML(t, signingKeyLine) + wantStartupError(t, err, "PIXA_TRUSTED_PROXY", "PIXA_SIGNINGKEY") +} + +// TestPixaPortAbortsStartupPointingToPort checks that PIXA_PORT aborts +// startup with a message saying to use PORT, which sets the port. +func TestPixaPortAbortsStartupPointingToPort(t *testing.T) { + t.Setenv("PIXA_PORT", "9090") + + _, err := configFromYAML(t, signingKeyLine) + wantStartupError(t, err, "PIXA_PORT", "use PORT") +} + // TestPortFromEnvironmentOverridesConfigFile checks that PORT wins over // the port in the config file. func TestPortFromEnvironmentOverridesConfigFile(t *testing.T) {