2017-01-23 18:48:35 +00:00
|
|
|
package tlsutil
|
|
|
|
|
2017-01-24 07:21:39 +00:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2017-01-23 18:48:35 +00:00
|
|
|
|
|
|
|
func TestParseCiphers(t *testing.T) {
|
2017-08-30 20:28:23 +00:00
|
|
|
testOk := "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305"
|
2017-01-24 07:21:39 +00:00
|
|
|
v, err := ParseCiphers(testOk)
|
|
|
|
if err != nil {
|
2017-01-23 18:48:35 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-08-30 20:28:23 +00:00
|
|
|
if len(v) != 17 {
|
2017-01-24 07:21:39 +00:00
|
|
|
t.Fatal("missed ciphers after parse")
|
|
|
|
}
|
|
|
|
|
2017-01-23 18:48:35 +00:00
|
|
|
testBad := "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,cipherX"
|
|
|
|
if _, err := ParseCiphers(testBad); err == nil {
|
2017-01-24 07:21:39 +00:00
|
|
|
t.Fatal("should fail on unsupported cipherX")
|
|
|
|
}
|
|
|
|
|
|
|
|
testOrder := "TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256"
|
|
|
|
v, _ = ParseCiphers(testOrder)
|
|
|
|
expected := []uint16{tls.TLS_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_RSA_WITH_AES_128_GCM_SHA256}
|
|
|
|
if !reflect.DeepEqual(expected, v) {
|
|
|
|
t.Fatal("cipher order is not preserved")
|
2017-01-23 18:48:35 +00:00
|
|
|
}
|
|
|
|
}
|