v3_cipher_suite_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // +build !cov,!cluster_proxy
  15. package e2e
  16. import (
  17. "fmt"
  18. "testing"
  19. "github.com/coreos/etcd/version"
  20. )
  21. func TestV3CurlCipherSuitesValid(t *testing.T) { testV3CurlCipherSuites(t, true) }
  22. func TestV3CurlCipherSuitesMismatch(t *testing.T) { testV3CurlCipherSuites(t, false) }
  23. func testV3CurlCipherSuites(t *testing.T, valid bool) {
  24. cc := configClientTLS
  25. cc.clusterSize = 1
  26. cc.cipherSuites = []string{
  27. "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
  28. "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  29. "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
  30. "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
  31. "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
  32. "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
  33. }
  34. testFunc := cipherSuiteTestValid
  35. if !valid {
  36. testFunc = cipherSuiteTestMismatch
  37. }
  38. testCtl(t, testFunc, withCfg(cc))
  39. }
  40. func cipherSuiteTestValid(cx ctlCtx) {
  41. if err := cURLGet(cx.epc, cURLReq{
  42. endpoint: "/metrics",
  43. expected: fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version),
  44. metricsURLScheme: cx.cfg.metricsURLScheme,
  45. ciphers: "ECDHE-RSA-AES128-GCM-SHA256", // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  46. }); err != nil {
  47. cx.t.Fatalf("failed get with curl (%v)", err)
  48. }
  49. }
  50. func cipherSuiteTestMismatch(cx ctlCtx) {
  51. if err := cURLGet(cx.epc, cURLReq{
  52. endpoint: "/metrics",
  53. expected: "alert handshake failure",
  54. metricsURLScheme: cx.cfg.metricsURLScheme,
  55. ciphers: "ECDHE-RSA-DES-CBC3-SHA", // TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  56. }); err != nil {
  57. cx.t.Fatalf("failed get with curl (%v)", err)
  58. }
  59. }