mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-27 10:47:06 +02:00
feat(rules): add post-request rules system with response manipulation (#160)
* Add comprehensive post-request rules support for response phase * Enable response body, status, and header manipulation via set commands * Refactor command handlers to support both request and response phases * Implement response modifier system for post-request template execution * Support response-based rule matching with status and header checks * Add comprehensive benchmarks for matcher performance * Refactor authentication and proxying commands for unified error handling * Support negated conditions with ! * Enhance error handling, error formatting and validation * Routes: add `rule_file` field with rule preset support * Environment variable substitution: now supports variables without `GODOXY_` prefix * new conditions: * `on resp_header <key> [<value>]` * `on status <status>` * new commands: * `require_auth` * `set resp_header <key> <template>` * `set resp_body <template>` * `set status <code>` * `log <level> <path> <template>` * `notify <level> <provider> <title_template> <body_template>`
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yusing/godoxy/internal/serialization"
|
||||
expect "github.com/yusing/goutils/testing"
|
||||
)
|
||||
|
||||
func TestParseRule(t *testing.T) {
|
||||
test := []map[string]any{
|
||||
{
|
||||
"name": "test",
|
||||
"on": "method POST",
|
||||
"do": "error 403 Forbidden",
|
||||
},
|
||||
{
|
||||
"name": "auth",
|
||||
"on": `basic_auth "username" "password" | basic_auth username2 "password2" | basic_auth "username3" "password3"`,
|
||||
"do": "bypass",
|
||||
},
|
||||
{
|
||||
"name": "default",
|
||||
"do": "require_basic_auth any_realm",
|
||||
},
|
||||
}
|
||||
|
||||
var rules struct {
|
||||
Rules Rules
|
||||
}
|
||||
err := serialization.MapUnmarshalValidate(serialization.SerializedObject{"rules": test}, &rules)
|
||||
expect.NoError(t, err)
|
||||
expect.Equal(t, len(rules.Rules), len(test))
|
||||
expect.Equal(t, rules.Rules[0].Name, "test")
|
||||
expect.Equal(t, rules.Rules[0].On.String(), "method POST")
|
||||
expect.Equal(t, rules.Rules[0].Do.String(), "error 403 Forbidden")
|
||||
|
||||
expect.Equal(t, rules.Rules[1].Name, "auth")
|
||||
expect.Equal(t, rules.Rules[1].On.String(), `basic_auth "username" "password" | basic_auth username2 "password2" | basic_auth "username3" "password3"`)
|
||||
expect.Equal(t, rules.Rules[1].Do.String(), "bypass")
|
||||
|
||||
expect.Equal(t, rules.Rules[2].Name, "default")
|
||||
expect.Equal(t, rules.Rules[2].Do.String(), "require_basic_auth any_realm")
|
||||
}
|
||||
|
||||
// TODO: real tests.
|
||||
Reference in New Issue
Block a user