summaryrefslogtreecommitdiff
diff options
authorMichael Vogt <mvo@ubuntu.com>2017-08-17 11:03:58 +0200
committerMichael Vogt <mvo@ubuntu.com>2017-08-17 11:05:26 +0200
commite1b4544854bed19499a1e5d36cd0a159dcc9b6e3 (patch)
treeff864b628d9446b5d7b0b69b951db13614a64e8f
parentd7853c0a5d8b881ee8dc1a72788e59e63ad12675 (diff)
Error if updateKeyValueStream tries to set a unsupported config
The updateKeyValueStream has a concept of the known configuration options (via allConfig). If the user tries to modify a config option that is not part of "allConfig" error.
-rw-r--r--corecfg/picfg_test.go10
-rw-r--r--corecfg/proxy.go6
-rw-r--r--corecfg/utils.go4
-rw-r--r--corecfg/utils_test.go13
4 files changed, 22 insertions, 11 deletions
diff --git a/corecfg/picfg_test.go b/corecfg/picfg_test.go
index 5689c1e79a..4ca3e13263 100644
--- a/corecfg/picfg_test.go
+++ b/corecfg/picfg_test.go
@@ -43,9 +43,7 @@ var _ = Suite(&piCfgSuite{})
var mockConfigTxt = `
# For more options and information see
# http://www.raspberrypi.org/documentation/configuration/config-txt.md
-# Some settings may impact device functionality. See link above for details
-# uncomment if you get no picture on HDMI for a default "safe" mode
-#hdmi_safe=1
+#hdmi_group=1
# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1
@@ -115,7 +113,7 @@ func (s *piCfgSuite) TestConfigurePiConfigNoChangeUnset(c *C) {
c.Assert(err, IsNil)
defer os.Chmod(filepath.Dir(s.mockConfigPath), 0755)
- err = corecfg.UpdatePiConfig(s.mockConfigPath, map[string]string{"hdmi_safe": ""})
+ err = corecfg.UpdatePiConfig(s.mockConfigPath, map[string]string{"hdmi_group": ""})
c.Assert(err, IsNil)
}
@@ -126,8 +124,8 @@ func (s *piCfgSuite) TestConfigurePiConfigNoChangeSet(c *C) {
c.Assert(err, IsNil)
defer os.Chmod(filepath.Dir(s.mockConfigPath), 0755)
- err = corecfg.UpdatePiConfig(s.mockConfigPath, map[string]string{"unrelated_options": "are-kept"})
- c.Assert(err, IsNil)
+ err = corecfg.UpdatePiConfig(s.mockConfigPath, map[string]string{"unrelated_options": "cannot-be-set"})
+ c.Assert(err, ErrorMatches, `cannot set unsupported configuration value "unrelated_options"`)
}
func (s *piCfgSuite) TestConfigurePiConfigIntegration(c *C) {
diff --git a/corecfg/proxy.go b/corecfg/proxy.go
index af84976686..a9123cd566 100644
--- a/corecfg/proxy.go
+++ b/corecfg/proxy.go
@@ -29,9 +29,9 @@ import (
)
var proxyConfigKeys = map[string]bool{
- "http": true,
- "https": true,
- "ftp": true,
+ "http_proxy": true,
+ "https_proxy": true,
+ "ftp_proxy": true,
}
func etcEnvironment() string {
diff --git a/corecfg/utils.go b/corecfg/utils.go
index fb1758365a..f6018b75b9 100644
--- a/corecfg/utils.go
+++ b/corecfg/utils.go
@@ -37,10 +37,12 @@ var rx = regexp.MustCompile(`^[ \t]*(#?)[ \t#]*([a-z_]+)=(.*)$`)
// the "config" input is applied. If changes need to be written a []string
// that contains the full file is returned. On error an error is returned.
func updateKeyValueStream(r io.Reader, allConfig map[string]bool, newConfig map[string]string) (toWrite []string, err error) {
- // build regexp
cfgKeys := make([]string, len(newConfig))
i := 0
for k := range newConfig {
+ if !allConfig[k] {
+ return nil, fmt.Errorf("cannot set unsupported configuration value %q", k)
+ }
cfgKeys[i] = k
i++
}
diff --git a/corecfg/utils_test.go b/corecfg/utils_test.go
index 578225e1a5..e13a8eaf0f 100644
--- a/corecfg/utils_test.go
+++ b/corecfg/utils_test.go
@@ -31,7 +31,7 @@ type utilsSuite struct{}
var _ = Suite(&utilsSuite{})
-func (s *utilsSuite) TestUpdateKeyValueStreamNoChanges(c *C) {
+func (s *utilsSuite) TestUpdateKeyValueStreamNoNewConfig(c *C) {
in := bytes.NewBufferString("foo=bar")
newConfig := map[string]string{}
allConfig := map[string]bool{}
@@ -41,6 +41,17 @@ func (s *utilsSuite) TestUpdateKeyValueStreamNoChanges(c *C) {
c.Check(toWrite, IsNil)
}
+func (s *utilsSuite) TestUpdateKeyValueStreamConfigNotInAllConfig(c *C) {
+ in := bytes.NewBufferString("")
+ newConfig := map[string]string{"unsupported-options": "cannot be set"}
+ allConfig := map[string]bool{
+ "foo": true,
+ }
+
+ _, err := corecfg.UpdateKeyValueStream(in, allConfig, newConfig)
+ c.Check(err, ErrorMatches, `cannot set unsupported configuration value \"unsupported-options"`)
+}
+
func (s *utilsSuite) TestUpdateKeyValueStreamOneChange(c *C) {
in := bytes.NewBufferString("foo=bar")
newConfig := map[string]string{"foo": "baz"}