(t *testing.T)
| 118 | } |
| 119 | |
| 120 | func TestServer_ReceiveAndForwardLogs(t *testing.T) { |
| 121 | t.Parallel() |
| 122 | |
| 123 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 124 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry()) |
| 125 | |
| 126 | ctx, cancel := context.WithCancel(context.Background()) |
| 127 | defer cancel() |
| 128 | |
| 129 | err := srv.Start() |
| 130 | require.NoError(t, err) |
| 131 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 132 | |
| 133 | reporter := &fakeReporter{} |
| 134 | |
| 135 | // Start forwarder in background. |
| 136 | forwarderDone := make(chan error, 1) |
| 137 | go func() { |
| 138 | forwarderDone <- srv.RunForwarder(ctx, reporter) |
| 139 | }() |
| 140 | |
| 141 | // Connect and send a log message. |
| 142 | conn, err := net.Dial("unix", socketPath) |
| 143 | require.NoError(t, err) |
| 144 | defer conn.Close() |
| 145 | |
| 146 | req := &agentproto.ReportBoundaryLogsRequest{ |
| 147 | Logs: []*agentproto.BoundaryLog{ |
| 148 | { |
| 149 | Allowed: true, |
| 150 | Time: timestamppb.Now(), |
| 151 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 152 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 153 | Method: "GET", |
| 154 | Url: "https://example.com", |
| 155 | }, |
| 156 | }, |
| 157 | }, |
| 158 | }, |
| 159 | } |
| 160 | |
| 161 | sendLogs(t, conn, req) |
| 162 | |
| 163 | // Wait for the reporter to receive the log. |
| 164 | require.Eventually(t, func() bool { |
| 165 | logs := reporter.getLogs() |
| 166 | return len(logs) == 1 |
| 167 | }, testutil.WaitShort, testutil.IntervalFast) |
| 168 | |
| 169 | logs := reporter.getLogs() |
| 170 | require.Len(t, logs, 1) |
| 171 | require.Len(t, logs[0].Logs, 1) |
| 172 | require.True(t, logs[0].Logs[0].Allowed) |
| 173 | require.Equal(t, "GET", logs[0].Logs[0].GetHttpRequest().Method) |
| 174 | require.Equal(t, "https://example.com", logs[0].Logs[0].GetHttpRequest().Url) |
| 175 | |
| 176 | cancel() |
| 177 | <-forwarderDone |
nothing calls this directly
no test coverage detected