//go:build integration // +build integration package test import ( "context" "net/http" "testing" "time" "github.com/oauth2-proxy/mockoidc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/xlgmokha/x/pkg/env" ) func environmentVariables(srv *mockoidc.MockOIDC) map[string]string { config := srv.Config() return map[string]string{ "APP_ENV": "test", "BIND_ADDR": ":8080", "DEBUG": env.Fetch("DEBUG", ""), "HMAC_SESSION_SECRET": "secret", "OAUTH_CLIENT_ID": config.ClientID, "OAUTH_CLIENT_SECRET": config.ClientSecret, "OAUTH_REDIRECT_URL": "", "OIDC_ISSUER": srv.Issuer(), } } func TestContainer(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() srv := NewOIDCTestServer(t) defer srv.Shutdown() container := NewContainer(t, ctx, environmentVariables(srv)) defer testcontainers.TerminateContainer(container) require.True(t, container.IsRunning()) sparkleEndpoint, err := container.PortEndpoint(ctx, "8080", "http") require.NoError(t, err) envoyEndpoint, err := container.PortEndpoint(ctx, "10000", "http") require.NoError(t, err) envoyAdminEndpoint, err := container.PortEndpoint(ctx, "9901", "http") require.NoError(t, err) for _, publicPath := range []string{ envoyAdminEndpoint + "/", envoyEndpoint + "/", envoyEndpoint + "/application.js", envoyEndpoint + "/favicon.ico", envoyEndpoint + "/favicon.png", envoyEndpoint + "/health", envoyEndpoint + "/index.html", envoyEndpoint + "/logo.png", sparkleEndpoint + "/", sparkleEndpoint + "/favicon.ico", sparkleEndpoint + "/health", srv.DiscoveryEndpoint(), } { t.Run(publicPath, func(t *testing.T) { assert.Equal(t, http.StatusOK, HttpGet(t, ctx, publicPath).StatusCode) }) } t.Run("envoy.yaml", func(t *testing.T) { response := HttpGet(t, ctx, envoyAdminEndpoint+"/config_dump") require.Equal(t, http.StatusOK, response.StatusCode) body := JSONBody[map[string]interface{}](t, response) assert.NotEmpty(t, "listener_0", body["configs"]) }) }