File: tls_test.go

package info (click to toggle)
coyim 0.3.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,064 kB
  • ctags: 4,528
  • sloc: xml: 5,120; sh: 328; python: 286; makefile: 235; ruby: 51
file content (59 lines) | stat: -rw-r--r-- 1,478 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package xmpp

import (
	"crypto/tls"
	"crypto/x509"
	"crypto/x509/pkix"

	. "gopkg.in/check.v1"
)

type TLSXmppSuite struct{}

var _ = Suite(&TLSXmppSuite{})

func (s *TLSXmppSuite) Test_certName_returnsEmptyInformation(c *C) {
	cert := &x509.Certificate{}
	cert.Subject = pkix.Name{}
	res := certName(cert)
	c.Assert(res, Equals, "")
}

func (s *TLSXmppSuite) Test_certName_usesNameInformation(c *C) {
	cert := &x509.Certificate{}
	cert.Subject = pkix.Name{}
	cert.Subject.Organization = []string{"Foo", "Bar.com"}
	cert.Subject.OrganizationalUnit = []string{"Somewhere", "Else", "Above", "Beyond"}
	cert.Subject.CommonName = "test.coyim"
	res := certName(cert)
	c.Assert(res, Equals, "O=Foo/O=Bar.com/OU=Somewhere/OU=Else/OU=Above/OU=Beyond/CN=test.coyim/")
}

func (s *TLSXmppSuite) Test_printTLSDetails_printsUnknownVersions(c *C) {
	mockWriter := mockConnIOReaderWriter{}
	state := tls.ConnectionState{
		Version: 0x0200,
	}

	printTLSDetails(&mockWriter, state)

	c.Assert(string(mockWriter.write), Equals, ""+
		"  SSL/TLS version: unknown\n"+
		"  Cipher suite: unknown\n",
	)
}

func (s *TLSXmppSuite) Test_printTLSDetails_printsCorrectVersions(c *C) {
	mockWriter := mockConnIOReaderWriter{}
	state := tls.ConnectionState{
		Version:     tls.VersionTLS11,
		CipherSuite: 0xc00a,
	}

	printTLSDetails(&mockWriter, state)

	c.Assert(string(mockWriter.write), Equals, ""+
		"  SSL/TLS version: TLS 1.1\n"+
		"  Cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA\n",
	)
}