mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Order FilterIDs before concatenated to RouteID
This commit is contained in:
committed by
Dan Christian Bogos
parent
74f9aa132e
commit
5bad75b8df
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
14
utils/set.go
14
utils/set.go
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user