GoDoxy/internal/route/rules/rules_test.go
Yuzerion 4a8bd48ad5
Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
fix: optimize memory usage, fix agent and code refactor (#118)
* refactor: simplify io code and make utils module independent

* fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler

* refactor: remove unused code

* refactor: remove the use of logging module in most code

* refactor: streamline domain mismatch check in certState function

* tweak: use ecdsa p-256 for autocert

* fix(tests): update health check tests for invalid host and add case for port in host

* feat(acme): custom acme directory

* refactor: code refactor and improved context and error handling

* tweak: optimize memory usage under load

* fix(oidc): restore old user matching behavior

* docs: add ChatGPT assistant to README

---------

Co-authored-by: yusing <yusing@6uo.me>
2025-05-25 09:45:57 +08:00

46 lines
1.3 KiB
Go

package rules
import (
"testing"
"github.com/yusing/go-proxy/internal/serialization"
. "github.com/yusing/go-proxy/internal/utils/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)
ExpectNoError(t, err)
ExpectEqual(t, len(rules.Rules), len(test))
ExpectEqual(t, rules.Rules[0].Name, "test")
ExpectEqual(t, rules.Rules[0].On.String(), "method POST")
ExpectEqual(t, rules.Rules[0].Do.String(), "error 403 Forbidden")
ExpectEqual(t, rules.Rules[1].Name, "auth")
ExpectEqual(t, rules.Rules[1].On.String(), `basic_auth "username" "password" | basic_auth username2 "password2" | basic_auth "username3" "password3"`)
ExpectEqual(t, rules.Rules[1].Do.String(), "bypass")
ExpectEqual(t, rules.Rules[2].Name, "default")
ExpectEqual(t, rules.Rules[2].Do.String(), "require_basic_auth any_realm")
}
// TODO: real tests.