From ffe8bf4d016e121c103b19126d2d40c6080ffbad Mon Sep 17 00:00:00 2001 From: iramasamy <111305748+iramasamy@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:43:30 -0700 Subject: [PATCH] Mfw 3933: sync-settings runs into marshal errors related to service endpoints (#299) version: bug --- services/settings/policy/condition.go | 2 +- services/settings/policy/object.go | 2 +- .../settings/policy/policy_settings_test.go | 27 +++++++++---------- .../policy/testdata/test_settings.json | 6 ++--- .../policy/testdata/test_settings_group.json | 4 +-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/services/settings/policy/condition.go b/services/settings/policy/condition.go index 3f932d53..c3939b3d 100644 --- a/services/settings/policy/condition.go +++ b/services/settings/policy/condition.go @@ -47,7 +47,7 @@ func (pCondition *PolicyCondition) UnmarshalJSON(data []byte) error { return fmt.Errorf("error while unmarshalling policy condition: value does not match type (%s) due to error (%v)", pCondition.CType, err) } // just string type values on these, no need to validate - case "DAY_OF_WEEK", "GEOIP_LOCATION", "INTERFACE", "SERVICE_ENDPOINT", "SERVICE_ENDPOINT_SERVER", "SERVICE_ENDPOINT_CLIENT", + case "DAY_OF_WEEK", "GEOIP_LOCATION", "INTERFACE", "SERVICE", "SERVER_SERVICE", "CLIENT_SERVICE", "PROTOCOL_TYPE", "APPLICATION_CATEGORY", "TIME_OF_DAY", "VLAN_TAG", "THREATPREVENTION", "APPLICATION", "SERVER_APPLICATION", "CLIENT_APPLICATION", "HOSTNAME": diff --git a/services/settings/policy/object.go b/services/settings/policy/object.go index 1558a39c..5b2b603a 100644 --- a/services/settings/policy/object.go +++ b/services/settings/policy/object.go @@ -50,7 +50,7 @@ type Action struct { // ServiceEndpoint is a particular object type, a object may be // identified by a list of these. type ServiceEndpoint struct { - Protocol []uint `json:"protocol"` + Protocol []string `json:"protocol"` Port []utilNet.PortSpecifierString `json:"port"` } diff --git a/services/settings/policy/policy_settings_test.go b/services/settings/policy/policy_settings_test.go index 3cf148e4..7f3ca22c 100644 --- a/services/settings/policy/policy_settings_test.go +++ b/services/settings/policy/policy_settings_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/google/gopacket/layers" "github.com/stretchr/testify/assert" "github.com/untangle/golang-shared/services/settings" "github.com/untangle/golang-shared/util/net" @@ -777,11 +776,11 @@ func TestObjectUnmarshal(t *testing.T) { assert.True(t, ok) assert.EqualValues(t, []ServiceEndpoint{ { - Protocol: []uint{uint(layers.IPProtocolTCP), uint(layers.IPProtocolUDP)}, + Protocol: []string{"6", "17"}, Port: []net.PortSpecifierString{"12345", "80", "53"}, }, { - Protocol: []uint{uint(layers.IPProtocolUDP)}, + Protocol: []string{"17"}, Port: []net.PortSpecifierString{"12345", "11", "22", "67", "66"}, }, }, endpointList) @@ -936,7 +935,7 @@ func TestGroupUnmarshalEdges(t *testing.T) { json: `{"name": "ServiceEndpointTest", "id": "702d4c99-9599-455f-8271-215e5680f038", "type": "ServiceEndpoint", - "items": [{"protocol": [17]]}`, + "items": [{"protocol": ["17"]]}`, expectedErr: true, expected: Object{}, }, @@ -947,8 +946,8 @@ func TestGroupUnmarshalEdges(t *testing.T) { "description": "Description", "type": "mfw-object-service", "items": [ - {"protocol": [17,6,1], "port": ["2222", "80", "88"]}, - {"protocol": [6], "port": ["2223", "11", "53"]} + {"protocol": ["17","6","1"], "port": ["2222", "80", "88"]}, + {"protocol": ["6"], "port": ["2223", "11", "53"]} ]}`, expectedErr: false, expected: Object{ @@ -958,11 +957,11 @@ func TestGroupUnmarshalEdges(t *testing.T) { ID: "702d4c99-9599-455f-8271-215e5680f038", Items: []ServiceEndpoint{ { - Protocol: []uint{uint(layers.IPProtocolUDP), uint(layers.IPProtocolTCP), uint(layers.IPProtocolICMPv4)}, + Protocol: []string{"17", "6", "1"}, Port: []net.PortSpecifierString{"2222", "80", "88"}, }, { - Protocol: []uint{uint(layers.IPProtocolTCP)}, + Protocol: []string{"6"}, Port: []net.PortSpecifierString{"2223", "11", "53"}, }, }, @@ -1232,11 +1231,11 @@ func TestGroupMarshal(t *testing.T) { ID: "702d4c99-9599-455f-8271-215e5680f038", Items: []ServiceEndpoint{ { - Protocol: []uint{uint(layers.IPProtocolUDP)}, + Protocol: []string{"17"}, Port: []net.PortSpecifierString{"2222"}, }, { - Protocol: []uint{uint(layers.IPProtocolTCP)}, + Protocol: []string{"6"}, Port: []net.PortSpecifierString{"2223"}, }, }, @@ -1246,8 +1245,8 @@ func TestGroupMarshal(t *testing.T) { "description": "Description", "type": "mfw-object-service", "items": [ - {"protocol": [17], "port": ["2222"]}, - {"protocol": [6], "port": ["2223"]}]}`, + {"protocol": ["17"], "port": ["2222"]}, + {"protocol": ["6"], "port": ["2223"]}]}`, }, { name: "ServiceEndpointTest with port ranges", @@ -1258,7 +1257,7 @@ func TestGroupMarshal(t *testing.T) { ID: "702d4c99-9599-455f-8271-215e5680f038", Items: []ServiceEndpoint{ { - Protocol: []uint{uint(layers.IPProtocolUDP)}, + Protocol: []string{"17"}, Port: []net.PortSpecifierString{"2222", "2223-2225"}, }, }, @@ -1268,7 +1267,7 @@ func TestGroupMarshal(t *testing.T) { "description": "Description", "type": "mfw-object-service", "items": [ - {"protocol": [17], "port": ["2222", "2223-2225"]} + {"protocol": ["17"], "port": ["2222", "2223-2225"]} ]}`, }, } diff --git a/services/settings/policy/testdata/test_settings.json b/services/settings/policy/testdata/test_settings.json index 9afbf88f..c12e27fc 100644 --- a/services/settings/policy/testdata/test_settings.json +++ b/services/settings/policy/testdata/test_settings.json @@ -181,15 +181,15 @@ "items": [ { "port": ["88"], - "protocol": [6] + "protocol": ["6"] }, { "port": ["123"], - "protocol": [51] + "protocol": ["51"] }, { "port": ["23"], - "protocol": [27] + "protocol": ["27"] } ] }, diff --git a/services/settings/policy/testdata/test_settings_group.json b/services/settings/policy/testdata/test_settings_group.json index 60750a83..57f8e270 100644 --- a/services/settings/policy/testdata/test_settings_group.json +++ b/services/settings/policy/testdata/test_settings_group.json @@ -88,11 +88,11 @@ "type": "mfw-object-service", "items": [ { - "protocol":[ 6,17], + "protocol":[ "6","17"], "port": ["12345", "80", "53"] }, { - "protocol": [17], + "protocol": ["17"], "port": ["12345", "11", "22", "67", "66"] } ]