v3_cipher_suite_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. "go.etcd.io/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. var err error
  52. for _, exp := range []string{"alert handshake failure", "failed setting cipher list"} {
  53. err = cURLGet(cx.epc, cURLReq{
  54. endpoint: "/metrics",
  55. expected: exp,
  56. metricsURLScheme: cx.cfg.metricsURLScheme,
  57. ciphers: "ECDHE-RSA-DES-CBC3-SHA", // TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  58. })
  59. if err == nil {
  60. break
  61. }
  62. }
  63. if err != nil {
  64. cx.t.Fatalf("failed get with curl (%v)", err)
  65. }
  66. }