Harden scan robustness and tests

This commit is contained in:
ZacharyZcR
2026-06-13 07:55:37 +08:00
parent 1595c92aed
commit 15a7670ba2
100 changed files with 4483 additions and 412 deletions
+34
View File
@@ -0,0 +1,34 @@
//go:build plugin_redis || !plugin_selective
package services
import (
"net"
"strings"
"testing"
"time"
)
func TestRedisReadReplyIsBounded(t *testing.T) {
conn := &redisReplyTestConn{Reader: strings.NewReader(strings.Repeat("a", maxRedisReplyBytes+1024))}
got, err := NewRedisPlugin().readReply(conn)
if err != nil {
t.Fatalf("readReply() error = %v", err)
}
if len(got) != maxRedisReplyBytes {
t.Fatalf("readReply() len = %d, want %d", len(got), maxRedisReplyBytes)
}
}
type redisReplyTestConn struct {
*strings.Reader
}
func (c *redisReplyTestConn) Write([]byte) (int, error) { return 0, nil }
func (c *redisReplyTestConn) Close() error { return nil }
func (c *redisReplyTestConn) LocalAddr() net.Addr { return nil }
func (c *redisReplyTestConn) RemoteAddr() net.Addr { return nil }
func (c *redisReplyTestConn) SetDeadline(time.Time) error { return nil }
func (c *redisReplyTestConn) SetReadDeadline(time.Time) error { return nil }
func (c *redisReplyTestConn) SetWriteDeadline(time.Time) error { return nil }