From 214a37ac39f20266f13cac2d5ceda86bcc4ee514 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 8 Nov 2016 16:24:06 +0700 Subject: [PATCH] add tests for inchoate CHLO --- handshake/crypto_setup_client.go | 18 +++++++++++----- handshake/crypto_setup_client_test.go | 30 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/handshake/crypto_setup_client.go b/handshake/crypto_setup_client.go index e3a40940..c8569026 100644 --- a/handshake/crypto_setup_client.go +++ b/handshake/crypto_setup_client.go @@ -36,7 +36,10 @@ func NewCryptoSetupClient( } func (h *cryptoSetupClient) HandleCryptoStream() error { - h.sendInchoateCHLO() + err := h.sendInchoateCHLO() + if err != nil { + return err + } for { var chloData bytes.Buffer @@ -73,14 +76,19 @@ func (h *cryptoSetupClient) HandshakeComplete() bool { return false } -func (h *cryptoSetupClient) sendInchoateCHLO() error { - b := &bytes.Buffer{} - +func (h *cryptoSetupClient) getInchoateCHLOValues() map[Tag][]byte { tags := make(map[Tag][]byte) tags[TagSNI] = []byte("quic.clemente.io") // TODO: use real SNI here tags[TagPDMD] = []byte("X509") - tags[TagPAD] = bytes.Repeat([]byte("0"), 1000) + tags[TagPAD] = bytes.Repeat([]byte("0"), protocol.ClientHelloMinimumSize) + return tags +} + +func (h *cryptoSetupClient) sendInchoateCHLO() error { + b := &bytes.Buffer{} + + tags := h.getInchoateCHLOValues() WriteHandshakeMessage(b, TagCHLO, tags) _, err := h.cryptoStream.Write(b.Bytes()) diff --git a/handshake/crypto_setup_client_test.go b/handshake/crypto_setup_client_test.go index 895aa563..c00996f7 100644 --- a/handshake/crypto_setup_client_test.go +++ b/handshake/crypto_setup_client_test.go @@ -1 +1,31 @@ package handshake + +import ( + "github.com/lucas-clemente/quic-go/protocol" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Crypto setup", func() { + var cs cryptoSetupClient + + BeforeEach(func() { + cs = cryptoSetupClient{ + cryptoStream: &mockStream{}, + } + }) + + Context("Inchoate CHLO", func() { + It("has the right values", func() { + tags := cs.getInchoateCHLOValues() + Expect(tags).To(HaveKey(TagSNI)) + Expect(tags[TagPDMD]).To(Equal([]byte("X509"))) + }) + + It("is longer than the miminum client hello size", func() { + err := cs.sendInchoateCHLO() + Expect(err).ToNot(HaveOccurred()) + Expect(cs.cryptoStream.(*mockStream).dataWritten.Len()).To(BeNumerically(">", protocol.ClientHelloMinimumSize)) + }) + }) +})