Skip to content

Commit

Permalink
add an integration test for custom connection ID generators
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored and joliveirinha committed Aug 23, 2022
1 parent 0bc50d9 commit 2816a49
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions integrationtests/self/conn_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package self_test

import (
"context"
"crypto/rand"
"fmt"
"io"
"math/rand"
mrand "math/rand"
"net"

"github.com/lucas-clemente/quic-go"
Expand All @@ -14,9 +15,26 @@ import (
. "github.com/onsi/gomega"
)

type connIDGenerator struct {
length int
}

func (c *connIDGenerator) GenerateConnectionID() ([]byte, error) {
b := make([]byte, c.length)
_, err := rand.Read(b)
if err != nil {
fmt.Fprintf(GinkgoWriter, "generating conn ID failed: %s", err)
}
return b, nil
}

func (c *connIDGenerator) ConnectionIDLen() int {
return c.length
}

var _ = Describe("Connection ID lengths tests", func() {
randomConnIDLen := func() int {
return 4 + int(rand.Int31n(15))
return 4 + int(mrand.Int31n(15))
}

runServer := func(conf *quic.Config) quic.Listener {
Expand Down Expand Up @@ -87,4 +105,19 @@ var _ = Describe("Connection ID lengths tests", func() {
defer ln.Close()
runClient(ln.Addr(), clientConf)
})

It("downloads a file when both client and server use a custom connection ID generator", func() {
serverConf := getQuicConfig(&quic.Config{
Versions: []protocol.VersionNumber{protocol.VersionTLS},
ConnectionIDGenerator: &connIDGenerator{length: randomConnIDLen()},
})
clientConf := getQuicConfig(&quic.Config{
Versions: []protocol.VersionNumber{protocol.VersionTLS},
ConnectionIDGenerator: &connIDGenerator{length: randomConnIDLen()},
})

ln := runServer(serverConf)
defer ln.Close()
runClient(ln.Addr(), clientConf)
})
})

0 comments on commit 2816a49

Please sign in to comment.