Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
user-discovery-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
user-discovery-bot
Commits
e757cd80
Commit
e757cd80
authored
Aug 28, 2019
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Work on fixing UDB tests
parent
1dcd9ec9
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
udb/register.go
+13
-3
13 additions, 3 deletions
udb/register.go
udb/register_test.go
+12
-8
12 additions, 8 deletions
udb/register_test.go
udb/search.go
+1
-1
1 addition, 1 deletion
udb/search.go
udb/search_test.go
+2
-4
2 additions, 4 deletions
udb/search_test.go
with
28 additions
and
16 deletions
udb/register.go
+
13
−
3
View file @
e757cd80
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
udb/register_test.go
+
12
−
8
View file @
e757cd80
...
...
@@ -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
u
sr2
.
KeyId
!=
fingerprint
{
t
.
Errorf
(
"GetUserKey fingerprint mismatch: %s v %s"
,
u
sr
.
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
)
}
}
...
...
This diff is collapsed.
Click to expand it.
udb/search.go
+
1
−
1
View file @
e757cd80
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
udb/search_test.go
+
2
−
4
View file @
e757cd80
...
...
@@ -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"
,
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment