forked from electricdusk/rushlink
db: Test truncated keys are invalid; NFC
This commit is contained in:
parent
f527f2fb38
commit
f530a543f9
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user