2024-10-11 14:58:36: merge [master:7f99b95ceaaed865d2833070a0397cf191949b8e];

This commit is contained in:
txix committed 2024-10-11 14:58:36 +03:00
1 parent 6db18c1495
commit 97c44fb3bd
26 files changed
+235 -266

No files matched your search

+47 -33
View File
@@ -8,28 +8,30 @@ import (
"net/url"
"strconv"
"testing"
"time"
etp "github.com/integration-system/isp-etp-go/v2"
etpcli "github.com/integration-system/isp-etp-go/v2/client"
"github.com/integration-system/isp-kit/cluster"
"github.com/integration-system/isp-kit/http/httpcli"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/require"
"isp-gate-service/assembly"
"isp-gate-service/conf"
"isp-gate-service/domain"
"isp-gate-service/routes"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/require"
etp "github.com/txix-open/etp/v3"
"github.com/txix-open/etp/v3/msg"
"github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/http/httpcli"
"github.com/google/uuid"
"github.com/integration-system/isp-kit/grpc"
"github.com/integration-system/isp-kit/grpc/client"
"github.com/integration-system/isp-kit/lb"
"github.com/integration-system/isp-kit/log"
"github.com/integration-system/isp-kit/requestid"
"github.com/integration-system/isp-kit/test"
"github.com/integration-system/isp-kit/test/grpct"
"github.com/integration-system/isp-kit/test/httpt"
"github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/lb"
"github.com/txix-open/isp-kit/log"
"github.com/txix-open/isp-kit/requestid"
"github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/grpct"
"github.com/txix-open/isp-kit/test/httpt"
"google.golang.org/grpc/metadata"
)
@@ -147,20 +149,16 @@ func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
requestId := requestid.Next()
wsServer := etp.NewServer(context.Background(), etp.ServerConfig{
ConnectionReadLimit: 2048,
InsecureSkipVerify: true,
})
wsServer.OnWithAck("hello", func(conn etp.Conn, data []byte) []byte {
headers := conn.RemoteHeader()
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id"))
assertHeaders(require, requestId, ctx, headers)
require.EqualValues("data", string(data))
return []byte("world")
wsServer := etp.NewServer(etp.WithServerReadLimit(2048))
wsServer.On("hello", wsEventHandlerMock{
requestId: requestId,
require: require,
t: test.T(),
})
wsMux := http.NewServeMux()
wsMux.Handle("/service", http.HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
wsServer.ServeHttp(writer, r)
wsServer.ServeHTTP(writer, r)
}))
targetService := httptest.NewServer(wsMux)
targetUrl, err := url.Parse(targetService.URL)
@@ -178,12 +176,11 @@ func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
require.NoError(err)
srv := httptest.NewServer(handler)
cli := etpcli.NewClient(etpcli.Config{
HttpHeaders: map[string][]string{
cli := etp.NewClient(etp.WithClientDialOptions(&etp.DialOptions{
HTTPHeader: map[string][]string{
"x-request-id": {requestId},
},
})
}))
requestUrl, err := url.Parse(srv.URL)
require.NoError(err)
requestUrl.Path = "ws/service"
@@ -193,13 +190,29 @@ func (s *HappyPathTestSuite) TestWsProxy() { // nolint: funlen
}.Encode()
err = cli.Dial(context.Background(), requestUrl.String())
require.NoError(err)
resp, err := cli.EmitWithAck(context.Background(), "hello", []byte("data"))
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
resp, err := cli.EmitWithAck(ctx, "hello", []byte("data"))
require.NoError(err)
require.EqualValues("world", string(resp))
err = cli.Close()
require.NoError(err)
}
type wsEventHandlerMock struct {
requestId string
require *require.Assertions
t require.TestingT
}
func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.Event) []byte {
headers := conn.HttpRequest().Header
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id"))
assertHeaders(s.require, s.requestId, ctx, headers)
require.EqualValues(s.t, "data", event.Data)
return []byte("world")
}
func (s *HappyPathTestSuite) TestAdminAuthorization() {
test, require := test.New(s.T())
config, redisCli, systemCli, adminCli := s.commonDependencies(test)
@@ -287,9 +300,10 @@ func (s *HappyPathTestSuite) commonDependencies(test *test.Test) (conf.Remote, r
Http: conf.Http{MaxRequestBodySizeInMb: 1, ProxyTimeoutInSec: 15},
Logging: conf.Logging{LogLevel: log.DebugLevel, RequestLogEnable: true, BodyLogEnable: true,
SkipBodyLoggingEndpointPrefixes: []string{"endpoint"}},
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
DailyLimits: []conf.DailyLimit{{ApplicationId: 1, RequestsPerDay: 100}},
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 100}},
Caching: conf.Caching{AuthorizationDataInSec: 1, AuthenticationDataInSec: 1},
DailyLimits: []conf.DailyLimit{{ApplicationId: 1, RequestsPerDay: 100}},
Throttling: []conf.Throttling{{ApplicationId: 1, RequestsPerSeconds: 100}},
EnableClientRequestIdForwarding: true,
}
systemService, systemCli := grpct.NewMock(test)
+5 -5
View File
@@ -11,11 +11,11 @@ import (
"isp-gate-service/domain"
"isp-gate-service/routes"
"github.com/integration-system/isp-kit/grpc"
"github.com/integration-system/isp-kit/grpc/client"
endpoint2 "github.com/integration-system/isp-kit/grpc/endpoint"
"github.com/integration-system/isp-kit/grpc/isp"
"github.com/integration-system/isp-kit/log"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/client"
endpoint2 "github.com/txix-open/isp-kit/grpc/endpoint"
"github.com/txix-open/isp-kit/grpc/isp"
"github.com/txix-open/isp-kit/log"
)
type request struct {
+1 -1
View File
@@ -3,8 +3,8 @@ package tests
import (
"fmt"
"github.com/integration-system/isp-kit/test"
"github.com/redis/go-redis/v9"
"github.com/txix-open/isp-kit/test"
)
type Redis struct {