mint_utils_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package quic
  2. import (
  3. "crypto/tls"
  4. "crypto/x509"
  5. "errors"
  6. "github.com/lucas-clemente/quic-go/internal/protocol"
  7. "github.com/lucas-clemente/quic-go/internal/testdata"
  8. . "github.com/onsi/ginkgo"
  9. . "github.com/onsi/gomega"
  10. )
  11. var _ = Describe("Mint Utils", func() {
  12. Context("generating a mint.Config", func() {
  13. It("sets non-blocking mode", func() {
  14. mintConf, err := tlsToMintConfig(nil, protocol.PerspectiveClient)
  15. Expect(err).ToNot(HaveOccurred())
  16. Expect(mintConf.NonBlocking).To(BeTrue())
  17. })
  18. It("sets the certificate chain", func() {
  19. tlsConf := testdata.GetTLSConfig()
  20. mintConf, err := tlsToMintConfig(tlsConf, protocol.PerspectiveClient)
  21. Expect(err).ToNot(HaveOccurred())
  22. Expect(mintConf.Certificates).ToNot(BeEmpty())
  23. Expect(mintConf.Certificates).To(HaveLen(len(tlsConf.Certificates)))
  24. })
  25. It("copies values from the tls.Config", func() {
  26. verifyErr := errors.New("test err")
  27. certPool := &x509.CertPool{}
  28. tlsConf := &tls.Config{
  29. RootCAs: certPool,
  30. ServerName: "www.example.com",
  31. InsecureSkipVerify: true,
  32. VerifyPeerCertificate: func(_ [][]byte, _ [][]*x509.Certificate) error {
  33. return verifyErr
  34. },
  35. }
  36. mintConf, err := tlsToMintConfig(tlsConf, protocol.PerspectiveClient)
  37. Expect(err).ToNot(HaveOccurred())
  38. Expect(mintConf.RootCAs).To(Equal(certPool))
  39. Expect(mintConf.ServerName).To(Equal("www.example.com"))
  40. Expect(mintConf.InsecureSkipVerify).To(BeTrue())
  41. Expect(mintConf.VerifyPeerCertificate(nil, nil)).To(MatchError(verifyErr))
  42. })
  43. It("requires client authentication", func() {
  44. mintConf, err := tlsToMintConfig(nil, protocol.PerspectiveClient)
  45. Expect(err).ToNot(HaveOccurred())
  46. Expect(mintConf.RequireClientAuth).To(BeFalse())
  47. conf := &tls.Config{ClientAuth: tls.RequireAnyClientCert}
  48. mintConf, err = tlsToMintConfig(conf, protocol.PerspectiveClient)
  49. Expect(err).ToNot(HaveOccurred())
  50. Expect(mintConf.RequireClientAuth).To(BeTrue())
  51. })
  52. It("rejects unsupported client auth types", func() {
  53. conf := &tls.Config{ClientAuth: tls.RequireAndVerifyClientCert}
  54. _, err := tlsToMintConfig(conf, protocol.PerspectiveClient)
  55. Expect(err).To(MatchError("mint currently only support ClientAuthType RequireAnyClientCert"))
  56. })
  57. })
  58. })