2018-03-11 18:49:10 +00:00
|
|
|
package peer
|
2018-03-09 20:44:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-01-04 21:44:21 +00:00
|
|
|
// TODO: Rewrite these tests (and others) using the news event bus interface.
|
2018-03-09 20:44:13 +00:00
|
|
|
func TestCwtchPeerGenerate(t *testing.T) {
|
2019-01-04 21:44:21 +00:00
|
|
|
/**
|
2018-10-06 03:50:55 +00:00
|
|
|
alice := NewCwtchPeer("alice")
|
2018-03-14 22:03:53 +00:00
|
|
|
|
2018-10-06 03:50:55 +00:00
|
|
|
groupID, _, _ := alice.StartGroup("test.server")
|
|
|
|
exportedGroup, _ := alice.ExportGroup(groupID)
|
|
|
|
t.Logf("Exported Group: %v from %v", exportedGroup, alice.GetProfile().Onion)
|
2018-06-09 07:49:18 +00:00
|
|
|
|
|
|
|
importedGroupID, err := alice.ImportGroup(exportedGroup)
|
2018-06-19 22:28:44 +00:00
|
|
|
group := alice.GetGroup(importedGroupID)
|
2018-06-09 07:49:18 +00:00
|
|
|
t.Logf("Imported Group: %v, err := %v %v", group, err, importedGroupID)
|
2019-01-04 21:44:21 +00:00
|
|
|
*/
|
2018-03-09 20:44:13 +00:00
|
|
|
}
|
2018-07-04 16:03:04 +00:00
|
|
|
|
|
|
|
func TestTrustPeer(t *testing.T) {
|
2019-01-04 21:44:21 +00:00
|
|
|
/**
|
2018-11-21 22:15:43 +00:00
|
|
|
groupName := "2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd"
|
2018-10-06 03:50:55 +00:00
|
|
|
alice := NewCwtchPeer("alice")
|
2019-01-04 21:44:21 +00:00
|
|
|
aem := new(event.Manager)
|
|
|
|
aem.Initialize()
|
|
|
|
alice.Init(connectivity.LocalProvider(),aem)
|
2018-11-22 22:29:05 +00:00
|
|
|
defer alice.Shutdown()
|
2018-10-06 03:50:55 +00:00
|
|
|
bob := NewCwtchPeer("bob")
|
2019-01-04 21:44:21 +00:00
|
|
|
bem := new(event.Manager)
|
|
|
|
bem.Initialize()
|
|
|
|
bob.Init(connectivity.LocalProvider(), bem)
|
2018-11-22 22:29:05 +00:00
|
|
|
defer bob.Shutdown()
|
2018-07-04 16:03:04 +00:00
|
|
|
|
|
|
|
bobOnion := bob.GetProfile().Onion
|
|
|
|
aliceOnion := alice.GetProfile().Onion
|
|
|
|
|
|
|
|
groupID, _, err := alice.StartGroup(groupName)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
groupAlice := alice.GetGroup(groupID)
|
|
|
|
if groupAlice.GroupID != groupID {
|
|
|
|
t.Errorf("Alice should be part of group %v, got %v instead", groupID, groupAlice)
|
|
|
|
}
|
|
|
|
|
|
|
|
exportedGroup, err := alice.ExportGroup(groupID)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = alice.InviteOnionToGroup(bobOnion, groupID)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("onion invitation should fail since alice does no trust bob")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = alice.TrustPeer(bobOnion)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("trust peer should fail since alice does not know about bob")
|
|
|
|
}
|
|
|
|
|
|
|
|
// bob adds alice contact by importing serialized group created by alice
|
|
|
|
_, err = bob.ImportGroup(exportedGroup)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = bob.TrustPeer(aliceOnion)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("bob must be able to trust alice, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = bob.InviteOnionToGroup(aliceOnion, groupID)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("bob trusts alice but peer connection is not ready yet. should not be able to invite her to group, instead got: %v", err)
|
|
|
|
}
|
2019-01-04 21:44:21 +00:00
|
|
|
*/
|
2018-07-04 16:03:04 +00:00
|
|
|
}
|