Merge branch 'servercheck' of cwtch.im/cwtch into p2ptimeline
This commit is contained in:
commit
b087d3667e
|
@ -34,6 +34,11 @@ type Group struct {
|
||||||
// NewGroup initializes a new group associated with a given CwtchServer
|
// NewGroup initializes a new group associated with a given CwtchServer
|
||||||
func NewGroup(server string) (*Group, error) {
|
func NewGroup(server string) (*Group, error) {
|
||||||
group := new(Group)
|
group := new(Group)
|
||||||
|
|
||||||
|
if utils.IsValidHostname(server) == false {
|
||||||
|
return nil, errors.New("Server is not a valid v3 onion")
|
||||||
|
}
|
||||||
|
|
||||||
group.GroupServer = server
|
group.GroupServer = server
|
||||||
|
|
||||||
var groupID [16]byte
|
var groupID [16]byte
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGroup(t *testing.T) {
|
func TestGroup(t *testing.T) {
|
||||||
g, _ := NewGroup("server.onion")
|
g, _ := NewGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
dgm := &protocol.DecryptedGroupMessage{
|
dgm := &protocol.DecryptedGroupMessage{
|
||||||
Onion: proto.String("onion"),
|
Onion: proto.String("onion"),
|
||||||
Text: proto.String("Hello World!"),
|
Text: proto.String("Hello World!"),
|
||||||
|
@ -30,3 +30,10 @@ func TestGroup(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Logf("Got message %v", message)
|
t.Logf("Got message %v", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGroupErr(t *testing.T) {
|
||||||
|
_, err := NewGroup("not a real group name")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Group Setup Should Have Failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestMessagePadding(t *testing.T) {
|
||||||
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
||||||
|
|
||||||
gid, invite, _ := alice.StartGroup("aaa.onion")
|
gid, invite, _ := alice.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
gci := &protocol.CwtchPeerPacket{}
|
gci := &protocol.CwtchPeerPacket{}
|
||||||
proto.Unmarshal(invite, gci)
|
proto.Unmarshal(invite, gci)
|
||||||
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
||||||
|
@ -50,7 +50,7 @@ func TestTranscriptConsistency(t *testing.T) {
|
||||||
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
||||||
|
|
||||||
gid, invite, _ := alice.StartGroup("aaa.onion")
|
gid, invite, _ := alice.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
gci := &protocol.CwtchPeerPacket{}
|
gci := &protocol.CwtchPeerPacket{}
|
||||||
proto.Unmarshal(invite, gci)
|
proto.Unmarshal(invite, gci)
|
||||||
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
||||||
|
|
|
@ -121,7 +121,6 @@ func (p *Profile) AddMessageToContactTimeline(onion string, fromMe bool, message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// AcceptInvite accepts a group invite
|
// AcceptInvite accepts a group invite
|
||||||
func (p *Profile) AcceptInvite(groupID string) (err error) {
|
func (p *Profile) AcceptInvite(groupID string) (err error) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
|
|
|
@ -7,30 +7,28 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestP2P(t *testing.T) {
|
func TestP2P(t *testing.T) {
|
||||||
sarah := GenerateNewProfile("Sarah")
|
sarah := GenerateNewProfile("Sarah")
|
||||||
alice := GenerateNewProfile("Alice")
|
alice := GenerateNewProfile("Alice")
|
||||||
|
|
||||||
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
|
|
||||||
sarah.AddMessageToContactTimeline(alice.Onion, false, "hello",time.Now())
|
sarah.AddMessageToContactTimeline(alice.Onion, false, "hello", time.Now())
|
||||||
sarah.AddMessageToContactTimeline(alice.Onion, true, "world",time.Now())
|
sarah.AddMessageToContactTimeline(alice.Onion, true, "world", time.Now())
|
||||||
|
|
||||||
contact,_ := sarah.GetContact(alice.Onion)
|
contact, _ := sarah.GetContact(alice.Onion)
|
||||||
for i,m := range contact.Timeline.GetMessages() {
|
for i, m := range contact.Timeline.GetMessages() {
|
||||||
if i == 0 && (m.Message != "hello" || m.PeerID != alice.Onion) {
|
if i == 0 && (m.Message != "hello" || m.PeerID != alice.Onion) {
|
||||||
t.Fatalf("Timeline is invalid: %v", m)
|
t.Fatalf("Timeline is invalid: %v", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 1 && (m.Message != "world" || m.PeerID != sarah.Onion) {
|
if i == 1 && (m.Message != "world" || m.PeerID != sarah.Onion) {
|
||||||
t.Fatalf("Timeline is invalid: %v", m)
|
t.Fatalf("Timeline is invalid: %v", m)
|
||||||
}
|
}
|
||||||
t.Logf("Message: %v", m)
|
t.Logf("Message: %v", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestProfileIdentity(t *testing.T) {
|
func TestProfileIdentity(t *testing.T) {
|
||||||
sarah := GenerateNewProfile("Sarah")
|
sarah := GenerateNewProfile("Sarah")
|
||||||
alice := GenerateNewProfile("Alice")
|
alice := GenerateNewProfile("Alice")
|
||||||
|
@ -91,8 +89,6 @@ func TestBlockPeer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func TestAcceptNonExistentGroup(t *testing.T) {
|
func TestAcceptNonExistentGroup(t *testing.T) {
|
||||||
sarah := GenerateNewProfile("Sarah")
|
sarah := GenerateNewProfile("Sarah")
|
||||||
sarah.AcceptInvite("doesnotexist")
|
sarah.AcceptInvite("doesnotexist")
|
||||||
|
@ -104,7 +100,7 @@ func TestRejectGroupInvite(t *testing.T) {
|
||||||
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
||||||
|
|
||||||
gid, invite, _ := alice.StartGroup("aaa.onion")
|
gid, invite, _ := alice.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
gci := &protocol.CwtchPeerPacket{}
|
gci := &protocol.CwtchPeerPacket{}
|
||||||
proto.Unmarshal(invite, gci)
|
proto.Unmarshal(invite, gci)
|
||||||
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
||||||
|
@ -128,7 +124,7 @@ func TestProfileGroup(t *testing.T) {
|
||||||
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
sarah.AddContact(alice.Onion, &alice.PublicProfile)
|
||||||
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
|
||||||
|
|
||||||
gid, invite, _ := alice.StartGroupWithMessage("aaa.onion", []byte("Hello World"))
|
gid, invite, _ := alice.StartGroupWithMessage("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd", []byte("Hello World"))
|
||||||
gci := &protocol.CwtchPeerPacket{}
|
gci := &protocol.CwtchPeerPacket{}
|
||||||
proto.Unmarshal(invite, gci)
|
proto.Unmarshal(invite, gci)
|
||||||
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
||||||
|
@ -141,7 +137,7 @@ func TestProfileGroup(t *testing.T) {
|
||||||
c, s1, _ := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
|
c, s1, _ := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
|
||||||
alice.AttemptDecryption(c, s1)
|
alice.AttemptDecryption(c, s1)
|
||||||
|
|
||||||
gid2, invite2, _ := alice.StartGroup("bbb.onion")
|
gid2, invite2, _ := alice.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
gci2 := &protocol.CwtchPeerPacket{}
|
gci2 := &protocol.CwtchPeerPacket{}
|
||||||
proto.Unmarshal(invite2, gci2)
|
proto.Unmarshal(invite2, gci2)
|
||||||
sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
|
sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
|
||||||
|
|
|
@ -77,7 +77,7 @@ func TestPeerPeerConnection(t *testing.T) {
|
||||||
if state != AUTHENTICATED {
|
if state != AUTHENTICATED {
|
||||||
t.Errorf("connection state should be authenticated(3), was instead %v", state)
|
t.Errorf("connection state should be authenticated(3), was instead %v", state)
|
||||||
}
|
}
|
||||||
_, invite, _ := profile.StartGroup("aaa.onion")
|
_, invite, _ := profile.StartGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
||||||
ppc.SendGroupInvite(invite)
|
ppc.SendGroupInvite(invite)
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
if tp.ReceivedGroupInvite == false {
|
if tp.ReceivedGroupInvite == false {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestCwtchPeerGenerate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrustPeer(t *testing.T) {
|
func TestTrustPeer(t *testing.T) {
|
||||||
groupName := "test.server"
|
groupName := "2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd"
|
||||||
alice := NewCwtchPeer("alice")
|
alice := NewCwtchPeer("alice")
|
||||||
alice.Init(connectivity.LocalProvider())
|
alice.Init(connectivity.LocalProvider())
|
||||||
bob := NewCwtchPeer("bob")
|
bob := NewCwtchPeer("bob")
|
||||||
|
|
Loading…
Reference in New Issue