Skip to content
Snippets Groups Projects
Commit bca7ca51 authored by Jonah Husson's avatar Jonah Husson
Browse files

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!23Release,!6Bob/contact
...@@ -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 client: %+v", c) jww.DEBUG.Printf("Printing contact: %+v", c)
cBytes := c.Marshal() cBytes := c.Marshal()
if len(cBytes) == 0 { if len(cBytes) == 0 {
jww.ERROR.Print("Marshaled client has a size of 0.") jww.ERROR.Print("Marshaled contact 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))
} }
......
...@@ -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: facts,
} }
// Assign each Fact with a matching hash to the Contact // Assign each Fact with a matching hash to the Contact
......
...@@ -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."+
"\nexpected: %+v\nreceived: %+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))}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment