2018-03-09 20:44:13 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2018-05-28 18:05:06 +00:00
|
|
|
"cwtch.im/cwtch/protocol"
|
2018-03-15 20:53:22 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2018-03-30 21:16:51 +00:00
|
|
|
"testing"
|
2018-03-15 20:53:22 +00:00
|
|
|
"time"
|
2018-03-09 20:44:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGroup(t *testing.T) {
|
2018-11-21 22:15:43 +00:00
|
|
|
g, _ := NewGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
|
2018-03-15 20:53:22 +00:00
|
|
|
dgm := &protocol.DecryptedGroupMessage{
|
2018-04-28 17:52:59 +00:00
|
|
|
Onion: proto.String("onion"),
|
|
|
|
Text: proto.String("Hello World!"),
|
|
|
|
Timestamp: proto.Int32(int32(time.Now().Unix())),
|
|
|
|
SignedGroupId: []byte{},
|
|
|
|
PreviousMessageSig: []byte{},
|
2018-05-28 17:44:47 +00:00
|
|
|
Padding: []byte{},
|
2018-03-15 20:53:22 +00:00
|
|
|
}
|
2018-09-27 00:08:54 +00:00
|
|
|
encMessage, _ := g.EncryptMessage(dgm)
|
2018-03-14 22:23:35 +00:00
|
|
|
ok, message := g.DecryptMessage(encMessage)
|
2018-03-15 20:53:22 +00:00
|
|
|
if !ok || message.GetText() != "Hello World!" {
|
2018-03-09 20:44:13 +00:00
|
|
|
t.Errorf("group encryption was invalid, or returned wrong message decrypted:%v message:%v", ok, message)
|
|
|
|
return
|
|
|
|
}
|
2018-11-02 23:43:40 +00:00
|
|
|
g.SetAttribute("test", "test_value")
|
|
|
|
value, exists := g.GetAttribute("test")
|
|
|
|
if !exists || value != "test_value" {
|
|
|
|
t.Errorf("Custom Attribute Should have been set, instead %v %v", exists, value)
|
|
|
|
}
|
2018-03-09 20:44:13 +00:00
|
|
|
t.Logf("Got message %v", message)
|
|
|
|
}
|
2018-11-21 22:15:43 +00:00
|
|
|
|
|
|
|
func TestGroupErr(t *testing.T) {
|
|
|
|
_, err := NewGroup("not a real group name")
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Group Setup Should Have Failed")
|
|
|
|
}
|
|
|
|
}
|