删除无用文件
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateRecordRequiresDangerousOperationsToCarryReviewID(t *testing.T) {
|
||||
record := Record{
|
||||
SourceService: "alert",
|
||||
ActorID: "u-1",
|
||||
Action: "policy.update",
|
||||
ObjectType: "notification_policy",
|
||||
ObjectID: "np-1",
|
||||
OperationRisk: RiskDangerous,
|
||||
}
|
||||
|
||||
if err := ValidateRecord(record); err == nil {
|
||||
t.Fatal("expected dangerous operation without approval id to fail")
|
||||
}
|
||||
|
||||
record.ApprovalID = "apr-1"
|
||||
if err := ValidateRecord(record); err != nil {
|
||||
t.Fatalf("expected valid dangerous audit record, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRecordClassifiesDangerousActions(t *testing.T) {
|
||||
record := NormalizeRecord(Record{
|
||||
SourceService: " alert ",
|
||||
Action: "notification_policy.update",
|
||||
ObjectType: " notification_policy ",
|
||||
ObjectID: " np-1 ",
|
||||
ActorID: " u-1 ",
|
||||
})
|
||||
|
||||
if record.SourceService != "alert" || record.ObjectType != "notification_policy" || record.ObjectID != "np-1" {
|
||||
t.Fatalf("record was not normalized: %#v", record)
|
||||
}
|
||||
if record.OperationRisk != RiskDangerous {
|
||||
t.Fatalf("notification policy changes must be dangerous, got %q", record.OperationRisk)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApprovalTransitionAllowsApproveOnlyFromPending(t *testing.T) {
|
||||
req := ApprovalRequest{Status: ApprovalPending}
|
||||
|
||||
approved, err := Transition(req, ApprovalApproved, "reviewer-1", "ok")
|
||||
if err != nil {
|
||||
t.Fatalf("expected pending approval to approve: %v", err)
|
||||
}
|
||||
if approved.Status != ApprovalApproved {
|
||||
t.Fatalf("unexpected status: %s", approved.Status)
|
||||
}
|
||||
if approved.ReviewerID != "reviewer-1" || approved.ReviewComment != "ok" {
|
||||
t.Fatalf("review metadata not stored: %#v", approved)
|
||||
}
|
||||
|
||||
if _, err := Transition(approved, ApprovalRejected, "reviewer-2", "late"); err == nil {
|
||||
t.Fatal("expected approved request to reject further transition")
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/ops/logs/internal/config"
|
||||
)
|
||||
|
||||
func TestValidateResourceEventRequest(t *testing.T) {
|
||||
req := &resourceEventRequest{
|
||||
EventID: "evt-1",
|
||||
EventTime: "2026-04-27T08:00:00Z",
|
||||
EventType: resourceEventUpsert,
|
||||
ResourceType: "server",
|
||||
ResourceID: "srv-1",
|
||||
ResourceName: "server-1",
|
||||
Version: 1,
|
||||
}
|
||||
if _, err := validateResourceEventRequest(req); err != nil {
|
||||
t.Fatalf("expected valid request, got error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateResourceEventRequestInvalidTime(t *testing.T) {
|
||||
req := &resourceEventRequest{
|
||||
EventID: "evt-1",
|
||||
EventTime: "bad-time",
|
||||
EventType: resourceEventUpsert,
|
||||
ResourceType: "server",
|
||||
ResourceID: "srv-1",
|
||||
Version: 1,
|
||||
}
|
||||
if _, err := validateResourceEventRequest(req); err == nil {
|
||||
t.Fatal("expected invalid time error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonEmptyUnique(t *testing.T) {
|
||||
got := nonEmptyUnique([]string{" 10.0.0.1 ", "", "10.0.0.1", "host-a", "host-a"})
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("unexpected unique size: %d", len(got))
|
||||
}
|
||||
if got[0] != "10.0.0.1" || got[1] != "host-a" {
|
||||
t.Fatalf("unexpected output: %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyResourceEventSignature(t *testing.T) {
|
||||
old := config.Spec.ResourceEvent.HMACSecret
|
||||
config.Spec.ResourceEvent.HMACSecret = "abc123"
|
||||
defer func() {
|
||||
config.Spec.ResourceEvent.HMACSecret = old
|
||||
}()
|
||||
|
||||
body := []byte(`{"event_id":"evt-1"}`)
|
||||
mac := hmac.New(sha256.New, []byte("abc123"))
|
||||
mac.Write(body)
|
||||
signature := fmt.Sprintf("%x", mac.Sum(nil))
|
||||
if err := verifyResourceEventSignature(signature, body); err != nil {
|
||||
t.Fatalf("expected signature to pass: %v", err)
|
||||
}
|
||||
if err := verifyResourceEventSignature("bad", body); err == nil {
|
||||
t.Fatal("expected invalid signature error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateEventTimeSkew(t *testing.T) {
|
||||
old := config.Spec.ResourceEvent.MaxSkewSecs
|
||||
config.Spec.ResourceEvent.MaxSkewSecs = 60
|
||||
defer func() {
|
||||
config.Spec.ResourceEvent.MaxSkewSecs = old
|
||||
}()
|
||||
|
||||
if err := validateEventTimeSkew(time.Now()); err != nil {
|
||||
t.Fatalf("expected current time to pass: %v", err)
|
||||
}
|
||||
if err := validateEventTimeSkew(time.Now().Add(-2 * time.Minute)); err == nil {
|
||||
t.Fatal("expected skew validation to fail for old timestamp")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user