Merge pull request #118 from abedra/keylength_test

Add test that ensure keylength check is working
This commit is contained in:
Armon Dadgar 2015-04-30 11:26:30 -07:00
commit 1da64f8c3b
1 changed files with 30 additions and 0 deletions

View File

@ -128,3 +128,33 @@ func TestEncrypt_Unique(t *testing.T) {
t.Fatalf("improper random seeding detected")
}
}
func TestInitialize_KeyLength(t *testing.T) {
inm := physical.NewInmem()
b, err := NewAESGCMBarrier(inm)
if err != nil {
t.Fatalf("err: %v", err)
}
long := []byte("ThisKeyDoesNotHaveTheRightLength!")
middle := []byte("ThisIsASecretKeyAndMore")
short := []byte("Key")
err = b.Initialize(long)
if err == nil {
t.Fatalf("Key length protection failed")
}
err = b.Initialize(middle)
if err == nil {
t.Fatalf("Key length protection failed")
}
err = b.Initialize(short)
if err == nil {
t.Fatalf("Key length protection failed")
}
}