Demonstrate source-aware path normalization
This commit is contained in:
@@ -18,6 +18,16 @@ type secretReferenceConfig struct {
|
||||
Sequence []Secret `yaml:"sequence"`
|
||||
}
|
||||
|
||||
type resolutionQueryReader struct {
|
||||
input *strings.Reader
|
||||
reads int
|
||||
}
|
||||
|
||||
func (reader *resolutionQueryReader) Read(data []byte) (int, error) {
|
||||
reader.reads++
|
||||
return reader.input.Read(data)
|
||||
}
|
||||
|
||||
func TestSecretReferencesResolveTypedShapesOncePerName(t *testing.T) {
|
||||
input := `required: SHARED_SECRET
|
||||
optional: OPTIONAL_SECRET
|
||||
@@ -152,6 +162,50 @@ func TestResolutionSelectsEffectiveSecretNameBeforeLookup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolutionInputQueriesDoNotReadOrResolveSecrets(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type config struct {
|
||||
Value string `yaml:"value"`
|
||||
Secret Secret `yaml:"secret"`
|
||||
}
|
||||
reader := &resolutionQueryReader{input: strings.NewReader("value: source\nsecret: QUERY_SECRET\n")}
|
||||
lookups := 0
|
||||
var callbackErr error
|
||||
result, err := loadWithSecretLookup(Reader("query.yml", reader), func(name string) (string, bool) {
|
||||
lookups++
|
||||
if name != "QUERY_SECRET" {
|
||||
t.Fatalf("secret lookup name = %q", name)
|
||||
}
|
||||
return "query-credential", true
|
||||
}, Options[config]{Definition: Definition[config]{Resolve: func(_ *config, resolution *Resolution) error {
|
||||
reads := reader.reads
|
||||
value, valueFound := resolution.InputInfo(Keys("value"))
|
||||
secret, secretFound := resolution.InputInfo(Keys("secret"))
|
||||
if !valueFound || !secretFound || len(value.Origin.Locations) != 1 || len(secret.Origin.Locations) != 1 {
|
||||
callbackErr = errors.New("entry metadata is incomplete")
|
||||
return callbackErr
|
||||
}
|
||||
if source, found := resolution.Source(value.Origin.Locations[0].SourceID); !found || source.Path != "" {
|
||||
callbackErr = errors.New("entry source is incomplete")
|
||||
return callbackErr
|
||||
}
|
||||
if reader.reads != reads || lookups != 0 {
|
||||
callbackErr = errors.New("entry query performed input or credential access")
|
||||
}
|
||||
return callbackErr
|
||||
}}})
|
||||
if callbackErr != nil {
|
||||
t.Fatal(callbackErr)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if lookups != 1 || result.Config.Secret.Value() != "query-credential" {
|
||||
t.Fatalf("secret resolution = lookups %d config %#v", lookups, result.Config)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidationCannotReplaceResolvedSecretWithSameName(t *testing.T) {
|
||||
type config struct {
|
||||
Secret Secret `yaml:"secret"`
|
||||
|
||||
Reference in New Issue
Block a user