Add proxy speed measurement, connection logs and standalone Android packaging
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMixedHTTPEntryUsesSelectedProxyAndCapturesConnections(t *testing.T) {
|
||||
upstream, count := socksEcho(t)
|
||||
defer upstream.Close()
|
||||
entry, port := reservePort(t)
|
||||
entry.Close()
|
||||
var engine Engine
|
||||
if err := engine.Start(context.Background(), Config{
|
||||
ListenPort: port, Feature: "proxy", Mode: "global",
|
||||
Proxy: map[string]any{"type": "socks", "server": "127.0.0.1", "server_port": upstream.Addr().(*net.TCPAddr).Port},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer engine.Close()
|
||||
conn, err := net.Dial("tcp", entry.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
conn.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
io.WriteString(conn, "CONNECT 198.51.100.8:443 HTTP/1.1\r\nHost: 198.51.100.8:443\r\n\r\n")
|
||||
reader := bufio.NewReader(conn)
|
||||
response, err := http.ReadResponse(reader, &http.Request{Method: "CONNECT"})
|
||||
if err != nil || response.StatusCode != 200 {
|
||||
t.Fatalf("CONNECT: %v %v", response, err)
|
||||
}
|
||||
io.WriteString(conn, "proxy-download")
|
||||
echoed := make([]byte, len("proxy-download"))
|
||||
if _, err = io.ReadFull(reader, echoed); err != nil || string(echoed) != "proxy-download" {
|
||||
t.Fatal("proxy tunnel failed", err)
|
||||
}
|
||||
if count.Load() != 1 {
|
||||
t.Fatal("download did not use selected outbound")
|
||||
}
|
||||
found := false
|
||||
for _, event := range engine.Snapshot().RuntimeEvents {
|
||||
if strings.Contains(event.Message, "198.51.100.8") {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("connection missing from runtime logs")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user