Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pg-parser): ignore deletion of startup request mocks during match #1341

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/proxy/integrations/postgresParser/postgres_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (p *PostgresParser) ProcessOutgoing(requestBuffer []byte, clientConn, destC
case models.MODE_RECORD:
encodePostgresOutgoing(requestBuffer, clientConn, destConn, p.hooks, p.logger, ctx)
case models.MODE_TEST:
decodePostgresOutgoing(requestBuffer, clientConn, destConn, p.hooks, p.logger, ctx)
logger := p.logger.With(zap.Any("Client IP Address", clientConn.RemoteAddr().String()), zap.Any("Client ConnectionID", util.GetNextID()), zap.Any("Destination ConnectionID", util.GetNextID()))
decodePostgresOutgoing(requestBuffer, clientConn, destConn, p.hooks, logger, ctx)
default:
p.logger.Info("Invalid mode detected while intercepting outgoing http call", zap.Any("mode", models.GetMode()))
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/proxy/integrations/postgresParser/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func matchingReadablePG(requestBuffers [][]byte, logger *zap.Logger, h *hooks.Ho
return false, nil, fmt.Errorf("error while fetching tcs mocks %v", err)
}

isConfig := false
for _, mock := range tcsMocks {
if mock == nil {
continue
Expand All @@ -414,10 +415,12 @@ func matchingReadablePG(requestBuffers [][]byte, logger *zap.Logger, h *hooks.Ho
if mock.Spec.PostgresRequests[requestIndex].Identfier == "StartupRequest" {
logger.Debug("CHANGING TO MD5 for Response")
mock.Spec.PostgresResponses[requestIndex].AuthType = 5
isConfig = true
continue
} else {
if len(encoded) > 0 && encoded[0] == 'p' {
logger.Debug("CHANGING TO MD5 for Request and Response")
isConfig = true
mock.Spec.PostgresRequests[requestIndex].PasswordMessage.Password = "md5fe4f2f657f01fa1dd9d111d5391e7c07"

mock.Spec.PostgresResponses[requestIndex].PacketTypes = []string{"R", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "K", "Z"}
Expand Down Expand Up @@ -492,10 +495,16 @@ func matchingReadablePG(requestBuffers [][]byte, logger *zap.Logger, h *hooks.Ho
}
}

idx := findBinaryStreamMatch(tcsMocks, requestBuffers, logger, h)
if idx != -1 {
isMatched = true
matchedMock = tcsMocks[idx]
if !isMatched {
idx := findBinaryStreamMatch(tcsMocks, requestBuffers, logger, h)
if idx != -1 {
isMatched = true
matchedMock = tcsMocks[idx]
}
}

if isConfig {
return true, matchedMock.Spec.PostgresResponses, nil
}

if isMatched {
Expand Down
Loading