Skip to content

Commit 0e204b7

Browse files
BattleRattlemholt
andauthored
admin: Respond with 4xx on non-existing config path (#5870)
Co-authored-by: Matt Holt <[email protected]>
1 parent fae195a commit 0e204b7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

admin.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,15 +1196,27 @@ traverseLoop:
11961196
}
11971197
case http.MethodPut:
11981198
if _, ok := v[part]; ok {
1199-
return fmt.Errorf("[%s] key already exists: %s", path, part)
1199+
return APIError{
1200+
HTTPStatus: http.StatusConflict,
1201+
Err: fmt.Errorf("[%s] key already exists: %s", path, part),
1202+
}
12001203
}
12011204
v[part] = val
12021205
case http.MethodPatch:
12031206
if _, ok := v[part]; !ok {
1204-
return fmt.Errorf("[%s] key does not exist: %s", path, part)
1207+
return APIError{
1208+
HTTPStatus: http.StatusNotFound,
1209+
Err: fmt.Errorf("[%s] key does not exist: %s", path, part),
1210+
}
12051211
}
12061212
v[part] = val
12071213
case http.MethodDelete:
1214+
if _, ok := v[part]; !ok {
1215+
return APIError{
1216+
HTTPStatus: http.StatusNotFound,
1217+
Err: fmt.Errorf("[%s] key does not exist: %s", path, part),
1218+
}
1219+
}
12081220
delete(v, part)
12091221
default:
12101222
return fmt.Errorf("unrecognized method %s", method)

admin_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func TestUnsyncedConfigAccess(t *testing.T) {
7575
path: "/bar/qq",
7676
expect: `{"foo": "jet", "bar": {"aa": "bb"}, "list": ["a", "b", "c"]}`,
7777
},
78+
{
79+
method: "DELETE",
80+
path: "/bar/qq",
81+
expect: `{"foo": "jet", "bar": {"aa": "bb"}, "list": ["a", "b", "c"]}`,
82+
shouldErr: true,
83+
},
7884
{
7985
method: "POST",
8086
path: "/list",

0 commit comments

Comments
 (0)