Bootstrap secrets for shared configuration acquisition
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
"go.maximumdirect.net/ckprompt"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
@@ -230,3 +232,38 @@ func TestRequestDefaultsRespectNamespaceAndCallerVariables(t *testing.T) {
|
||||
t.Fatalf("generic request changed: %v", result.Vars)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationBootstrapReportsAndPreservesFailure(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
secrets := filepath.Join(dir, "secrets")
|
||||
if err := os.Mkdir(secrets, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("AUDITA_BOOTSTRAP_TEST", "prior")
|
||||
if err := os.WriteFile(filepath.Join(secrets, "AUDITA_BOOTSTRAP_TEST"), []byte("synthetic-secret"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
main := filepath.Join(dir, "config.yml")
|
||||
if err := os.WriteFile(main, []byte("version: 3\nconfig:\n secrets_dir: secrets\n secrets_overwrite: true\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app, err := buildApplication()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out, stderr bytes.Buffer
|
||||
result := app.Execute(context.Background(), []string{"config", "show", "--scope", "app", "--config", main, "--verbose"}, commandkit.Streams{Out: &out, Err: &stderr})
|
||||
if result.Status != 0 || os.Getenv("AUDITA_BOOTSTRAP_TEST") != "synthetic-secret" || !strings.Contains(stderr.String(), "AUDITA_BOOTSTRAP_TEST") || strings.Contains(stderr.String(), "synthetic-secret") {
|
||||
t.Fatalf("status=%d stdout=%q stderr=%q", result.Status, out.String(), stderr.String())
|
||||
}
|
||||
if err := os.WriteFile(main, []byte("version: 3\nconfig:\n secrets_dir: missing\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out.Reset()
|
||||
stderr.Reset()
|
||||
result = app.Execute(context.Background(), []string{"config", "show", "--scope", "app", "--config", main, "--quiet"}, commandkit.Streams{Out: &out, Err: &stderr})
|
||||
var native *ck.SecretsError
|
||||
if result.Status != 1 || !errors.As(result.Cause, &native) || !strings.Contains(stderr.String(), "secrets.") || strings.Contains(stderr.String(), "synthetic-secret") {
|
||||
t.Fatalf("status=%d cause=%v stdout=%q stderr=%q", result.Status, result.Cause, out.String(), stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user