Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package rulematch
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prism/proxy/internal/store"
|
||||
)
|
||||
|
||||
func TestMatchDomainSuffix(t *testing.T) {
|
||||
rules := []store.Rule{
|
||||
{Priority: 10, RuleType: "DOMAIN-SUFFIX", Payload: "google.com", Target: "PROXY", Source: "manual", Enabled: true},
|
||||
{Priority: 20, RuleType: "DOMAIN", Payload: "exact.com", Target: "DIRECT", Source: "manual", Enabled: true},
|
||||
}
|
||||
res := Match(rules, "DIRECT", "https://www.google.com/search", true)
|
||||
if !res.Matched || res.RuleType != "DOMAIN-SUFFIX" || res.Target != "PROXY" {
|
||||
t.Fatalf("unexpected: %+v", res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchFallback(t *testing.T) {
|
||||
rules := []store.Rule{
|
||||
{Priority: 10, RuleType: "DOMAIN", Payload: "other.com", Target: "PROXY", Source: "manual", Enabled: true},
|
||||
}
|
||||
res := Match(rules, "country:HK", "https://example.com", true)
|
||||
if res.RuleType != "MATCH" || res.Target != "country:HK" {
|
||||
t.Fatalf("unexpected: %+v", res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHost(t *testing.T) {
|
||||
host, port := ParseHost("https://foo.com:8443/path")
|
||||
if host != "foo.com" || port != "8443" {
|
||||
t.Fatalf("got %q %q", host, port)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user