go.etcd.io/etcd@v3.3.27+incompatible/pkg/tlsutil/cipher_suites_test.go (about)

     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  	"go/importer"
    19  	"reflect"
    20  	"strings"
    21  	"testing"
    22  )
    23  
    24  func TestGetCipherSuites(t *testing.T) {
    25  	pkg, err := importer.For("source", nil).Import("crypto/tls")
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	cm := make(map[string]uint16)
    30  	for _, s := range pkg.Scope().Names() {
    31  		if strings.HasPrefix(s, "TLS_RSA_") || strings.HasPrefix(s, "TLS_ECDHE_") {
    32  			v, ok := GetCipherSuite(s)
    33  			if !ok {
    34  				t.Fatalf("Go implements missing cipher suite %q (%v)", s, v)
    35  			}
    36  			cm[s] = v
    37  		}
    38  	}
    39  	if !reflect.DeepEqual(cm, cipherSuites) {
    40  		t.Fatalf("found unmatched cipher suites %v (Go) != %v", cm, cipherSuites)
    41  	}
    42  }