File tree Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ require (
7474 github.com/stretchr/objx v0.5.0 // indirect
7575 github.com/tklauser/go-sysconf v0.3.11 // indirect
7676 github.com/tklauser/numcpus v0.6.1 // indirect
77+ github.com/wagslane/go-password-validator v0.3.0 // indirect
7778 github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
7879 github.com/yusufpapurcu/wmi v1.2.3 // indirect
7980 golang.org/x/net v0.12.0 // indirect
Original file line number Diff line number Diff line change @@ -684,6 +684,8 @@ github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5
684684github.com/vishvananda/netlink v1.1.0 /go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE =
685685github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc /go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI =
686686github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df /go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU =
687+ github.com/wagslane/go-password-validator v0.3.0 h1:vfxOPzGHkz5S146HDpavl0cw1DSVP061Ry2PX0/ON6I =
688+ github.com/wagslane/go-password-validator v0.3.0 /go.mod h1:TI1XJ6T5fRdRnHqHt14pvy1tNVnrwe7m3/f1f2fDphQ =
687689github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243 /go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4 =
688690github.com/willf/bitset v1.1.11 /go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI =
689691github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f /go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU =
Original file line number Diff line number Diff line change 66package validator
77
88import (
9+ "fmt"
10+
911 "github.com/pkg/errors"
12+ passwordvalidator "github.com/wagslane/go-password-validator"
1013
1114 "gitlab.com/postgres-ai/database-lab/v3/pkg/client/dblabapi/types"
1215)
1316
17+ const minEntropyBits = 60
18+
1419// Service provides a validation service.
1520type Service struct {
1621}
@@ -29,5 +34,9 @@ func (v Service) ValidateCloneRequest(cloneRequest *types.CloneCreateRequest) er
2934 return errors .New ("missing DB password" )
3035 }
3136
37+ if err := passwordvalidator .Validate (cloneRequest .DB .Password , minEntropyBits ); err != nil {
38+ return fmt .Errorf ("password validation: %w" , err )
39+ }
40+
3241 return nil
3342}
Original file line number Diff line number Diff line change @@ -18,12 +18,24 @@ func TestValidationCloneRequest(t *testing.T) {
1818 & types.CloneCreateRequest {
1919 DB : & types.DatabaseRequest {
2020 Username : "username" ,
21- Password : "password " ,
21+ Password : "secret_password " ,
2222 }})
2323
2424 assert .Nil (t , err )
2525}
2626
27+ func TestWeakPassword (t * testing.T ) {
28+ validator := Service {}
29+ err := validator .ValidateCloneRequest (
30+ & types.CloneCreateRequest {
31+ DB : & types.DatabaseRequest {
32+ Username : "username" ,
33+ Password : "password" ,
34+ }})
35+
36+ assert .ErrorContains (t , err , "insecure password" )
37+ }
38+
2739func TestValidationCloneRequestErrors (t * testing.T ) {
2840 validator := Service {}
2941
You can’t perform that action at this time.
0 commit comments