CI / changes (push) Successful in 12s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 25s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m15s
CI / bird2 (push) Successful in 18s
CI / release (push) Successful in 3m59s
Introduced a comprehensive firewall blocklist feature, allowing for the management of firewall clients and their associated rules. This includes endpoints for enrolling clients, listing clients and rules, and reporting apply statuses. Enhanced the API to support firewall operations, including the ability to handle block/accept policies. Updated the documentation to reflect these changes and added necessary components in the web UI for better user interaction. Additionally, modified the agent server to support firewall failover and integrated firewall functionality into the existing architecture.
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package firewall
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestEvaluate_emptyRules(t *testing.T) {
|
|
prefixes := map[string][]string{"c1": {"1.2.3.0/24"}}
|
|
got := Evaluate("client1", nil, prefixes)
|
|
if len(got) != 0 {
|
|
t.Fatalf("expected empty blocklist, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestEvaluate_onlyAccept(t *testing.T) {
|
|
wild := (*string)(nil)
|
|
rules := []Rule{{Priority: 1, Action: "accept", CommunityID: wild}}
|
|
prefixes := map[string][]string{"c1": {"1.2.3.0/24"}}
|
|
got := Evaluate("client1", rules, prefixes)
|
|
if len(got) != 0 {
|
|
t.Fatalf("accept alone must not block, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestEvaluate_explicitBlock(t *testing.T) {
|
|
cid := "c1"
|
|
rules := []Rule{{Priority: 1, Action: "block", CommunityID: &cid}}
|
|
prefixes := map[string][]string{"c1": {"1.2.3.0/24", "5.6.7.8/32"}, "c2": {"9.9.9.9/32"}}
|
|
got := Evaluate("client1", rules, prefixes)
|
|
if len(got) != 2 {
|
|
t.Fatalf("expected 2 prefixes, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestEvaluate_clientOverrideAccept(t *testing.T) {
|
|
wild := (*string)(nil)
|
|
cTrusted := "trusted"
|
|
clientID := "srv1"
|
|
rules := []Rule{
|
|
{Priority: 1, Action: "block", CommunityID: wild},
|
|
{ClientID: &clientID, Priority: 1, Action: "accept", CommunityID: &cTrusted},
|
|
}
|
|
prefixes := map[string][]string{
|
|
"trusted": {"1.1.1.0/24"},
|
|
"bad": {"2.2.2.0/24"},
|
|
}
|
|
got := Evaluate(clientID, rules, prefixes)
|
|
if len(got) != 1 || got[0] != "2.2.2.0/24" {
|
|
t.Fatalf("expected only bad community, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestEvaluate_clientOverrideWins(t *testing.T) {
|
|
cid := "c1"
|
|
clientID := "srv1"
|
|
rules := []Rule{
|
|
{Priority: 1, Action: "accept", CommunityID: &cid},
|
|
{ClientID: &clientID, Priority: 1, Action: "block", CommunityID: &cid},
|
|
}
|
|
prefixes := map[string][]string{"c1": {"1.2.3.0/24"}}
|
|
got := Evaluate(clientID, rules, prefixes)
|
|
if len(got) != 1 {
|
|
t.Fatalf("client override should block, got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestEvaluate_noCommunityKey(t *testing.T) {
|
|
empty := ""
|
|
rules := []Rule{{Priority: 1, Action: "block", CommunityID: &empty}}
|
|
prefixes := map[string][]string{"": {"10.0.0.0/8"}}
|
|
got := Evaluate("c", rules, prefixes)
|
|
if len(got) != 1 {
|
|
t.Fatalf("expected prefix without community, got %v", got)
|
|
}
|
|
}
|