Skip to content

Commit

Permalink
Always use mitmproxy in tests FOR CLIENTS
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 30, 2023
1 parent 1ff4255 commit 2cd3642
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions internal/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"os/exec"
"sync"
"testing"
"time"

Expand All @@ -24,6 +25,8 @@ type SlidingSyncDeployment struct {
slidingSync testcontainers.Container
reverseProxy testcontainers.Container
slidingSyncURL string
proxyURLToHS map[string]string
mu sync.RWMutex
tcpdump *exec.Cmd
}

Expand All @@ -36,6 +39,12 @@ func (d *SlidingSyncDeployment) SlidingSyncURL(t *testing.T) string {
return d.slidingSyncURL
}

func (d *SlidingSyncDeployment) ReverseProxyURLForHS(hsName string) string {
d.mu.RLock()
defer d.mu.RUnlock()
return d.proxyURLToHS[hsName]
}

func (d *SlidingSyncDeployment) Teardown(writeLogs bool) {
if d.slidingSync != nil {
if writeLogs {
Expand All @@ -54,6 +63,12 @@ func (d *SlidingSyncDeployment) Teardown(writeLogs bool) {
}
}
if d.reverseProxy != nil {
if writeLogs {
err := writeContainerLogs(d.reverseProxy, "container-mitmproxy.log")
if err != nil {
log.Printf("failed to write sliding sync logs: %s", err)
}
}
if err := d.reverseProxy.Terminate(context.Background()); err != nil {
log.Fatalf("failed to stop reverse proxy: %s", err)
}
Expand Down Expand Up @@ -176,6 +191,10 @@ func RunNewDeployment(t *testing.T, shouldTCPDump bool) *SlidingSyncDeployment {
reverseProxy: mitmproxyContainer,
slidingSyncURL: ssURL,
tcpdump: cmd,
proxyURLToHS: map[string]string{
"hs1": rpHS1URL,
"hs2": rpHS2URL,
},
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,7 @@ func (c *TestContext) MustLoginDevice(t *testing.T, existing *client.CSAPI, clie

func (c *TestContext) MustLoginClient(t *testing.T, cli *client.CSAPI, clientType api.ClientType) api.Client {
t.Helper()
return MustLoginClient(t, clientType, api.FromComplementClient(cli, "complement-crypto-password"), c.Deployment.SlidingSyncURL(t))
cfg := api.FromComplementClient(cli, "complement-crypto-password")
cfg.BaseURL = c.Deployment.ReverseProxyURLForHS(clientType.HS)
return MustLoginClient(t, clientType, cfg, c.Deployment.SlidingSyncURL(t))
}

0 comments on commit 2cd3642

Please sign in to comment.