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-15 20:53:22 +00:00
|
|
|
/**sarah := GenerateNewProfile("Sarah")
|
2018-03-09 20:44:13 +00:00
|
|
|
alice := GenerateNewProfile("Alice")
|
|
|
|
sarah.AddContact("alice.onion", alice.PublicProfile)
|
|
|
|
alice.AddContact("sarah.onion", sarah.PublicProfile)
|
|
|
|
|
|
|
|
group := NewGroup("server.onion")
|
|
|
|
alice.AddGroup(group)
|
|
|
|
sarah.AddGroup(group)
|
|
|
|
|
|
|
|
c, s := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
|
|
|
|
ok, gid, onion, message := alice.AttemptDecryption(c, s)
|
|
|
|
|
|
|
|
if ok && gid == group.GroupID && onion == "sarah.onion" && message == "Hello World" {
|
|
|
|
t.Logf("Success!")
|
|
|
|
} else {
|
|
|
|
t.Errorf("Failed to decrypt group message %v %v %v %v", ok, gid, onion, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
group2 := NewGroup("server2.onion")
|
|
|
|
sarah.AddGroup(group2)
|
|
|
|
alice.AddGroup(group2)
|
|
|
|
c2, _ := sarah.EncryptMessageToGroup("Hello World", group2.GroupID)
|
|
|
|
ok, gid, onion, message = alice.AttemptDecryption(c2, s)
|
|
|
|
if onion != "not-verified" {
|
|
|
|
t.Errorf("verification should have failed %v %v %v %v", ok, gid, onion, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
bob := GenerateNewProfile("Bob")
|
|
|
|
bob.AddGroup(group)
|
|
|
|
c, s = bob.EncryptMessageToGroup("Hello", group.GroupID)
|
|
|
|
ok, gid, onion, message = alice.AttemptDecryption(c, s)
|
|
|
|
|
|
|
|
if ok && gid == group.GroupID && onion == "not-verified" && message == "Hello" {
|
|
|
|
t.Logf("Success!")
|
|
|
|
} else {
|
|
|
|
t.Errorf("Failed to decrypt unverified group message %v %v %v %v", ok, gid, onion, message)
|
2018-03-15 20:53:22 +00:00
|
|
|
}*/
|
2018-03-09 20:44:13 +00:00
|
|
|
}
|