Skip to content

Commit

Permalink
Forbid delete method in readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrergeru committed Nov 15, 2023
1 parent 5f43be1 commit cea15c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/middleware/readonly_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ func ReadOnlyMiddleware(config *api.Config) func(next http.Handler) http.Handler
}

func isMutatingMethod(method string) bool {
return method == http.MethodPut || method == http.MethodPost || method == http.MethodPatch
return method == http.MethodPut ||
method == http.MethodPost ||
method == http.MethodPatch ||
method == http.MethodDelete
}
5 changes: 5 additions & 0 deletions api/middleware/readonly_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func TestReadonlyModeMiddleware(t *testing.T) {
Convey("Performing patch request", func() {
actual := PerformRequestWithReadonlyModeMiddleware(config, http.MethodPatch)

So(actual, ShouldEqual, http.StatusForbidden)
})
Convey("Performing delete request", func() {
actual := PerformRequestWithReadonlyModeMiddleware(config, http.MethodDelete)

So(actual, ShouldEqual, http.StatusForbidden)
})
})
Expand Down
2 changes: 1 addition & 1 deletion local/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ web:
is_plotting_available: true
is_plotting_default_on: true
is_subscription_to_all_tags_available: true
is_readonly_enabled: false
is_readonly_enabled: true
notification_history:
ttl: 48h
query_limit: 10000
Expand Down

0 comments on commit cea15c9

Please sign in to comment.