Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
bca7ca51
Commit
bca7ca51
authored
3 years ago
by
Jonah Husson
Browse files
Options
Downloads
Plain Diff
Merge branch 'Bob/Contact' into 'release'
Bob/contact See merge request
!6
parents
2395939a
5acfaaa7
No related branches found
No related tags found
2 merge requests
!23
Release
,
!6
Bob/contact
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/ud.go
+2
-2
2 additions, 2 deletions
cmd/ud.go
ud/search.go
+6
-3
6 additions, 3 deletions
ud/search.go
ud/search_test.go
+40
-0
40 additions, 0 deletions
ud/search_test.go
with
48 additions
and
5 deletions
cmd/ud.go
+
2
−
2
View file @
bca7ca51
...
@@ -243,10 +243,10 @@ func init() {
...
@@ -243,10 +243,10 @@ func init() {
}
}
func
printContact
(
c
contact
.
Contact
)
{
func
printContact
(
c
contact
.
Contact
)
{
jww
.
DEBUG
.
Printf
(
"Printing c
lien
t: %+v"
,
c
)
jww
.
DEBUG
.
Printf
(
"Printing c
ontac
t: %+v"
,
c
)
cBytes
:=
c
.
Marshal
()
cBytes
:=
c
.
Marshal
()
if
len
(
cBytes
)
==
0
{
if
len
(
cBytes
)
==
0
{
jww
.
ERROR
.
Print
(
"Marshaled c
lien
t has a size of 0."
)
jww
.
ERROR
.
Print
(
"Marshaled c
ontac
t has a size of 0."
)
}
else
{
}
else
{
jww
.
DEBUG
.
Printf
(
"Printing marshaled contact of size %d."
,
len
(
cBytes
))
jww
.
DEBUG
.
Printf
(
"Printing marshaled contact of size %d."
,
len
(
cBytes
))
}
}
...
...
This diff is collapsed.
Click to expand it.
ud/search.go
+
6
−
3
View file @
bca7ca51
...
@@ -74,7 +74,7 @@ func (m *Manager) searchResponseHandler(factMap map[string]fact.Fact,
...
@@ -74,7 +74,7 @@ func (m *Manager) searchResponseHandler(factMap map[string]fact.Fact,
}
}
//return an error if no facts are found
//return an error if no facts are found
if
len
(
searchResponse
.
Contacts
)
==
0
{
if
len
(
searchResponse
.
Contacts
)
==
0
{
go
callback
(
nil
,
errors
.
New
(
"No contacts found in search"
))
go
callback
(
nil
,
errors
.
New
(
"No contacts found in search"
))
}
}
...
@@ -119,12 +119,15 @@ func (m *Manager) parseContacts(response []*Contact,
...
@@ -119,12 +119,15 @@ func (m *Manager) parseContacts(response []*Contact,
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"failed to parse Contact user ID: %+v"
,
err
)
return
nil
,
errors
.
Errorf
(
"failed to parse Contact user ID: %+v"
,
err
)
}
}
var
facts
[]
fact
.
Fact
if
c
.
Username
!=
""
{
facts
=
[]
fact
.
Fact
{{
c
.
Username
,
fact
.
Username
}}
}
// Create new Contact
// Create new Contact
contacts
[
i
]
=
contact
.
Contact
{
contacts
[
i
]
=
contact
.
Contact
{
ID
:
uid
,
ID
:
uid
,
DhPubKey
:
m
.
grp
.
NewIntFromBytes
(
c
.
PubKey
),
DhPubKey
:
m
.
grp
.
NewIntFromBytes
(
c
.
PubKey
),
Facts
:
[]
fact
.
Fact
{}
,
Facts
:
fact
s
,
}
}
// Assign each Fact with a matching hash to the Contact
// Assign each Fact with a matching hash to the Contact
...
...
This diff is collapsed.
Click to expand it.
ud/search_test.go
+
40
−
0
View file @
bca7ca51
...
@@ -448,6 +448,46 @@ func TestManager_parseContacts(t *testing.T) {
...
@@ -448,6 +448,46 @@ func TestManager_parseContacts(t *testing.T) {
}
}
}
}
func
TestManager_parseContacts_username
(
t
*
testing
.
T
)
{
m
:=
&
Manager
{
grp
:
cyclic
.
NewGroup
(
large
.
NewInt
(
107
),
large
.
NewInt
(
2
))}
// Generate fact list
var
factList
fact
.
FactList
for
i
:=
0
;
i
<
10
;
i
++
{
factList
=
append
(
factList
,
fact
.
Fact
{
Fact
:
fmt
.
Sprintf
(
"fact %d"
,
i
),
T
:
fact
.
FactType
(
rand
.
Intn
(
4
)),
})
}
factHashes
,
factMap
:=
hashFactList
(
factList
)
var
contacts
[]
*
Contact
var
expectedContacts
[]
contact
.
Contact
for
i
,
hash
:=
range
factHashes
{
contacts
=
append
(
contacts
,
&
Contact
{
UserID
:
id
.
NewIdFromString
(
"user"
,
id
.
User
,
t
)
.
Marshal
(),
Username
:
"zezima"
,
PubKey
:
[]
byte
{
byte
(
i
+
1
)},
TrigFacts
:
[]
*
HashFact
{
hash
},
})
expectedContacts
=
append
(
expectedContacts
,
contact
.
Contact
{
ID
:
id
.
NewIdFromString
(
"user"
,
id
.
User
,
t
),
DhPubKey
:
m
.
grp
.
NewIntFromBytes
([]
byte
{
byte
(
i
+
1
)}),
Facts
:
fact
.
FactList
{{
"zezima"
,
fact
.
Username
},
factMap
[
string
(
hash
.
Hash
)]},
})
}
testContacts
,
err
:=
m
.
parseContacts
(
contacts
,
factMap
)
if
err
!=
nil
{
t
.
Errorf
(
"parseContacts() returned an error: %+v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
expectedContacts
,
testContacts
)
{
t
.
Errorf
(
"parseContacts() did not return the expected contacts."
+
"
\n
expected: %+v
\n
received: %+v"
,
expectedContacts
,
testContacts
)
}
}
// Error path: provided contact IDs are malformed and cannot be unmarshaled.
// Error path: provided contact IDs are malformed and cannot be unmarshaled.
func
TestManager_parseContacts_IdUnmarshalError
(
t
*
testing
.
T
)
{
func
TestManager_parseContacts_IdUnmarshalError
(
t
*
testing
.
T
)
{
m
:=
&
Manager
{
grp
:
cyclic
.
NewGroup
(
large
.
NewInt
(
107
),
large
.
NewInt
(
2
))}
m
:=
&
Manager
{
grp
:
cyclic
.
NewGroup
(
large
.
NewInt
(
107
),
large
.
NewInt
(
2
))}
...
...
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