2018-03-09 20:44:13 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.mascherari.press/cwtch/protocol"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProfile(t *testing.T) {
|
|
|
|
profile := GenerateNewProfile("Sarah")
|
|
|
|
err := profile.Save("./profile_test")
|
|
|
|
if err != nil {
|
2018-03-12 18:43:51 +00:00
|
|
|
t.Errorf("Should have saved profile, but got error: %v", err)
|
2018-03-09 20:44:13 +00:00
|
|
|
}
|
|
|
|
loadedProfile, err := LoadProfile("./profile_test")
|
|
|
|
if err != nil || loadedProfile.Name != "Sarah" {
|
|
|
|
t.Errorf("Issue loading profile from file %v %v", err, loadedProfile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProfileIdentity(t *testing.T) {
|
|
|
|
sarah := GenerateNewProfile("Sarah")
|
|
|
|
alice := GenerateNewProfile("Alice")
|
|
|
|
|
|
|
|
message := sarah.GetCwtchIdentity()
|
|
|
|
|
|
|
|
ci := &protocol.CwtchIdentity{}
|
|
|
|
err := proto.Unmarshal(message, ci)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("alice should have added sarah as a contact %v", err)
|
|
|
|
}
|
2018-03-14 22:03:53 +00:00
|
|
|
alice.AddCwtchIdentity("sarah.onion", ci)
|
2018-03-09 20:44:13 +00:00
|
|
|
if alice.Contacts["sarah.onion"].Name != "Sarah" {
|
|
|
|
t.Errorf("alice should have added sarah as a contact %v", alice.Contacts)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("%v", alice)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProfileGroup(t *testing.T) {
|
2018-03-30 21:16:51 +00:00
|
|
|
sarah := GenerateNewProfile("Sarah")
|
2018-03-09 20:44:13 +00:00
|
|
|
alice := GenerateNewProfile("Alice")
|
2018-03-30 21:16:51 +00:00
|
|
|
sarah.AddContact(alice.Onion, alice.PublicProfile)
|
|
|
|
alice.AddContact(sarah.Onion, sarah.PublicProfile)
|
2018-03-09 20:44:13 +00:00
|
|
|
|
2018-03-30 21:16:51 +00:00
|
|
|
gid, invite := alice.StartGroup("aaa.onion")
|
|
|
|
gci := &protocol.CwtchPeerPacket{}
|
|
|
|
proto.Unmarshal(invite, gci)
|
|
|
|
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
|
2018-03-09 20:44:13 +00:00
|
|
|
|
2018-03-30 21:16:51 +00:00
|
|
|
group := alice.GetGroupByGroupId(gid)
|
2018-03-09 20:44:13 +00:00
|
|
|
c, s := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
|
2018-03-30 21:16:51 +00:00
|
|
|
alice.AttemptDecryption(c, s)
|
2018-03-09 20:44:13 +00:00
|
|
|
|
2018-03-30 21:16:51 +00:00
|
|
|
gid2, invite2 := alice.StartGroup("bbb.onion")
|
|
|
|
gci2 := &protocol.CwtchPeerPacket{}
|
|
|
|
proto.Unmarshal(invite2, gci2)
|
|
|
|
sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
|
|
|
|
group2 := alice.GetGroupByGroupId(gid2)
|
2018-03-09 20:44:13 +00:00
|
|
|
c2, _ := sarah.EncryptMessageToGroup("Hello World", group2.GroupID)
|
2018-03-30 21:16:51 +00:00
|
|
|
alice.AttemptDecryption(c2, s)
|
2018-03-09 20:44:13 +00:00
|
|
|
|
|
|
|
}
|