Skip to content

Commit fc6f51b

Browse files
committed
Add other query messages checks
1 parent be76afe commit fc6f51b

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

query_test.go

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
package otr3
22

3-
import "testing"
3+
import (
4+
"testing"
5+
)
46

5-
func Test_receiveQueryMessage_ignoreAdditionaltext(t *testing.T) {
7+
func Test_receiveQueryMessage_ignoreVersion1(t *testing.T) {
8+
queryMsg := []byte("?OTR?")
9+
10+
c := &Conversation{Policies: policies(allowV2 | allowV3)}
11+
c.SetOurKeys([]PrivateKey{bobPrivateKey})
12+
msg, err := c.receiveQueryMessage(queryMsg)
13+
14+
expError := OtrError{msg: "unsupported OTR version", conflict: false}
15+
assertEquals(t, err, expError)
16+
assertNil(t, msg)
17+
}
18+
19+
func Test_receiveQueryMessage_ignoreVersion1AndSupportVersion2(t *testing.T) {
20+
queryMsg := []byte("?OTR?v2?")
21+
22+
c := &Conversation{Policies: policies(allowV2 | allowV3)}
23+
c.SetOurKeys([]PrivateKey{bobPrivateKey})
24+
msg, err := c.receiveQueryMessage(queryMsg)
25+
26+
assertNil(t, err)
27+
assertEquals(t, c.ake.state, authStateAwaitingDHKey{})
28+
assertDeepEquals(t, dhMsgType(msg[0]), msgTypeDHCommit)
29+
assertDeepEquals(t, dhMsgVersion(msg[0]), uint16(2))
30+
}
31+
32+
func Test_receiveQueryMessage_ignoreBizarreClaim(t *testing.T) {
33+
queryMsg := []byte("?OTRv?")
34+
35+
c := &Conversation{Policies: policies(allowV2 | allowV3)}
36+
c.SetOurKeys([]PrivateKey{bobPrivateKey})
37+
msg, err := c.receiveQueryMessage(queryMsg)
38+
39+
expError := OtrError{msg: "unsupported OTR version", conflict: false}
40+
assertEquals(t, err, expError)
41+
assertNil(t, msg)
42+
}
43+
44+
func Test_receiveQueryMessage_ignoreAdditionalText(t *testing.T) {
645
queryMsg := []byte("?OTRv2? I like number 3")
746

847
c := &Conversation{Policies: policies(allowV2 | allowV3)}

0 commit comments

Comments
 (0)