test: prohibit legacy safe and audit aliases
This commit is contained in:
@@ -38,6 +38,13 @@ func TestSafeAndAuditResourceContracts(t *testing.T) {
|
||||
assertContract(t, ExpectedResources(), "audit", "audit_operation_log", ReadOnly, "list")
|
||||
assertContract(t, ExpectedResources(), "audit", "audit_export_log", ReadOnly, "list")
|
||||
assertContract(t, ExpectedResources(), "audit", "audit_approval", ReadOnly, "list")
|
||||
|
||||
for _, contract := range ExpectedResources() {
|
||||
if (contract.Domain == "safety" && strings.HasPrefix(contract.Name, "saf_")) ||
|
||||
(contract.Domain == "audit" && strings.HasPrefix(contract.Name, "aud_")) {
|
||||
t.Fatalf("legacy resource contract %s/%s must not be registered", contract.Domain, contract.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceDefinitionAllowsOnlySupportedMethods(t *testing.T) {
|
||||
|
||||
@@ -127,10 +127,18 @@ func TestPlatformDeviceSafetyCommerceAndDeliveryRoutesFollowTheirContracts(t *te
|
||||
}
|
||||
|
||||
disposal := "/heqi/platform/v1/safety/safe_event/:identity/disposals"
|
||||
assertRouteMethods(t, routes, disposal, http.MethodPost)
|
||||
assertRouteMethods(t, routes, disposal, http.MethodGet, http.MethodPost)
|
||||
if routes[disposal][http.MethodDelete] {
|
||||
t.Fatal("safety event disposals must be append-only")
|
||||
}
|
||||
|
||||
for _, resource := range []string{"/safety/saf_rule", "/safety/saf_event", "/safety/saf_inspection"} {
|
||||
path := "/heqi/platform/v1" + resource
|
||||
assertNoRouteMethods(t, routes, path, http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
assertNoRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
assertNoRouteMethods(t, routes, path+"/:identity/status", http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
}
|
||||
assertNoRouteMethods(t, routes, "/heqi/platform/v1/safety/saf_event/:identity/disposals", http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
}
|
||||
|
||||
func TestPlatformFinanceContentAndAuditRoutesFollowTheirContracts(t *testing.T) {
|
||||
@@ -170,6 +178,13 @@ func TestPlatformFinanceContentAndAuditRoutesFollowTheirContracts(t *testing.T)
|
||||
}
|
||||
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1/audit/audit_approval/:identity/approve", http.MethodPost)
|
||||
|
||||
for _, resource := range []string{"/audit/aud_operation_log", "/audit/aud_export_log", "/audit/aud_approval"} {
|
||||
path := "/heqi/platform/v1" + resource
|
||||
assertNoRouteMethods(t, routes, path, http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
assertNoRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
}
|
||||
assertNoRouteMethods(t, routes, "/heqi/platform/v1/audit/aud_approval/:identity/approve", http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)
|
||||
}
|
||||
|
||||
func assertRouteMethods(t *testing.T, routes map[string]map[string]bool, path string, methods ...string) {
|
||||
|
||||
Reference in New Issue
Block a user