Test CLI inheritance inspection and use
This commit is contained in:
@@ -73,6 +73,92 @@ func TestConfigCommandsExposeComposedSourcesAndResolvedValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCommandsInspectInheritedBackends(t *testing.T) {
|
||||
const keyName = "SCRIPTORIUM_INHERITANCE_TEST_API_KEY"
|
||||
const keyValue = "synthetic-inheritance-key-bytes"
|
||||
path := writeAppConfigFile(t, `backends:
|
||||
base:
|
||||
endpoint: http://127.0.0.1:1/v1
|
||||
api_key_env: SCRIPTORIUM_INHERITANCE_TEST_API_KEY
|
||||
concurrency_limit: 2
|
||||
queue_capacity: 4
|
||||
extra_params:
|
||||
enabled: true
|
||||
shared: visible-value
|
||||
child:
|
||||
extends: base
|
||||
queue_capacity: 0
|
||||
extra_params:
|
||||
enabled: false
|
||||
`)
|
||||
t.Setenv(keyName, keyValue)
|
||||
if err := os.Unsetenv(keyName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, stdout, stderr := runCLICommand(t, configCommand, []string{"validate", "--config", path})
|
||||
if code != ExitOK || stdout != "" || stderr != "" {
|
||||
t.Fatalf("config validate required credentials or an engine: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
if err := os.Setenv(keyName, keyValue); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
code, stdout, stderr = runCLICommand(t, configCommand, []string{"show", "--config", path})
|
||||
if code != ExitOK || stderr != "" || strings.Contains(stdout, keyValue) {
|
||||
t.Fatalf("config show failed or disclosed credential bytes: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
for _, fragment := range []string{
|
||||
"endpoint: http://127.0.0.1:1/v1",
|
||||
"api_key_env: SCRIPTORIUM_INHERITANCE_TEST_API_KEY",
|
||||
"shared: visible-value",
|
||||
"enabled: false",
|
||||
"queue_capacity: 0",
|
||||
} {
|
||||
if !strings.Contains(stdout, fragment) {
|
||||
t.Fatalf("config show omitted %q: %s", fragment, stdout)
|
||||
}
|
||||
}
|
||||
if strings.Contains(stdout, "extends:") {
|
||||
t.Fatalf("config show exposed the structural directive: %s", stdout)
|
||||
}
|
||||
|
||||
code, stdout, stderr = runCLICommand(t, configCommand, []string{"explain", "--path", "/backends/child/endpoint", "--config", path})
|
||||
if code != ExitOK || stderr != "" || strings.Contains(stdout, keyValue) {
|
||||
t.Fatalf("endpoint explanation failed or disclosed credential bytes: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
for _, fragment := range []string{"/backends/base/endpoint", "/backends/child/endpoint", "/backends/child/extends", "http://127.0.0.1:1/v1"} {
|
||||
if !strings.Contains(stdout, fragment) {
|
||||
t.Fatalf("endpoint explanation omitted %q: %s", fragment, stdout)
|
||||
}
|
||||
}
|
||||
code, stdout, stderr = runCLICommand(t, configCommand, []string{"explain", "--path", "/backends/child/extra_params/enabled", "--config", path})
|
||||
if code != ExitOK || stderr != "" || !strings.Contains(stdout, "true") || !strings.Contains(stdout, "false") || strings.Contains(stdout, keyValue) {
|
||||
t.Fatalf("parameter explanation lost history or exposed credential bytes: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
|
||||
code, stdout, stderr = runCLICommand(t, configCommand, []string{"sources", "--config", path})
|
||||
if code != ExitOK || stderr != "" || strings.Contains(stdout, keyValue) {
|
||||
t.Fatalf("config sources failed: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
var sources []configurationSource
|
||||
if err := json.Unmarshal([]byte(stdout), &sources); err != nil || len(sources) != 1 || sources[0].Layer != "base" {
|
||||
t.Fatalf("inheritance fabricated a source record: %+v (%v)", sources, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigValidateRendersReservedInheritanceFailure(t *testing.T) {
|
||||
path := writeAppConfigFile(t, `backends:
|
||||
worker:
|
||||
endpoint: http://127.0.0.1:1/v1
|
||||
extra_params:
|
||||
extends: missing
|
||||
`)
|
||||
code, stdout, stderr := runCLICommand(t, configCommand, []string{"validate", "--config", path})
|
||||
if code != ExitRuntimeError || stdout != "" || !strings.Contains(stderr, "inheritance.missing") || !strings.Contains(stderr, "/backends/worker/extra_params/extends") {
|
||||
t.Fatalf("reserved inheritance failure was not safely reported: code=%d out=%q err=%q", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigInspectionKeepsReferencesAndOrdinaryParameters(t *testing.T) {
|
||||
const name = "SCRIPTORIUM_CONFIG_TEST_API_KEY"
|
||||
const secret = "synthetic-secret-value-should-not-appear"
|
||||
|
||||
Reference in New Issue
Block a user