good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit cb6aebc2 authored by José Nieto's avatar José Nieto Committed by GitHub
Browse files

Merge pull request #643 from upper/default-sslmode

Update default sslmode
parents 4e2011c8 eb6759b0
No related branches found
No related tags found
No related merge requests found
//go:build !pq
// +build !pq // +build !pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) { ...@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) {
host = "127.0.0.1" host = "127.0.0.1"
} }
if port == "" { if port == "" {
port = "5432" port = "26257"
} }
u = append(u, "host="+escaper.Replace(host)) u = append(u, "host="+escaper.Replace(host))
u = append(u, "port="+escaper.Replace(port)) u = append(u, "port="+escaper.Replace(port))
...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) { ...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
c.Options = map[string]string{} c.Options = map[string]string{}
} }
// If not present, SSL mode is assumed disabled. // If not present, SSL mode is assumed "prefer".
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" { if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
c.Options["sslmode"] = "disable" c.Options["sslmode"] = "prefer"
} }
// Disabled by default // Disabled by default
......
//go:build !pq
// +build !pq // +build !pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) { ...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
// Adding a host with port. // Adding a host with port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, "host=localhost port=1234 sslmode=disable statement_cache_capacity=0", c.String()) assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
// Adding a host. // Adding a host.
c.Host = "localhost" c.Host = "localhost"
assert.Equal(t, "host=localhost sslmode=disable statement_cache_capacity=0", c.String()) assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
// Adding a username. // Adding a username.
c.User = "Anakin" c.User = "Anakin"
assert.Equal(t, `host=localhost sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a password with special characters. // Adding a password with special characters.
c.Password = "Some Sort of ' Password" c.Password = "Some Sort of ' Password"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a port. // Adding a port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a database. // Adding a database.
c.Database = "MyDatabase" c.Database = "MyDatabase"
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding options. // Adding options.
c.Options = map[string]string{ c.Options = map[string]string{
......
//go:build pq
// +build pq // +build pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) { ...@@ -49,7 +50,7 @@ func (c ConnectionURL) String() (s string) {
host = "127.0.0.1" host = "127.0.0.1"
} }
if port == "" { if port == "" {
port = "5432" port = "26257"
} }
u = append(u, "host="+escaper.Replace(host)) u = append(u, "host="+escaper.Replace(host))
u = append(u, "port="+escaper.Replace(port)) u = append(u, "port="+escaper.Replace(port))
...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) { ...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
c.Options = map[string]string{} c.Options = map[string]string{}
} }
// If not present, SSL mode is assumed disabled. // If not present, SSL mode is assumed "prefer".
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" { if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
c.Options["sslmode"] = "disable" c.Options["sslmode"] = "prefer"
} }
for k, v := range c.Options { for k, v := range c.Options {
......
//go:build pq
// +build pq // +build pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) { ...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
// Adding a host with port. // Adding a host with port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, "host=localhost port=1234 sslmode=disable", c.String()) assert.Equal(t, "host=localhost port=1234 sslmode=prefer", c.String())
// Adding a host. // Adding a host.
c.Host = "localhost" c.Host = "localhost"
assert.Equal(t, "host=localhost sslmode=disable", c.String()) assert.Equal(t, "host=localhost sslmode=prefer", c.String())
// Adding a username. // Adding a username.
c.User = "Anakin" c.User = "Anakin"
assert.Equal(t, `host=localhost sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String())
// Adding a password with special characters. // Adding a password with special characters.
c.Password = "Some Sort of ' Password" c.Password = "Some Sort of ' Password"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
// Adding a port. // Adding a port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
// Adding a database. // Adding a database.
c.Database = "MyDatabase" c.Database = "MyDatabase"
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
// Adding options. // Adding options.
c.Options = map[string]string{ c.Options = map[string]string{
......
//go:build !pq
// +build !pq // +build !pq
package postgresql package postgresql
...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) { ...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
c.Options = map[string]string{} c.Options = map[string]string{}
} }
// If not present, SSL mode is assumed disabled. // If not present, SSL mode is assumed "prefer".
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" { if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
c.Options["sslmode"] = "disable" c.Options["sslmode"] = "prefer"
} }
// Disabled by default // Disabled by default
......
//go:build !pq
// +build !pq // +build !pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) { ...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
// Adding a host with port. // Adding a host with port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, "host=localhost port=1234 sslmode=disable statement_cache_capacity=0", c.String()) assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
// Adding a host. // Adding a host.
c.Host = "localhost" c.Host = "localhost"
assert.Equal(t, "host=localhost sslmode=disable statement_cache_capacity=0", c.String()) assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
// Adding a username. // Adding a username.
c.User = "Anakin" c.User = "Anakin"
assert.Equal(t, `host=localhost sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a password with special characters. // Adding a password with special characters.
c.Password = "Some Sort of ' Password" c.Password = "Some Sort of ' Password"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a port. // Adding a port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding a database. // Adding a database.
c.Database = "MyDatabase" c.Database = "MyDatabase"
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable statement_cache_capacity=0 user=Anakin`, c.String()) assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
// Adding options. // Adding options.
c.Options = map[string]string{ c.Options = map[string]string{
......
//go:build pq
// +build pq // +build pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) { ...@@ -75,9 +76,9 @@ func (c ConnectionURL) String() (s string) {
c.Options = map[string]string{} c.Options = map[string]string{}
} }
// If not present, SSL mode is assumed disabled. // If not present, SSL mode is assumed "prefer".
if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" { if sslMode, ok := c.Options["sslmode"]; !ok || sslMode == "" {
c.Options["sslmode"] = "disable" c.Options["sslmode"] = "prefer"
} }
for k, v := range c.Options { for k, v := range c.Options {
......
//go:build pq
// +build pq // +build pq
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved. // Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) { ...@@ -37,27 +38,27 @@ func TestConnectionURL(t *testing.T) {
// Adding a host with port. // Adding a host with port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, "host=localhost port=1234 sslmode=disable", c.String()) assert.Equal(t, "host=localhost port=1234 sslmode=prefer", c.String())
// Adding a host. // Adding a host.
c.Host = "localhost" c.Host = "localhost"
assert.Equal(t, "host=localhost sslmode=disable", c.String()) assert.Equal(t, "host=localhost sslmode=prefer", c.String())
// Adding a username. // Adding a username.
c.User = "Anakin" c.User = "Anakin"
assert.Equal(t, `host=localhost sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost sslmode=prefer user=Anakin`, c.String())
// Adding a password with special characters. // Adding a password with special characters.
c.Password = "Some Sort of ' Password" c.Password = "Some Sort of ' Password"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
// Adding a port. // Adding a port.
c.Host = "localhost:1234" c.Host = "localhost:1234"
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
// Adding a database. // Adding a database.
c.Database = "MyDatabase" c.Database = "MyDatabase"
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=disable user=Anakin`, c.String()) assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
// Adding options. // Adding options.
c.Options = map[string]string{ c.Options = map[string]string{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment