Skip to content

Commit

Permalink
Prevent any API requests on accounts that are in deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Oct 29, 2024
1 parent f6b5ffc commit f1751d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/api/keppel/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ func TestAccountsAPI(t *testing.T) {
},
}.Check(t, h)

status := http.StatusOK
var body assert.HTTPResponseBody
body = assert.JSONObject{
"account": accountExpect,
}
if isDeleting {
status = http.StatusConflict
body = assert.StringData("account is deleting\n")
}

assert.HTTPRequest{
Method: "GET",
Path: "/keppel/v1/accounts/second",
Expand Down Expand Up @@ -1885,9 +1895,9 @@ func TestDeleteAccount(t *testing.T) {
assert.HTTPRequest{
Method: "DELETE",
Path: "/keppel/v1/accounts/test1",
Header: map[string]string{"X-Test-Perms": "view:tenant1,change:tenant1"},
ExpectStatus: http.StatusConflict,
ExpectBody: assert.StringData("account is deleting\n"),
"error": "account is already set to be deleted",
},
}.Check(t, h)

// that didn't touch the DB
Expand Down
4 changes: 4 additions & 0 deletions internal/api/keppel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func (a *API) findAccountFromRequest(w http.ResponseWriter, r *http.Request, _ *
http.Error(w, "account not found", http.StatusNotFound)
return nil
}
if account.IsDeleting {
http.Error(w, "account is deleting", http.StatusConflict)
return nil
}
return account
}

Expand Down

0 comments on commit f1751d8

Please sign in to comment.