-
Notifications
You must be signed in to change notification settings - Fork 14
/
disconnect_test.go
79 lines (63 loc) · 2.13 KB
/
disconnect_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
package otr3
import (
"math/big"
"testing"
)
func Test_processDisconnectedTLV_forgetAllKeysAndTransitionToFinished(t *testing.T) {
c := &Conversation{}
c.msgState = encrypted
c.keys.theirCurrentDHPubKey = big.NewInt(99)
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
assertEquals(t, c.msgState, finished)
assertDeepEquals(t, c.keys, keyManagementContext{})
}
func Test_processDisconnectedTLV_signalsASecurityEvent(t *testing.T) {
c := &Conversation{}
c.msgState = encrypted
c.keys.theirCurrentDHPubKey = big.NewInt(99)
c.expectSecurityEvent(t, func() {
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
}, GoneInsecure)
}
func Test_processDisconnectedTLV_isActuallyInsecureWhenTheEventIsSignalled(t *testing.T) {
c := &Conversation{}
c.msgState = encrypted
c.keys.theirCurrentDHPubKey = big.NewInt(99)
c.securityEventHandler = dynamicSecurityEventHandler{func(event SecurityEvent) {
assertEquals(t, c.msgState, finished)
}}
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
}
func Test_processDisconnectedTLV_doesntSignalsASecurityEventIfWeWereInPlaintext(t *testing.T) {
c := &Conversation{}
c.msgState = plainText
c.keys.theirCurrentDHPubKey = big.NewInt(99)
c.doesntExpectSecurityEvent(t, func() {
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
})
}
func Test_processDisconnectedTLV_doesntSignalsASecurityEventIfWeAreInFinished(t *testing.T) {
c := &Conversation{}
c.msgState = finished
c.keys.theirCurrentDHPubKey = big.NewInt(99)
c.doesntExpectSecurityEvent(t, func() {
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
})
}
func Test_processDisconnectedTLV_wipesSMPState(t *testing.T) {
c := &Conversation{}
c.smp.state = smpStateExpect2{}
c.smp.secret = bnFromHex("ABCDE56321F9A9F8E364607C8C82DECD8E8E6209E2CB952C7E649620F5286FE3")
c.smp.s1 = fixtureSmp1()
c.smp.s2 = fixtureSmp2()
c.smp.s3 = fixtureSmp3()
q := "Hello"
c.smp.question = &q
_, _ = c.processDisconnectedTLV(tlv{}, dataMessageExtra{})
assertNil(t, c.smp.state)
assertNil(t, c.smp.question)
assertNil(t, c.smp.secret)
assertNil(t, c.smp.s1)
assertNil(t, c.smp.s2)
assertNil(t, c.smp.s3)
}