@@ -685,6 +685,44 @@ func TestVerifyRules(t *testing.T) {
685685 }
686686}
687687
688+ func TestVerifyRules_MissingDefaultActionInDryRun (t * testing.T ) {
689+ mockIpt := newMockIPTables ()
690+
691+ // Make sure the chain exists
692+ chainName := "TEST_CHAIN"
693+ mockIpt .chains [chainName ] = true
694+
695+ // Add some rules that are missing the final default lines
696+ // (The code expects: -A TEST_CHAIN -j LOG --log-prefix "DROP_<logIdentifier> "
697+ // plus a trailing -A TEST_CHAIN -j ACCEPT)
698+ // We'll omit them so the code path returns "default rule not found"
699+ mockIpt .rules [chainName ] = []string {
700+ // Possibly also no user rules at all, or partial user rules, doesn't matter
701+ `-A TEST_CHAIN -d 192.168.1.1 -p tcp --dport 80 -j LOG --log-prefix "DROP_TEST123 "` ,
702+ // or we can just have an empty slice if we want
703+ }
704+
705+ manager := & IPTablesManager {
706+ ipt : mockIpt ,
707+ mainChainName : "CNI-OUTBOUND" ,
708+ defaultAction : "DROP" ,
709+ logIdentifier : "TEST123" ,
710+ dryRun : true , // CRUCIAL
711+ }
712+
713+ // No user OutboundRules in this example
714+ userRules := []OutboundRule {}
715+
716+ // Now call VerifyRules, expecting it to fail with "default rule not found"
717+ err := manager .VerifyRules (chainName , userRules )
718+ if err == nil {
719+ t .Fatalf ("Expected an error about missing default rule but got nil" )
720+ }
721+ if ! strings .Contains (err .Error (), "default rule not found" ) {
722+ t .Errorf ("Unexpected error: %v" , err )
723+ }
724+ }
725+
688726func TestVerifyRulesListError (t * testing.T ) {
689727 mockIpt := newMockIPTables ()
690728 manager := & IPTablesManager {
0 commit comments