From 5e1b1a088309b3475a86f632f216727374a008b2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 20 Nov 2022 16:31:24 +0900 Subject: [PATCH] integration: Add http3 affinity cookie test --- integration-tests/nghttpx_http3_test.go | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/integration-tests/nghttpx_http3_test.go b/integration-tests/nghttpx_http3_test.go index 87f28e05..9bac1652 100644 --- a/integration-tests/nghttpx_http3_test.go +++ b/integration-tests/nghttpx_http3_test.go @@ -7,6 +7,7 @@ import ( "crypto/rand" "io" "net/http" + "regexp" "testing" "golang.org/x/net/http2/hpack" @@ -216,3 +217,32 @@ func TestH3H1HTTPSRedirect(t *testing.T) { t.Errorf("status = %v; want %v", got, want) } } + +// TestH3H1AffinityCookieTLS tests that affinity cookie is sent back +// in https. +func TestH3H1AffinityCookieTLS(t *testing.T) { + opts := options{ + args: []string{"--affinity-cookie"}, + quic: true, + } + st := newServerTester(t, opts) + defer st.Close() + + res, err := st.http3(requestParam{ + name: "TestH3H1AffinityCookieTLS", + scheme: "https", + }) + if err != nil { + t.Fatalf("Error st.http3() = %v", err) + } + + if got, want := res.status, 200; got != want { + t.Errorf("status = %v; want %v", got, want) + } + + const pattern = `affinity=[0-9a-f]{8}; Path=/foo/bar; Secure` + validCookie := regexp.MustCompile(pattern) + if got := res.header.Get("Set-Cookie"); !validCookie.MatchString(got) { + t.Errorf("Set-Cookie: %v; want pattern %v", got, pattern) + } +}