mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-21 21:30:51 +01:00
Add new configuration options and tests
This commit introduces new methods to enable HIBP checks, exclude specific characters, and set a fixed password length in the password generator configuration. It also includes tests to verify that these new options work correctly in the password configuration.
This commit is contained in:
parent
d4d2067cbf
commit
d6cfc79cf2
2 changed files with 60 additions and 0 deletions
22
config.go
22
config.go
|
@ -88,6 +88,28 @@ func WithAlgorithm(algo Algorithm) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// WithCheckHIBP enables the HIBP check for newly generated passwords
|
||||
func WithCheckHIBP() Option {
|
||||
return func(config *Config) {
|
||||
config.CheckHIBP = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithExcludeChars sets a list of characters to be excluded in the generated
|
||||
// passwords
|
||||
func WithExcludeChars(chars string) Option {
|
||||
return func(config *Config) {
|
||||
config.ExcludeChars = chars
|
||||
}
|
||||
}
|
||||
|
||||
// WithFixedLength sets a fixed password length
|
||||
func WithFixedLength(length int64) Option {
|
||||
return func(config *Config) {
|
||||
config.FixedLength = length
|
||||
}
|
||||
}
|
||||
|
||||
// WithMinLength overrides the minimum password length
|
||||
func WithMinLength(length int64) Option {
|
||||
return func(config *Config) {
|
||||
|
|
|
@ -63,6 +63,44 @@ func TestWithAlgorithm(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWithCheckHIBP(t *testing.T) {
|
||||
c := NewConfig(WithCheckHIBP())
|
||||
if c == nil {
|
||||
t.Errorf("NewConfig(WithCheckHIBP()) failed, expected config pointer but got nil")
|
||||
return
|
||||
}
|
||||
if c.CheckHIBP != true {
|
||||
t.Errorf("NewConfig(WithCheckHIBP()) failed, expected min length: %t, got: %t",
|
||||
true, c.CheckHIBP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithExcludeChars(t *testing.T) {
|
||||
e := "abcdefg"
|
||||
c := NewConfig(WithExcludeChars(e))
|
||||
if c == nil {
|
||||
t.Errorf("NewConfig(WithExcludeChars()) failed, expected config pointer but got nil")
|
||||
return
|
||||
}
|
||||
if c.ExcludeChars != e {
|
||||
t.Errorf("NewConfig(WithExcludeChars()) failed, expected min length: %s, got: %s",
|
||||
e, c.ExcludeChars)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithFixedLength(t *testing.T) {
|
||||
var e int64 = 10
|
||||
c := NewConfig(WithFixedLength(e))
|
||||
if c == nil {
|
||||
t.Errorf("NewConfig(WithFixedLength()) failed, expected config pointer but got nil")
|
||||
return
|
||||
}
|
||||
if c.FixedLength != e {
|
||||
t.Errorf("NewConfig(WithFixedLength()) failed, expected min length: %d, got: %d",
|
||||
e, c.FixedLength)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithMaxLength(t *testing.T) {
|
||||
var e int64 = 123
|
||||
c := NewConfig(WithMaxLength(e))
|
||||
|
|
Loading…
Reference in a new issue