github.com/TeaOSLab/EdgeNode@v1.3.8/internal/iplibrary/action_firewalld_test.go (about)

     1  package iplibrary
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
     5  	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestFirewalldAction_AddItem(t *testing.T) {
    11  	{
    12  		action := NewFirewalldAction()
    13  		action.config = &firewallconfigs.FirewallActionFirewalldConfig{
    14  			Path: "/usr/bin/firewalld",
    15  		}
    16  		err := action.AddItem(IPListTypeWhite, &pb.IPItem{
    17  			Type:      "ipv4",
    18  			Id:        1,
    19  			IpFrom:    "192.168.1.100",
    20  			ExpiredAt: time.Now().Unix() + 30,
    21  		})
    22  		if err != nil {
    23  			t.Fatal(err)
    24  		}
    25  		t.Log("ok")
    26  	}
    27  
    28  	{
    29  		action := NewFirewalldAction()
    30  		action.config = &firewallconfigs.FirewallActionFirewalldConfig{
    31  			Path: "/usr/bin/firewalld",
    32  		}
    33  		err := action.AddItem(IPListTypeBlack, &pb.IPItem{
    34  			Type:      "ipv4",
    35  			Id:        1,
    36  			IpFrom:    "192.168.1.101",
    37  			ExpiredAt: time.Now().Unix() + 30,
    38  		})
    39  		if err != nil {
    40  			t.Fatal(err)
    41  		}
    42  		t.Log("ok")
    43  	}
    44  }
    45  
    46  func TestFirewalldAction_DeleteItem(t *testing.T) {
    47  	action := NewFirewalldAction()
    48  	action.config = &firewallconfigs.FirewallActionFirewalldConfig{
    49  		Path: "/usr/bin/firewalld",
    50  	}
    51  	err := action.DeleteItem(IPListTypeWhite, &pb.IPItem{
    52  		Type:      "ipv4",
    53  		Id:        1,
    54  		IpFrom:    "192.168.1.100",
    55  		ExpiredAt: time.Now().Unix() + 30,
    56  	})
    57  	if err != nil {
    58  		t.Fatal(err)
    59  	}
    60  	t.Log("ok")
    61  }
    62  
    63  func TestFirewalldAction_MultipleItem(t *testing.T) {
    64  	action := NewFirewalldAction()
    65  	action.config = &firewallconfigs.FirewallActionFirewalldConfig{
    66  		Path: "/usr/bin/firewalld",
    67  	}
    68  	err := action.AddItem(IPListTypeBlack, &pb.IPItem{
    69  		Type:      "ipv4",
    70  		Id:        1,
    71  		IpFrom:    "192.168.1.30",
    72  		IpTo:      "192.168.1.200",
    73  		ExpiredAt: time.Now().Unix() + 30,
    74  	})
    75  	if err != nil {
    76  		t.Fatal(err)
    77  	}
    78  	t.Log("ok")
    79  }