cwtch/model/group_test.go

40 lines
1.1 KiB
Go
Raw Normal View History

2018-03-09 20:44:13 +00:00
package model
import (
2018-05-28 18:05:06 +00:00
"cwtch.im/cwtch/protocol"
"github.com/golang/protobuf/proto"
2018-03-30 21:16:51 +00:00
"testing"
"time"
2018-03-09 20:44:13 +00:00
)
func TestGroup(t *testing.T) {
g, _ := NewGroup("2c3kmoobnyghj2zw6pwv7d57yzld753auo3ugauezzpvfak3ahc4bdyd")
dgm := &protocol.DecryptedGroupMessage{
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{},
}
encMessage, _ := g.EncryptMessage(dgm)
2018-03-14 22:23:35 +00:00
ok, message := g.DecryptMessage(encMessage)
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)
}
func TestGroupErr(t *testing.T) {
_, err := NewGroup("not a real group name")
if err == nil {
t.Errorf("Group Setup Should Have Failed")
}
}