support regex and player name sniff
This commit is contained in:
@@ -63,6 +63,37 @@ func TestRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRegexPatternMatch verifies a wildcard regex pattern routes a matching
|
||||
// player (whole-hostname, case-insensitive) and drops a non-matching one, and
|
||||
// that the client maps the hub-echoed pattern back to its destination.
|
||||
func TestRegexPatternMatch(t *testing.T) {
|
||||
const psk = "e2e-regex"
|
||||
port := freePort(t)
|
||||
hubAddr := fmt.Sprintf("127.0.0.1:%d", port)
|
||||
startHub(t, port, psk)
|
||||
dest := newMockDest(t, modeEcho)
|
||||
startClient(t, hubAddr, psk, 2, []client.Mapping{
|
||||
{Pattern: `mc\d+\.local`, Destination: dest.addr},
|
||||
})
|
||||
|
||||
// Matches the regex (digit wildcard, mixed case); the whole hostname matches.
|
||||
pc := dialPlayer(t, hubAddr, "MC7.Local")
|
||||
defer pc.Close()
|
||||
playerEcho(t, pc, []byte("regex hello"))
|
||||
ev := dest.waitEvent(t, 5*time.Second)
|
||||
if ev.handshakeAddr != "MC7.Local" {
|
||||
t.Fatalf("destination saw handshake address %q, want verbatim %q", ev.handshakeAddr, "MC7.Local")
|
||||
}
|
||||
|
||||
// A host that does not fully match the pattern is dropped ('\d+' needs a digit).
|
||||
pc2 := dialPlayer(t, hubAddr, "mc.local")
|
||||
defer pc2.Close()
|
||||
_ = pc2.SetReadDeadline(time.Now().Add(3 * time.Second))
|
||||
if _, err := pc2.Read(make([]byte, 16)); err == nil {
|
||||
t.Fatalf("expected the hub to drop a host that does not match the regex")
|
||||
}
|
||||
}
|
||||
|
||||
// TestLargeTransfer pushes a multi-megabyte payload both ways to exercise mux
|
||||
// framing and back-pressure.
|
||||
func TestLargeTransfer(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user