(t *testing.T)
| 211 | } |
| 212 | |
| 213 | func TestProtocolMatching(t *testing.T) { |
| 214 | rules := []PolicyRule{ |
| 215 | { |
| 216 | ID: "allow-https-only", |
| 217 | Order: 1, |
| 218 | Action: "allow", |
| 219 | ACLName: "https_domains", |
| 220 | Protocol: "https", |
| 221 | Domains: []string{".github.com"}, |
| 222 | }, |
| 223 | { |
| 224 | ID: "deny-all", |
| 225 | Order: 2, |
| 226 | Action: "deny", |
| 227 | ACLName: "all", |
| 228 | Protocol: "both", |
| 229 | Domains: []string{}, |
| 230 | }, |
| 231 | } |
| 232 | |
| 233 | t.Run("HTTPS rule matches CONNECT request", func(t *testing.T) { |
| 234 | entry := AuditLogEntry{Host: "api.github.com:443", Method: "CONNECT", Status: 200, Decision: "TCP_TUNNEL"} |
| 235 | rule := findMatchingRule(entry, rules) |
| 236 | require.NotNil(t, rule, "Should match HTTPS rule") |
| 237 | assert.Equal(t, "allow-https-only", rule.ID, "HTTPS rule should match CONNECT request") |
| 238 | }) |
| 239 | |
| 240 | t.Run("HTTPS rule skipped for HTTP request", func(t *testing.T) { |
| 241 | entry := AuditLogEntry{Host: "api.github.com:80", Method: "GET", Status: 403, Decision: "NONE_NONE"} |
| 242 | rule := findMatchingRule(entry, rules) |
| 243 | // HTTPS-only rule skipped for GET → falls through to deny-all |
| 244 | require.NotNil(t, rule, "Should fall through to deny-all") |
| 245 | assert.Equal(t, "deny-all", rule.ID, "HTTPS rule should not match HTTP GET request") |
| 246 | }) |
| 247 | } |
| 248 | |
| 249 | func TestIsEntryHTTPS(t *testing.T) { |
| 250 | assert.True(t, isEntryHTTPS(AuditLogEntry{Method: "CONNECT"}), "CONNECT should be HTTPS") |
nothing calls this directly
no test coverage detected