TestBoundaryLogs_EndToEnd is an end-to-end test that sends a protobuf message over the agent's unix socket (as boundary would) and verifies it is ultimately logged by coderd with the correct structured fields.
(t *testing.T)
| 46 | // message over the agent's unix socket (as boundary would) and verifies |
| 47 | // it is ultimately logged by coderd with the correct structured fields. |
| 48 | func TestBoundaryLogs_EndToEnd(t *testing.T) { |
| 49 | t.Parallel() |
| 50 | |
| 51 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 52 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry()) |
| 53 | |
| 54 | err := srv.Start() |
| 55 | require.NoError(t, err) |
| 56 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 57 | |
| 58 | sink := testutil.NewFakeSink(t) |
| 59 | logger := sink.Logger(slog.LevelInfo) |
| 60 | workspaceID := uuid.New() |
| 61 | templateID := uuid.New() |
| 62 | templateVersionID := uuid.New() |
| 63 | reporter := &agentapi.BoundaryLogsAPI{ |
| 64 | Log: logger, |
| 65 | WorkspaceID: workspaceID, |
| 66 | TemplateID: templateID, |
| 67 | TemplateVersionID: templateVersionID, |
| 68 | } |
| 69 | |
| 70 | ctx, cancel := context.WithCancel(context.Background()) |
| 71 | defer cancel() |
| 72 | forwarderDone := make(chan error, 1) |
| 73 | go func() { |
| 74 | forwarderDone <- srv.RunForwarder(ctx, reporter) |
| 75 | }() |
| 76 | |
| 77 | conn, err := net.Dial("unix", socketPath) |
| 78 | require.NoError(t, err) |
| 79 | defer conn.Close() |
| 80 | |
| 81 | // Allowed HTTP request. |
| 82 | req := &agentproto.ReportBoundaryLogsRequest{ |
| 83 | Logs: []*agentproto.BoundaryLog{ |
| 84 | { |
| 85 | Allowed: true, |
| 86 | Time: timestamppb.Now(), |
| 87 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 88 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 89 | Method: "GET", |
| 90 | Url: "https://example.com/allowed", |
| 91 | MatchedRule: "*.example.com", |
| 92 | }, |
| 93 | }, |
| 94 | }, |
| 95 | }, |
| 96 | } |
| 97 | sendBoundaryLogsRequest(t, conn, req) |
| 98 | |
| 99 | require.Eventually(t, func() bool { |
| 100 | return len(sink.Entries()) >= 1 |
| 101 | }, testutil.WaitShort, testutil.IntervalFast) |
| 102 | |
| 103 | entries := sink.Entries() |
| 104 | require.Len(t, entries, 1) |
| 105 | entry := entries[0] |
nothing calls this directly
no test coverage detected