Skip to content

Commit cd560a6

Browse files
works
1 parent 5301fb3 commit cd560a6

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ module github.com/coder/boundary
22

33
go 1.24
44

5-
require github.com/coder/serpent v0.10.0
5+
require (
6+
github.com/coder/serpent v0.10.0
7+
github.com/stretchr/testify v1.8.4
8+
)
69

710
require (
811
cdr.dev/slog v1.6.2-0.20240126064726-20367d4aede6 // indirect
912
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1013
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 // indirect
14+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1115
github.com/hashicorp/errwrap v1.1.0 // indirect
1216
github.com/hashicorp/go-multierror v1.1.1 // indirect
1317
github.com/kr/text v0.2.0 // indirect
@@ -18,6 +22,7 @@ require (
1822
github.com/muesli/termenv v0.15.2 // indirect
1923
github.com/pion/transport/v2 v2.0.0 // indirect
2024
github.com/pion/udp v0.1.4 // indirect
25+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2126
github.com/rivo/uniseg v0.4.4 // indirect
2227
github.com/spf13/pflag v1.0.5 // indirect
2328
go.opentelemetry.io/otel v1.19.0 // indirect

proxy/proxy_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ package proxy
33
import (
44
"context"
55
"crypto/tls"
6-
"io"
6+
"fmt"
7+
"io/ioutil"
78
"log/slog"
89
"net/http"
10+
"os"
911
"testing"
1012
"time"
1113

14+
"github.com/stretchr/testify/require"
15+
1216
"github.com/coder/boundary/audit"
1317
"github.com/coder/boundary/rules"
1418
)
@@ -23,8 +27,8 @@ func (m *mockAuditor) AuditRequest(req audit.Request) {
2327
// TestProxyServerBasicHTTP tests basic HTTP request handling
2428
func TestProxyServerBasicHTTP(t *testing.T) {
2529
// Create test logger
26-
logger := slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{
27-
Level: slog.LevelError, // Reduce noise during testing
30+
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
31+
Level: slog.LevelDebug, // Reduce noise during testing
2832
}))
2933

3034
// Create test rules (allow all for testing)
@@ -46,7 +50,7 @@ func TestProxyServerBasicHTTP(t *testing.T) {
4650

4751
// Create proxy server
4852
server := NewProxyServer(Config{
49-
HTTPPort: 0, // Use random port
53+
HTTPPort: 8080, // Use random port
5054
RuleEngine: ruleEngine,
5155
Auditor: auditor,
5256
Logger: logger,
@@ -79,22 +83,33 @@ func TestProxyServerBasicHTTP(t *testing.T) {
7983
}
8084

8185
// Make request to proxy
82-
req, err := http.NewRequest("GET", "http://localhost:8080/test", nil)
86+
req, err := http.NewRequest("GET", "http://localhost:8080", nil)
8387
if err != nil {
8488
t.Fatalf("Failed to create request: %v", err)
8589
}
90+
// Override the Host header to coder.com
91+
req.Host = "coder.com"
92+
//req.Header.Set("Host", "coder.com")
8693

8794
// Set Host header (important for URL parsing)
88-
req.Host = "localhost:8080"
95+
//req.Host = "localhost:8080"
8996

9097
// Make the request
9198
resp, err := client.Do(req)
9299
if err != nil {
93100
t.Logf("Request failed (expected for proxy without target): %v", err)
94101
// This is expected since we're not forwarding to a real target
95-
} else {
96-
resp.Body.Close()
97102
}
103+
//else {
104+
// resp.Body.Close()
105+
//}
106+
fmt.Printf("err: %v\n", err)
107+
108+
body, err := ioutil.ReadAll(resp.Body)
109+
require.NoError(t, err)
110+
fmt.Printf("body: %s\n", body)
111+
112+
resp.Body.Close()
98113
})
99114

100115
// Test CONNECT request

0 commit comments

Comments
 (0)