-
Notifications
You must be signed in to change notification settings - Fork 7
/
starttls_test.go
73 lines (69 loc) · 2 KB
/
starttls_test.go
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
package dane
/*
* Note: these test routines may not work unless you adapt this file
* to use validating DNS resolvers and appropriately configured DANE TLS
* servers you have access to.
*/
import (
"fmt"
"testing"
)
func TestDialStartTLS(t *testing.T) {
testCases := []struct {
host string
ip string
port int
appname string
sname string
resolver *Resolver
needsuccess bool
}{
{"mail.example.com", "50.116.63.23", 25, "smtp", "", resolver1, true},
{"mail.example.com", "50.116.63.23", 25, "blah", "", resolver1, false},
{"locutus.example.com", "104.236.200.251", 143, "imap", "", resolver1, true},
{"locutus.example.com", "104.236.200.251", 110, "pop3", "", resolver1, true},
//{"truck.team1664.org", "109.190.84.43", 5222, "xmpp-client", "team1664.org", resolver1, true},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("## %s %s %d", tc.host, tc.ip, tc.port), func(t *testing.T) {
defer fmt.Println("")
daneconfig := NewConfig(tc.host, tc.ip, tc.port)
daneconfig.SetAppName(tc.appname)
daneconfig.SetServiceName(tc.sname)
daneconfig.NoPKIXfallback()
server := daneconfig.Server
fmt.Printf("## STARTTLS: %s %s %s\n", server, tc.appname, tc.sname)
tlsa, err := GetTLSA(tc.resolver, server.Name, server.Port)
if err != nil {
fmt.Printf("Result: FAILED: %s\n", err.Error())
if tc.needsuccess {
t.Fatalf("%s", err)
}
return
}
daneconfig.SetTLSA(tlsa)
conn, err := DialStartTLS(daneconfig)
if daneconfig.Transcript != "" {
fmt.Printf("%s", daneconfig.Transcript)
}
if daneconfig.TLSA != nil {
daneconfig.TLSA.Results()
}
if err != nil {
fmt.Printf("Result: FAILED: %s\n", err.Error())
if tc.needsuccess {
t.Fatalf("DialStartTLS: %s.", err)
}
return
}
conn.Close()
if daneconfig.Okdane {
fmt.Printf("Result: DANE OK\n")
} else if daneconfig.Okpkix {
fmt.Printf("Result: PKIX OK\n")
} else {
fmt.Printf("Result: FAILED\n")
}
}) // end t.Run()
}
}