File: version_test.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (62 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download | duplicates (3)
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
package otr3

import "testing"

func Test_newOtrVersion_returnsTheCorrectOTRVersionForAValidVersionNumber(t *testing.T) {
	v, _ := newOtrVersion(3, policies(allowV3))
	_, ok := v.(otrV3)
	assertEquals(t, ok, true)
}

func Test_newOtrVersion_returnsUnsupportedVersionErrorIfGivenAWrongVersion(t *testing.T) {
	_, err := newOtrVersion(4, policies(allowV3))
	assertEquals(t, err, errUnsupportedOTRVersion)
}

func Test_newOtrVersion_returnsAnErrorIfGivenAVersionThatIsntAllowedByPolicy(t *testing.T) {
	_, err := newOtrVersion(3, policies(allowV2))
	assertEquals(t, err, errInvalidVersion)
}

func Test_checkVersion_returnsErrorIfTheMessageIsCorrupt(t *testing.T) {
	c := &Conversation{}
	e := c.checkVersion([]byte{0x00})
	assertEquals(t, e, errInvalidOTRMessage)
}

func Test_checkVersion_setsTheConversationVersionIfWeHaveNoExistingVersion(t *testing.T) {
	c := &Conversation{Policies: policies(allowV3)}
	c.ourKeys = []PrivateKey{alicePrivateKey}
	e := c.checkVersion([]byte{0x00, 0x03})
	assertEquals(t, e, nil)
	assertDeepEquals(t, c.version, otrV3{})
}

func Test_checkVersion_setsTheConversationVersionIfWeHaveTheCorrectPolicy(t *testing.T) {
	c := &Conversation{Policies: policies(allowV2)}
	c.ourKeys = []PrivateKey{alicePrivateKey}
	e := c.checkVersion([]byte{0x00, 0x02})
	assertEquals(t, e, nil)
	assertDeepEquals(t, c.version, otrV2{})
}

func Test_checkVersion_returnsTheErrorFromNewOtrVersion(t *testing.T) {
	c := &Conversation{Policies: policies(allowV2)}
	c.ourKeys = []PrivateKey{alicePrivateKey}
	e := c.checkVersion([]byte{0x00, 0x03})
	assertEquals(t, e, errUnsupportedOTRVersion)
}

func Test_checkVersion_doesNotSetConversationVersionIfOneIsAlreadySet(t *testing.T) {
	c := &Conversation{Policies: policies(allowV2 | allowV3), version: otrV3{}}
	c.ourKeys = []PrivateKey{alicePrivateKey}
	c.checkVersion([]byte{0x00, 0x02})
	assertEquals(t, otrV3{}, c.version)
}

func Test_checkVersion_returnsErrorIfCurrentVersionIsDifferentFromMessageVersion(t *testing.T) {
	c := &Conversation{Policies: policies(allowV2 | allowV3), version: otrV3{}}
	c.ourKeys = []PrivateKey{alicePrivateKey}
	e := c.checkVersion([]byte{0x00, 0x02})
	assertEquals(t, e, errWrongProtocolVersion)
}