-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathin_memory_storage_test.go
92 lines (71 loc) · 3.49 KB
/
in_memory_storage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package prekeyserver
import (
"time"
"github.com/otrv4/gotrx"
. "gopkg.in/check.v1"
)
func (s *GenericServerSuite) Test_inMemoryStorage_numberStored_returns0ForUnknownUser(c *C) {
is := &inMemoryStorage{}
c.Assert(is.numberStored("[email protected]", 0x11223344), Equals, uint32(0))
}
func (s *GenericServerSuite) Test_inMemoryStorage_numberStored_returnsNumberOfPrekeyMessages(c *C) {
is := createInMemoryStorage()
se := is.storageEntryFor("[email protected]")
se.prekeyMessages[0x11223344] = []*prekeyMessage{nil, nil}
c.Assert(is.numberStored("[email protected]", 0x11223344), Equals, uint32(2))
}
func (s *GenericServerSuite) Test_inMemoryStorage_cleanup_willRemoveExpiredClientProfiles(c *C) {
is := createInMemoryStorage()
cp := generateSitaTestData().clientProfile
cp.Expiration = time.Date(2017, 11, 5, 13, 46, 00, 13, time.UTC)
cp.Sig = gotrx.CreateEddsaSignature(cp.GenerateSignature(sita.longTerm))
cp2 := generateSitaTestData().clientProfile
cp2.InstanceTag = 0x42424242
cp2.Sig = gotrx.CreateEddsaSignature(cp2.GenerateSignature(sita.longTerm))
is.storeClientProfile("[email protected]", cp)
is.storeClientProfile("[email protected]", cp2)
is.storeClientProfile("[email protected]", sita.clientProfile)
is.storeClientProfile("[email protected]", cp)
is.cleanup()
c.Assert(is.perUser, HasLen, 2)
c.Assert(is.perUser["[email protected]"].clientProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"].clientProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"], IsNil)
}
func (s *GenericServerSuite) Test_inMemoryStorage_cleanup_willRemoveExpiredPrekeyProfiles(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
is := createInMemoryStorage()
pp1, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2017, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pp2, _ := generatePrekeyProfile(gs, 0x42424242, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
is.storePrekeyProfile("[email protected]", pp1)
is.storePrekeyProfile("[email protected]", pp2)
is.storePrekeyProfile("[email protected]", pp2)
is.storePrekeyProfile("[email protected]", pp1)
is.cleanup()
c.Assert(is.perUser, HasLen, 2)
c.Assert(is.perUser["[email protected]"].prekeyProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"].prekeyProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"], IsNil)
}
func (s *GenericServerSuite) Test_inMemoryStorage_cleanup_shouldNotRemoveUserIfThereArePrekeyMessages(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
is := createInMemoryStorage()
pp1, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2017, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pp2, _ := generatePrekeyProfile(gs, 0x42424242, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pm1, _, _, _ := generatePrekeyMessage(gs, sita.instanceTag)
is.storePrekeyProfile("[email protected]", pp1)
is.storePrekeyProfile("[email protected]", pp2)
is.storePrekeyProfile("[email protected]", pp2)
is.storePrekeyProfile("[email protected]", pp1)
is.storePrekeyMessages("[email protected]", []*prekeyMessage{pm1})
is.cleanup()
c.Assert(is.perUser, HasLen, 3)
c.Assert(is.perUser["[email protected]"].prekeyProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"].prekeyProfiles, HasLen, 1)
c.Assert(is.perUser["[email protected]"].prekeyProfiles, HasLen, 0)
c.Assert(is.perUser["[email protected]"].prekeyMessages, HasLen, 1)
}