mirror of
https://github.com/fatedier/frp.git
synced 2026-08-24 09:18:51 +00:00
log: improve prefix handling (#5489)
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
|
||||
"github.com/fatedier/frp/pkg/auth"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/fatedier/frp/pkg/config/v1/validation"
|
||||
modelmetrics "github.com/fatedier/frp/pkg/metrics"
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
"github.com/fatedier/frp/pkg/nathole"
|
||||
@@ -791,6 +792,9 @@ func (svr *Service) RegisterControl(
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := validation.ValidateRunID(loginMsg.RunID); err != nil {
|
||||
return nil, fmt.Errorf("invalid run id: %w", err)
|
||||
}
|
||||
|
||||
ctx := netpkg.NewContextFromConn(ctlConn)
|
||||
xl := xlog.FromContextSafe(ctx)
|
||||
|
||||
@@ -17,10 +17,12 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -31,6 +33,7 @@ import (
|
||||
|
||||
"github.com/fatedier/frp/pkg/auth"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/fatedier/frp/pkg/config/v1/validation"
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
plugin "github.com/fatedier/frp/pkg/plugin/server"
|
||||
"github.com/fatedier/frp/pkg/proto/wire"
|
||||
@@ -638,6 +641,22 @@ func TestServiceRegisterControlRejectsInvalidCodecSelection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceRegisterControlRejectsInvalidRunID(t *testing.T) {
|
||||
for _, runID := range []string{
|
||||
"run\nforged",
|
||||
strings.Repeat("a", validation.MaxRunIDLength+1),
|
||||
} {
|
||||
t.Run(fmt.Sprintf("run_id_%d", len(runID)), func(t *testing.T) {
|
||||
svr := newControlTestService(t)
|
||||
conn := newDeadlineReadConn()
|
||||
msgConn := msg.NewConn(conn, msg.NewV1ReadWriter(conn))
|
||||
ctl, err := svr.RegisterControl(msgConn, &msg.Login{RunID: runID}, true, wire.ProtocolV1, "")
|
||||
require.Nil(t, ctl)
|
||||
require.ErrorContains(t, err, "invalid run id")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceRegisterControlPoolCountBoundaries(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user