Skip to content

Commit cb6aebc

Browse files
authored
Merge pull request #643 from upper/default-sslmode
Update default sslmode
2 parents 4e2011c + eb6759b commit cb6aebc

File tree

8 files changed

+42
-34
lines changed

8 files changed

+42
-34
lines changed

adapter/cockroachdb/connection_pgx.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) {
4950
host = "127.0.0.1"
5051
}
5152
if port == "" {
52-
port = "5432"
53+
port = "26257"
5354
}
5455
u = append(u, "host="+escaper.Replace(host))
5556
u = append(u, "port="+escaper.Replace(port))
@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
7576
c.Options = map[string]string{}
7677
}
7778

78-
// If not present, SSL mode is assumed disabled.
79+
// If not present, SSL mode is assumed "prefer".
7980
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
80-
c.Options["sslmode"] = "disable"
81+
c.Options["sslmode"] = "prefer"
8182
}
8283

8384
// Disabled by default

adapter/cockroachdb/connection_pgx_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
3738

3839
// Adding a host with port.
3940
c.Host = "localhost:1234"
40-
assert.Equal(t, "host=localhost port=1234 sslmode=disable statement_cache_capacity=0", c.String())
41+
assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
4142

4243
// Adding a host.
4344
c.Host = "localhost"
44-
assert.Equal(t, "host=localhost sslmode=disable statement_cache_capacity=0", c.String())
45+
assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
4546

4647
// Adding a username.
4748
c.User = "Anakin"
48-
assert.Equal(t, `host=localhost sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
4950

5051
// Adding a password with special characters.
5152
c.Password = "Some Sort of ' Password"
52-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5354

5455
// Adding a port.
5556
c.Host = "localhost:1234"
56-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
57+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5758

5859
// Adding a database.
5960
c.Database = "MyDatabase"
60-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
6162

6263
// Adding options.
6364
c.Options = map[string]string{

adapter/cockroachdb/connection_pq.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) {
4950
host = "127.0.0.1"
5051
}
5152
if port == "" {
52-
port = "5432"
53+
port = "26257"
5354
}
5455
u = append(u, "host="+escaper.Replace(host))
5556
u = append(u, "port="+escaper.Replace(port))
@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
7576
c.Options = map[string]string{}
7677
}
7778

78-
// If not present, SSL mode is assumed disabled.
79+
// If not present, SSL mode is assumed "prefer".
7980
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
80-
c.Options["sslmode"] = "disable"
81+
c.Options["sslmode"] = "prefer"
8182
}
8283

8384
for k, v := range c.Options {

adapter/cockroachdb/connection_pq_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
3738

3839
// Adding a host with port.
3940
c.Host = "localhost:1234"
40-
assert.Equal(t, "host=localhost port=1234 sslmode=disable", c.String())
41+
assert.Equal(t, "host=localhost port=1234 sslmode=prefer", c.String())
4142

4243
// Adding a host.
4344
c.Host = "localhost"
44-
assert.Equal(t, "host=localhost sslmode=disable", c.String())
45+
assert.Equal(t, "host=localhost sslmode=prefer", c.String())
4546

4647
// Adding a username.
4748
c.User = "Anakin"
48-
assert.Equal(t, `host=localhost sslmode=disable user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String())
4950

5051
// Adding a password with special characters.
5152
c.Password = "Some Sort of ' Password"
52-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
5354

5455
// Adding a port.
5556
c.Host = "localhost:1234"
56-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String())
57+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
5758

5859
// Adding a database.
5960
c.Database = "MyDatabase"
60-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
6162

6263
// Adding options.
6364
c.Options = map[string]string{

adapter/postgresql/connection_pgx.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
package postgresql
@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
7576
c.Options = map[string]string{}
7677
}
7778

78-
// If not present, SSL mode is assumed disabled.
79+
// If not present, SSL mode is assumed "prefer".
7980
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
80-
c.Options["sslmode"] = "disable"
81+
c.Options["sslmode"] = "prefer"
8182
}
8283

8384
// Disabled by default

adapter/postgresql/connection_pgx_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
3738

3839
// Adding a host with port.
3940
c.Host = "localhost:1234"
40-
assert.Equal(t, "host=localhost port=1234 sslmode=disable statement_cache_capacity=0", c.String())
41+
assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
4142

4243
// Adding a host.
4344
c.Host = "localhost"
44-
assert.Equal(t, "host=localhost sslmode=disable statement_cache_capacity=0", c.String())
45+
assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
4546

4647
// Adding a username.
4748
c.User = "Anakin"
48-
assert.Equal(t, `host=localhost sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
4950

5051
// Adding a password with special characters.
5152
c.Password = "Some Sort of ' Password"
52-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5354

5455
// Adding a port.
5556
c.Host = "localhost:1234"
56-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
57+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
5758

5859
// Adding a database.
5960
c.Database = "MyDatabase"
60-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
6162

6263
// Adding options.
6364
c.Options = map[string]string{

adapter/postgresql/connection_pq.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
7576
c.Options = map[string]string{}
7677
}
7778

78-
// If not present, SSL mode is assumed disabled.
79+
// If not present, SSL mode is assumed "prefer".
7980
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
80-
c.Options["sslmode"] = "disable"
81+
c.Options["sslmode"] = "prefer"
8182
}
8283

8384
for k, v := range c.Options {

adapter/postgresql/connection_pq_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
3738

3839
// Adding a host with port.
3940
c.Host = "localhost:1234"
40-
assert.Equal(t, "host=localhost port=1234 sslmode=disable", c.String())
41+
assert.Equal(t, "host=localhost port=1234 sslmode=prefer", c.String())
4142

4243
// Adding a host.
4344
c.Host = "localhost"
44-
assert.Equal(t, "host=localhost sslmode=disable", c.String())
45+
assert.Equal(t, "host=localhost sslmode=prefer", c.String())
4546

4647
// Adding a username.
4748
c.User = "Anakin"
48-
assert.Equal(t, `host=localhost sslmode=disable user=Anakin`, c.String())
49+
assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String())
4950

5051
// Adding a password with special characters.
5152
c.Password = "Some Sort of ' Password"
52-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable user=Anakin`, c.String())
53+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
5354

5455
// Adding a port.
5556
c.Host = "localhost:1234"
56-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String())
57+
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
5758

5859
// Adding a database.
5960
c.Database = "MyDatabase"
60-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
6162

6263
// Adding options.
6364
c.Options = map[string]string{

0 commit comments

Comments
 (0)