2018-03-09 20:44:13 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2020-07-14 00:46:05 +00:00
|
|
|
"cwtch.im/cwtch/protocol/groups"
|
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")
|
2020-07-14 00:46:05 +00:00
|
|
|
dgm := &groups.DecryptedGroupMessage{
|
|
|
|
Onion: "onion",
|
|
|
|
Text: "Hello World!",
|
|
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
|
|
SignedGroupID: []byte{},
|
2018-04-28 17:52:59 +00:00
|
|
|
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)
|
2020-07-14 00:46:05 +00:00
|
|
|
if !ok || message.Text != "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")
|
|
|
|
}
|
|
|
|
}
|