db: Test truncated keys are invalid; NFC

This commit is contained in:
Daan Sprenkels 2020-12-17 15:15:04 +01:00
parent f527f2fb38
commit f530a543f9

View File

@ -75,3 +75,26 @@ func TestGeneratedKeysAreValid(t *testing.T) {
}
}
}
func TestTruncatedKeysAreInvalid(t *testing.T) {
db, err := OpenTemporaryDB()
if err != nil {
t.Error(err)
}
var minimumEntropy int
checkTruncatedKeysInvalid := func(truncRand uint) bool {
key, err := GeneratePasteKey(db, minimumEntropy)
if err != nil {
return false
}
trunc := int(truncRand % uint(len(key)-1))
key = key[:trunc]
return ValidatePasteKey(key) == ErrKeyInvalidLength
}
for minimumEntropy = 0; minimumEntropy <= 80; minimumEntropy++ {
if err = quick.Check(checkTruncatedKeysInvalid, nil); err != nil {
t.Error(err)
}
}
}