1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-01-08 04:03:58 +02:00

Return an error when unknown options are found in the config file

This commit is contained in:
Joel Speed 2020-04-29 19:45:26 +01:00
parent c5be09ca48
commit 00fed1a31f
No known key found for this signature in database
GPG Key ID: 6E80578D6751DEFB
2 changed files with 15 additions and 1 deletions

View File

@ -38,7 +38,9 @@ func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error
return fmt.Errorf("unable to register flags: %w", err)
}
err = v.Unmarshal(into, decodeFromCfgTag)
// UnmarhsalExact will return an error if the config includes options that are
// not mapped to felds of the into struct
err = v.UnmarshalExact(into, decodeFromCfgTag)
if err != nil {
return fmt.Errorf("error unmarshalling config: %w", err)
}

View File

@ -283,6 +283,18 @@ var _ = Describe("Load", func() {
unexported: "unexported",
},
}),
Entry("with an unknown option in the config file", &testOptionsTableInput{
configFile: []byte(`unknown_option="foo"`),
flagSet: func() *pflag.FlagSet { return testOptionsFlagSet },
expectedErr: fmt.Errorf("error unmarshalling config: 1 error(s) decoding:\n\n* '' has invalid keys: unknown_option"),
// Viper will unmarshal before returning the error, so this is the default output
expectedOutput: &TestOptions{
StringOption: "default",
Sub: TestOptionSubStruct{
StringSliceOption: []string{"a", "b"},
},
},
}),
)
})
})