Skip to content

Commit 7fa8dbb

Browse files
authored
Merge pull request #329 from SUNET/masv/test/integration
Masv/test/integration
2 parents 08da876 + 0ecf566 commit 7fa8dbb

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

developer_tools/scripts/create_pki.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ mkdir -p "${PKI_DIR}"
1212
# Service TLS certificates
1313
service_names="apigw verifier ui registry issuer mockas vc"
1414

15+
# Docker bridge IPs for IP SAN entries (from docker-compose.yaml vc-dev-net)
16+
service_ip() {
17+
case "$1" in
18+
apigw) echo "172.16.50.2" ;;
19+
verifier) echo "172.16.50.6" ;;
20+
ui) echo "172.16.50.50" ;;
21+
registry) echo "172.16.50.8" ;;
22+
issuer) echo "172.16.50.4" ;;
23+
mockas) echo "172.16.50.13" ;;
24+
*) echo "" ;;
25+
esac
26+
}
27+
1528
# Generate CA key and cert
1629
cat > ca.conf <<EOF
1730
[req]
@@ -65,6 +78,7 @@ EOF
6578
fi
6679

6780
if [ ! -f ${service_name}.ext ]; then
81+
ip=$(service_ip "${service_name}")
6882
cat > ${service_name}.ext <<EOF
6983
# v3.ext
7084
authorityKeyIdentifier=keyid,issuer
@@ -75,6 +89,9 @@ subjectAltName = @alt_names
7589
[alt_names]
7690
DNS.1 = ${service_name}.vc.docker
7791
EOF
92+
if [ -n "$ip" ]; then
93+
echo "IP.1 = ${ip}" >> ${service_name}.ext
94+
fi
7895
ext_generated=1
7996
fi
8097

internal/apigw/httpserver/service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func New(ctx context.Context, cfg *model.Cfg, apiv1 *apiv1.Client, tracer *trace
6868

6969
if s.cfg.APIGW.APIServer.TLS.Enable {
7070
s.sessionsOptions.Secure = true
71-
//s.sessionsOptions.SameSite = http.SameSiteStrictMode
7271
}
7372

7473
// Session keys resolved by the cache service (HA-shared or ephemeral).

internal/verifier/httpserver/service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func New(ctx context.Context, cfg *model.Cfg, apiv1 *apiv1.Client, notify *notif
7171

7272
if s.cfg.Verifier.APIServer.TLS.Enable {
7373
s.sessionsOptions.Secure = true
74-
//s.sessionsOptions.SameSite = http.SameSiteStrictMode
7574
}
7675

7776
// Session keys resolved by the cache service (HA-shared or ephemeral).

internal/wallet/integration/stack_test.go

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/elliptic"
2121
"crypto/rand"
2222
"crypto/sha256"
23+
"crypto/x509"
2324
"encoding/base64"
2425
"encoding/json"
2526
"fmt"
@@ -47,17 +48,21 @@ import (
4748

4849
// Stack service addresses (Docker bridge IPs on vc-dev-net)
4950
var (
50-
apigwURL = envOrDefault("STACK_APIGW_URL", "http://172.16.50.2:8080") // NOSONAR
51-
verifierURL = envOrDefault("STACK_VERIFIER_URL", "http://172.16.50.6:8080") // NOSONAR
52-
mockasURL = envOrDefault("STACK_MOCKAS_URL", "http://172.16.50.13:8080") // NOSONAR
51+
apigwURL = envOrDefault("STACK_APIGW_URL", "https://172.16.50.2:8080") // NOSONAR
52+
verifierURL = envOrDefault("STACK_VERIFIER_URL", "https://172.16.50.6:8080") // NOSONAR
53+
mockasURL = envOrDefault("STACK_MOCKAS_URL", "https://172.16.50.13:8080") // NOSONAR
5354

5455
// The public URLs the services use for self-referencing
55-
apigwPublicURL = envOrDefault("STACK_APIGW_PUBLIC_URL", "http://apigw.vc.docker:8080") // NOSONAR
56-
verifierPublicURL = envOrDefault("STACK_VERIFIER_PUBLIC_URL", "http://verifier.vc.docker:8080") // NOSONAR
56+
apigwPublicURL = envOrDefault("STACK_APIGW_PUBLIC_URL", "https://apigw.vc.docker:8080") // NOSONAR
57+
verifierPublicURL = envOrDefault("STACK_VERIFIER_PUBLIC_URL", "https://verifier.vc.docker:8080") // NOSONAR
58+
59+
// tlsTransport is a shared TLS transport that trusts the dev rootCA.
60+
// Initialised by TestMain before any tests run.
61+
tlsTransport *http.Transport
5762

5863
// OAuth client config matching config.yaml
5964
oauthClientID = "1003" // NOSONAR
60-
oauthRedirect = "https://dev.wallet.sunet.se" // NOSONAR
65+
oauthRedirect = "http://localhost:3000" // NOSONAR — must match apigw oauth_server in config_minimal.yaml
6166
testUsername = "wallet_test_user" // NOSONAR
6267
testPassword = "wallet_test_pass_42" // NOSONAR
6368

@@ -73,6 +78,32 @@ func envOrDefault(key, def string) string {
7378
return def
7479
}
7580

81+
// TestMain sets up an http.DefaultClient that trusts the dev rootCA so all
82+
// stack tests can talk to TLS-enabled services without per-call changes.
83+
func TestMain(m *testing.M) {
84+
caPath := envOrDefault("STACK_ROOT_CA", "../../../developer_tools/pki/rootCA.crt")
85+
caPEM, err := os.ReadFile(caPath)
86+
if err != nil {
87+
fmt.Fprintf(os.Stderr, "reading rootCA %s: %v\n", caPath, err)
88+
os.Exit(1)
89+
}
90+
pool, _ := x509.SystemCertPool()
91+
if pool == nil {
92+
pool = x509.NewCertPool()
93+
}
94+
if !pool.AppendCertsFromPEM(caPEM) {
95+
fmt.Fprintf(os.Stderr, "rootCA %s contains no valid certificates\n", caPath)
96+
os.Exit(1)
97+
}
98+
tlsTransport = http.DefaultTransport.(*http.Transport).Clone()
99+
tlsTransport.TLSClientConfig.RootCAs = pool
100+
http.DefaultClient = &http.Client{
101+
Transport: tlsTransport,
102+
Timeout: 30 * time.Second,
103+
}
104+
os.Exit(m.Run())
105+
}
106+
76107
// rewritePublicToInternal replaces Docker-internal hostnames with bridge IPs
77108
// so requests from the dev container actually reach the services.
78109
func rewritePublicToInternal(rawURL string) string {
@@ -1179,9 +1210,9 @@ func doConsentFlow(t *testing.T, authorizeEndpoint, requestURI, clientID string)
11791210

11801211
jar, _ := cookiejar.New(nil)
11811212
client := &http.Client{
1182-
Jar: jar,
1183-
Timeout: 15 * time.Second,
1184-
// Follow redirects (consent page redirects)
1213+
Transport: tlsTransport,
1214+
Jar: jar,
1215+
Timeout: 15 * time.Second,
11851216
}
11861217

11871218
// Step 1: GET /authorize?request_uri=...&client_id=...
@@ -1224,8 +1255,9 @@ func doConsentFlow(t *testing.T, authorizeEndpoint, requestURI, clientID string)
12241255

12251256
// Use no-redirect client to capture the response with the code
12261257
noRedirectClient := &http.Client{
1227-
Jar: jar,
1228-
Timeout: 15 * time.Second,
1258+
Transport: tlsTransport,
1259+
Jar: jar,
1260+
Timeout: 15 * time.Second,
12291261
CheckRedirect: func(req *http.Request, via []*http.Request) error {
12301262
return http.ErrUseLastResponse
12311263
},

0 commit comments

Comments
 (0)