(t *testing.T)
| 433 | } |
| 434 | |
| 435 | func TestServer_InvalidProtobuf(t *testing.T) { |
| 436 | t.Parallel() |
| 437 | |
| 438 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 439 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry()) |
| 440 | |
| 441 | err := srv.Start() |
| 442 | require.NoError(t, err) |
| 443 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 444 | |
| 445 | reporter := &fakeReporter{} |
| 446 | |
| 447 | ctx, cancel := context.WithCancel(context.Background()) |
| 448 | defer cancel() |
| 449 | forwarderDone := make(chan error, 1) |
| 450 | go func() { |
| 451 | forwarderDone <- srv.RunForwarder(ctx, reporter) |
| 452 | }() |
| 453 | |
| 454 | conn, err := net.Dial("unix", socketPath) |
| 455 | require.NoError(t, err) |
| 456 | defer conn.Close() |
| 457 | |
| 458 | // Send a valid header with garbage protobuf data. |
| 459 | // The server should log an unmarshal error but continue processing. |
| 460 | invalidProto := []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF} |
| 461 | //nolint: gosec // codec.DataLength is always less than the size of the header. |
| 462 | header := (uint32(codec.TagV1) << codec.DataLength) | uint32(len(invalidProto)) |
| 463 | err = binary.Write(conn, binary.BigEndian, header) |
| 464 | require.NoError(t, err) |
| 465 | _, err = conn.Write(invalidProto) |
| 466 | require.NoError(t, err) |
| 467 | |
| 468 | // Now send a valid message. The server should continue processing. |
| 469 | req := &agentproto.ReportBoundaryLogsRequest{ |
| 470 | Logs: []*agentproto.BoundaryLog{ |
| 471 | { |
| 472 | Allowed: true, |
| 473 | Time: timestamppb.Now(), |
| 474 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 475 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 476 | Method: "GET", |
| 477 | Url: "https://example.com/valid", |
| 478 | }, |
| 479 | }, |
| 480 | }, |
| 481 | }, |
| 482 | } |
| 483 | sendLogs(t, conn, req) |
| 484 | |
| 485 | require.Eventually(t, func() bool { |
| 486 | logs := reporter.getLogs() |
| 487 | return len(logs) == 1 |
| 488 | }, testutil.WaitShort, testutil.IntervalFast) |
| 489 | |
| 490 | cancel() |
| 491 | <-forwarderDone |
| 492 | } |
nothing calls this directly
no test coverage detected