Skip to content

Commit

Permalink
Mfw 3933: sync-settings runs into marshal errors related to service e…
Browse files Browse the repository at this point in the history
…ndpoints (#299)

version: bug
  • Loading branch information
iramasamy authored Nov 20, 2023
1 parent e28b852 commit ffe8bf4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion services/settings/policy/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":

Expand Down
2 changes: 1 addition & 1 deletion services/settings/policy/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
27 changes: 13 additions & 14 deletions services/settings/policy/policy_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{},
},
Expand All @@ -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{
Expand All @@ -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"},
},
},
Expand Down Expand Up @@ -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"},
},
},
Expand All @@ -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",
Expand All @@ -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"},
},
},
Expand All @@ -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"]}
]}`,
},
}
Expand Down
6 changes: 3 additions & 3 deletions services/settings/policy/testdata/test_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@
"items": [
{
"port": ["88"],
"protocol": [6]
"protocol": ["6"]
},
{
"port": ["123"],
"protocol": [51]
"protocol": ["51"]
},
{
"port": ["23"],
"protocol": [27]
"protocol": ["27"]
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions services/settings/policy/testdata/test_settings_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
Expand Down

0 comments on commit ffe8bf4

Please sign in to comment.