Skip to content

Commit

Permalink
Test hash uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushroshan committed Jan 23, 2025
1 parent c21c47d commit b8e4b86
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/corazawaf/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package corazawaf

import (
"errors"
"hash/fnv"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -715,19 +714,17 @@ func TestGetTransformationID(t *testing.T) {
"t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls",
"t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls,t:cmdLine",
}
hashes := make(map[uint64]string)
hashes := make(map[int]string)
for _, value := range transformations_values {
// split the string by comma
transformations := strings.Split(value, ",")
currentID := 0
// iterate over the transformations
for _, transformation := range transformations {
transformation = strings.Split(strings.Trim(transformation, " "), ":")[1]
nextName := strconv.Itoa(currentID) + "+" + transformation
hasher := fnv.New64a()
hasher.Write([]byte(nextName))
id := hasher.Sum64()
transformationName := strings.Split(strings.Trim(transformation, " "), ":")[1]
id := transformationID(currentID, transformationName)
oldname, ok := hashes[id]
nextName := strconv.Itoa(currentID) + "+" + transformationName
if ok {
assert.Equal(t, oldname, nextName, "Hash collision detected for %s and %s:: %d", oldname, nextName, id)
}
Expand Down

0 comments on commit b8e4b86

Please sign in to comment.