test: Add a test to check an already exposed port cannot be exposed again

This also fixes a pre-existing issue with this test file, an exposed
port was not unexposed before attempting to expose it again, which
caused a test failure after the PortsForwarder.Expose() fix.

Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
This commit is contained in:
Gunjan Vyas
2025-01-10 16:15:47 +05:30
committed by Christophe Fergeau
parent 382696f48d
commit 233ecd891f

View File

@@ -226,6 +226,17 @@ var _ = ginkgo.Describe("port forwarding", func() {
g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK)) g.Expect(resp.StatusCode).To(gomega.Equal(http.StatusOK))
}).Should(gomega.Succeed()) }).Should(gomega.Succeed())
gomega.Eventually(func(g gomega.Gomega) {
// exposing the port again should return an error
out, _ = sshExec(`curl http://gateway.containers.internal/services/forwarder/expose -X POST -d'{"protocol":"unix","local":"` + unix2tcpfwdsock + `","remote":"tcp://192.168.127.2:8080"}'`)
g.Expect(string(out)).Should(gomega.ContainSubstring("proxy already running"))
// unexpose the port
out, err = sshExec(`curl http://gateway.containers.internal/services/forwarder/unexpose -X POST -d'{"protocol":"unix","local":"` + unix2tcpfwdsock + `","remote":"tcp://192.168.127.2:8080"}'`)
g.Expect(err).ShouldNot(gomega.HaveOccurred())
g.Expect(string(out)).Should(gomega.Equal(""))
}).Should(gomega.Succeed())
}) })
ginkgo.It("should expose and reach rootless podman API using unix to unix forwarding over ssh", func() { ginkgo.It("should expose and reach rootless podman API using unix to unix forwarding over ssh", func() {