File: auth_test.go

package info (click to toggle)
golang-go-dbus 1~bzr20150122-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 328 kB
  • sloc: makefile: 13
file content (35 lines) | stat: -rw-r--r-- 802 bytes parent folder | download
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
package dbus

import (
	"bufio"
	. "gopkg.in/check.v1"
	"net"
)

func (s *S) TestAuthenticate(c *C) {
	server, client := net.Pipe()
	clientWrites := []string{}
	complete := make(chan int)
	go func() {
		r := bufio.NewReader(server)
		// Read the nul byte that marks the start of the protocol
		zero := []byte{0}
		r.Read(zero)

		clientWrites = append(clientWrites, string(zero))
		line, _, _ := r.ReadLine()
		clientWrites = append(clientWrites, string(line))

		server.Write([]byte("OK\r\n"))
		line, _, _ = r.ReadLine()
		clientWrites = append(clientWrites, string(line))

		complete <- 1
	}()

	c.Check(authenticate(client, nil), Equals, nil)
	<-complete
	c.Check(clientWrites[0], Equals, "\x00")
	c.Check(clientWrites[1][:13], Equals, "AUTH EXTERNAL")
	c.Check(clientWrites[2], Equals, "BEGIN")
}