Skip to content

Commit

Permalink
test: ensure random password generator adheres to default password po…
Browse files Browse the repository at this point in the history
…licy
  • Loading branch information
reubenmiller committed Jan 24, 2024
1 parent d571c1d commit d628def
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
github.com/sethvargo/go-password v0.2.0
github.com/spf13/viper v1.18.2
github.com/tidwall/gjson v1.17.0
github.com/vbauerster/mpb/v6 v6.0.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=
github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand Down
13 changes: 13 additions & 0 deletions internal/pkg/testingutils/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package testingutils
import (
"math/rand"
"time"

"github.com/sethvargo/go-password/password"
)

const charset = "abcdefghijklmnopqrstuvwxyz" +
Expand All @@ -22,3 +24,14 @@ func stringWithCharset(length int, charset string) string {
func RandomString(length int) string {
return stringWithCharset(length, charset)
}

// RandomPassword generate a random password that meets the default
// Cumulocity IoT password policy
func RandomPassword(length int) string {
value, err := password.Generate(length, 10, 10, false, false)
if err != nil {
// Panic as this should not happen
panic("could not generate password")
}
return value
}
2 changes: 1 addition & 1 deletion test/c8y_test/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestUserService_GetUserByUsername(t *testing.T) {
func TestUserService_CRUD(t *testing.T) {
client := createTestClient()
name := "myciuser" + testingutils.RandomString(7)
password := testingutils.RandomString(32)
password := testingutils.RandomPassword(32)
userInput := c8y.NewUser(name, name+"@no-reply.org", password)
userInput.
SetFirstName("User01").
Expand Down

0 comments on commit d628def

Please sign in to comment.