Validate explanation pointers before loading configuration
This commit is contained in:
@@ -75,6 +75,11 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
||||
return 2
|
||||
}
|
||||
pointer := fs.Arg(0)
|
||||
parsed, err := configkit.ParsePath(pointer)
|
||||
if err != nil || parsed.String() != pointer {
|
||||
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
|
||||
return 2
|
||||
}
|
||||
if *scope == "promptkit" {
|
||||
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||
if err != nil {
|
||||
@@ -101,11 +106,6 @@ func runConfigExplain(args []string, stdout, stderr io.Writer, opts Options) int
|
||||
}
|
||||
return 0
|
||||
}
|
||||
parsed, err := configkit.ParsePath(pointer)
|
||||
if err != nil || parsed.String() != pointer {
|
||||
fmt.Fprintf(stderr, "notarius: %q is not a canonical JSON Pointer\n", pointer)
|
||||
return 2
|
||||
}
|
||||
loaded, _, err := loadConfigKit(*configPath, *overlay, nil, opts)
|
||||
if err != nil {
|
||||
writeConfigLoadError(stderr, err)
|
||||
|
||||
@@ -15,6 +15,23 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestExplainRejectsMalformedPointerBeforeLoadingEitherScope(t *testing.T) {
|
||||
for _, scope := range []string{"notarius", "promptkit"} {
|
||||
t.Run(scope, func(t *testing.T) {
|
||||
var stdout, stderr strings.Builder
|
||||
options := commandContractOptions(t)
|
||||
options.LookupEnv = func(string) (string, bool) {
|
||||
t.Fatal("configuration discovery ran for invalid syntax")
|
||||
return "", false
|
||||
}
|
||||
code := RunWithOptions([]string{"config", "explain", "--scope", scope, "--config", filepath.Join(t.TempDir(), "missing.yml"), "/profiles/~2"}, &stdout, &stderr, options)
|
||||
if code != 2 || stdout.Len() != 0 || !strings.Contains(stderr.String(), "canonical JSON Pointer") {
|
||||
t.Fatalf("code=%d stdout=%q stderr=%q", code, stdout.String(), stderr.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigKitReadOnlyCommandsLoadImportsAndOverlays(t *testing.T) {
|
||||
t.Parallel()
|
||||
root := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user