Use an interface for making tests and reporting test results
This commit is contained in:
parent
f48afca7e8
commit
5bbb306006
6 changed files with 174 additions and 82 deletions
61
testsuite/protocols.go
Normal file
61
testsuite/protocols.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package testsuite
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"github.com/nemunaire/eyespot"
|
||||
)
|
||||
|
||||
type Protocols struct {
|
||||
}
|
||||
|
||||
func (Protocols) GetTestDescription() string {
|
||||
return "Test for protocols accepted by the remote host."
|
||||
}
|
||||
|
||||
func (test Protocols) Run(protocol string, host string) (map[string]eyespot.Result, error) {
|
||||
var results = map[string]eyespot.Result{}
|
||||
|
||||
for _, v := range []uint16{
|
||||
tls.VersionSSL30,
|
||||
tls.VersionTLS10,
|
||||
tls.VersionTLS11,
|
||||
tls.VersionTLS12,
|
||||
} {
|
||||
if r, err := protocol_test(protocol, host, v); err != nil {
|
||||
return results, err
|
||||
} else {
|
||||
var cstr string
|
||||
|
||||
switch v {
|
||||
case tls.VersionSSL30:
|
||||
cstr = "VersionSSL30"
|
||||
case tls.VersionTLS10:
|
||||
cstr = "VersionTLS10"
|
||||
case tls.VersionTLS11:
|
||||
cstr = "VersionTLS11"
|
||||
case tls.VersionTLS12:
|
||||
cstr = "VersionTLS12"
|
||||
default:
|
||||
cstr = ""
|
||||
}
|
||||
|
||||
results[cstr] = eyespot.Result{r}
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func protocol_test(protocol string, host string, version uint16) (bool, error) {
|
||||
conn, err := tls.Dial(protocol, host, &tls.Config{
|
||||
MinVersion: version,
|
||||
MaxVersion: version,
|
||||
InsecureSkipVerify: true,
|
||||
})
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
defer conn.Close();
|
||||
|
||||
return true, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue