Official cwtch.im peer and server implementations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

profile_test.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package model
  2. import (
  3. "git.mascherari.press/cwtch/protocol"
  4. "github.com/golang/protobuf/proto"
  5. "testing"
  6. )
  7. func TestProfile(t *testing.T) {
  8. profile := GenerateNewProfile("Sarah")
  9. err := profile.Save("./profile_test")
  10. if err != nil {
  11. t.Errorf("Should have saved profile, but got error: %v", err)
  12. }
  13. loadedProfile, err := LoadProfile("./profile_test")
  14. if err != nil || loadedProfile.Name != "Sarah" {
  15. t.Errorf("Issue loading profile from file %v %v", err, loadedProfile)
  16. }
  17. }
  18. func TestProfileIdentity(t *testing.T) {
  19. sarah := GenerateNewProfile("Sarah")
  20. alice := GenerateNewProfile("Alice")
  21. message := sarah.GetCwtchIdentity()
  22. ci := &protocol.CwtchIdentity{}
  23. err := proto.Unmarshal(message, ci)
  24. if err != nil {
  25. t.Errorf("alice should have added sarah as a contact %v", err)
  26. }
  27. alice.AddCwtchIdentity("sarah.onion", ci)
  28. if alice.Contacts["sarah.onion"].Name != "Sarah" {
  29. t.Errorf("alice should have added sarah as a contact %v", alice.Contacts)
  30. }
  31. t.Logf("%v", alice)
  32. }
  33. func TestProfileGroup(t *testing.T) {
  34. sarah := GenerateNewProfile("Sarah")
  35. alice := GenerateNewProfile("Alice")
  36. sarah.AddContact(alice.Onion, alice.PublicProfile)
  37. alice.AddContact(sarah.Onion, sarah.PublicProfile)
  38. gid, invite := alice.StartGroup("aaa.onion")
  39. gci := &protocol.CwtchPeerPacket{}
  40. proto.Unmarshal(invite, gci)
  41. sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
  42. group := alice.GetGroupByGroupId(gid)
  43. c, s := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
  44. alice.AttemptDecryption(c, s)
  45. gid2, invite2 := alice.StartGroup("bbb.onion")
  46. gci2 := &protocol.CwtchPeerPacket{}
  47. proto.Unmarshal(invite2, gci2)
  48. sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)
  49. group2 := alice.GetGroupByGroupId(gid2)
  50. c2, _ := sarah.EncryptMessageToGroup("Hello World", group2.GroupID)
  51. alice.AttemptDecryption(c2, s)
  52. }