Files
telemt-api/internal/proxy/mihomo_test.go
T
Denozordec 2d7b06260e
Publish telemt-api gateway Docker image / test (push) Successful in 34s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m55s
Implement Mihomo external-controller support in configuration and gateway
- Added optional Mihomo configuration fields in `config.compose.yaml` and `config.example.yaml` for enhanced integration with the Mihomo external-controller.
- Updated the `Gateway` to handle Mihomo API requests, including proxying and error handling for Mihomo-specific endpoints.
- Enhanced the documentation in `GATEWAY_RUN.md` to guide users on configuring Mihomo integration.
- Introduced new utility functions in the web client for interacting with Mihomo API endpoints, improving the overall user experience.
- Updated the sidebar in the Svelte components to include a link to the Mihomo section, enhancing navigation.
2026-03-31 00:32:19 +07:00

38 lines
954 B
Go

package proxy
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestMihomoForwardRewritesPathAndAuth(t *testing.T) {
target, err := url.Parse("http://127.0.0.1:9090")
if err != nil {
t.Fatal(err)
}
cap := &captureTransport{}
h := NewMihomoForward(target, "/api/mtg/mihomo", "Bearer testsecret", cap, nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://gw/api/mtg/mihomo/proxies", nil)
if err != nil {
t.Fatal(err)
}
req.Header.Set("Authorization", "Bearer client-should-not-forward")
h.ServeHTTP(httptest.NewRecorder(), req)
if cap.got == nil {
t.Fatal("no outgoing request captured")
}
if got := cap.got.Header.Get("Authorization"); got != "Bearer testsecret" {
t.Fatalf("Authorization: got %q want Bearer testsecret", got)
}
want, err := url.Parse("http://127.0.0.1:9090/proxies")
if err != nil {
t.Fatal(err)
}
assertSameURL(t, cap.got.URL, want)
}