work on rule reqmod resmod codegen for serialization

This commit is contained in:
Kevin Pham
2023-12-03 23:34:46 -06:00
parent a83a95c5a5
commit 7883b32335
10 changed files with 454 additions and 25 deletions

View File

@@ -0,0 +1,45 @@
package ruleset_v2
import (
"encoding/json"
"fmt"
//"io"
"testing"
)
func TestRuleUnmarshalJSON(t *testing.T) {
ruleJSON := `{
"domains": [
"example.com",
"www.example.com"
],
"response_modifiers": [
"APIContent()",
"SetContentSecurityPolicy(\"foobar\")",
"SetIncomingCookie(\"authorization-bearer\", \"hunter2\")"
],
"response_modifiers": []
}`
//fmt.Println(ruleJSON)
rule := &Rule{}
err := json.Unmarshal([]byte(ruleJSON), rule)
if err != nil {
t.Errorf("expected no error in Unmarshal, got '%s'", err)
return
}
if len(rule.Domains) != 2 {
t.Errorf("expected number of domains to be 2")
return
}
if !(rule.Domains[0] == "example.com" || rule.Domains[1] == "example.com") {
t.Errorf("expected domain to be example.com")
return
}
if len(rule.ResponseModifications) == 3 {
t.Errorf("expected number of ResponseModifications to be 3")
}
fmt.Println(rule.ResponseModifications)
}