Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
askolesov committed Nov 3, 2024
1 parent a33eacb commit 79b32bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
9 changes: 2 additions & 7 deletions cmd/obfsproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@ func main() {
return fmt.Errorf("failed to create codec chain: %w", err)
}

// Create proxy with appropriate transformer
var proxy *pkg.Proxy
if isServer {
proxy = pkg.NewProxy(listenAddr, targetAddr, chain.NewDecoder())
} else {
proxy = pkg.NewProxy(listenAddr, targetAddr, chain.NewEncoder())
}
// Create proxy with codec
proxy := pkg.NewProxy(listenAddr, targetAddr, isServer, chain)

if err := proxy.Start(); err != nil {
fmt.Printf("Error: %v\n", err)
Expand Down
7 changes: 4 additions & 3 deletions integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ test:
sleep 3

# Run the tests
bash -c "set -o pipefail; go test -v ./integration_test.go | tee /dev/stderr"; test_exit_code=$$?
go test -v ./integration_test.go

# Stop the containers
docker compose down --volumes --remove-orphans

# Exit with the test exit code
exit $$test_exit_code
.PHONY: clean
clean:
docker compose down --volumes --remove-orphans
12 changes: 5 additions & 7 deletions integration/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
version: '3.8'

services:
obfuscating-proxy:
obfuscating-proxy: # server
build:
context: ./../
dockerfile: ./docker/Dockerfile
command: ["obfsproxy", "-l", "0.0.0.0:8080", "-t", "deobfuscating-proxy:8081"]
command: ["obfsproxy", "-l", "0.0.0.0:8080", "-t", "deobfuscating-proxy:8081", "-k", "test-key", "-r", "50", "-s"]
ports:
- "8080:8080"

deobfuscating-proxy:
deobfuscating-proxy: # client
build:
context: ./../
dockerfile: ./docker/Dockerfile
command: ["obfsproxy", "-l", "0.0.0.0:8081", "-t", "mock-server:80"]
command: ["obfsproxy", "-l", "0.0.0.0:8081", "-t", "mock-server:80", "-k", "test-key", "-r", "50", "-c"]
ports:
- "8081:8081"

mock-server:
mock-server: # target
image: nginx:alpine
volumes:
- ./mock-server.conf:/etc/nginx/conf.d/default.conf
Expand Down
25 changes: 16 additions & 9 deletions pkg/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ type Proxy struct {
ListenAddr string
TargetAddr string

Transformer codec.Transformer
IsServer bool
Codec codec.Codec
}

func NewProxy(listenAddr, targetAddr string, transformer codec.Transformer) *Proxy {
func NewProxy(listenAddr, targetAddr string, isServer bool, codec codec.Codec) *Proxy {
return &Proxy{
ListenAddr: listenAddr,
TargetAddr: targetAddr,
Transformer: transformer,
ListenAddr: listenAddr,
TargetAddr: targetAddr,
IsServer: isServer,
Codec: codec,
}
}

Expand Down Expand Up @@ -52,11 +54,16 @@ func (p *Proxy) handleConnection(clientConn net.Conn) {
}
defer targetConn.Close()

go p.proxy(clientConn, targetConn)
p.proxy(targetConn, clientConn)
if p.IsServer {
go p.proxy(clientConn, targetConn, p.Codec.NewDecoder())
p.proxy(targetConn, clientConn, p.Codec.NewEncoder())
} else {
go p.proxy(clientConn, targetConn, p.Codec.NewEncoder())
p.proxy(targetConn, clientConn, p.Codec.NewDecoder())
}
}

func (p *Proxy) proxy(dst, src net.Conn) {
func (p *Proxy) proxy(dst, src net.Conn, t codec.Transformer) {
buf := make([]byte, 1024)
for {
n, err := src.Read(buf)
Expand All @@ -69,7 +76,7 @@ func (p *Proxy) proxy(dst, src net.Conn) {

buf = buf[:n]

buf = p.Transformer(buf)
buf = t(buf)

_, err = dst.Write(buf)
if err != nil {
Expand Down

0 comments on commit 79b32bf

Please sign in to comment.