platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
76
selective-vpn-api/app/transport_snapshot_commit_test.go
Normal file
76
selective-vpn-api/app/transport_snapshot_commit_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCompileTransportPolicyPlanForSnapshotRebuildsLegacyNftScopePlan(t *testing.T) {
|
||||
policy := TransportPolicyState{
|
||||
Revision: 5,
|
||||
Intents: []TransportPolicyIntent{
|
||||
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c1"},
|
||||
},
|
||||
}
|
||||
clients := []TransportClient{{
|
||||
ID: "c1",
|
||||
Kind: TransportClientSingBox,
|
||||
IfaceID: "shared",
|
||||
MarkHex: "0x120",
|
||||
PriorityBase: 13300,
|
||||
}}
|
||||
legacyPlan := TransportPolicyCompilePlan{
|
||||
PolicyRevision: 5,
|
||||
Interfaces: []TransportPolicyCompileInterface{
|
||||
{
|
||||
IfaceID: "shared",
|
||||
Sets: []TransportPolicyCompileSet{
|
||||
{SelectorType: "domain", Name: "agvpn_pi_shared_domain"},
|
||||
},
|
||||
Rules: []TransportPolicyCompileRule{
|
||||
{SelectorType: "domain", SelectorValue: "example.com", ClientID: "c1", NftSet: "agvpn_pi_shared_domain"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
next, changed := compileTransportPolicyPlanForSnapshot(policy, clients, legacyPlan)
|
||||
if !changed {
|
||||
t.Fatalf("expected recompile for legacy plan")
|
||||
}
|
||||
if len(next.Interfaces) != 1 || len(next.Interfaces[0].Rules) != 1 {
|
||||
t.Fatalf("unexpected compiled plan shape: %#v", next)
|
||||
}
|
||||
r := next.Interfaces[0].Rules[0]
|
||||
if r.OwnerScope == "" {
|
||||
t.Fatalf("expected owner_scope in compiled rule: %#v", r)
|
||||
}
|
||||
if r.NftSet == "agvpn_pi_shared_domain" {
|
||||
t.Fatalf("expected owner-scoped nft set, got legacy name: %#v", r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompileTransportPolicyPlanForSnapshotKeepsFreshPlan(t *testing.T) {
|
||||
policy := TransportPolicyState{
|
||||
Revision: 7,
|
||||
Intents: []TransportPolicyIntent{
|
||||
{SelectorType: "cidr", SelectorValue: "10.1.0.0/24", ClientID: "c1"},
|
||||
},
|
||||
}
|
||||
clients := []TransportClient{{
|
||||
ID: "c1",
|
||||
Kind: TransportClientSingBox,
|
||||
IfaceID: "edge-a",
|
||||
MarkHex: "0x120",
|
||||
PriorityBase: 13300,
|
||||
}}
|
||||
fresh, conflicts := compileTransportPolicyPlan(policy.Intents, clients, policy.Revision)
|
||||
if len(conflicts) != 0 {
|
||||
t.Fatalf("unexpected compile conflicts: %#v", conflicts)
|
||||
}
|
||||
|
||||
next, changed := compileTransportPolicyPlanForSnapshot(policy, clients, fresh)
|
||||
if changed {
|
||||
t.Fatalf("did not expect recompile for fresh owner-scoped plan")
|
||||
}
|
||||
if next.PolicyRevision != fresh.PolicyRevision || next.RuleCount != fresh.RuleCount {
|
||||
t.Fatalf("unexpected plan mismatch: next=%#v fresh=%#v", next, fresh)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user