Skip to content
Snippets Groups Projects
Commit ef760a16 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

fixed tests in storage

parent b713f209
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,9 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
gitlab.com/elixxir/comms v0.0.0-20200915164538-d15120cc8fa5
gitlab.com/elixxir/crypto v0.0.0-20200915172523-b2f2c63560c9
gitlab.com/elixxir/crypto v0.0.0-20200915211245-8a519dfcc38d
gitlab.com/elixxir/ekv v0.1.1
gitlab.com/elixxir/primitives v0.0.0-20200915181454-994a60142fce
gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50
gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7
gitlab.com/xx_network/crypto v0.0.0-20200812183430-c77a5281c686
gitlab.com/xx_network/primitives v0.0.0-20200812183720-516a65a4a9b2
......
......@@ -209,6 +209,8 @@ gitlab.com/elixxir/crypto v0.0.0-20200907171019-008a9d4aa264 h1:8jk4yHw15PpjTPHM
gitlab.com/elixxir/crypto v0.0.0-20200907171019-008a9d4aa264/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI=
gitlab.com/elixxir/crypto v0.0.0-20200915172523-b2f2c63560c9 h1:omuo67rgWzlorzLlQQumUkES1w3M5elKFq4PmB+HjJw=
gitlab.com/elixxir/crypto v0.0.0-20200915172523-b2f2c63560c9/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI=
gitlab.com/elixxir/crypto v0.0.0-20200915211245-8a519dfcc38d h1:6D2r42dFuUm96KjeNYH7XzRy8l+8rbl8G5IZGdVfjOI=
gitlab.com/elixxir/crypto v0.0.0-20200915211245-8a519dfcc38d/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI=
gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 h1:m1zDQ6UadpuMnV7nvnyR+DUXE3AisRnVjajTb1xZE4c=
gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s=
gitlab.com/elixxir/ekv v0.1.1 h1:Em3rF8sv+tNbQGXbcpYzAS2blWRAP708JGhYlkN74Kg=
......@@ -236,6 +238,8 @@ gitlab.com/elixxir/primitives v0.0.0-20200910160236-9ccbae60724d h1:XsJHSTmP/7hL
gitlab.com/elixxir/primitives v0.0.0-20200910160236-9ccbae60724d/go.mod h1:pJx2DZk9s8vVMnLN7x0hIPngDjbNSdOP6kk3RLlRxHg=
gitlab.com/elixxir/primitives v0.0.0-20200915181454-994a60142fce h1:TaDQ8jQlHECVxLi2xe0BqX6P9/9/Hz5zAVIJDm6CaxM=
gitlab.com/elixxir/primitives v0.0.0-20200915181454-994a60142fce/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50 h1:J0A2JsYlb0He1lTGDy+6KX3s/87uklk/pLv9FKv9yp8=
gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
gitlab.com/xx_network/comms v0.0.0-20200806235452-3a82720833ba h1:7nozLSNBX0CfP53DDiDNLJx9obhYGfGf5na0/c9rMso=
gitlab.com/xx_network/comms v0.0.0-20200806235452-3a82720833ba/go.mod h1:idLzPGYig57XE7xuU93OlIF9s6NgSJj7OArQvsd5DjY=
......
......@@ -15,40 +15,41 @@ import (
func TestRoundKeys_Encrypt_Consistency(t *testing.T) {
const numKeys = 5
expectedPayload := []byte{80, 118, 187, 96, 114, 221, 253, 46, 231, 113,
200, 88, 90, 42, 236, 96, 82, 244, 197, 32, 147, 185, 33, 27, 55, 128,
63, 247, 24, 218, 177, 8, 153, 34, 177, 57, 2, 153, 44, 134, 66, 57,
212, 140, 254, 125, 34, 173, 58, 39, 130, 130, 12, 114, 81, 254, 120,
194, 181, 159, 166, 167, 67, 172, 201, 191, 150, 161, 217, 178, 234, 65,
31, 240, 120, 69, 195, 196, 80, 206, 119, 14, 233, 193, 9, 108, 212,
157, 13, 160, 48, 171, 244, 106, 109, 48, 216, 117, 60, 98, 166, 26, 5,
26, 98, 115, 184, 87, 123, 197, 69, 159, 136, 247, 43, 165, 86, 11, 27,
7, 73, 189, 199, 68, 75, 34, 123, 245, 65, 169, 192, 46, 250, 47, 192,
238, 211, 196, 26, 254, 33, 53, 92, 9, 138, 197, 34, 209, 102, 58, 170,
119, 118, 73, 249, 235, 109, 81, 114, 186, 20, 247, 61, 94, 158, 50, 12,
217, 207, 216, 175, 83, 34, 244, 48, 159, 9, 101, 149, 92, 21, 4, 135,
91, 14, 142, 43, 5, 140, 197, 63, 216, 105, 20, 73, 38, 38, 250, 158,
140, 149, 187, 166, 194, 59, 75, 92, 21, 91, 166, 245, 54, 37, 103, 27,
168, 214, 252, 121, 175, 125, 190, 163, 178, 138, 1, 114, 247, 205, 105,
14, 248, 177, 89, 190, 205, 10, 109, 193, 189, 73, 117, 239, 179, 10,
164, 248, 251, 235, 232, 215, 56, 56, 250, 203, 114, 34, 208, 116, 94,
204, 165, 70, 109, 26, 155, 11, 210, 64, 8, 37, 34, 84, 30, 106, 41, 98,
135, 63, 62, 225, 212, 251, 245, 36, 238, 166, 142, 76, 192, 46, 169,
18, 55, 87, 245, 101, 224, 213, 225, 164, 109, 248, 50, 142, 122, 14,
76, 52, 179, 118, 95, 58, 86, 73, 12, 169, 85, 1, 19, 125, 190, 244,
231, 233, 95, 72, 101, 178, 230, 107, 59, 109, 220, 114, 155, 138, 96,
208, 167, 169, 143, 94, 145, 141, 24, 56, 167, 135, 128, 85, 147, 22,
67, 199, 154, 127, 174, 220, 210, 220, 5, 237, 28, 225, 234, 187, 83,
124, 215, 185, 38, 149, 87, 1, 29, 109, 31, 132, 145, 85, 90, 195, 226,
252, 60, 113, 155, 82, 238, 120, 154, 185, 36, 164, 199, 4, 146, 76, 3,
243, 19, 215, 192, 133, 159, 34, 27, 37, 138, 246, 45, 170, 99, 169, 46,
253, 98, 203, 52, 242, 203, 106, 141, 75, 140, 90, 118, 38, 162, 107,
182, 181, 6, 105, 208, 97, 66, 82, 72, 235, 56, 173, 242, 87, 241, 48,
29, 191, 72, 89, 200, 163, 192, 252, 187, 181, 54, 144, 53, 173, 137,
142, 19, 207, 3, 207, 169, 12, 148, 198, 225, 195, 118, 85, 153, 159,
168, 245, 16, 229, 227, 89, 224, 30, 127, 217, 193, 212, 52, 211, 120,
73, 204, 82, 82, 253, 238, 96, 186, 243, 26, 246, 157, 241, 120, 47,
170, 83, 175, 58, 179}
expectedPayload := []byte{238, 89, 139, 116, 56, 196, 216, 152, 225, 189,
121, 167, 229, 248, 92, 126, 162, 229, 250, 212, 228, 97, 178, 47, 42,
180, 141, 141, 146, 231, 15, 231, 53, 205, 36, 72, 83, 92, 92, 51, 97,
145, 223, 41, 119, 80, 248, 61, 120, 175, 3, 219, 153, 76, 119, 160,
153, 193, 161, 241, 67, 250, 35, 182, 140, 211, 244, 112, 82, 5, 153,
91, 33, 15, 7, 61, 215, 133, 235, 214, 247, 93, 142, 131, 192, 203, 82,
249, 225, 237, 17, 88, 245, 3, 146, 230, 204, 30, 29, 113, 152, 140, 94,
22, 232, 100, 203, 35, 161, 143, 236, 131, 6, 122, 102, 77, 112, 218,
33, 150, 25, 237, 108, 73, 167, 124, 172, 188, 196, 121, 247, 55, 62,
188, 38, 157, 122, 24, 174, 235, 110, 1, 166, 65, 186, 233, 136, 172,
180, 89, 64, 19, 46, 173, 45, 14, 118, 31, 56, 213, 105, 2, 105, 195,
102, 144, 229, 70, 3, 62, 53, 148, 159, 108, 236, 146, 90, 207, 133,
94, 138, 101, 183, 16, 35, 172, 0, 214, 78, 108, 13, 104, 55, 216, 43,
168, 255, 100, 41, 86, 3, 168, 241, 136, 162, 1, 220, 151, 80, 98, 229,
104, 100, 159, 137, 17, 24, 101, 213, 203, 27, 165, 214, 118, 204, 139,
176, 53, 102, 240, 153, 245, 37, 146, 99, 207, 218, 36, 38, 216, 63,
133, 197, 93, 61, 162, 64, 182, 197, 50, 126, 92, 3, 28, 172, 63, 28,
223, 42, 169, 151, 62, 98, 84, 142, 63, 45, 75, 241, 43, 172, 32, 198,
52, 106, 16, 182, 85, 206, 236, 59, 164, 58, 108, 168, 164, 209, 88,
190, 213, 106, 182, 247, 242, 112, 63, 184, 246, 115, 210, 135, 152,
78, 168, 43, 200, 154, 119, 239, 215, 156, 59, 65, 246, 58, 57, 43,
95, 130, 179, 79, 94, 219, 164, 222, 139, 155, 12, 120, 202, 104, 87,
105, 251, 32, 118, 22, 166, 134, 240, 193, 231, 99, 20, 54, 110, 10,
31, 203, 67, 71, 124, 184, 251, 84, 243, 160, 108, 225, 163, 233, 238,
39, 76, 205, 117, 13, 29, 234, 61, 140, 33, 135, 60, 192, 169, 80, 75,
50, 49, 210, 117, 143, 175, 209, 237, 41, 228, 90, 34, 84, 195, 118,
176, 169, 71, 214, 199, 128, 227, 248, 211, 131, 27, 38, 247, 68, 10,
72, 226, 24, 78, 152, 242, 8, 181, 51, 22, 103, 90, 168, 115, 174, 56,
80, 41, 64, 41, 104, 137, 206, 71, 23, 99, 30, 47, 77, 92, 40, 49, 3,
79, 195, 31, 193, 38, 90, 226, 81, 244, 178, 101, 77, 10, 136, 45, 73,
1, 183, 197, 176, 29, 15, 66, 211, 148, 33, 219, 97, 139, 211, 234,
253, 68, 194, 215, 231, 81, 218, 142, 160, 252, 252, 212, 42, 146, 25,
28, 227, 140, 81, 202, 212, 140, 63, 12, 82, 214, 222, 76, 13, 194,
141, 75, 17, 37, 145, 27, 155, 162, 165, 234}
expectedKmacs := [][]byte{
{241, 132, 2, 131, 104, 92, 89, 120, 177, 8, 201,
......@@ -107,8 +108,9 @@ func TestRoundKeys_Encrypt_Consistency(t *testing.T) {
encMsg, kmacs := rk.Encrypt(msg, salt)
if !bytes.Equal(encMsg.GetData(), expectedPayload) {
t.Errorf("Encrypted messages do not match")
if !bytes.Equal(encMsg.Marshal(), expectedPayload) {
t.Errorf("Encrypted messages do not match\n "+
"expected: %v\n received: %v", expectedPayload, encMsg.Marshal())
}
if !reflect.DeepEqual(kmacs, expectedKmacs) {
......
......@@ -165,7 +165,7 @@ func TestSession_Load(t *testing.T) {
t.Fatal(err)
}
// Load another, hopefully identical session from the storage
sessionB, err := loadSession(sessionA.manager, versioned.NewKV(make(ekv.Memstore)))
sessionB, err := loadSession(sessionA.manager, sessionA.kv)
if err != nil {
t.Fatal(err)
}
......@@ -223,6 +223,7 @@ func TestSession_Serialization(t *testing.T) {
sDeserialized := &Session{
manager: &Manager{ctx: ctx},
kv: s.kv,
}
err = sDeserialized.unmarshal(sSerialized)
if err != nil {
......
......@@ -215,7 +215,9 @@ func TestLoadStateVector(t *testing.T) {
keyNums := []uint32{139, 145, 300, 360, 420, 761, 868, 875, 893, 995}
const numKeys = 1000
sv, err := newStateVector(versioned.NewKV(make(ekv.Memstore)), "key", numKeys)
kv := versioned.NewKV(make(ekv.Memstore))
sv, err := newStateVector(kv, "key", numKeys)
if err != nil {
t.Fatal(err)
}
......@@ -227,7 +229,7 @@ func TestLoadStateVector(t *testing.T) {
if err != nil {
t.Fatal(err)
}
sv2, err := loadStateVector(versioned.NewKV(make(ekv.Memstore)), "key")
sv2, err := loadStateVector(kv, "key")
if err != nil {
t.Fatal(err)
}
......
......@@ -19,6 +19,7 @@ import (
"gitlab.com/elixxir/client/storage/utility"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
......@@ -62,7 +63,7 @@ func initStore(baseDir, password string) (*Session, error) {
// Creates new UserData in the session
func New(baseDir, password string, uid *id.ID, salt []byte, rsaKey *rsa.PrivateKey,
isPrecanned bool, cmixDHPrivKey, e2eDHPrivKey *cyclic.Int, cmixGrp,
e2eGrp *cyclic.Group) (*Session, error) {
e2eGrp *cyclic.Group, rng *fastRNG.StreamGenerator) (*Session, error) {
s, err := initStore(baseDir, password)
if err != nil {
......@@ -85,7 +86,7 @@ func New(baseDir, password string, uid *id.ID, salt []byte, rsaKey *rsa.PrivateK
return nil, errors.WithMessage(err, "Failed to create session")
}
s.e2e, err = e2e.NewStore(e2eGrp, s.kv, e2eDHPrivKey)
s.e2e, err = e2e.NewStore(e2eGrp, s.kv, e2eDHPrivKey, rng)
if err != nil {
return nil, errors.WithMessage(err, "Failed to create session")
}
......@@ -107,7 +108,7 @@ func New(baseDir, password string, uid *id.ID, salt []byte, rsaKey *rsa.PrivateK
}
// Loads existing user data into the session
func Load(baseDir, password string) (*Session, error) {
func Load(baseDir, password string, rng *fastRNG.StreamGenerator) (*Session, error) {
s, err := initStore(baseDir, password)
if err != nil {
return nil, errors.WithMessage(err, "Failed to load Session")
......@@ -128,7 +129,7 @@ func Load(baseDir, password string) (*Session, error) {
return nil, errors.WithMessage(err, "Failed to load Session")
}
s.e2e, err = e2e.LoadStore(s.kv)
s.e2e, err = e2e.LoadStore(s.kv, rng)
if err != nil {
return nil, errors.WithMessage(err, "Failed to load Session")
}
......
......@@ -6,20 +6,13 @@
package storage
import (
"bytes"
"gitlab.com/elixxir/client/storage/versioned"
"os"
"testing"
"time"
)
/*
func initTest(t *testing.T) *Session {
err := os.RemoveAll(".session_testdir")
if err != nil {
t.Errorf(err.Error())
}
s, err := Init(".session_testdir", "test")
s, err := New(".session_testdir", "test")
if err != nil {
t.Log(s)
t.Errorf("failed to init: %+v", err)
......@@ -50,4 +43,4 @@ func TestSession_Smoke(t *testing.T) {
if bytes.Compare(o.Data, []byte("test")) != 0 {
t.Errorf("Failed to get data")
}
}
}*/
......@@ -65,7 +65,6 @@ func NewKV(data ekv.KeyValue) *KV {
root.data = data
newKV.r = &root
newKV.prefix = PrefixSeparator
return &newKV
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment