@@ -13,7 +13,6 @@ import (
1313 "encoding/json"
1414 "fmt"
1515 "math/rand"
16- "reflect"
1716 "sort"
1817 "sync"
1918 "testing"
@@ -907,143 +906,6 @@ func TestMetrics(t *testing.T) {
907906 })
908907}
909908
910- // This test needs a working encoder to function properly, as it first encodes the objects before decoding them
911- func TestDecoder (t * testing.T ) {
912- t .Run ("Errors" , func (t * testing.T ) {
913- e := newMaxEncoder ()
914- objBuilder := func (value any ) * wafObject {
915- encoded , err := e .Encode (value )
916- require .NoError (t , err , "Encoding object failed" )
917- return encoded
918- }
919-
920- for _ , tc := range []struct {
921- Name string
922- ExpectedValue map [string ][]string
923- }{
924- {
925- Name : "empty" ,
926- ExpectedValue : map [string ][]string {},
927- },
928- {
929- Name : "one-empty-entry" ,
930- ExpectedValue : map [string ][]string {
931- "afasdfafs" : nil ,
932- },
933- },
934- {
935- Name : "one-filled-entry" ,
936- ExpectedValue : map [string ][]string {
937- "afasdfafs" : {"rule1" , "rule2" },
938- },
939- },
940- {
941- Name : "multiple-entries" ,
942- ExpectedValue : map [string ][]string {
943- "afasdfafs" : {"rule1" , "rule2" },
944- "sfdsafdsa" : {"rule3" , "rule4" },
945- },
946- },
947- } {
948- t .Run (tc .Name , func (t * testing.T ) {
949- val , err := decodeErrors (objBuilder (tc .ExpectedValue ))
950- require .NoErrorf (t , err , "Error decoding the object: %v" , err )
951- require .Equal (t , tc .ExpectedValue , val )
952- })
953- }
954-
955- keepAlive (e .cgoRefs .arrayRefs )
956- keepAlive (e .cgoRefs .stringRefs )
957- })
958- t .Run ("Values" , func (t * testing.T ) {
959-
960- for _ , tc := range []struct {
961- name string
962- data any
963- }{
964- {
965- name : "int64" ,
966- data : int64 (- 4 ),
967- },
968- {
969- name : "uint64" ,
970- data : uint64 (4 ),
971- },
972- {
973- name : "float64" ,
974- data : 4.4444 ,
975- },
976- {
977- name : "bool" ,
978- data : true ,
979- },
980- {
981- name : "bool" ,
982- data : false ,
983- },
984- {
985- name : "string" ,
986- data : "" ,
987- },
988- {
989- name : "string" ,
990- data : "EliottAndFrancoisLoveDecoding" ,
991- },
992- {
993- name : "string" ,
994- data : "123" ,
995- },
996- {
997- name : "slice" ,
998- data : []any {int64 (1 ), int64 (2 ), int64 (3 ), int64 (4 )},
999- },
1000- {
1001- name : "slice" ,
1002- data : []any {"1" , "2" , "3" , "4" },
1003- },
1004- {
1005- name : "slice" ,
1006- data : []any {true , false , false , true , true , true },
1007- },
1008- {
1009- name : "slice-nested" ,
1010- data : []any {[]any {true , false }, []any {false , false }, []any {true , true , true }},
1011- },
1012- {
1013- name : "map" ,
1014- data : map [string ]any {"1" : int64 (1 ), "2" : int64 (2 ), "3" : int64 (3 )},
1015- },
1016- {
1017- name : "map" ,
1018- data : map [string ]any {"1" : uint64 (1 ), "2" : uint64 (2 ), "3" : uint64 (3 )},
1019- },
1020- {
1021- name : "map" ,
1022- data : map [string ]any {"1" : 1.111 , "2" : 2.222 , "3" : 3.333 },
1023- },
1024- {
1025- name : "map" ,
1026- data : map [string ]any {"1" : "1" , "2" : "2" , "3" : "3" },
1027- },
1028- {
1029- name : "map-nested" ,
1030- data : map [string ]any {"1" : map [string ]any {"1" : int64 (1 ), "2" : int64 (2 )}, "2" : map [string ]any {"3" : int64 (3 ), "4" : int64 (4 )}},
1031- },
1032- } {
1033- t .Run (tc .name , func (t * testing.T ) {
1034- e := newMaxEncoder ()
1035- obj , err := e .Encode (tc .data )
1036- require .NoError (t , err )
1037-
1038- val , err := decodeObject (obj )
1039- require .NoError (t , err )
1040- require .True (t , reflect .DeepEqual (tc .data , val ))
1041- })
1042- }
1043-
1044- })
1045- }
1046-
1047909func TestObfuscatorConfig (t * testing.T ) {
1048910 rule := newArachniTestRule ([]ruleInput {{Address : "my.addr" , KeyPath : []string {"key" }}}, nil )
1049911 t .Run ("key" , func (t * testing.T ) {
0 commit comments