...

Source file src/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites_test.go

Documentation: go.etcd.io/etcd/client/pkg/v3/tlsutil

     1  // Copyright 2018 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package tlsutil
    16  
    17  import (
    18  	"crypto/tls"
    19  	"testing"
    20  )
    21  
    22  func TestGetCipherSuite_not_existing(t *testing.T) {
    23  	_, ok := GetCipherSuite("not_existing")
    24  	if ok {
    25  		t.Fatal("Expected not ok")
    26  	}
    27  }
    28  
    29  func CipherSuiteExpectedToExist(tb testing.TB, cipher string, expectedId uint16) {
    30  	vid, ok := GetCipherSuite(cipher)
    31  	if !ok {
    32  		tb.Errorf("Expected %v cipher to exist", cipher)
    33  	}
    34  	if vid != expectedId {
    35  		tb.Errorf("For %v expected=%v found=%v", cipher, expectedId, vid)
    36  	}
    37  }
    38  
    39  func TestGetCipherSuite_success(t *testing.T) {
    40  	CipherSuiteExpectedToExist(t, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
    41  	CipherSuiteExpectedToExist(t, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
    42  
    43  	// Explicit test for legacy names
    44  	CipherSuiteExpectedToExist(t, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256)
    45  	CipherSuiteExpectedToExist(t, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256)
    46  }
    47  
    48  func TestGetCipherSuite_insecure(t *testing.T) {
    49  	CipherSuiteExpectedToExist(t, "TLS_ECDHE_RSA_WITH_RC4_128_SHA", tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA)
    50  }
    51  

View as plain text