feat(tunnel): require explicit target schemes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-05-15 13:16:49 -04:00
parent 9edea27148
commit 8dfb14f1e7
7 changed files with 78 additions and 19 deletions

45
tunnel/forwarder_test.go Normal file
View File

@@ -0,0 +1,45 @@
package tunnel
import (
"testing"
"reichard.io/conduit/store"
)
func TestNewForwarderRequiresExplicitScheme(t *testing.T) {
_, err := NewForwarder("localhost:8282", store.NewTunnelStore(1))
if err == nil {
t.Fatal("expected error for target without scheme")
}
}
func TestNewForwarderSupportsExplicitSchemes(t *testing.T) {
tests := []struct {
name string
target string
forwarderType ForwarderType
}{
{name: "http", target: "http://localhost:8282", forwarderType: ForwarderHTTP},
{name: "https", target: "https://localhost:8282", forwarderType: ForwarderHTTP},
{name: "tcp", target: "tcp://localhost:8282", forwarderType: ForwarderTCP},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
forwarder, err := NewForwarder(tt.target, store.NewTunnelStore(1))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if forwarder.Type() != tt.forwarderType {
t.Fatalf("expected forwarder type %v, got %v", tt.forwarderType, forwarder.Type())
}
})
}
}
func TestNewForwarderRejectsUnsupportedScheme(t *testing.T) {
_, err := NewForwarder("udp://localhost:8282", store.NewTunnelStore(1))
if err == nil {
t.Fatal("expected error for unsupported scheme")
}
}