From 22412851b4262212826a81406a2c8d19dbfb3c5f Mon Sep 17 00:00:00 2001 From: fatedier Date: Tue, 11 Jan 2022 16:32:20 +0800 Subject: [PATCH] server plugin: add client address in Login operation, fix #2742 (#2751) --- pkg/plugin/server/types.go | 2 ++ server/service.go | 3 ++- test/e2e/plugin/server.go | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/plugin/server/types.go b/pkg/plugin/server/types.go index 82d4032c..4df79f46 100644 --- a/pkg/plugin/server/types.go +++ b/pkg/plugin/server/types.go @@ -33,6 +33,8 @@ type Response struct { type LoginContent struct { msg.Login + + ClientAddress string `json:"client_address,omitempty"` } type UserInfo struct { diff --git a/server/service.go b/server/service.go index 97a65f80..f6e015a5 100644 --- a/server/service.go +++ b/server/service.go @@ -334,7 +334,8 @@ func (svr *Service) handleConnection(ctx context.Context, conn net.Conn) { case *msg.Login: // server plugin hook content := &plugin.LoginContent{ - Login: *m, + Login: *m, + ClientAddress: conn.RemoteAddr().String(), } retContent, err := svr.pluginManager.Login(content) if err == nil { diff --git a/test/e2e/plugin/server.go b/test/e2e/plugin/server.go index 0cd618f9..79ecff44 100644 --- a/test/e2e/plugin/server.go +++ b/test/e2e/plugin/server.go @@ -24,9 +24,14 @@ var _ = Describe("[Feature: Server-Plugins]", func() { It("Auth for custom meta token", func() { localPort := f.AllocPort() + + clientAddressGot := false handler := func(req *plugin.Request) *plugin.Response { var ret plugin.Response content := req.Content.(*plugin.LoginContent) + if content.ClientAddress != "" { + clientAddressGot = true + } if content.Metas["token"] == "123" { ret.Unchange = true } else { @@ -69,6 +74,8 @@ var _ = Describe("[Feature: Server-Plugins]", func() { framework.NewRequestExpect(f).Port(remotePort).Ensure() framework.NewRequestExpect(f).Port(remotePort2).ExpectError(true).Ensure() + + framework.ExpectTrue(clientAddressGot) }) })