~seirdy/moac

moac/pwgen/special_test.go -rw-r--r-- 909 bytes
97035daeRohan Kumar Chore(deps): bump deps 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package pwgen_test

import (
	"errors"
	"testing"

	"git.sr.ht/~seirdy/moac/v2/charsets"
	"git.sr.ht/~seirdy/moac/v2/pwgen"
)

// TestGenPwHandlesSuperLongPw runs few slow tests, so run it first.
func TestGenPwHandlesSuperLongPw(t *testing.T) {
	t.Parallel()

	pwr := pwgen.PwRequirements{
		CharsetsWanted: charsets.ParseCharsets([]string{"ascii", "latin", "🦖؆ص😈"}),
		MinLen:         getLoops() * getLoops(),
	}

	if _, err := pwgen.GenPW(pwr); err != nil {
		t.Errorf("error in GenPW: %s", err.Error())
	}
}

func TestGenPwHandlesSingleEmptyCharset(t *testing.T) {
	t.Parallel()

	pwr := pwgen.PwRequirements{
		CharsetsWanted: []charsets.Charset{charsets.CustomCharset(make([]rune, 0))},
		TargetEntropy:  128,
	}

	_, err := pwgen.GenPW(pwr)

	if !errors.Is(err, pwgen.ErrInvalidLenBounds) {
		t.Errorf("expected error %s from GenPW, got %s", pwgen.ErrInvalidLenBounds.Error(), err.Error())
	}
}