mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-20 10:00:58 +00:00
380aff4d82
* Add remote routing URL support * Harden remote routing refresh * fix(sub): harden remote routing fetch and accept Mihomo src rule flag Remote routing bytes reach the YAML/JSON parsers from goroutines that run outside Gin's recovery, so a parser panic on crafted input would take down the whole panel. Contain it in fetch() (a panic now degrades to a failed refresh that keeps the last-good value and releases the in-flight slot) and start the refresh, cache-load and startup-warm goroutines through common.GoRecover like the other background workers. The route-graph validator only skipped a trailing no-resolve flag, so a valid Mihomo rule like IP-CIDR,x,DIRECT,no-resolve,src was rejected as an unknown target; skip both option flags. Also deduplicate the HTTPS-source classification into common.ParseRemoteRoutingURL so the save-time validator and the resolver can never drift (internal/sub imports internal/web/service, so the copy existed only to avoid the import cycle), move the test-only mergeRemoteClashRulesYAML helper into the test file, and trim oversized comment blocks. --------- Co-authored-by: Duxxie <yelloduxx@users.noreply.github.com> Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/web/entity"
|
|
)
|
|
|
|
func TestValidateRemoteRoutingURLSettings(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
value string
|
|
want string
|
|
wantError string
|
|
}{
|
|
{name: "valid HTTPS", value: " https://example.com/rules#fragment ", want: "https://example.com/rules"},
|
|
{name: "credentials", value: "https://user:pass@example.com/rules", wantError: "must not contain URL credentials"},
|
|
{name: "missing host", value: "https:///rules", wantError: "absolute HTTPS URL"},
|
|
{name: "legacy HTTP stays inline", value: "http://example.com/rules", want: "http://example.com/rules"},
|
|
{name: "multiline Clash stays inline", value: "https://example.com/rules\nMATCH,PROXY", want: "https://example.com/rules\nMATCH,PROXY"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
settings := &entity.AllSetting{SubRoutingRules: tt.value}
|
|
err := validateSettingsURLs(settings)
|
|
if tt.wantError != "" {
|
|
if err == nil || !strings.Contains(err.Error(), tt.wantError) {
|
|
t.Fatalf("err=%v, want %q", err, tt.wantError)
|
|
}
|
|
return
|
|
}
|
|
if err != nil || settings.SubRoutingRules != tt.want {
|
|
t.Fatalf("value=%q err=%v", settings.SubRoutingRules, err)
|
|
}
|
|
})
|
|
}
|
|
}
|