Skip to content

Commit

Permalink
Merge branch 'master' into auditor-server-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
masomel authored Dec 20, 2017
2 parents df1762c + c9491a4 commit 94beaec
Show file tree
Hide file tree
Showing 24 changed files with 420 additions and 824 deletions.
2 changes: 1 addition & 1 deletion application/bots/twitterbot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestCannotUnmarshallRequest(t *testing.T) {
func TestInvalidRequestType(t *testing.T) {
username := "alice"
request, _ := json.Marshal(&protocol.Request{
Type: protocol.KeyLookupType,
Type: protocol.KeyLookupInEpochType,
Request: &protocol.RegistrationRequest{
Username: username + "@twitter",
Key: []byte{1, 2, 3},
Expand Down
9 changes: 5 additions & 4 deletions application/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ func UnmarshalResponse(t int, msg []byte) *protocol.Response {
// DirectoryResponse is omitempty for the places
// where Error is in Errors
if res.DirectoryResponse == nil {
if !protocol.Errors[res.Error] {
response := &protocol.Response{
Error: res.Error,
}
if err := response.Validate(); err != nil {
return &protocol.Response{
Error: protocol.ErrMalformedMessage,
}
}
return &protocol.Response{
Error: res.Error,
}
return response
}

switch t {
Expand Down
5 changes: 2 additions & 3 deletions application/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ func TestUnmarshalSampleClientMessage(t *testing.T) {
res := d.Register(&protocol.RegistrationRequest{
Username: "alice",
Key: []byte("key")})
msg, _ := MarshalResponse(res)
response := UnmarshalResponse(protocol.RegistrationType, []byte(msg))
str := response.DirectoryResponse.(*protocol.DirectoryProof).STR[0]
response := UnmarshalResponse(protocol.RegistrationType, []byte(msg))
str := response.DirectoryResponse.(*protocol.DirectoryProof).STR[0]
if !bytes.Equal(d.LatestSTR().Serialize(), str.Serialize()) {
t.Error("Cannot unmarshal Associate Data properly")
}
Expand Down
28 changes: 28 additions & 0 deletions crypto/testutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package crypto

import (
"bytes"

"github.com/coniks-sys/coniks-go/crypto/sign"
"github.com/coniks-sys/coniks-go/crypto/vrf"
)

// NewStaticTestVRFKey returns a static VRF private key for _tests_.
func NewStaticTestVRFKey() vrf.PrivateKey {
sk, err := vrf.GenerateKey(bytes.NewReader(
[]byte("deterministic tests need 256 bit")))
if err != nil {
panic(err)
}
return sk
}

// NewStaticTestSigningKey returns a static private signing key for _tests_.
func NewStaticTestSigningKey() sign.PrivateKey {
sk, err := sign.GenerateKey(bytes.NewReader(
[]byte("deterministic tests need 256 bit")))
if err != nil {
panic(err)
}
return sk
}
31 changes: 11 additions & 20 deletions merkletree/merkletree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ import (
"bytes"
"testing"

"github.com/coniks-sys/coniks-go/crypto/vrf"
"github.com/coniks-sys/coniks-go/utils"
"golang.org/x/crypto/sha3"
)

var vrfPrivKey1, _ = vrf.GenerateKey(bytes.NewReader(
[]byte("deterministic tests need 256 bit")))

var vrfPrivKey2, _ = vrf.GenerateKey(bytes.NewReader(
[]byte("deterministic tests need 32 byte")))

// TODO: When #178 is merged, 3 tests below should be removed.
func TestOneEntry(t *testing.T) {
m, err := NewMerkleTree()
if err != nil {
Expand All @@ -26,7 +20,7 @@ func TestOneEntry(t *testing.T) {

key := "key"
val := []byte("value")
index := vrfPrivKey1.Compute([]byte(key))
index := staticVRFKey.Compute([]byte(key))
if err := m.Set(index, key, val); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -90,10 +84,10 @@ func TestTwoEntries(t *testing.T) {
}

key1 := "key1"
index1 := vrfPrivKey1.Compute([]byte(key1))
index1 := staticVRFKey.Compute([]byte(key1))
val1 := []byte("value1")
key2 := "key2"
index2 := vrfPrivKey1.Compute([]byte(key2))
index2 := staticVRFKey.Compute([]byte(key2))
val2 := []byte("value2")

if err := m.Set(index1, key1, val1); err != nil {
Expand Down Expand Up @@ -130,13 +124,13 @@ func TestThreeEntries(t *testing.T) {
}

key1 := "key1"
index1 := vrfPrivKey1.Compute([]byte(key1))
index1 := staticVRFKey.Compute([]byte(key1))
val1 := []byte("value1")
key2 := "key2"
index2 := vrfPrivKey1.Compute([]byte(key2))
index2 := staticVRFKey.Compute([]byte(key2))
val2 := []byte("value2")
key3 := "key3"
index3 := vrfPrivKey1.Compute([]byte(key3))
index3 := staticVRFKey.Compute([]byte(key3))
val3 := []byte("value3")

if err := m.Set(index1, key1, val1); err != nil {
Expand Down Expand Up @@ -191,13 +185,10 @@ func TestThreeEntries(t *testing.T) {
}

func TestInsertExistedKey(t *testing.T) {
m, err := NewMerkleTree()
if err != nil {
t.Fatal(err)
}
m := newEmptyTreeForTest(t)

key1 := "key"
index1 := vrfPrivKey1.Compute([]byte(key1))
index1 := staticVRFKey.Compute([]byte(key1))
val1 := append([]byte(nil), "value"...)

if err := m.Set(index1, key1, val1); err != nil {
Expand Down Expand Up @@ -241,10 +232,10 @@ func TestInsertExistedKey(t *testing.T) {

func TestTreeClone(t *testing.T) {
key1 := "key1"
index1 := vrfPrivKey1.Compute([]byte(key1))
index1 := staticVRFKey.Compute([]byte(key1))
val1 := []byte("value1")
key2 := "key2"
index2 := vrfPrivKey1.Compute([]byte(key2))
index2 := staticVRFKey.Compute([]byte(key2))
val2 := []byte("value2")

m1, err := NewMerkleTree()
Expand Down
Loading

0 comments on commit 94beaec

Please sign in to comment.