diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 33f45e1c4..ec1eee11c 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1928,7 +1928,8 @@ func (tps TPRoutes) AsTPRouteProfile() (result []*utils.TPRouteProfile) { } routeID := tp.RouteID if tp.RouteFilterIDs != "" { - routeID = utils.ConcatenatedKey(routeID, tp.RouteFilterIDs) + routeID = utils.ConcatenatedKey(routeID, + utils.NewStringSet(strings.Split(tp.RouteFilterIDs, utils.INFIELD_SEP)).Sha1()) } sup, found := routeMap[tenID][routeID] if !found { diff --git a/utils/coreutils.go b/utils/coreutils.go index 980d23f8d..7629a5316 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -117,6 +117,7 @@ func FirstNonEmpty(vals ...string) string { } // Sha1 generate the SHA1 hash from any string +// the order of string matters func Sha1(attrs ...string) string { hasher := sha1.New() for _, attr := range attrs { diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 3a9b1dd83..5d39ec7af 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -74,6 +74,21 @@ func TestSha1(t *testing.T) { } } +func TestSha1ReverseOrder(t *testing.T) { + rcv := Sha1("test1", "test2") + revOrd := Sha1("test2", "test1") + // Sha1 consider order when generating + if reflect.DeepEqual(revOrd, rcv) { + t.Errorf("Expecting: %s, received: %s", revOrd, rcv) + } + + rcv = Sha1("test1") + revOrd = Sha1("test1") + if !reflect.DeepEqual(revOrd, rcv) { + t.Errorf("Expecting: %s, received: %s", revOrd, rcv) + } +} + func TestUUID(t *testing.T) { uuid := GenUUID() if len(uuid) == 0 { diff --git a/utils/set.go b/utils/set.go index 770c1752e..46ba39ffa 100644 --- a/utils/set.go +++ b/utils/set.go @@ -18,6 +18,8 @@ along with this program. If not, see package utils +import "sort" + // NewStringSet returns a new StringSet func NewStringSet(dataSlice []string) (s StringSet) { s = make(StringSet) @@ -62,6 +64,18 @@ func (s StringSet) AsSlice() []string { return result } +// AsOrderedSlice returns the keys as ordered string slice +func (s StringSet) AsOrderedSlice() (ss []string) { + ss = s.AsSlice() + sort.Strings(ss) + return +} + +// Sha1 returns the Sha1 on top of ordered slice +func (s StringSet) Sha1() string { + return Sha1(s.AsOrderedSlice()...) +} + // Size returns the size of the set func (s StringSet) Size() int { return len(s)