github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/internal/supervisor/iptablesctrl/icmp_linux_test.go (about)

     1  // +build !windows,!rhel6
     2  
     3  package iptablesctrl
     4  
     5  import "testing"
     6  
     7  func Test_getICMPv6(t *testing.T) {
     8  	tests := []struct {
     9  		name string
    10  		want string
    11  	}{
    12  		{"icmpv6DefaultAllow", "(icmp6[0] == 133 and icmp6[1] == 0) or (icmp6[0] == 134 and icmp6[1] == 0) or (icmp6[0] == 135 and icmp6[1] == 0) or (icmp6[0] == 136 and icmp6[1] == 0) or (icmp6[0] == 141 and icmp6[1] == 0) or (icmp6[0] == 142 and icmp6[1] == 0)"},
    13  	}
    14  	for _, tt := range tests {
    15  		t.Run(tt.name, func(t *testing.T) {
    16  			if got := getICMPv6(); got != tt.want {
    17  				t.Errorf("getICMPv6() = %v, want %v", got, tt.want)
    18  			}
    19  		})
    20  	}
    21  }
    22  
    23  func Test_generateExpr(t *testing.T) {
    24  	type args struct {
    25  		icmpTypeCode      string
    26  		policyRestriction []string
    27  	}
    28  	tests := []struct {
    29  		name string
    30  		args args
    31  		want string
    32  	}{
    33  		{"1", args{"icmp", []string{}}, "((icmp))"},
    34  		{"2", args{"icmp6", []string{}}, "((icmp6))"},
    35  		{"3", args{"icmp/1", []string{}}, "(((icmp) and (icmp[0] == 1)))"},
    36  		{"4", args{"icmp6/1", []string{}}, "(((icmp6) and (icmp6[0] == 1)))"},
    37  		{"5", args{"icmp/255", []string{}}, "(((icmp) and (icmp[0] == 255)))"},
    38  		{"6", args{"icmp/1/2", []string{}}, "((((icmp) and (icmp[0] == 1)) and ((icmp[1] == 2))))"},
    39  		{"7", args{"icmp/1/2,3,4", []string{}}, "((((icmp) and (icmp[0] == 1)) and ((icmp[1] == 2)or(icmp[1] == 3)or(icmp[1] == 4))))"},
    40  		{"8", args{"icmp/1/0:255", []string{}}, "((((icmp) and (icmp[0] == 1)) and (((icmp[1] >= 0) and (icmp[1] <= 255)))))"},
    41  		{"9", args{"icmp/1/1,2,3:255", []string{}}, "((((icmp) and (icmp[0] == 1)) and ((icmp[1] == 1)or(icmp[1] == 2)or((icmp[1] >= 3) and (icmp[1] <= 255)))))"},
    42  		{"10", args{"icmp6/255", []string{}}, "(((icmp6) and (icmp6[0] == 255)))"},
    43  		{"11", args{"icmp6/1/2", []string{}}, "((((icmp6) and (icmp6[0] == 1)) and ((icmp6[1] == 2))))"},
    44  		{"12", args{"icmp6/1/2,3,4", []string{}}, "((((icmp6) and (icmp6[0] == 1)) and ((icmp6[1] == 2)or(icmp6[1] == 3)or(icmp6[1] == 4))))"},
    45  		{"13", args{"icmp6/1/0:255", []string{}}, "((((icmp6) and (icmp6[0] == 1)) and (((icmp6[1] >= 0) and (icmp6[1] <= 255)))))"},
    46  		{"14", args{"icmp6/1/1,2,3:255", []string{}}, "((((icmp6) and (icmp6[0] == 1)) and ((icmp6[1] == 1)or(icmp6[1] == 2)or((icmp6[1] >= 3) and (icmp6[1] <= 255)))))"},
    47  		{"15", args{"icmp", []string{"icmp/1/1"}}, "(((((icmp) and (icmp[0] == 1)) and ((icmp[1] == 1)))) and (icmp))"},
    48  		{"16", args{"icmp6", []string{"icmp6/1/0:255"}}, "(((((icmp6) and (icmp6[0] == 1)) and (((icmp6[1] >= 0) and (icmp6[1] <= 255))))) and (icmp6))"},
    49  		{"17", args{"icmp/1", []string{"icmp", "icmp6"}}, "(((icmp) or (icmp6)) and ((icmp) and (icmp[0] == 1)))"},
    50  	}
    51  	for _, tt := range tests {
    52  		t.Run(tt.name, func(t *testing.T) {
    53  			if got := generateExpr(tt.args.icmpTypeCode, tt.args.policyRestriction); got != tt.want {
    54  				t.Errorf("generateExpr() = %v, want %v", got, tt.want)
    55  			}
    56  		})
    57  	}
    58  }