1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
//go:build integration
// +build integration
package test
import (
"context"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/xlgmokha/x/pkg/env"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web"
)
func environmentVariables(srv *web.OIDCServer) map[string]string {
return map[string]string{
"APP_ENV": "test",
"DEBUG": env.Fetch("DEBUG", ""),
"HMAC_SESSION_SECRET": "secret",
"OAUTH_CLIENT_ID": srv.MockOIDC.ClientID,
"OAUTH_CLIENT_SECRET": srv.MockOIDC.ClientSecret,
"OIDC_ISSUER": srv.Issuer(),
}
}
func TestContainer(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
srv := web.NewOIDCServer(t)
defer srv.Close()
container := NewContainer(t, ctx, environmentVariables(srv))
defer testcontainers.TerminateContainer(container)
require.True(t, container.IsRunning())
envoyEndpoint, err := container.PortEndpoint(ctx, "10000", "http")
require.NoError(t, err)
for _, publicPath := range []string{
envoyEndpoint + "/",
envoyEndpoint + "/application.js",
envoyEndpoint + "/favicon.ico",
envoyEndpoint + "/favicon.png",
envoyEndpoint + "/health",
envoyEndpoint + "/index.html",
envoyEndpoint + "/logo.png",
srv.DiscoveryEndpoint(),
} {
t.Run(publicPath, func(t *testing.T) {
assert.Equal(t, http.StatusOK, HttpGet(t, ctx, publicPath).StatusCode)
})
}
}
|