Skip to content

Commit

Permalink
e2e: make FlagProxyLocalhost test all allow and deny values
Browse files Browse the repository at this point in the history
It would be interesting to add direct mode test.
We are missing the possibility to assert that the request had a certain route to be added in #317.
  • Loading branch information
mmatczuk committed Jul 31, 2023
1 parent fe89686 commit 7024b2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 14 additions & 10 deletions e2e/setups.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func AllSetups() []setup.Setup {
ss = append(ss, DefaultsSetups()...)
ss = append(ss, AuthSetups()...)
ss = append(ss, PacSetups()...)

ss = append(ss, FlagProxyLocalhost()...)
ss = append(ss,
FlagProxyLocalhostAllowSetup(),
FlagHeaderSetup(),
FlagResponseHeaderSetup(),

Expand Down Expand Up @@ -146,16 +147,19 @@ func PacSetups() []setup.Setup {
}
}

func FlagProxyLocalhostAllowSetup() setup.Setup {
return setup.Setup{
Name: "flag-proxy-localhost",
Compose: compose.NewBuilder().
AddService(
forwarder.ProxyService().
WithLocalhostMode("allow")).
MustBuild(),
Run: "^TestFlagProxyLocalhost",
func FlagProxyLocalhost() (ss []setup.Setup) {
for _, mode := range []string{"deny", "allow"} {
ss = append(ss, setup.Setup{
Name: "flag-proxy-localhost-" + mode,
Compose: compose.NewBuilder().
AddService(
forwarder.ProxyService().
WithLocalhostMode(mode)).
MustBuild(),
Run: "^TestFlagProxyLocalhost/" + mode + "$",
})
}
return
}

func FlagHeaderSetup() setup.Setup {
Expand Down
24 changes: 10 additions & 14 deletions e2e/tests/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package tests
import (
"net"
"net/http"
"os"
"testing"
)

Expand All @@ -21,19 +20,16 @@ func TestFlagProxyLocalhost(t *testing.T) {
"127.0.0.1",
}

if os.Getenv("FORWARDER_PROXY_LOCALHOST") == "allow" {
t.Run("allow", func(t *testing.T) {
for _, h := range hosts {
newClient(t, "http://"+net.JoinHostPort(h, "10000")).GET("/version").ExpectStatus(http.StatusOK)
}
})
} else {
t.Run("deny", func(t *testing.T) {
for _, h := range hosts {
newClient(t, "http://"+net.JoinHostPort(h, "10000")).GET("/version").ExpectStatus(http.StatusBadGateway)
}
})
}
t.Run("allow", func(t *testing.T) {
for _, h := range hosts {
newClient(t, "http://"+net.JoinHostPort(h, "10000")).GET("/version").ExpectStatus(http.StatusOK)
}
})
t.Run("deny", func(t *testing.T) {
for _, h := range hosts {
newClient(t, "http://"+net.JoinHostPort(h, "10000")).GET("/version").ExpectStatus(http.StatusBadGateway)
}
})
}

func TestFlagHeader(t *testing.T) {
Expand Down

0 comments on commit 7024b2c

Please sign in to comment.