Files
gvisor-tap-vsock/test-win-sshproxy/basic_test.go
Gunjan Vyas c60cf839d6 Fix all linting errors found by cross-lint
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2025-09-03 13:05:13 +05:30

92 lines
2.4 KiB
Go

//go:build windows
// +build windows
package e2e
import (
"context"
"io"
"net"
"net/http"
"os"
"os/exec"
"strings"
"time"
winio "github.com/Microsoft/go-winio"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var timeout = 1 * time.Minute
var _ = Describe("connectivity", func() {
It("proxy exits as requested, without a kill", func() {
err := startProxy()
Expect(err).ShouldNot(HaveOccurred())
var pid, tid uint32
for i := 0; i < 20; i++ {
pid, tid, err = readTid()
if err == nil && tid != 0 {
break
}
time.Sleep(100 * time.Millisecond)
}
Expect(tid).ShouldNot(Equal(0))
Expect(err).ShouldNot(HaveOccurred())
proc, err := os.FindProcess(int(pid))
Expect(err).ShouldNot(HaveOccurred())
Expect(proc).ShouldNot(BeNil())
err = stopProxy(true)
Expect(err).ShouldNot(HaveOccurred())
})
It("proxies over a windows pipe", func() {
err := startProxy()
Expect(err).ShouldNot(HaveOccurred())
defer func() {
Expect(stopProxy(false)).ShouldNot(HaveOccurred())
}()
httpClient := &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return winio.DialPipe(`\\.\pipe\fake_docker_engine`, &timeout)
},
},
}
Eventually(func(g Gomega) {
resp, err := httpClient.Get("http://host/ping")
g.Expect(err).ShouldNot(HaveOccurred())
defer resp.Body.Close()
g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
g.Expect(resp.ContentLength).To(Equal(int64(4)))
reply := make([]byte, resp.ContentLength)
_, err = io.ReadAtLeast(resp.Body, reply, len(reply))
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(string(reply)).To(Equal("pong"))
}).Should(Succeed())
})
It("windows event logs were created", func() {
cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
reader, err := cmd.StdoutPipe()
Expect(err).ShouldNot(HaveOccurred())
err = cmd.Start()
Expect(err).ShouldNot(HaveOccurred())
output, err := io.ReadAll(reader)
Expect(err).ShouldNot(HaveOccurred())
err = cmd.Wait()
Expect(err).ShouldNot(HaveOccurred())
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
})
})