|
14 | 14 |
|
15 | 15 | # Helper functions to run the minimal integration tests |
16 | 16 |
|
17 | | -$PROJECT_ROOT = (Get-Item -Path ".\" -Verbose).FullName |
| 17 | +$PROJECT_ROOT = (Get-Item -Path ".\").FullName |
18 | 18 | $integration_tests_config="${PROJECT_ROOT}/ci/etc/integration-tests-config.ps1" |
19 | 19 | . "${integration_tests_config}" |
20 | 20 |
|
21 | 21 | function Test-Integration-Enabled { |
22 | 22 | if ((Test-Path env:KOKORO_GFILE_DIR) -and |
23 | 23 | (Test-Path "${env:KOKORO_GFILE_DIR}/kokoro-run-key.json")) { |
24 | | - return $True |
| 24 | + return $True |
25 | 25 | } |
26 | 26 | return $False |
27 | 27 | } |
28 | 28 |
|
| 29 | +function Debug-Network { |
| 30 | + param([string]$targetUrl) |
| 31 | + Write-Host -ForegroundColor Cyan "`n--- NETWORK DEBUG START ($targetUrl) ---" |
| 32 | + try { |
| 33 | + $uri = New-Object System.Uri($targetUrl) |
| 34 | + $hostName = $uri.DnsSafeHost |
| 35 | + |
| 36 | + # 1. DNS Resolution |
| 37 | + Write-Host "1. Testing DNS resolution for $hostName..." |
| 38 | + $dns = Resolve-DnsName -Name $hostName -ErrorAction SilentlyContinue |
| 39 | + if ($dns) { $dns | Format-Table -AutoSize | Out-Host } else { Write-Host -ForegroundColor Red "DNS Resolution FAILED" } |
| 40 | + |
| 41 | + # 2. Basic TCP Connectivity (checking port 443) |
| 42 | + Write-Host "`n2. Testing TCP connectivity to $hostName`:443..." |
| 43 | + try { |
| 44 | + $tcp = Test-NetConnection -ComputerName $hostName -Port 443 -WarningAction SilentlyContinue |
| 45 | + if ($tcp.TcpTestSucceeded) { Write-Host "TCP connection SUCCEEDED" } else { Write-Host -ForegroundColor Red "TCP connection FAILED" } |
| 46 | + Write-Host "Detailed Info: $($tcp | Out-String)" |
| 47 | + } catch { |
| 48 | + Write-Host -ForegroundColor Red "Test-NetConnection failed to run: $_" |
| 49 | + } |
| 50 | + |
| 51 | + # 3. Proxy Detection |
| 52 | + Write-Host "`n3. Checking System Proxy for $targetUrl..." |
| 53 | + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() |
| 54 | + $proxyUri = $proxy.GetProxy($uri) |
| 55 | + Write-Host "Effective Proxy: $proxyUri" |
| 56 | + Write-Host "Is Bypassed: $($proxy.IsBypassed($uri))" |
| 57 | + |
| 58 | + } catch { |
| 59 | + Write-Host -ForegroundColor Red "An error occurred during network debug: $_" |
| 60 | + } |
| 61 | + Write-Host -ForegroundColor Cyan "--- NETWORK DEBUG END ---`n" |
| 62 | +} |
| 63 | + |
29 | 64 | function Install-Roots-Pem { |
30 | | - Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) " ` |
31 | | - "Downloading roots.pem [$_]" |
| 65 | + # Run pre-flight network checks to aid debugging if downloading fails later. |
| 66 | + Debug-Network -targetUrl "https://curl.se/ca/cacert.pem" |
| 67 | + |
32 | 68 | ForEach($attempt in (1, 2, 3)) { |
| 69 | + Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) " ` |
| 70 | + "Downloading roots.pem [$attempt]" |
33 | 71 | try { |
| 72 | + # Use the standard Mozilla CA bundle from curl.se. |
| 73 | + # This is more comprehensive than pki.google.com and includes |
| 74 | + # the DigiCert roots currently used by some GCS endpoints. |
34 | 75 | (New-Object System.Net.WebClient).Downloadfile( |
35 | | - 'https://pki.google.com/roots.pem', |
| 76 | + 'https://curl.se/ca/cacert.pem', |
36 | 77 | "${env:KOKORO_GFILE_DIR}/roots.pem") |
| 78 | + |
| 79 | + # --- DEBUG START --- |
| 80 | + # Verify the downloaded file works for GCS connections |
| 81 | + Write-Host -ForegroundColor Cyan "`nDEBUG: Testing SSL connection to GCS with verbose output..." |
| 82 | + try { |
| 83 | + # We use curl.exe (if available) to debug the handshake using the same CA bundle. |
| 84 | + # standard error (2) is redirected to standard output (1) so we see the verbose logs. |
| 85 | + & curl.exe -v https://storage.googleapis.com --cacert "${env:KOKORO_GFILE_DIR}/roots.pem" 2>&1 | Out-Host |
| 86 | + } catch { |
| 87 | + Write-Host -ForegroundColor Red "Debug curl command failed to run." |
| 88 | + } |
| 89 | + # --- DEBUG END --- |
| 90 | + |
37 | 91 | return |
38 | 92 | } catch { |
39 | | - Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download error" |
| 93 | + Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download error: $_" |
| 94 | + # If download fails, maybe the proxy blocks curl.se but allows google.com? |
| 95 | + # Let's debug the GCS endpoint too if we are failing. |
| 96 | + if ($attempt -eq 3) { |
| 97 | + Debug-Network -targetUrl "https://storage.googleapis.com" |
| 98 | + } |
40 | 99 | } |
41 | 100 | Start-Sleep -Seconds (60 * $attempt) |
42 | 101 | } |
|
0 commit comments