Skip to content

Commit

Permalink
Add more tests for random passwords
Browse files Browse the repository at this point in the history
Signed-off-by: James Pond <[email protected]>
  • Loading branch information
jamesponddotco committed Sep 11, 2023
1 parent 7eb59da commit 53701d7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package acopw_test
import (
"crypto/rand"
"errors"
"strings"
"testing"

"git.sr.ht/~jamesponddotco/acopw-go"
Expand Down Expand Up @@ -54,6 +55,49 @@ func TestRandom_Generate(t *testing.T) {
},
expectedErr: acopw.ErrInvalidCharset,
},
{
name: "CharsetExclusions",
random: &acopw.Random{
ExcludedCharset: []string{"a", "1", "@"},
},
validate: func(generated string) bool {
return !strings.ContainsAny(generated, "a1@")
},
},
{
name: "ZeroLength",
random: &acopw.Random{
Rand: rand.Reader,
Length: 0,
},
validate: func(generated string) bool {
return len(generated) == acopw.DefaultRandomLength
},
},
{
name: "UseLowerOnly",
random: &acopw.Random{
UseLower: true,
UseUpper: false,
UseNumbers: false,
UseSymbols: false,
},
validate: func(generated string) bool {
return strings.ToLower(generated) == generated
},
},
{
name: "UseUpperOnly",
random: &acopw.Random{
UseLower: false,
UseUpper: true,
UseNumbers: false,
UseSymbols: false,
},
validate: func(generated string) bool {
return strings.ToUpper(generated) == generated
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 53701d7

Please sign in to comment.