This file is indexed.

/usr/share/gocode/src/github.com/mitchellh/go-vnc/client_auth_test.go is in golang-github-mitchellh-go-vnc-dev 0.0~git20150629.0.723ed98-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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package vnc

import (
	"testing"
	"net"
	"time"
	"bytes"
)

type fakeNetConnection struct {
	DataToSend []byte
	Test *testing.T
	ExpectData []byte
	Finished bool
	Matched bool
}

func (fc fakeNetConnection) Read(b []byte) (n int, err error) {
	for i := 0; i < 16; i++ {
		b[i] = fc.DataToSend[i]
	}

	fc.Finished = false

	return len(b), nil
}

func (fc *fakeNetConnection) Write(b []byte) (n int, err error) {
	fc.Matched = bytes.Equal(b, fc.ExpectData)
	fc.Finished = true

	return len(b), nil
}

func (fc *fakeNetConnection) Close() error { return nil; }
func (fc *fakeNetConnection) LocalAddr() net.Addr { return nil; }
func (fc *fakeNetConnection) RemoteAddr() net.Addr { return nil; }
func (fc *fakeNetConnection) SetDeadline(t time.Time) error { return nil; }
func (fc *fakeNetConnection) SetReadDeadline(t time.Time) error { return nil; }
func (fc *fakeNetConnection) SetWriteDeadline(t time.Time) error { return nil; }

func TestClientAuthNone_Impl(t *testing.T) {
	var raw interface{}
	raw = new(ClientAuthNone)
	if _, ok := raw.(ClientAuth); !ok {
		t.Fatal("ClientAuthNone doesn't implement ClientAuth")
	}
}

func TestClientAuthPasswordSuccess_Impl(t *testing.T) {
	// Values ripped using WireShark
	randomValue := []byte{
		0xa4,
		0x51,
		0x3f,
		0xa5,
		0x1f,
		0x87,
		0x06,
		0x10,
		0xa4,
		0x5f,
		0xae,
		0xbf,
		0x4d,
		0xac,
		0x12,
		0x22,
	}

	expectedResponse := []byte{
		0x71,
		0xe4,
		0x41,
		0x30,
		0x43,
		0x65,
		0x4e,
		0x39,
		0xda,
		0x6d,
		0x49,
		0x93,
		0x43,
		0xf6,
		0x5e,
		0x29,
	}

	raw := PasswordAuth{Password: "Ch_#!T@8"}

	// Only about 12 hours into Go at the moment...
	// if _, ok := raw.(ClientAuth); !ok {
	// 	t.Fatal("PasswordAuth doesn't implement ClientAuth")
	// }

	conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
	err := raw.Handshake(conn)

	if (err != nil) {
		t.Fatal(err)
	}

	if !conn.Matched {
		t.Fatal("PasswordAuth didn't pass the right response back to the wire")
	}

	if !conn.Finished {
		t.Fatal("PasswordAuth didn't complete properly")
	}
}

func TestClientAuthPasswordReject_Impl(t *testing.T) {
	// Values ripped using WireShark
	randomValue := []byte{
		0xa4,
		0x51,
		0x3f,
		0xa5,
		0x1f,
		0x87,
		0x06,
		0x10,
		0xa4,
		0x5f,
		0xae,
		0xbf,
		0x4d,
		0xac,
		0x12,
		0x22,
	}

	expectedResponse := []byte{
		0x71,
		0xe4,
		0x41,
		0x30,
		0x43,
		0x65,
		0x4e,
		0x39,
		0xda,
		0x6d,
		0x49,
		0x93,
		0x43,
		0xf6,
		0x5e,
		0x29,
	}

	raw := PasswordAuth{Password: "Ch_#!T@"}

	conn := &fakeNetConnection{DataToSend: randomValue, ExpectData: expectedResponse, Test: t}
	err := raw.Handshake(conn)

	if (err != nil) {
		t.Fatal(err)
	}

	if conn.Matched {
		t.Fatal("PasswordAuth didn't pass the right response back to the wire")
	}

	if !conn.Finished {
		t.Fatal("PasswordAuth didn't complete properly")
	}
}