Skip to content
Snippets Groups Projects
Commit 05d65874 authored by Josh Brooks's avatar Josh Brooks
Browse files

WIP: Fix ud tests

parent 33551a72
No related branches found
No related tags found
4 merge requests!510Release,!207WIP: Client Restructure,!203Symmetric broadcast,!199Xx 3866/user discovery
...@@ -58,6 +58,15 @@ func (rk *cypher) Encrypt(rp message.ResponsePart) ( ...@@ -58,6 +58,15 @@ func (rk *cypher) Encrypt(rp message.ResponsePart) (
fp format.Fingerprint, encryptedPayload, mac []byte) { fp format.Fingerprint, encryptedPayload, mac []byte) {
fp = rk.GetFingerprint() fp = rk.GetFingerprint()
key := rk.getKey() key := rk.getKey()
fmt.Printf("encrypt:"+
"\nfp: %v"+
"\nkey: %v\n"+
"contents: %v\n"+
"mac: %v\n", base64.StdEncoding.EncodeToString(fp.Bytes()),
base64.StdEncoding.EncodeToString(key),
base64.StdEncoding.EncodeToString(rp.Marshal()),
base64.StdEncoding.EncodeToString(mac))
// FIXME: Encryption is identical to what is used by e2e.Crypt, lets make // FIXME: Encryption is identical to what is used by e2e.Crypt, lets make
// them the same code path. // them the same code path.
encryptedPayload = cAuth.Crypt(key, fp[:24], rp.Marshal()) encryptedPayload = cAuth.Crypt(key, fp[:24], rp.Marshal())
...@@ -69,7 +78,7 @@ func (rk *cypher) Decrypt(contents, mac []byte) ([]byte, error) { ...@@ -69,7 +78,7 @@ func (rk *cypher) Decrypt(contents, mac []byte) ([]byte, error) {
fp := rk.GetFingerprint() fp := rk.GetFingerprint()
key := rk.getKey() key := rk.getKey()
fmt.Printf("rk vals:"+ fmt.Printf("decrypt:"+
"\nfp: %v"+ "\nfp: %v"+
"\nkey: %v\n"+ "\nkey: %v\n"+
"contents: %v\n"+ "contents: %v\n"+
......
...@@ -98,7 +98,7 @@ func GetMaxRequestSize(net CMix, e2eGrp *cyclic.Group) int { ...@@ -98,7 +98,7 @@ func GetMaxRequestSize(net CMix, e2eGrp *cyclic.Group) int {
// //
// The network follower must be running and healthy to transmit. // The network follower must be running and healthy to transmit.
func TransmitRequest(recipient contact.Contact, tag string, payload []byte, func TransmitRequest(recipient contact.Contact, tag string, payload []byte,
callback Response, param RequestParams, net cmix.Client, rng csprng.Source, callback Response, param RequestParams, net CMix, rng csprng.Source,
e2eGrp *cyclic.Group) ([]id.Round, receptionID.EphemeralIdentity, error) { e2eGrp *cyclic.Group) ([]id.Round, receptionID.EphemeralIdentity, error) {
if len(payload) > GetMaxRequestSize(net, e2eGrp) { if len(payload) > GetMaxRequestSize(net, e2eGrp) {
......
...@@ -30,7 +30,7 @@ type lookupCallback func(contact.Contact, error) ...@@ -30,7 +30,7 @@ type lookupCallback func(contact.Contact, error)
func Lookup(services CMix, func Lookup(services CMix,
rng csprng.Source, grp *cyclic.Group, rng csprng.Source, grp *cyclic.Group,
udContact contact.Contact, callback lookupCallback, udContact contact.Contact, callback lookupCallback,
uid *id.ID, timeout time.Duration) (id.Round, uid *id.ID, timeout time.Duration) ([]id.Round,
receptionID.EphemeralIdentity, error) { receptionID.EphemeralIdentity, error) {
jww.INFO.Printf("ud.Lookup(%s, %s)", uid, timeout) jww.INFO.Printf("ud.Lookup(%s, %s)", uid, timeout)
...@@ -74,7 +74,7 @@ func lookup(net CMix, ...@@ -74,7 +74,7 @@ func lookup(net CMix,
request := &LookupSend{UserID: uid.Marshal()} request := &LookupSend{UserID: uid.Marshal()}
requestMarshaled, err := proto.Marshal(request) requestMarshaled, err := proto.Marshal(request)
if err != nil { if err != nil {
return id.Round(0), return []id.Round{},
receptionID.EphemeralIdentity{}, errors.WithMessage(err, receptionID.EphemeralIdentity{}, errors.WithMessage(err,
"Failed to form outgoing lookup request.") "Failed to form outgoing lookup request.")
} }
...@@ -105,7 +105,7 @@ type lookupResponse struct { ...@@ -105,7 +105,7 @@ type lookupResponse struct {
func (m lookupResponse) Callback(payload []byte, func (m lookupResponse) Callback(payload []byte,
receptionID receptionID.EphemeralIdentity, receptionID receptionID.EphemeralIdentity,
round rounds.Round, err error) { rounds []rounds.Round, err error) {
if err != nil { if err != nil {
go m.cb(contact.Contact{}, errors.WithMessage(err, "Failed to lookup.")) go m.cb(contact.Contact{}, errors.WithMessage(err, "Failed to lookup."))
......
...@@ -36,7 +36,7 @@ type searchCallback func([]contact.Contact, error) ...@@ -36,7 +36,7 @@ type searchCallback func([]contact.Contact, error)
func Search(services CMix, events event.Reporter, func Search(services CMix, events event.Reporter,
rng csprng.Source, grp *cyclic.Group, rng csprng.Source, grp *cyclic.Group,
udContact contact.Contact, callback searchCallback, udContact contact.Contact, callback searchCallback,
list fact.FactList, timeout time.Duration) (id.Round, list fact.FactList, timeout time.Duration) ([]id.Round,
receptionID.EphemeralIdentity, error) { receptionID.EphemeralIdentity, error) {
jww.INFO.Printf("ud.Search(%s, %s)", list.Stringify(), timeout) jww.INFO.Printf("ud.Search(%s, %s)", list.Stringify(), timeout)
...@@ -46,7 +46,7 @@ func Search(services CMix, events event.Reporter, ...@@ -46,7 +46,7 @@ func Search(services CMix, events event.Reporter,
request := &SearchSend{Fact: factHashes} request := &SearchSend{Fact: factHashes}
requestMarshaled, err := proto.Marshal(request) requestMarshaled, err := proto.Marshal(request)
if err != nil { if err != nil {
return id.Round(0), receptionID.EphemeralIdentity{}, return []id.Round{}, receptionID.EphemeralIdentity{},
errors.WithMessage(err, "Failed to form outgoing search request.") errors.WithMessage(err, "Failed to form outgoing search request.")
} }
...@@ -67,7 +67,7 @@ func Search(services CMix, events event.Reporter, ...@@ -67,7 +67,7 @@ func Search(services CMix, events event.Reporter,
rndId, ephId, err := single.TransmitRequest(udContact, SearchTag, requestMarshaled, rndId, ephId, err := single.TransmitRequest(udContact, SearchTag, requestMarshaled,
response, p, services, rng, grp) response, p, services, rng, grp)
if err != nil { if err != nil {
return id.Round(0), receptionID.EphemeralIdentity{}, return []id.Round{}, receptionID.EphemeralIdentity{},
errors.WithMessage(err, "Failed to transmit search request.") errors.WithMessage(err, "Failed to transmit search request.")
} }
...@@ -89,7 +89,7 @@ type searchResponse struct { ...@@ -89,7 +89,7 @@ type searchResponse struct {
func (m searchResponse) Callback(payload []byte, func (m searchResponse) Callback(payload []byte,
receptionID receptionID.EphemeralIdentity, receptionID receptionID.EphemeralIdentity,
round rounds.Round, err error) { round []rounds.Round, err error) {
fmt.Println("in callback") fmt.Println("in callback")
if err != nil { if err != nil {
go m.cb(nil, errors.WithMessage(err, "Failed to search.")) go m.cb(nil, errors.WithMessage(err, "Failed to search."))
......
...@@ -3,6 +3,7 @@ package ud ...@@ -3,6 +3,7 @@ package ud
import ( import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"gitlab.com/elixxir/client/single"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
dh "gitlab.com/elixxir/crypto/diffieHellman" dh "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/crypto/e2e/singleUse" "gitlab.com/elixxir/crypto/e2e/singleUse"
...@@ -70,6 +71,14 @@ func TestManager_Search(t *testing.T) { ...@@ -70,6 +71,14 @@ func TestManager_Search(t *testing.T) {
}) })
} }
udMockPrivKey := tnm.GetInstance().GetE2EGroup().NewInt(25)
receiver := newMockReceiver(callbackChan)
mockListener := single.Listen(SearchTag, tnm.c.ID, udMockPrivKey,
tnm, grp, receiver)
defer mockListener.Stop()
udContact, err := m.GetContact() udContact, err := m.GetContact()
if err != nil { if err != nil {
t.Fatalf("Failed to get ud contact: %+v", err) t.Fatalf("Failed to get ud contact: %+v", err)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment