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

Function TestServer_InvalidHeader

agent/boundarylogproxy/proxy_test.go:494–542  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

492}
493
494func TestServer_InvalidHeader(t *testing.T) {
495 t.Parallel()
496
497 socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock")
498 srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry())
499
500 err := srv.Start()
501 require.NoError(t, err)
502 t.Cleanup(func() { require.NoError(t, srv.Close()) })
503
504 reporter := &fakeReporter{}
505
506 ctx, cancel := context.WithCancel(context.Background())
507 defer cancel()
508 forwarderDone := make(chan error, 1)
509 go func() {
510 forwarderDone <- srv.RunForwarder(ctx, reporter)
511 }()
512
513 // sendInvalidHeader sends a header and verifies the server closes the
514 // connection.
515 sendInvalidHeader := func(t *testing.T, name string, header uint32) {
516 t.Helper()
517
518 conn, err := net.Dial("unix", socketPath)
519 require.NoError(t, err)
520 defer conn.Close()
521
522 err = binary.Write(conn, binary.BigEndian, header)
523 require.NoError(t, err, name)
524
525 // The server closes the connection on invalid header, so the next
526 // write should fail with a broken pipe error.
527 require.Eventually(t, func() bool {
528 _, err := conn.Write([]byte{0x00})
529 return err != nil
530 }, testutil.WaitShort, testutil.IntervalFast, name)
531 }
532
533 // TagV1 with length exceeding MaxMessageSizeV1.
534 sendInvalidHeader(t, "v1 too large", (uint32(codec.TagV1)<<codec.DataLength)|(codec.MaxMessageSizeV1+1))
535
536 // Unknown tag.
537 const bogusTag = 0xFF
538 sendInvalidHeader(t, "unknown tag too large", (bogusTag<<codec.DataLength)|(codec.MaxMessageSizeV1+1))
539
540 cancel()
541 <-forwarderDone
542}
543
544func TestServer_AllowRequest(t *testing.T) {
545 t.Parallel()

Callers

nothing calls this directly

Calls 11

StartMethod · 0.95
CloseMethod · 0.95
RunForwarderMethod · 0.95
TempDirUnixSocketFunction · 0.92
NewServerFunction · 0.92
LoggerFunction · 0.92
CleanupMethod · 0.65
HelperMethod · 0.65
DialMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected