mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-04-18 07:15:34 +00:00
Add real test cases for passvault.
This commit is contained in:
@@ -4,65 +4,30 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var emptyKey = make([]byte, 16)
|
||||
var dummy = make([]byte, 16)
|
||||
|
||||
func TestUsesFlush(t *testing.T) {
|
||||
singleUse := ActiveUser{
|
||||
Admin: true,
|
||||
Expiry: nextYear,
|
||||
Uses: 1,
|
||||
key: emptyKey,
|
||||
func TestRSAEncryptDecrypt(t *testing.T) {
|
||||
myRec, err := createPasswordRec("mypasswordisweak", true)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating record")
|
||||
}
|
||||
|
||||
LiveKeys["first"] = singleUse
|
||||
|
||||
FlushCache()
|
||||
if len(LiveKeys) != 1 {
|
||||
t.Fatalf("Error in number of live keys")
|
||||
_, err = myRec.GetKeyRSAPub()
|
||||
if err != nil {
|
||||
t.Fatalf("Error extracting RSA Pub")
|
||||
}
|
||||
|
||||
|
||||
EncryptKey(dummy, "first")
|
||||
|
||||
FlushCache()
|
||||
if len(LiveKeys) != 0 {
|
||||
t.Fatalf("Error in number of live keys")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeFlush(t *testing.T) {
|
||||
oneSec, _ := time.ParseDuration("1s")
|
||||
one := now.Add(oneSec)
|
||||
|
||||
singleUse := ActiveUser{
|
||||
Admin: true,
|
||||
Expiry: one,
|
||||
Uses: 10,
|
||||
key: emptyKey,
|
||||
}
|
||||
|
||||
LiveKeys["first"] = singleUse
|
||||
|
||||
FlushCache()
|
||||
if len(LiveKeys) != 1 {
|
||||
t.Fatalf("Error in number of live keys")
|
||||
}
|
||||
|
||||
EncryptKey(dummy, "first")
|
||||
|
||||
FlushCache()
|
||||
if len(LiveKeys) != 1 {
|
||||
t.Fatalf("Error in number of live keys")
|
||||
}
|
||||
|
||||
time.Sleep(oneSec)
|
||||
|
||||
_, err := DecryptKey(dummy, "first")
|
||||
|
||||
rsaPriv, err := myRec.GetKeyRSA("mypasswordiswrong")
|
||||
if err == nil {
|
||||
t.Fatalf("Error in pruning expired key")
|
||||
t.Fatalf("Incorrect password did not fail")
|
||||
}
|
||||
|
||||
rsaPriv, err = myRec.GetKeyRSA("mypasswordisweak")
|
||||
if err != nil {
|
||||
t.Fatalf("Error decrypting RSA key")
|
||||
}
|
||||
|
||||
err = rsaPriv.Validate()
|
||||
if err != nil {
|
||||
t.Fatalf("Error validating RSA key")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user