mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-01 09:32:35 +02:00

Some checks are pending
Docker Image CI (socket-proxy) / build (push) Waiting to run
* 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>
46 lines
1.3 KiB
Go
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.
|