Skip to content

Commit

Permalink
add e2e tests with connection IDs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mangum <[email protected]>
  • Loading branch information
hasheddan committed Jul 18, 2023
1 parent fce30ef commit 9a6591a
Showing 1 changed file with 98 additions and 48 deletions.
146 changes: 98 additions & 48 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,21 @@ func serverPion(c *comm) {
close(c.serverDone)
}

type dtlsConfOpts func(*dtls.Config)

func withConnectionIDGenerator(g func() []byte) dtlsConfOpts {
return func(c *dtls.Config) {
c.ConnectionIDGenerator = g
}
}

/*
Simple DTLS Client/Server can communicate
- Assert that you can send messages both ways
- Assert that Close() on both ends work
- Assert that no Goroutines are leaked
*/
func testPionE2ESimple(t *testing.T, server, client func(*comm)) {
func testPionE2ESimple(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand All @@ -282,10 +290,12 @@ func testPionE2ESimple(t *testing.T, server, client func(*comm)) {
}

cfg := &dtls.Config{
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
InsecureSkipVerify: true,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
InsecureSkipVerify: true,
}
for _, o := range opts {
o(cfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, cfg, cfg, serverPort, server, client)
Expand All @@ -295,7 +305,7 @@ func testPionE2ESimple(t *testing.T, server, client func(*comm)) {
}
}

func testPionE2ESimplePSK(t *testing.T, server, client func(*comm)) {
func testPionE2ESimplePSK(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand All @@ -318,9 +328,11 @@ func testPionE2ESimplePSK(t *testing.T, server, client func(*comm)) {
PSK: func(hint []byte) ([]byte, error) {
return []byte{0xAB, 0xC1, 0x23}, nil
},
PSKIdentityHint: []byte{0x01, 0x02, 0x03, 0x04, 0x05},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
PSKIdentityHint: []byte{0x01, 0x02, 0x03, 0x04, 0x05},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
}
for _, o := range opts {
o(cfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, cfg, cfg, serverPort, server, client)
Expand All @@ -330,7 +342,7 @@ func testPionE2ESimplePSK(t *testing.T, server, client func(*comm)) {
}
}

func testPionE2EMTUs(t *testing.T, server, client func(*comm)) {
func testPionE2EMTUs(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand All @@ -353,11 +365,13 @@ func testPionE2EMTUs(t *testing.T, server, client func(*comm)) {
}

cfg := &dtls.Config{
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
MTU: mtu,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
MTU: mtu,
}
for _, o := range opts {
o(cfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, cfg, cfg, serverPort, server, client)
Expand All @@ -367,7 +381,7 @@ func testPionE2EMTUs(t *testing.T, server, client func(*comm)) {
}
}

func testPionE2ESimpleED25519(t *testing.T, server, client func(*comm)) {
func testPionE2ESimpleED25519(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand Down Expand Up @@ -396,10 +410,12 @@ func testPionE2ESimpleED25519(t *testing.T, server, client func(*comm)) {
}

cfg := &dtls.Config{
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
InsecureSkipVerify: true,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{cert},
CipherSuites: []dtls.CipherSuiteID{cipherSuite},
InsecureSkipVerify: true,
}
for _, o := range opts {
o(cfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, cfg, cfg, serverPort, server, client)
Expand All @@ -409,7 +425,7 @@ func testPionE2ESimpleED25519(t *testing.T, server, client func(*comm)) {
}
}

func testPionE2ESimpleED25519ClientCert(t *testing.T, server, client func(*comm)) {
func testPionE2ESimpleED25519ClientCert(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand Down Expand Up @@ -438,24 +454,26 @@ func testPionE2ESimpleED25519ClientCert(t *testing.T, server, client func(*comm)
}

scfg := &dtls.Config{
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
}
ccfg := &dtls.Config{
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
}
for _, o := range opts {
o(scfg)
o(ccfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, ccfg, scfg, serverPort, server, client)
defer comm.cleanup(t)
comm.assert(t)
}

func testPionE2ESimpleECDSAClientCert(t *testing.T, server, client func(*comm)) {
func testPionE2ESimpleECDSAClientCert(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand Down Expand Up @@ -483,25 +501,27 @@ func testPionE2ESimpleECDSAClientCert(t *testing.T, server, client func(*comm))
clientCAs.AddCert(caCert)

scfg := &dtls.Config{
ClientCAs: clientCAs,
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
ClientCAs: clientCAs,
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
}
ccfg := &dtls.Config{
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
}
for _, o := range opts {
o(scfg)
o(ccfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, ccfg, scfg, serverPort, server, client)
defer comm.cleanup(t)
comm.assert(t)
}

func testPionE2ESimpleRSAClientCert(t *testing.T, server, client func(*comm)) {
func testPionE2ESimpleRSAClientCert(t *testing.T, server, client func(*comm), opts ...dtlsConfOpts) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand Down Expand Up @@ -530,16 +550,18 @@ func testPionE2ESimpleRSAClientCert(t *testing.T, server, client func(*comm)) {
}

scfg := &dtls.Config{
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{scert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
ClientAuth: dtls.RequireAnyClientCert,
}
ccfg := &dtls.Config{
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
ConnectionIDGenerator: dtls.RandomCIDGenerator(8),
Certificates: []tls.Certificate{ccert},
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
InsecureSkipVerify: true,
}
for _, o := range opts {
o(scfg)
o(ccfg)
}
serverPort := randomPort(t)
comm := newComm(ctx, ccfg, scfg, serverPort, server, client)
Expand Down Expand Up @@ -574,3 +596,31 @@ func TestPionE2ESimpleECDSAClientCert(t *testing.T) {
func TestPionE2ESimpleRSAClientCert(t *testing.T) {
testPionE2ESimpleRSAClientCert(t, serverPion, clientPion)
}

func TestPionE2ESimpleCID(t *testing.T) {
testPionE2ESimple(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimplePSKCID(t *testing.T) {
testPionE2ESimplePSK(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2EMTUsCID(t *testing.T) {
testPionE2EMTUs(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimpleED25519CID(t *testing.T) {
testPionE2ESimpleED25519(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimpleED25519ClientCertCID(t *testing.T) {
testPionE2ESimpleED25519ClientCert(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimpleECDSAClientCertCID(t *testing.T) {
testPionE2ESimpleECDSAClientCert(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

func TestPionE2ESimpleRSAClientCertCID(t *testing.T) {
testPionE2ESimpleRSAClientCert(t, serverPion, clientPion, withConnectionIDGenerator(dtls.RandomCIDGenerator(8)))
}

0 comments on commit 9a6591a

Please sign in to comment.