Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit a72f710

Browse files
committed
configs: check that config doesn't contain extra fields
Signed-off-by: Andrey Vagin <[email protected]>
1 parent f78bf21 commit a72f710

File tree

7 files changed

+30
-7
lines changed

7 files changed

+30
-7
lines changed

Diff for: configs/config_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package configs
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"os"
67
"path/filepath"
78
"testing"
@@ -43,6 +44,34 @@ func loadConfig(name string) (*Config, error) {
4344
return nil, err
4445
}
4546

47+
// Check that a config doesn't contain extra fields
48+
var configMap, abstractMap map[string]interface{}
49+
50+
if _, err := f.Seek(0, 0); err != nil {
51+
return nil, err
52+
}
53+
54+
if err := json.NewDecoder(f).Decode(&abstractMap); err != nil {
55+
return nil, err
56+
}
57+
58+
configData, err := json.Marshal(&container)
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
if err := json.Unmarshal(configData, &configMap); err != nil {
64+
return nil, err
65+
}
66+
67+
for k := range configMap {
68+
delete(abstractMap, k)
69+
}
70+
71+
if len(abstractMap) != 0 {
72+
return nil, fmt.Errorf("unknown fields: %s", abstractMap)
73+
}
74+
4675
return container, nil
4776
}
4877

Diff for: sample_configs/apparmor.json

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "",
106106
"hostname": "nsinit",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",

Diff for: sample_configs/attach_to_bridge.json

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "",
106106
"hostname": "koye",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",

Diff for: sample_configs/host-pid.json

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "",
106106
"hostname": "nsinit",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",

Diff for: sample_configs/minimal.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "",
106106
"hostname": "nsinit",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",
@@ -338,4 +337,4 @@
338337
"/proc/irq",
339338
"/proc/bus"
340339
]
341-
}
340+
}

Diff for: sample_configs/selinux.json

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "system_u:system_r:svirt_lxc_net_t:s0:c164,c475",
106106
"hostname": "nsinit",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",

Diff for: sample_configs/userns.json

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
],
105105
"mount_label": "",
106106
"hostname": "nsinit",
107-
"console": "",
108107
"namespaces": [
109108
{
110109
"type": "NEWNS",

0 commit comments

Comments
 (0)