fix: harden platform audit coverage

This commit is contained in:
2026-07-27 11:13:55 +08:00
parent 48fc80b003
commit 0ba4136e1a
7 changed files with 125 additions and 13 deletions

View File

@@ -24,8 +24,11 @@ func TestEveryContractHasRegisteredRoute(t *testing.T) {
case platform.ReadOnly:
assertRouteMethods(t, routes, path, http.MethodGet)
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet)
assertNoRouteMethods(t, routes, path, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
assertNoRouteMethods(t, routes, path+"/:identity", http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
case platform.AppendOnly:
assertRouteMethods(t, routes, path, http.MethodPost)
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertNoRouteMethods(t, routes, path, http.MethodPut, http.MethodPatch, http.MethodDelete)
default:
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPut, http.MethodDelete)
@@ -169,3 +172,12 @@ func assertRouteMethods(t *testing.T, routes map[string]map[string]bool, path st
}
}
}
func assertNoRouteMethods(t *testing.T, routes map[string]map[string]bool, path string, methods ...string) {
t.Helper()
for _, method := range methods {
if routes[path][method] {
t.Errorf("route %s %s must not be registered", method, path)
}
}
}