MCPcopy Create free account
hub / github.com/github/gh-aw / TestComputeFirewallDiff_StatusChanges

Function TestComputeFirewallDiff_StatusChanges

pkg/cli/audit_diff_test.go:115–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

113}
114
115func TestComputeFirewallDiff_StatusChanges(t *testing.T) {
116 run1 := &FirewallAnalysis{
117 RequestsByDomain: map[string]DomainRequestStats{
118 "staging.api.com:443": {Allowed: 10, Blocked: 0},
119 "legacy.service.com:443": {Allowed: 0, Blocked: 5},
120 },
121 }
122 run2 := &FirewallAnalysis{
123 RequestsByDomain: map[string]DomainRequestStats{
124 "staging.api.com:443": {Allowed: 0, Blocked: 3},
125 "legacy.service.com:443": {Allowed: 7, Blocked: 0},
126 },
127 }
128
129 diff := computeFirewallDiff(100, 200, run1, run2)
130
131 assert.Len(t, diff.StatusChanges, 2, "Should have 2 status changes")
132
133 // legacy.service.com: denied → allowed (anomaly: previously denied, now allowed)
134 legacyEntry := findDiffEntry(diff.StatusChanges, "legacy.service.com:443")
135 require.NotNil(t, legacyEntry, "Should find legacy.service.com in status changes")
136 assert.Equal(t, "denied", legacyEntry.Run1Status, "Was denied in run 1")
137 assert.Equal(t, "allowed", legacyEntry.Run2Status, "Now allowed in run 2")
138 assert.True(t, legacyEntry.IsAnomaly, "Should be flagged as anomaly")
139 assert.Equal(t, "previously denied, now allowed", legacyEntry.AnomalyNote, "Anomaly note should explain the flip")
140
141 // staging.api.com: allowed → denied (anomaly)
142 stagingEntry := findDiffEntry(diff.StatusChanges, "staging.api.com:443")
143 require.NotNil(t, stagingEntry, "Should find staging.api.com in status changes")
144 assert.Equal(t, "allowed", stagingEntry.Run1Status, "Was allowed in run 1")
145 assert.Equal(t, "denied", stagingEntry.Run2Status, "Now denied in run 2")
146 assert.True(t, stagingEntry.IsAnomaly, "Should be flagged as anomaly")
147
148 assert.Equal(t, 2, diff.Summary.StatusChangeCount, "Summary should show 2 status changes")
149 assert.True(t, diff.Summary.HasAnomalies, "Should have anomalies")
150}
151
152func TestComputeFirewallDiff_VolumeChanges(t *testing.T) {
153 run1 := &FirewallAnalysis{

Callers

nothing calls this directly

Calls 2

computeFirewallDiffFunction · 0.85
findDiffEntryFunction · 0.85

Tested by

no test coverage detected