(t *testing.T)
| 542 | } |
| 543 | |
| 544 | func TestServer_AllowRequest(t *testing.T) { |
| 545 | t.Parallel() |
| 546 | |
| 547 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 548 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry()) |
| 549 | |
| 550 | err := srv.Start() |
| 551 | require.NoError(t, err) |
| 552 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 553 | |
| 554 | reporter := &fakeReporter{} |
| 555 | |
| 556 | ctx, cancel := context.WithCancel(context.Background()) |
| 557 | defer cancel() |
| 558 | forwarderDone := make(chan error, 1) |
| 559 | go func() { |
| 560 | forwarderDone <- srv.RunForwarder(ctx, reporter) |
| 561 | }() |
| 562 | |
| 563 | conn, err := net.Dial("unix", socketPath) |
| 564 | require.NoError(t, err) |
| 565 | defer conn.Close() |
| 566 | |
| 567 | // Send an allowed request with a matched rule. |
| 568 | logTime := timestamppb.Now() |
| 569 | req := &agentproto.ReportBoundaryLogsRequest{ |
| 570 | Logs: []*agentproto.BoundaryLog{ |
| 571 | { |
| 572 | Allowed: true, |
| 573 | Time: logTime, |
| 574 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 575 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 576 | Method: "GET", |
| 577 | Url: "https://malicious.com/attack", |
| 578 | MatchedRule: "*.malicious.com", |
| 579 | }, |
| 580 | }, |
| 581 | }, |
| 582 | }, |
| 583 | } |
| 584 | sendLogs(t, conn, req) |
| 585 | |
| 586 | require.Eventually(t, func() bool { |
| 587 | logs := reporter.getLogs() |
| 588 | return len(logs) == 1 |
| 589 | }, testutil.WaitShort, testutil.IntervalFast) |
| 590 | |
| 591 | logs := reporter.getLogs() |
| 592 | require.Len(t, logs, 1) |
| 593 | require.True(t, logs[0].Logs[0].Allowed) |
| 594 | require.Equal(t, logTime.Seconds, logs[0].Logs[0].Time.Seconds) |
| 595 | require.Equal(t, logTime.Nanos, logs[0].Logs[0].Time.Nanos) |
| 596 | require.Equal(t, "*.malicious.com", logs[0].Logs[0].GetHttpRequest().MatchedRule) |
| 597 | |
| 598 | cancel() |
| 599 | <-forwarderDone |
| 600 | } |
| 601 |
nothing calls this directly
no test coverage detected