diff --git a/configs/config_test.go b/configs/config_test.go index 2fc0513f1..765d5e50d 100644 --- a/configs/config_test.go +++ b/configs/config_test.go @@ -2,6 +2,7 @@ package configs import ( "encoding/json" + "fmt" "os" "path/filepath" "testing" @@ -43,6 +44,34 @@ func loadConfig(name string) (*Config, error) { return nil, err } + // Check that a config doesn't contain extra fields + var configMap, abstractMap map[string]interface{} + + if _, err := f.Seek(0, 0); err != nil { + return nil, err + } + + if err := json.NewDecoder(f).Decode(&abstractMap); err != nil { + return nil, err + } + + configData, err := json.Marshal(&container) + if err != nil { + return nil, err + } + + if err := json.Unmarshal(configData, &configMap); err != nil { + return nil, err + } + + for k := range configMap { + delete(abstractMap, k) + } + + if len(abstractMap) != 0 { + return nil, fmt.Errorf("unknown fields: %s", abstractMap) + } + return container, nil } diff --git a/sample_configs/apparmor.json b/sample_configs/apparmor.json index b8860bbbb..843c2c61e 100644 --- a/sample_configs/apparmor.json +++ b/sample_configs/apparmor.json @@ -104,7 +104,6 @@ ], "mount_label": "", "hostname": "nsinit", - "console": "", "namespaces": [ { "type": "NEWNS", diff --git a/sample_configs/attach_to_bridge.json b/sample_configs/attach_to_bridge.json index a2b8738b2..11335b25f 100644 --- a/sample_configs/attach_to_bridge.json +++ b/sample_configs/attach_to_bridge.json @@ -104,7 +104,6 @@ ], "mount_label": "", "hostname": "koye", - "console": "", "namespaces": [ { "type": "NEWNS", diff --git a/sample_configs/host-pid.json b/sample_configs/host-pid.json index b5eb89bc7..bf4615044 100644 --- a/sample_configs/host-pid.json +++ b/sample_configs/host-pid.json @@ -104,7 +104,6 @@ ], "mount_label": "", "hostname": "nsinit", - "console": "", "namespaces": [ { "type": "NEWNS", diff --git a/sample_configs/minimal.json b/sample_configs/minimal.json index b936ebdf1..c2f741095 100644 --- a/sample_configs/minimal.json +++ b/sample_configs/minimal.json @@ -104,7 +104,6 @@ ], "mount_label": "", "hostname": "nsinit", - "console": "", "namespaces": [ { "type": "NEWNS", @@ -338,4 +337,4 @@ "/proc/irq", "/proc/bus" ] -} \ No newline at end of file +} diff --git a/sample_configs/selinux.json b/sample_configs/selinux.json index 033d3be12..dddfdf144 100644 --- a/sample_configs/selinux.json +++ b/sample_configs/selinux.json @@ -104,7 +104,6 @@ ], "mount_label": "system_u:system_r:svirt_lxc_net_t:s0:c164,c475", "hostname": "nsinit", - "console": "", "namespaces": [ { "type": "NEWNS", diff --git a/sample_configs/userns.json b/sample_configs/userns.json index 0b0644fb8..2b1fb90b4 100644 --- a/sample_configs/userns.json +++ b/sample_configs/userns.json @@ -104,7 +104,6 @@ ], "mount_label": "", "hostname": "nsinit", - "console": "", "namespaces": [ { "type": "NEWNS",