Files
3x-ui/internal/web/cadence_test.go
T
Duxxie 380aff4d82 Add remote routing URL support (#6168)
* 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>
2026-08-18 16:02:11 +02:00

36 lines
1.2 KiB
Go

package web
import (
"testing"
"github.com/robfig/cron/v3"
)
// All centralized background-job cadences must remain valid cron specs. This is
// the guard for the "single tuning surface" refactor: editing a cadence to an
// invalid spec fails here instead of silently dropping a job at startup.
//
// NOTE: package web embeds the built frontend (//go:embed all:dist), so this
// test compiles only after `npm run build` has populated web/dist — the normal
// repo build flow.
func TestJobCadencesAreValidCronSpecs(t *testing.T) {
cadences := map[string]string{
"cadenceXrayRunning": cadenceXrayRunning,
"cadenceXrayRestart": cadenceXrayRestart,
"cadenceXrayTraffic": cadenceXrayTraffic,
"cadenceMtproto": cadenceMtproto,
"cadenceClientIPScan": cadenceClientIPScan,
"cadenceNodeHeartbeat": cadenceNodeHeartbeat,
"cadenceNodeTraffic": cadenceNodeTraffic,
"cadenceOutboundSub": cadenceOutboundSub,
"cadenceRemoteRouting": cadenceRemoteRouting,
"cadenceCheckHash": cadenceCheckHash,
"cadenceCPUAlarm": cadenceCPUAlarm,
}
for name, spec := range cadences {
if _, err := cron.ParseStandard(spec); err != nil {
t.Errorf("%s = %q is not a valid cron spec: %v", name, spec, err)
}
}
}