Official cwtch.im peer and server implementations. https://cwtch.im
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.

group_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package model
  2. import (
  3. "cwtch.im/cwtch/protocol"
  4. "github.com/golang/protobuf/proto"
  5. "testing"
  6. "time"
  7. )
  8. func TestGroup(t *testing.T) {
  9. g, _ := NewGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
  10. dgm := &protocol.DecryptedGroupMessage{
  11. Onion: proto.String("onion"),
  12. Text: proto.String("Hello World!"),
  13. Timestamp: proto.Int32(int32(time.Now().Unix())),
  14. SignedGroupId: []byte{},
  15. PreviousMessageSig: []byte{},
  16. Padding: []byte{},
  17. }
  18. encMessage, _ := g.EncryptMessage(dgm)
  19. ok, message := g.DecryptMessage(encMessage)
  20. if !ok || message.GetText() != "Hello World!" {
  21. t.Errorf("group encryption was invalid, or returned wrong message decrypted:%v message:%v", ok, message)
  22. return
  23. }
  24. g.SetAttribute("test", "test_value")
  25. value, exists := g.GetAttribute("test")
  26. if !exists || value != "test_value" {
  27. t.Errorf("Custom Attribute Should have been set, instead %v %v", exists, value)
  28. }
  29. t.Logf("Got message %v", message)
  30. }
  31. func TestGroupErr(t *testing.T) {
  32. _, err := NewGroup("not a real group name")
  33. if err == nil {
  34. t.Errorf("Group Setup Should Have Failed")
  35. }
  36. }