Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci #75

Merged
merged 11 commits into from
Jun 12, 2023
Prev Previous commit
Next Next commit
fix: ssh unit tests
  • Loading branch information
shoriwe committed Jun 12, 2023
commit 380283a8b200e89e0ad499904938b64fa67fb018
47 changes: 19 additions & 28 deletions proxies/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxies
import (
"net/http"
"testing"
"time"

"github.com/gavv/httpexpect/v2"
"github.com/shoriwe/fullproxy/v4/reverse"
Expand All @@ -14,7 +13,9 @@ import (

func TestSSH_Addr(t *testing.T) {
listener := network.ListenAny()
defer listener.Close()
client := sshd.DefaultClient(t)
defer client.Close()
go sshd.KeepAlive(client)
s := &Forward{
Listener: listener,
Expand All @@ -26,7 +27,9 @@ func TestSSH_Addr(t *testing.T) {
func TestSSH_Serve(t *testing.T) {
t.Run("Trigger KeepAlive", func(tt *testing.T) {
listener := network.ListenAny()
defer listener.Close()
client := sshd.DefaultClient(tt)
defer client.Close()
go sshd.KeepAlive(client)
s := &Forward{
Network: "tcp",
Expand All @@ -39,52 +42,42 @@ func TestSSH_Serve(t *testing.T) {
expect := httpexpect.Default(tt, "http://"+listener.Addr().String())
expect.GET("/").Expect().Status(http.StatusOK).Body().Contains("ECHO")
})
t.Run("Error KeepAlive", func(tt *testing.T) {
listener := network.ListenAny()
client := sshd.DefaultClient(tt)
go sshd.KeepAlive(client)
s := &Forward{
Network: "tcp",
Address: "echo:80",
Listener: listener,
Dial: client.Dial,
}
go s.Serve()
time.Sleep(2 * time.Second)
s.Close()
time.Sleep(2 * time.Second)
})
}

func TestSSH_Serve_Local(t *testing.T) {
t.Run("Basic", func(tt *testing.T) {
listener := network.ListenAny()
client := sshd.DefaultClient(tt)
go sshd.KeepAlive(client)
sshClient := sshd.DefaultClient(tt)
go sshd.KeepAlive(sshClient)
s := &Forward{
Network: "tcp",
Address: "echo:80",
Listener: listener,
Dial: client.Dial,
Dial: sshClient.Dial,
}
defer s.Close()
go s.Serve()
expect := httpexpect.Default(tt, "http://"+listener.Addr().String())
expect.GET("/").Expect().Status(http.StatusOK).Body().Contains("ECHO")
})
t.Run("Reverse", func(tt *testing.T) {
// Master
data := network.ListenAny()
defer data.Close()
control := network.ListenAny()
defer control.Close()
master := network.Dial(control.Addr().String())
defer master.Close()
listener := network.ListenAny()
defer listener.Close()
// Slave
masterConn := network.Dial(control.Addr().String())
defer masterConn.Close()
slaveListener := network.ListenAny()
defer slaveListener.Close()
// SSH Conn
sshClient := sshd.DefaultClient(tt)
go sshd.KeepAlive(sshClient)
// Slave
slave := &reverse.Slave{
Listener: listener,
Master: master,
Listener: slaveListener,
Master: masterConn,
}
defer slave.Close()
go slave.Serve()
Expand All @@ -95,13 +88,11 @@ func TestSSH_Serve_Local(t *testing.T) {
}
defer m.Close()
//
client := sshd.DefaultClient(tt)
go sshd.KeepAlive(client)
s := &Forward{
Network: "tcp",
Address: "echo:80",
Listener: m,
Dial: client.Dial,
Dial: sshClient.Dial,
}
defer s.Close()
go s.Serve()
Expand Down