Skip to content

Commit 62ff327

Browse files
Merge pull request #10246 from smartcontractkit/fix/release-2.4.0-re-enabling-simple-passwords-restriction
2 parents 28ed702 + fdd5395 commit 62ff327

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

core/config/toml/types.go

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func validateDBURL(dbURI url.URL) error {
148148
func (d *DatabaseSecrets) ValidateConfig() (err error) {
149149
if d.URL == nil || (*url.URL)(d.URL).String() == "" {
150150
err = multierr.Append(err, configutils.ErrEmpty{Name: "URL", Msg: "must be provided and non-empty"})
151+
} else if *d.AllowSimplePasswords && build.IsProd() {
152+
err = multierr.Append(err, configutils.ErrInvalid{Name: "AllowSimplePasswords", Value: true, Msg: "insecure configs are not allowed on secure builds"})
151153
} else if !*d.AllowSimplePasswords {
152154
if verr := validateDBURL((url.URL)(*d.URL)); verr != nil {
153155
err = multierr.Append(err, configutils.ErrInvalid{Name: "URL", Value: "*****", Msg: dbURLPasswordComplexity(verr)})

core/config/toml/types_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package toml
22

33
import (
44
"fmt"
5+
"net/url"
6+
"strings"
57
"testing"
68

79
"github.com/stretchr/testify/assert"
810

11+
"github.com/smartcontractkit/chainlink/v2/core/build"
912
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
1013
"github.com/smartcontractkit/chainlink/v2/core/store/models"
1114
"github.com/smartcontractkit/chainlink/v2/core/utils"
@@ -97,3 +100,77 @@ func Test_validateDBURL(t *testing.T) {
97100
})
98101
}
99102
}
103+
104+
func TestValidateConfig(t *testing.T) {
105+
validUrl := models.URL(url.URL{Scheme: "https", Host: "localhost"})
106+
validSecretURL := *models.NewSecretURL(&validUrl)
107+
108+
invalidEmptyUrl := models.URL(url.URL{})
109+
invalidEmptySecretURL := *models.NewSecretURL(&invalidEmptyUrl)
110+
111+
invalidBackupURL := models.URL(url.URL{Scheme: "http", Host: "localhost"})
112+
invalidBackupSecretURL := *models.NewSecretURL(&invalidBackupURL)
113+
114+
tests := []struct {
115+
name string
116+
input *DatabaseSecrets
117+
skip bool
118+
expectedErrContains []string
119+
}{
120+
{
121+
name: "Nil URL",
122+
input: &DatabaseSecrets{
123+
URL: nil,
124+
},
125+
expectedErrContains: []string{"URL: empty: must be provided and non-empty"},
126+
},
127+
{
128+
name: "Empty URL",
129+
input: &DatabaseSecrets{
130+
URL: &invalidEmptySecretURL,
131+
},
132+
expectedErrContains: []string{"URL: empty: must be provided and non-empty"},
133+
},
134+
{
135+
name: "Insecure Password in Production",
136+
input: &DatabaseSecrets{
137+
URL: &validSecretURL,
138+
AllowSimplePasswords: &[]bool{true}[0],
139+
},
140+
skip: !build.IsProd(),
141+
expectedErrContains: []string{"insecure configs are not allowed on secure builds"},
142+
},
143+
{
144+
name: "Invalid Backup URL with Simple Passwords Not Allowed",
145+
input: &DatabaseSecrets{
146+
URL: &validSecretURL,
147+
BackupURL: &invalidBackupSecretURL,
148+
AllowSimplePasswords: &[]bool{false}[0],
149+
},
150+
expectedErrContains: []string{"missing or insufficiently complex password"},
151+
},
152+
}
153+
154+
for _, tt := range tests {
155+
t.Run(tt.name, func(t *testing.T) {
156+
// needed while -tags test is supported
157+
if tt.skip {
158+
t.SkipNow()
159+
}
160+
err := tt.input.ValidateConfig()
161+
if err == nil && len(tt.expectedErrContains) > 0 {
162+
t.Errorf("expected errors but got none")
163+
return
164+
}
165+
166+
if err != nil {
167+
errStr := err.Error()
168+
for _, expectedErrSubStr := range tt.expectedErrContains {
169+
if !strings.Contains(errStr, expectedErrSubStr) {
170+
t.Errorf("expected error to contain substring %q but got %v", expectedErrSubStr, errStr)
171+
}
172+
}
173+
}
174+
})
175+
}
176+
}

docs/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [dev]
1111

12-
...
1312

1413
## 2.4.0 - UNRELEASED
1514
### Fixed

0 commit comments

Comments
 (0)