MCPcopy Index your code
hub / github.com/coder/coder / BenchmarkHTTPCookieConfigMiddleware

Function BenchmarkHTTPCookieConfigMiddleware

codersdk/deployment_test.go:1514–1589  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1512}
1513
1514func BenchmarkHTTPCookieConfigMiddleware(b *testing.B) {
1515 noop := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
1516
1517 // Realistic cookies that are always present in production.
1518 baseCookies := []*http.Cookie{
1519 {Name: "_ga", Value: "GA1.1.661026807.1770083336"},
1520 {Name: "_ga_G0Q1B9GRC0", Value: "GS2.1.s1771343727$o49$g1$t1771343993$j48$l0$h0"},
1521 {Name: "csrf_token", Value: "gDiKk8GjTM2iCUHAPfN9GlC+DGjzAprlLi2vJ+5TBU0="},
1522 }
1523
1524 cases := []struct {
1525 name string
1526 cfg codersdk.HTTPCookieConfig
1527 extraCookies []*http.Cookie
1528 }{
1529 {
1530 name: "Disabled",
1531 cfg: codersdk.HTTPCookieConfig{},
1532 extraCookies: []*http.Cookie{
1533 {Name: codersdk.SessionTokenCookie, Value: "KybJV9fNul-u11vlll9wiF6eLQDxBVucD"},
1534 },
1535 },
1536 {
1537 name: "Enabled_NoPrefixedCookies",
1538 cfg: codersdk.HTTPCookieConfig{EnableHostPrefix: true},
1539 extraCookies: []*http.Cookie{
1540 {Name: codersdk.SessionTokenCookie, Value: "KybJV9fNul-u11vlll9wiF6eLQDxBVucD"},
1541 },
1542 },
1543 {
1544 name: "Enabled_WithPrefixedCookie",
1545 cfg: codersdk.HTTPCookieConfig{EnableHostPrefix: true},
1546 extraCookies: []*http.Cookie{
1547 {Name: "__Host-" + codersdk.SessionTokenCookie, Value: "KybJV9fNul-u11vlll9wiF6eLQDxBVucD"},
1548 },
1549 },
1550 {
1551 name: "Enabled_MultiplePrefixedCookies",
1552 cfg: codersdk.HTTPCookieConfig{EnableHostPrefix: true},
1553 extraCookies: []*http.Cookie{
1554 {Name: "__Host-" + codersdk.SessionTokenCookie, Value: "KybJV9fNul-u11vlll9wiF6eLQDxBVucD"},
1555 {Name: "__Host-" + codersdk.PathAppSessionTokenCookie, Value: "xyz123"},
1556 {Name: "__Host-" + codersdk.SubdomainAppSessionTokenCookie, Value: "abc456"},
1557 {Name: "__Host-" + "foobar", Value: "do-not-change-me"},
1558 },
1559 },
1560 {
1561 name: "Enabled_NonSessionPrefixedCookies",
1562 cfg: codersdk.HTTPCookieConfig{EnableHostPrefix: true},
1563 extraCookies: []*http.Cookie{
1564 {Name: "__Host-" + codersdk.SessionTokenCookie, Value: "KybJV9fNul-u11vlll9wiF6eLQDxBVucD"},
1565 },
1566 },
1567 }
1568
1569 for _, tc := range cases {
1570 b.Run(tc.name, func(b *testing.B) {
1571 handler := tc.cfg.Middleware(noop)

Callers

nothing calls this directly

Calls 3

MiddlewareMethod · 0.80
RunMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected