mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 22:32:24 +08:00
Fix postgresql host-v6 literals (#46876)
Ipv6 literals in postgresql hosts previously worked and were subsequently broken. This change fixes the parsing and adds additional test cases.
This commit is contained in:
@ -67,6 +67,24 @@ func TestGenerateConnectionString(t *testing.T) {
|
||||
tlsSettings: tlsSettings{Mode: "verify-full"},
|
||||
expConnStr: "user='user' password='password' host='host' dbname='database' port=1234 sslmode='verify-full'",
|
||||
},
|
||||
{
|
||||
desc: "Ipv6 host",
|
||||
host: "[::1]",
|
||||
user: "user",
|
||||
password: "password",
|
||||
database: "database",
|
||||
tlsSettings: tlsSettings{Mode: "verify-full"},
|
||||
expConnStr: "user='user' password='password' host='[::1]' dbname='database' sslmode='verify-full'",
|
||||
},
|
||||
{
|
||||
desc: "Ipv6/port host",
|
||||
host: "[::1]:1234",
|
||||
user: "user",
|
||||
password: "password",
|
||||
database: "database",
|
||||
tlsSettings: tlsSettings{Mode: "verify-full"},
|
||||
expConnStr: "user='user' password='password' host='[::1]' dbname='database' port=1234 sslmode='verify-full'",
|
||||
},
|
||||
{
|
||||
desc: "Invalid port",
|
||||
host: "host:invalid",
|
||||
@ -84,6 +102,15 @@ func TestGenerateConnectionString(t *testing.T) {
|
||||
tlsSettings: tlsSettings{Mode: "verify-full"},
|
||||
expConnStr: `user='user' password='p\'\\assword' host='host' dbname='database' sslmode='verify-full'`,
|
||||
},
|
||||
{
|
||||
desc: "User/DB with single quote and backslash",
|
||||
host: "host",
|
||||
user: `u'\ser`,
|
||||
password: `password`,
|
||||
database: `d'\atabase`,
|
||||
tlsSettings: tlsSettings{Mode: "verify-full"},
|
||||
expConnStr: `user='u\'\\ser' password='password' host='host' dbname='d\'\\atabase' sslmode='verify-full'`,
|
||||
},
|
||||
{
|
||||
desc: "Custom TLS mode disabled",
|
||||
host: "host",
|
||||
|
Reference in New Issue
Block a user