mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-10 17:43:15 +08:00
- 架构升级:从driver专属拨号器改为通用本地端口转发模式
- 并发安全:sync.Once保护Close操作,RWMutex保护状态访问,双向errc等待
- 连接池化:GetOrCreateLocalForwarder/GetOrCreateSSHClient实现缓存复用
- SQL安全:kingbase_impl.go引入esc函数,防止双引号注入(""ldf_server""问题)
- Schema动态化:三级fallback(schema.table解析→dbName参数→current_schema())
- 代码复用:scanRows统一行扫描逻辑,normalizeQueryValueWithDBType增强类型处理
Close #40
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package app
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeSQLForPgLike_FixesBrokenDoubleDoubleQuotes(t *testing.T) {
|
|
in := `SELECT * FROM ""ldf_server"".""t_user"" LIMIT 1`
|
|
out := sanitizeSQLForPgLike("kingbase", in)
|
|
want := `SELECT * FROM "ldf_server"."t_user" LIMIT 1`
|
|
if out != want {
|
|
t.Fatalf("unexpected sanitize output:\nIN: %s\nOUT: %s\nWANT: %s", in, out, want)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSQLForPgLike_FixesBrokenDoubleDoubleQuotes_WithExtraQuotes(t *testing.T) {
|
|
in := `SELECT * FROM ""ldf_server""".""t_user"" LIMIT 1`
|
|
out := sanitizeSQLForPgLike("kingbase", in)
|
|
want := `SELECT * FROM "ldf_server"."t_user" LIMIT 1`
|
|
if out != want {
|
|
t.Fatalf("unexpected sanitize output:\nIN: %s\nOUT: %s\nWANT: %s", in, out, want)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSQLForPgLike_FixesBrokenDoubleDoubleQuotes_WithQuadQuotes(t *testing.T) {
|
|
in := `SELECT * FROM """"ldf_server"""".""t_user"" LIMIT 1`
|
|
out := sanitizeSQLForPgLike("kingbase", in)
|
|
want := `SELECT * FROM "ldf_server"."t_user" LIMIT 1`
|
|
if out != want {
|
|
t.Fatalf("unexpected sanitize output:\nIN: %s\nOUT: %s\nWANT: %s", in, out, want)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSQLForPgLike_DoesNotTouchEscapedQuotesInsideIdentifier(t *testing.T) {
|
|
in := `SELECT "a""b" FROM "t""x"`
|
|
out := sanitizeSQLForPgLike("postgres", in)
|
|
if out != in {
|
|
t.Fatalf("should keep valid escaped quotes inside identifier:\nIN: %s\nOUT: %s", in, out)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSQLForPgLike_DoesNotTouchDollarQuotedStrings(t *testing.T) {
|
|
in := "SELECT $$\"\"ldf_server\"\"$$, \"\"ldf_server\"\""
|
|
out := sanitizeSQLForPgLike("postgres", in)
|
|
want := "SELECT $$\"\"ldf_server\"\"$$, \"ldf_server\""
|
|
if out != want {
|
|
t.Fatalf("unexpected sanitize output for dollar quoted string:\nIN: %s\nOUT: %s\nWANT: %s", in, out, want)
|
|
}
|
|
}
|
|
|
|
func TestSanitizeSQLForPgLike_DoesNotModifyOtherDBTypes(t *testing.T) {
|
|
in := `SELECT * FROM ""ldf_server""`
|
|
out := sanitizeSQLForPgLike("mysql", in)
|
|
if out != in {
|
|
t.Fatalf("non-PG-like db should not be sanitized:\nIN: %s\nOUT: %s", in, out)
|
|
}
|
|
}
|