@@ -3,12 +3,16 @@ package proxy
3
3
import (
4
4
"context"
5
5
"crypto/tls"
6
- "io"
6
+ "fmt"
7
+ "io/ioutil"
7
8
"log/slog"
8
9
"net/http"
10
+ "os"
9
11
"testing"
10
12
"time"
11
13
14
+ "github.com/stretchr/testify/require"
15
+
12
16
"github.com/coder/boundary/audit"
13
17
"github.com/coder/boundary/rules"
14
18
)
@@ -23,8 +27,8 @@ func (m *mockAuditor) AuditRequest(req audit.Request) {
23
27
// TestProxyServerBasicHTTP tests basic HTTP request handling
24
28
func TestProxyServerBasicHTTP (t * testing.T ) {
25
29
// 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
28
32
}))
29
33
30
34
// Create test rules (allow all for testing)
@@ -46,7 +50,7 @@ func TestProxyServerBasicHTTP(t *testing.T) {
46
50
47
51
// Create proxy server
48
52
server := NewProxyServer (Config {
49
- HTTPPort : 0 , // Use random port
53
+ HTTPPort : 8080 , // Use random port
50
54
RuleEngine : ruleEngine ,
51
55
Auditor : auditor ,
52
56
Logger : logger ,
@@ -79,22 +83,33 @@ func TestProxyServerBasicHTTP(t *testing.T) {
79
83
}
80
84
81
85
// 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 )
83
87
if err != nil {
84
88
t .Fatalf ("Failed to create request: %v" , err )
85
89
}
90
+ // Override the Host header to coder.com
91
+ req .Host = "coder.com"
92
+ //req.Header.Set("Host", "coder.com")
86
93
87
94
// Set Host header (important for URL parsing)
88
- req .Host = "localhost:8080"
95
+ // req.Host = "localhost:8080"
89
96
90
97
// Make the request
91
98
resp , err := client .Do (req )
92
99
if err != nil {
93
100
t .Logf ("Request failed (expected for proxy without target): %v" , err )
94
101
// This is expected since we're not forwarding to a real target
95
- } else {
96
- resp .Body .Close ()
97
102
}
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 ()
98
113
})
99
114
100
115
// Test CONNECT request
0 commit comments