Wrote decrypt tests

This commit is contained in:
Ivan Tomilov 2017-06-13 15:39:07 +07:00
parent c8997b998a
commit 373cd7b621
1 changed files with 41 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package doubleratchet package doubleratchet
import ( import (
"fmt"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
) )
@ -105,7 +106,7 @@ func TestState_RatchetEncryptDecrypt_Basic(t *testing.T) {
require.NotEmpty(t, m.Ciphertext) require.NotEmpty(t, m.Ciphertext)
} }
func TestState_RatchetDecrypt_BasicCommunication(t *testing.T) { func TestState_RatchetDecrypt_BasicCommunicationAliceSends(t *testing.T) {
// Arrange. // Arrange.
var ( var (
bobI, _ = New(sk) bobI, _ = New(sk)
@ -113,18 +114,46 @@ func TestState_RatchetDecrypt_BasicCommunication(t *testing.T) {
aliceI, _ = New(sk, WithRemoteKey(bob.DHs.PublicKey())) aliceI, _ = New(sk, WithRemoteKey(bob.DHs.PublicKey()))
alice = aliceI.(*state) alice = aliceI.(*state)
pt = []byte("1337")
) )
for i := 0; i < 10; i++ {
pt := fmt.Sprintf("msg%d", i)
t.Run(pt, func(t *testing.T) {
// Act. // Act.
var ( var (
m = alice.RatchetEncrypt(pt, nil) m = alice.RatchetEncrypt([]byte(pt), nil)
decrypted, err = bob.RatchetDecrypt(m, nil) decrypted, err = bob.RatchetDecrypt(m, nil)
) )
// Assert. // Assert.
require.Nil(t, err) require.Nil(t, err)
require.Equal(t, []byte(pt), decrypted)
require.Equal(t, pt, decrypted) })
}
}
func TestState_RatchetDecrypt_BasicCommunicationBobSends(t *testing.T) {
// Arrange.
var (
bobI, _ = New(sk)
bob = bobI.(*state)
aliceI, _ = New(sk, WithRemoteKey(bob.DHs.PublicKey()))
alice = aliceI.(*state)
)
for i := 0; i < 10; i++ {
pt := fmt.Sprintf("msg%d", i)
t.Run(pt, func(t *testing.T) {
// Act.
var (
m = bob.RatchetEncrypt([]byte(pt), nil)
decrypted, err = alice.RatchetDecrypt(m, nil)
)
// Assert.
require.Nil(t, err)
require.Equal(t, []byte(pt), decrypted)
})
}
} }