TestDialQuicWithSkipPortReuse tests that DialQuic works correctly with the WithSkipPortReuse option.
(t *testing.T)
| 715 | |
| 716 | // TestDialQuicWithSkipPortReuse tests that DialQuic works correctly with the WithSkipPortReuse option. |
| 717 | func TestDialQuicWithSkipPortReuse(t *testing.T) { |
| 718 | t.Parallel() |
| 719 | |
| 720 | ctx, cancel := context.WithCancel(t.Context()) |
| 721 | defer cancel() |
| 722 | |
| 723 | // Start a mock QUIC server (similar to TestQUICServer) |
| 724 | udpListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}) |
| 725 | require.NoError(t, err) |
| 726 | defer func() { _ = udpListener.Close() }() |
| 727 | |
| 728 | serverAddr := netip.MustParseAddrPort(udpListener.LocalAddr().String()) |
| 729 | |
| 730 | quicTransport := &quic.Transport{Conn: udpListener, ConnectionIDLength: 16} |
| 731 | quicListener, err := quicTransport.Listen(testTLSServerConfig, testQUICConfig) |
| 732 | require.NoError(t, err) |
| 733 | |
| 734 | serverDone := make(chan struct{}) |
| 735 | go func() { |
| 736 | // Accept one connection |
| 737 | session, err := quicListener.Accept(ctx) |
| 738 | if err != nil { |
| 739 | close(serverDone) |
| 740 | return |
| 741 | } |
| 742 | // Keep session open until context is cancelled |
| 743 | <-ctx.Done() |
| 744 | _ = session.CloseWithError(0, "test done") |
| 745 | close(serverDone) |
| 746 | }() |
| 747 | |
| 748 | // Test DialQuic with WithSkipPortReuse option |
| 749 | tlsClientConfig := &tls.Config{ |
| 750 | // nolint: gosec |
| 751 | InsecureSkipVerify: true, |
| 752 | NextProtos: []string{"argotunnel"}, |
| 753 | } |
| 754 | |
| 755 | log := zerolog.New(io.Discard) |
| 756 | dialCtx, dialCancel := context.WithTimeout(t.Context(), 5*time.Second) |
| 757 | defer dialCancel() |
| 758 | |
| 759 | // Dial with skipPortReuse option - should use a random ephemeral port |
| 760 | conn, err := DialQuic( |
| 761 | dialCtx, |
| 762 | testQUICConfig, |
| 763 | tlsClientConfig, |
| 764 | serverAddr, |
| 765 | nil, // connect on a random port |
| 766 | 0, |
| 767 | &log, |
| 768 | dialopts.DialOpts{SkipPortReuse: true}, |
| 769 | ) |
| 770 | require.NoError(t, err) |
| 771 | require.NotNil(t, conn) |
| 772 | |
| 773 | // Verify we can get connection state |
| 774 | _ = conn.ConnectionState() |
nothing calls this directly
no test coverage detected