| 1 | // Copyright 2026 The frp Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package visitor |
| 16 | |
| 17 | import ( |
| 18 | "net" |
| 19 | "testing" |
| 20 | "time" |
| 21 | |
| 22 | "github.com/stretchr/testify/require" |
| 23 | |
| 24 | "github.com/fatedier/frp/pkg/proto/wire" |
| 25 | "github.com/fatedier/frp/pkg/util/util" |
| 26 | ) |
| 27 | |
| 28 | func TestManagerNewConnCarriesWireProtocol(t *testing.T) { |
| 29 | vm := NewManager() |
| 30 | listener, err := vm.Listen("sudp", "secret", []string{"*"}) |
| 31 | require.NoError(t, err) |
| 32 | defer listener.Close() |
| 33 | |
| 34 | client, server := net.Pipe() |
| 35 | defer client.Close() |
| 36 | defer server.Close() |
| 37 | |
| 38 | now := time.Now().Unix() |
| 39 | errCh := make(chan error, 1) |
| 40 | go func() { |
| 41 | errCh <- vm.NewConn( |
| 42 | "sudp", |
| 43 | server, |
| 44 | now, |
| 45 | util.GetAuthKey("secret", now), |
| 46 | false, |
| 47 | false, |
| 48 | "user", |
| 49 | wire.ProtocolV2, |
| 50 | ) |
| 51 | }() |
| 52 | |
| 53 | acceptedConn, err := listener.Accept() |
| 54 | require.NoError(t, err) |
| 55 | defer acceptedConn.Close() |
| 56 | |
| 57 | getter, ok := acceptedConn.(interface{ WireProtocol() string }) |
| 58 | require.True(t, ok) |
| 59 | require.Equal(t, wire.ProtocolV2, getter.WireProtocol()) |
| 60 | require.NoError(t, <-errCh) |
| 61 | } |