This file is indexed.

/usr/share/gocode/src/github.com/twstrike/otr3/query_test.go is in golang-github-twstrike-otr3-dev 0.0~git20161015.0.744856d-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package otr3

import "testing"

func Test_receiveQueryMessage_sendDHCommitv3AndTransitToStateAwaitingDHKey(t *testing.T) {
	queryMsg := []byte("?OTRv?23?")

	c := &Conversation{Policies: policies(allowV3)}
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	msg, err := c.receiveQueryMessage(queryMsg)

	assertNil(t, err)
	assertEquals(t, c.ake.state, authStateAwaitingDHKey{})
	assertDeepEquals(t, dhMsgType(msg[0]), msgTypeDHCommit)
	assertDeepEquals(t, dhMsgVersion(msg[0]), uint16(3))
}

func Test_receiveQueryMessageV2_sendDHCommitv2(t *testing.T) {
	queryMsg := []byte("?OTRv?23?")

	c := &Conversation{Policies: policies(allowV2)}
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	msg, err := c.receiveQueryMessage(queryMsg)

	assertNil(t, err)
	assertEquals(t, c.ake.state, authStateAwaitingDHKey{})
	assertDeepEquals(t, dhMsgType(msg[0]), msgTypeDHCommit)
	assertDeepEquals(t, dhMsgVersion(msg[0]), uint16(2))
}

func Test_receiveQueryMessageV2V3_sendDHCommitv3WhenV2AndV3AreAllowed(t *testing.T) {
	queryMsg := []byte("?OTRv?23?")

	c := &Conversation{Policies: policies(allowV2 | allowV3)}
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	msg, err := c.receiveQueryMessage(queryMsg)

	assertNil(t, err)
	assertEquals(t, c.ake.state, authStateAwaitingDHKey{})
	assertDeepEquals(t, dhMsgType(msg[0]), msgTypeDHCommit)
	assertDeepEquals(t, dhMsgVersion(msg[0]), uint16(3))
}

func Test_receiveQueryMessage_StoresRAndXAndGx(t *testing.T) {
	fixture := fixtureConversation()
	fixture.dhCommitMessage()

	cxt := &Conversation{
		version: otrV3{},
		Rand:    fixtureRand(),
	}
	cxt.SetOurKeys([]PrivateKey{bobPrivateKey})

	_, err := cxt.sendDHCommit()

	assertNil(t, err)
	assertDeepEquals(t, cxt.ake.r, fixture.ake.r)
	assertDeepEquals(t, cxt.ake.secretExponent, fixture.ake.secretExponent)
	assertDeepEquals(t, cxt.ake.ourPublicValue, fixture.ake.ourPublicValue)
}

func Test_receiveQueryMessage_signalsMessageEventOnFailure(t *testing.T) {
	queryMsg := []byte("?OTRv3?")

	c := newConversation(nil, fixedRand([]string{"ABCD"}))
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	c.Policies.add(allowV3)
	c.expectMessageEvent(t, func() {
		c.receiveQueryMessage(queryMsg)
	}, MessageEventSetupError, nil, errShortRandomRead)
}

func Test_receiveQueryMessage_returnsErrorIfNoCompatibleVersionCouldBeFound(t *testing.T) {
	c := &Conversation{Policies: policies(allowV3)}
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	_, err := c.receiveQueryMessage([]byte("?OTRv?2?"))
	assertEquals(t, err, errUnsupportedOTRVersion)
}

func Test_receiveQueryMessage_returnsErrorIfDhCommitMessageGeneratesError(t *testing.T) {
	c := &Conversation{
		Policies: policies(allowV2),
		Rand:     fixedRand([]string{"ABCDABCD"}),
	}
	c.SetOurKeys([]PrivateKey{bobPrivateKey})
	_, err := c.receiveQueryMessage([]byte("?OTRv2?"))
	assertEquals(t, err, errShortRandomRead)
}

func Test_parseOTRQueryMessage(t *testing.T) {
	var exp = map[string][]int{
		"?OTR?":     []int{1},
		"?OTRv2?":   []int{2},
		"?OTRv23?":  []int{2, 3},
		"?OTR?v2":   []int{1, 2},
		"?OTRv248?": []int{2, 4, 8},
		"?OTR?v?":   []int{1},
		"?OTRv?":    []int{},
	}

	for queryMsg, versions := range exp {
		m := []byte(queryMsg)
		assertDeepEquals(t, parseOTRQueryMessage(m), versions)
	}
}

func Test_extractVersionsFromQueryMessage_returnsNilForUnsupportedVersions(t *testing.T) {
	p := policies(0)
	msg := []byte("?OTR?")
	versions := extractVersionsFromQueryMessage(p, msg)

	assertEquals(t, versions, 0)
}

func Test_extractVersionsFromQueryMessage_acceptsBothV2AndV3IfThePolicyAllows(t *testing.T) {
	msg := []byte("?OTRv32?")
	p := policies(allowV2 | allowV3)
	versions := extractVersionsFromQueryMessage(p, msg)

	assertEquals(t, versions, 1<<2|1<<3)
}

func Test_extractVersionsFromQueryMessage_acceptsOTRV2IfHasOnlyAllowV2Policy(t *testing.T) {
	msg := []byte("?OTRv32?")
	p := policies(allowV2)
	versions := extractVersionsFromQueryMessage(p, msg)

	assertEquals(t, versions, 1<<2)
}

func Test_QueryMessage_returnsARegularQueryMessage(t *testing.T) {
	c := &Conversation{Policies: policies(allowV3)}
	assertEquals(t, string(c.QueryMessage()), "?OTRv3?")
}

func Test_QueryMessage_returnsAQueryMessageWithExtraMessage(t *testing.T) {
	c := &Conversation{Policies: policies(allowV3)}
	c.SetFriendlyQueryMessage("hello foobarium")
	assertEquals(t, string(c.QueryMessage()), "?OTRv3? hello foobarium")
}