@@ -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)
4950var (
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.
78109func 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