mirror of
https://github.com/fatedier/frp.git
synced 2026-04-28 03:49:09 +08:00
protocol: add v2 wire protocol with binary framing and capability negotiation (#5294)
This commit is contained in:
55
pkg/msg/msg_test.go
Normal file
55
pkg/msg/msg_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2026 The frp Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package msg
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestV1MessageTypeIDsAreStable(t *testing.T) {
|
||||
require.Equal(t, byte('o'), TypeLogin)
|
||||
require.Equal(t, byte('1'), TypeLoginResp)
|
||||
require.Equal(t, byte('p'), TypeNewProxy)
|
||||
require.Equal(t, byte('2'), TypeNewProxyResp)
|
||||
require.Equal(t, byte('c'), TypeCloseProxy)
|
||||
require.Equal(t, byte('w'), TypeNewWorkConn)
|
||||
require.Equal(t, byte('r'), TypeReqWorkConn)
|
||||
require.Equal(t, byte('s'), TypeStartWorkConn)
|
||||
require.Equal(t, byte('v'), TypeNewVisitorConn)
|
||||
require.Equal(t, byte('3'), TypeNewVisitorConnResp)
|
||||
require.Equal(t, byte('h'), TypePing)
|
||||
require.Equal(t, byte('4'), TypePong)
|
||||
require.Equal(t, byte('u'), TypeUDPPacket)
|
||||
require.Equal(t, byte('i'), TypeNatHoleVisitor)
|
||||
require.Equal(t, byte('n'), TypeNatHoleClient)
|
||||
require.Equal(t, byte('m'), TypeNatHoleResp)
|
||||
require.Equal(t, byte('5'), TypeNatHoleSid)
|
||||
require.Equal(t, byte('6'), TypeNatHoleReport)
|
||||
}
|
||||
|
||||
func TestMessageTypeMapIsCompleteAndUnique(t *testing.T) {
|
||||
require.Len(t, msgTypeMap, 18)
|
||||
|
||||
msgTypes := make(map[reflect.Type]struct{}, len(msgTypeMap))
|
||||
|
||||
for _, m := range msgTypeMap {
|
||||
msgType := reflect.TypeOf(m)
|
||||
require.NotContains(t, msgTypes, msgType)
|
||||
msgTypes[msgType] = struct{}{}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user