File: tls_test.go

package info (click to toggle)
golang-vhost 0.0~git20140120-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 104 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 631 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
package vhost

import (
	"crypto/tls"
	"net"
	"testing"
)

func TestSNI(t *testing.T) {
	var testHostname string = "foo.example.com"

	l, err := net.Listen("tcp", "127.0.0.1:12345")
	if err != nil {
		panic(err)
	}
	defer l.Close()

	go func() {
		conf := &tls.Config{ServerName: testHostname}
		conn, err := tls.Dial("tcp", "127.0.0.1:12345", conf)
		if err != nil {
			panic(err)
		}
		conn.Close()
	}()

	conn, err := l.Accept()
	if err != nil {
		panic(err)
	}
	c, err := TLS(conn)
	if err != nil {
		panic(err)
	}

	if c.Host() != testHostname {
		t.Errorf("Connection Host() is %s, expected %s", c.Host(), testHostname)
	}
}