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

Work on fixing UDB tests

parent 1dcd9ec9
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ import (
"fmt"
"gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/elixxir/user-discovery-bot/fingerprint"
"gitlab.com/elixxir/user-discovery-bot/storage"
)
......@@ -40,6 +41,7 @@ func Register(userId *id.User, args []string) {
RegErr("Invalid command syntax!")
return
}
fmt.Println("in register func")
regType := args[0]
regVal := args[1]
......@@ -76,6 +78,7 @@ func Register(userId *id.User, args []string) {
usr.SetValue(regVal)
}
//Hardcoded email value, change later
//Hardcoded email value, change later
usr.SetValueType(0)
......@@ -107,6 +110,7 @@ func PushKey(userId *id.User, args []string) {
Send(userId, PUSHKEY_USAGE, cmixproto.Type_UDB_PUSH_KEY_RESPONSE)
Log.INFO.Printf("PushKey user %d error: %s", userId, msg)
}
fmt.Println("in pushkey")
if len(args) != 2 {
PushErr("Invalid command syntax!")
return
......@@ -115,7 +119,8 @@ func PushKey(userId *id.User, args []string) {
// keyId := args[0] Note: Legacy, key id is not needed anymore as it is
// sent as a single message
keyMat := args[1]
fmt.Println(keyMat)
fmt.Println(string(keyMat))
// Decode keyMat
// FIXME: Not sure I like having to base64 stuff here, but it's this or hex
// Maybe add support to client for these pubkey conversions?
......@@ -128,8 +133,13 @@ func PushKey(userId *id.User, args []string) {
usr := storage.NewUser()
usr.SetID(userId.Bytes())
usr.SetKey(newKeyBytes)
_ = storage.UserDiscoveryDb.UpsertUser(usr)
fmt.Println(usr)
keyFP := fingerprint.Fingerprint(newKeyBytes)
fmt.Println("keyfp")
fmt.Println(string(keyFP))
usr.SetKeyID(string(keyFP))
err := storage.UserDiscoveryDb.UpsertUser(usr)
fmt.Println(err)
msg := fmt.Sprintf("PUSHKEY COMPLETE %s", keyMat)
Log.DEBUG.Printf("User %d: %s", userId, msg)
Send(userId, msg, cmixproto.Type_UDB_PUSH_KEY_RESPONSE)
......
......@@ -73,9 +73,8 @@ func NewMessage(msg string, msgType cmixproto.Type) *parse.Message {
// not sure how I feel about it.
func TestRegisterHappyPath(t *testing.T) {
//DataStore = storage.NewRamStorage()
m := &storage.MapImpl{
Users: make(map[*id.User]*storage.User),
}
storage.UserDiscoveryDb = storage.NewDatabase("test", "password", "regCodes", "0.0.0.0:6969")
pubKeyBits := "S8KXBczy0jins9uS4LgBPt0bkFl8t00MnZmExQ6GcOcu8O7DKgAsNzLU7a" +
"+gMTbIsS995IL/kuFF8wcBaQJBY23095PMSQ/nMuetzhk9HdXxrGIiKBo3C/n4SClpq4H+PoF9XziEVKua8JxGM2o83KiCK3tNUpaZbAAElkjueY7wuD96h4oaA+WV5Nh87cnIZ+fAG0uLve2LSHZ0FBZb3glOpNAOv7PFWkvN2BO37ztOQCXTJe72Y5ReoYn7nWVNxGUh0ilal+BRuJt1GZ7whOGDRE0IXfURIoK2yjyAnyZJWWMhfGsL5S6iL4aXUs03mc8BHKRq3HRjvTE10l3YFA=="
......@@ -89,6 +88,9 @@ func TestRegisterHappyPath(t *testing.T) {
fingerprint,
}
//Preregister fingerpritn
msg := NewMessage(msgs[0], cmixproto.Type_UDB_PUSH_KEY)
pl.Hear(msg, false)
msg = NewMessage(msgs[1], cmixproto.Type_UDB_REGISTER)
......@@ -99,7 +101,8 @@ func TestRegisterHappyPath(t *testing.T) {
// Assert expected state
usr := storage.NewUser()
usr.SetKeyID(fingerprint)
retrievedUsr, err := m.GetUser(usr)
retrievedUsr, err := storage.UserDiscoveryDb.GetUser(usr)
fmt.Println(retrievedUsr)
if err != nil {
t.Errorf("Could not retrieve key %s", fingerprint)
}
......@@ -111,12 +114,13 @@ func TestRegisterHappyPath(t *testing.T) {
usr2ID := id.NewUserFromUint(4, t)
usr2 := storage.NewUser()
usr2.SetID(usr2ID.Bytes())
err = m.UpsertUser(usr2)
err = storage.UserDiscoveryDb.UpsertUser(usr2)
fmt.Println(err)
if err != nil {
t.Errorf("Could not retrieve user key 1!")
}
if u != fingerprint {
t.Errorf("GetUserKey fingerprint mismatch: %s v %s", u, fingerprint)
if usr2.KeyId != fingerprint {
t.Errorf("GetUserKey fingerprint mismatch: %s v %s", usr.KeyId, fingerprint)
}
usr3 := storage.NewUser()
usr3.SetValue("rick@elixxir.io")
......@@ -126,7 +130,7 @@ func TestRegisterHappyPath(t *testing.T) {
t.Errorf("Could not retrieve by e-mail address!")
}
if retrievedUser.KeyId != fingerprint {
t.Errorf("GetKeys fingerprint mismatch: %v v %s", ks[0], fingerprint)
t.Errorf("GetKeys fingerprint mismatch: %v v %s", retrievedUsr.KeyId, fingerprint)
}
}
......
......@@ -65,7 +65,7 @@ func Search(userId *id.User, args []string) {
// Correctly send the messages with actual userID based on email, followed by key fingerprint
//TODO: Make sure this thing works
for i := range searchedUserKeyID {
msg := fmt.Sprintf("SEARCH %s FOUND %s %s", regVal,
msg := fmt.Sprintf("SEARCH %s FOUND %+v %+v", regVal,
base64.StdEncoding.EncodeToString(searchedUserID[:]), searchedUserKeyID[i])
Log.INFO.Printf("User %d: %s", userId, msg)
Send(userId, msg, cmixproto.Type_UDB_SEARCH_RESPONSE)
......
......@@ -8,12 +8,10 @@ package udb
import (
"gitlab.com/elixxir/client/cmixproto"
"gitlab.com/elixxir/user-discovery-bot/storage"
"testing"
)
func TestSearchHappyPath(t *testing.T) {
DataStore = storage.NewRamStorage()
// Load a user
TestRegisterHappyPath(t)
// NOTE: This is kind of hard, since we can't see the response and search
......@@ -42,7 +40,7 @@ func TestSearch_Invalid_Type(t *testing.T) {
// Test invalid user
func TestSearch_Invalid_User(t *testing.T) {
DataStore = storage.NewRamStorage()
msgs := []string{
"SEARCH EMAIL cat@elixxir.io",
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment