fix handshake tests

This commit is contained in:
Marten Seemann 2018-11-24 16:41:08 +07:00
parent b70779f12c
commit 09e1e2ad8c
1 changed files with 10 additions and 1 deletions

View File

@ -106,15 +106,18 @@ var _ = Describe("Transport", func() {
clientInsecureConn, serverInsecureConn := connect() clientInsecureConn, serverInsecureConn := connect()
done := make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
_, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn) _, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("tls: bad certificate")) Expect(err.Error()).To(ContainSubstring("tls: bad certificate"))
close(done)
}() }()
// dial, but expect the wrong peer ID // dial, but expect the wrong peer ID
_, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, thirdPartyID) _, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, thirdPartyID)
Expect(err).To(MatchError("peer IDs don't match")) Expect(err).To(MatchError("peer IDs don't match"))
Eventually(done).Should(BeClosed())
}) })
It("fails if the client presents an invalid cert chain", func() { It("fails if the client presents an invalid cert chain", func() {
@ -126,16 +129,19 @@ var _ = Describe("Transport", func() {
clientInsecureConn, serverInsecureConn := connect() clientInsecureConn, serverInsecureConn := connect()
done := make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
_, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn) _, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("crypto/rsa: verification error")) Expect(err.Error()).To(ContainSubstring("crypto/rsa: verification error"))
close(done)
}() }()
_, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID) _, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("tls: bad certificate")) Expect(err.Error()).To(ContainSubstring("tls: bad certificate"))
Eventually(done).Should(BeClosed())
}) })
It("fails if the server presents an invalid cert chain", func() { It("fails if the server presents an invalid cert chain", func() {
@ -147,15 +153,18 @@ var _ = Describe("Transport", func() {
clientInsecureConn, serverInsecureConn := connect() clientInsecureConn, serverInsecureConn := connect()
done := make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
_, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn) _, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("tls: bad certificate")) // TLS returns a weird error here: "remote error: tls: unexpected message"
close(done)
}() }()
_, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID) _, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("crypto/rsa: verification error")) Expect(err.Error()).To(ContainSubstring("crypto/rsa: verification error"))
Eventually(done).Should(BeClosed())
}) })
}) })