|
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 | + Debug-Network -targetUrl "https://curl.se/ca/cacert.pem" |
| 66 | + |
32 | 67 | ForEach($attempt in (1, 2, 3)) { |
| 68 | + Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) " ` |
| 69 | + "Downloading roots.pem [$attempt]" |
33 | 70 | try { |
34 | 71 | (New-Object System.Net.WebClient).Downloadfile( |
35 | | - 'https://pki.google.com/roots.pem', |
| 72 | + 'https://curl.se/ca/cacert.pem', |
36 | 73 | "${env:KOKORO_GFILE_DIR}/roots.pem") |
| 74 | + |
| 75 | + # --- CHANGE 1: Inspect both Root and Intermediate (CA) stores --- |
| 76 | + # Many corporate proxies operate via an Intermediate CA. |
| 77 | + $storesToCheck = @("Root", "CA") |
| 78 | + |
| 79 | + Write-Host "Appending Windows System Certificates to roots.pem..." |
| 80 | + |
| 81 | + foreach ($storeName in $storesToCheck) { |
| 82 | + Write-Host -ForegroundColor Cyan "Processing Store: LocalMachine\$storeName" |
| 83 | + $certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $storeName, "LocalMachine" |
| 84 | + $certStore.Open('ReadOnly') |
| 85 | + |
| 86 | + $certStore.Certificates | ForEach-Object { |
| 87 | + $cert = $_ |
| 88 | + # --- CHANGE 2: Log the Subject Name --- |
| 89 | + # This lets us verify if the corporate proxy cert is actually present. |
| 90 | + Write-Host " Adding: $($cert.Subject)" |
| 91 | + |
| 92 | + $pem = "`r`n-----BEGIN CERTIFICATE-----`r`n" + |
| 93 | + [Convert]::ToBase64String($cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert), 'InsertLineBreaks') + |
| 94 | + "`r`n-----END CERTIFICATE-----`r`n" |
| 95 | + Add-Content -Path "${env:KOKORO_GFILE_DIR}/roots.pem" -Value $pem -Encoding Ascii |
| 96 | + } |
| 97 | + $certStore.Close() |
| 98 | + } |
| 99 | + |
| 100 | + # --- DEBUG START --- |
| 101 | + $pemPath = "${env:KOKORO_GFILE_DIR}/roots.pem" |
| 102 | + Write-Host -ForegroundColor Cyan "`nDEBUG: Inspecting roots.pem..." |
| 103 | + |
| 104 | + $corruption = Select-String -Path $pemPath -Pattern "-----END CERTIFICATE----------BEGIN CERTIFICATE-----" |
| 105 | + if ($corruption) { |
| 106 | + Write-Host -ForegroundColor Red "FAIL: Found corrupted certificate boundaries (missing newline)!" |
| 107 | + } else { |
| 108 | + Write-Host -ForegroundColor Green "PASS: No certificate boundary corruption detected." |
| 109 | + } |
| 110 | + |
| 111 | + Write-Host -ForegroundColor Cyan "`nDEBUG: Testing SSL connection to GCS..." |
| 112 | + |
| 113 | + # Fix: Relax ErrorActionPreference so curl -v stderr doesn't crash the script |
| 114 | + $OldEAP = $ErrorActionPreference |
| 115 | + $ErrorActionPreference = "Continue" |
| 116 | + |
| 117 | + try { |
| 118 | + & curl.exe --version |
| 119 | + & curl.exe -v https://storage.googleapis.com --cacert $pemPath 2>&1 | Out-Host |
| 120 | + if ($LastExitCode -ne 0) { |
| 121 | + Write-Host -ForegroundColor Red "Curl exited with error code: $LastExitCode" |
| 122 | + } else { |
| 123 | + Write-Host -ForegroundColor Green "Curl connection test PASSED." |
| 124 | + } |
| 125 | + } catch { |
| 126 | + Write-Host -ForegroundColor Red "Debug curl command failed unexpectedly: $_" |
| 127 | + } finally { |
| 128 | + $ErrorActionPreference = $OldEAP |
| 129 | + } |
| 130 | + # --- DEBUG END --- |
| 131 | + |
37 | 132 | return |
38 | 133 | } catch { |
39 | | - Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download error" |
| 134 | + Write-Host -ForegroundColor Yellow "`n$(Get-Date -Format o) download/setup error: $_" |
| 135 | + if ($attempt -eq 3) { |
| 136 | + Debug-Network -targetUrl "https://storage.googleapis.com" |
| 137 | + } |
40 | 138 | } |
41 | 139 | Start-Sleep -Seconds (60 * $attempt) |
42 | 140 | } |
|
0 commit comments