From bd9e2374ec83c887fd0157be899edd6e682ee185 Mon Sep 17 00:00:00 2001 From: Stefano Scafiti Date: Sun, 7 Apr 2024 13:16:59 +0200 Subject: [PATCH] Add TestPgsqlServer_InvalidTraffic --- pkg/pgsql/server/pgsql_integration_test.go | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/pgsql/server/pgsql_integration_test.go b/pkg/pgsql/server/pgsql_integration_test.go index b40c173583..77d13a4ea3 100644 --- a/pkg/pgsql/server/pgsql_integration_test.go +++ b/pkg/pgsql/server/pgsql_integration_test.go @@ -24,6 +24,7 @@ import ( "encoding/hex" "fmt" "math/rand" + "net/http" "os" "testing" "time" @@ -1180,3 +1181,33 @@ func TestPgsqlServer_ExtendedQueryPGMultiFieldsPreparedMultiInsertError(t *testi _, err = db.Exec(context.Background(), fmt.Sprintf("INSERT INTO %s (id, amount, total, title, content, isPresent) VALUES (?, ?, ?, ?, ?, ?); INSERT INTO %s (id, amount, total, title, content, isPresent) VALUES (?, ?, ?, ?, ?, ?)", table, table), 1, 1000, 6000, "title 1", blobContent, true, 2, 2000, 12000, "title 2", blobContent2, true) require.ErrorContains(t, err, errors.ErrMaxStmtNumberExceeded.Error()) } + +func TestPgsqlServer_InvalidTraffic(t *testing.T) { + td := t.TempDir() + + options := server.DefaultOptions(). + WithDir(td). + WithPort(0). + WithPgsqlServer(true). + WithPgsqlServerPort(0). + WithMetricsServer(false). + WithWebServer(false) + + srv := server.DefaultServer().WithOptions(options).(*server.ImmuServer) + + err := srv.Initialize() + if err != nil { + panic(err) + } + + go func() { + srv.Start() + }() + + defer func() { + srv.Stop() + }() + + _, err = http.Get(fmt.Sprintf("http://localhost:%d", srv.PgsqlSrv.GetPort())) + require.Error(t, err) +}