ReplayPlan two-person apply already required digest match; this pins the missing ApprovalRef negative so dry-run tickets cannot skip the ticket field. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package events
|
|
|
|
import "testing"
|
|
|
|
func TestAuthorizeReplayDryRunRequiresScope(t *testing.T) {
|
|
if err := AuthorizeReplayPlan(ReplayPlan{DryRun: true, Operator: "ops", Reason: "fix", Consumer: ConsumerNotify}); err != ErrReplayScope {
|
|
t.Fatalf("%v", err)
|
|
}
|
|
}
|
|
|
|
func TestApplyReplayRequiresMatchingDigestAndTwoPerson(t *testing.T) {
|
|
p := ReplayPlan{
|
|
PlanID: "p1", Operator: "ops", Approver: "sec", Environment: "dev",
|
|
ProjectID: 9, Consumer: ConsumerNotify, EventIDs: []string{"e1"},
|
|
Reason: "repair", ApprovalRef: "ticket-1", DryRun: true,
|
|
}
|
|
digest := p.Digest()
|
|
p.DryRun = false
|
|
if err := ApplyReplay(p, digest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p.Approver = p.Operator
|
|
if err := ApplyReplay(p, digest); err == nil {
|
|
t.Fatal("same operator/approver must fail")
|
|
}
|
|
p.Approver = "sec"
|
|
if err := ApplyReplay(p, "deadbeef"); err == nil {
|
|
t.Fatal("digest mismatch must fail")
|
|
}
|
|
p.ApprovalRef = ""
|
|
if err := ApplyReplay(p, digest); err == nil {
|
|
t.Fatal("apply without approval ref must fail")
|
|
}
|
|
}
|
|
|
|
func TestLegacyAuthorizeReplayStillDryRunOnly(t *testing.T) {
|
|
if err := AuthorizeReplay(ReplayRequest{DryRun: false, Consumer: "x", Operator: "o", Reason: "r"}); err != ErrReplayScope {
|
|
t.Fatalf("%v", err)
|
|
}
|
|
}
|