|
6 | 6 | # you may not use this file except in compliance with the License. |
7 | 7 | # You may obtain a copy of the License at |
8 | 8 | # |
9 | | -# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
10 | 10 | # |
11 | 11 | # Unless required by applicable law or agreed to in writing, software |
12 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
@@ -62,32 +62,150 @@ if ($LastExitCode) { |
62 | 62 | . ci/kokoro/windows/lib/integration.ps1 |
63 | 63 |
|
64 | 64 | function Invoke-REST-Quickstart { |
65 | | - bazelisk $common_flags run $build_flags ` |
66 | | - //google/cloud/storage/quickstart:quickstart -- ` |
67 | | - "${env:GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME}" |
68 | | - if ($LastExitCode) { |
69 | | - Write-Host -ForegroundColor Red "bazel run (storage/quickstart) failed with exit code ${LastExitCode}." |
70 | | - Exit ${LastExitCode} |
| 65 | + param($bazel_bin) |
| 66 | + try { |
| 67 | + $executable = Join-Path $bazel_bin "google/cloud/storage/quickstart/quickstart.exe" |
| 68 | + Write-Host "Running REST Quickstart, attempting to run: $executable" |
| 69 | + if (-not (Test-Path $executable)) { |
| 70 | + Write-Host -ForegroundColor Red "Executable not found at the specified path." |
| 71 | + Exit 1 |
| 72 | + } |
| 73 | + & $executable "${env:GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME}" |
| 74 | + if ($LastExitCode) { |
| 75 | + Write-Host -ForegroundColor Red "Execution of (storage/quickstart) failed with exit code ${LastExitCode}." |
| 76 | + Exit ${LastExitCode} |
| 77 | + } |
| 78 | + } catch { |
| 79 | + Write-Host -ForegroundColor Red "Caught exception while trying to run storage/quickstart: $_" |
| 80 | + Exit 1 |
71 | 81 | } |
72 | 82 | } |
73 | 83 |
|
74 | 84 | function Invoke-gRPC-Quickstart { |
75 | | - bazelisk $common_flags run $build_flags ` |
76 | | - //google/cloud/pubsub/quickstart:quickstart -- ` |
77 | | - "${env:GOOGLE_CLOUD_PROJECT}" "${env:GOOGLE_CLOUD_CPP_PUBSUB_TEST_QUICKSTART_TOPIC}" |
78 | | - if ($LastExitCode) { |
79 | | - Write-Host -ForegroundColor Red "bazel run (pubsub/quickstart) failed with exit code ${LastExitCode}." |
80 | | - Exit ${LastExitCode} |
| 85 | + param($bazel_bin) |
| 86 | + try { |
| 87 | + $executable = Join-Path $bazel_bin "google/cloud/pubsub/quickstart/quickstart.exe" |
| 88 | + Write-Host "Running gRPC Quickstart, attempting to run: $executable" |
| 89 | + if (-not (Test-Path $executable)) { |
| 90 | + Write-Host -ForegroundColor Red "Executable not found at the specified path." |
| 91 | + Exit 1 |
| 92 | + } |
| 93 | + & $executable "${env:GOOGLE_CLOUD_PROJECT}" "${env:GOOGLE_CLOUD_CPP_PUBSUB_TEST_QUICKSTART_TOPIC}" |
| 94 | + if ($LastExitCode) { |
| 95 | + Write-Host -ForegroundColor Red "Execution of (pubsub/quickstart) failed with exit code ${LastExitCode}." |
| 96 | + Exit ${LastExitCode} |
| 97 | + } |
| 98 | + } catch { |
| 99 | + Write-Host -ForegroundColor Red "Caught exception while trying to run pubsub/quickstart: $_" |
| 100 | + Exit 1 |
81 | 101 | } |
82 | 102 | } |
83 | 103 |
|
84 | 104 | if (Test-Integration-Enabled) { |
85 | 105 | Write-Host "`n$(Get-Date -Format o) Running minimal quickstart prorams" |
| 106 | + |
| 107 | + # 1. Install the certificates |
86 | 108 | Install-Roots-Pem |
87 | | - ${env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH}="${env:KOKORO_GFILE_DIR}/roots.pem" |
88 | | - ${env:GOOGLE_APPLICATION_CREDENTIALS}="${env:KOKORO_GFILE_DIR}/kokoro-run-key.json" |
89 | | - Invoke-REST-Quickstart |
90 | | - Invoke-gRPC-Quickstart |
| 109 | + |
| 110 | + # 2. Normalize paths to use Forward Slashes (/) |
| 111 | + # This is critical for C++ binaries (BoringSSL/libcurl) to parse paths correctly on Windows. |
| 112 | + $RawRootsPath = Join-Path $env:KOKORO_GFILE_DIR "roots.pem" |
| 113 | + $RootsPath = $RawRootsPath -replace '\\', '/' |
| 114 | + |
| 115 | + $RawKeyPath = Join-Path $env:KOKORO_GFILE_DIR "kokoro-run-key.json" |
| 116 | + $KeyPath = $RawKeyPath -replace '\\', '/' |
| 117 | + |
| 118 | + # 3. Set ALL SSL Environment Variables |
| 119 | + # OpenSSL/BoringSSL may look at SSL_CERT_FILE before CURL_CA_BUNDLE |
| 120 | + $env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = $RootsPath |
| 121 | + $env:CURL_CA_BUNDLE = $RootsPath |
| 122 | + $env:SSL_CERT_FILE = $RootsPath |
| 123 | + $env:GOOGLE_APPLICATION_CREDENTIALS = $KeyPath |
| 124 | + |
| 125 | + # 4. Enable Deep Library Logging |
| 126 | + $env:GOOGLE_CLOUD_CPP_ENABLE_TRACING="http" |
| 127 | + $env:CURL_VERBOSE="1" |
| 128 | + |
| 129 | + # --- DEBUG CHECKS --- |
| 130 | + Write-Host -ForegroundColor Cyan "`n--- DEBUG: Environment & File Check ---" |
| 131 | + Write-Host "Roots Path: $RootsPath" |
| 132 | + |
| 133 | + Write-Host "`n[Check 1] Environment Variables:" |
| 134 | + Get-ChildItem Env: | Where-Object { $_.Name -match 'CURL_|GOOGLE_|GRPC_|SSL_' } | Format-Table -AutoSize | Out-Host |
| 135 | + |
| 136 | + Write-Host "`n[Check 2] File Verify:" |
| 137 | + if (Test-Path $RootsPath) { |
| 138 | + Write-Host -ForegroundColor Green "File exists." |
| 139 | + Get-Item $RootsPath | Select-Object Length, LastWriteTime |
| 140 | + } else { |
| 141 | + Write-Host -ForegroundColor Red "CRITICAL: File not found at $RootsPath" |
| 142 | + } |
| 143 | + Write-Host "--- DEBUG END ---`n" |
| 144 | + |
| 145 | + bazelisk $common_flags build $build_flags ` |
| 146 | + //google/cloud/storage/quickstart:quickstart ` |
| 147 | + //google/cloud/pubsub/quickstart:quickstart |
| 148 | + |
| 149 | + $bazel_bin = (bazelisk $common_flags info $build_flags bazel-bin).Trim() |
| 150 | + # Fix bazel-bin path for PowerShell invocation just in case |
| 151 | + $bazel_bin = $bazel_bin.Replace('/', '\') |
| 152 | + Write-Host "bazel-bin directory: $bazel_bin" |
| 153 | + |
| 154 | + # --- VERIFICATION EXPERIMENT START --- |
| 155 | + Write-Host -ForegroundColor Cyan "`n--- EXPERIMENT: The 'Strip & Retry' Test ---" |
| 156 | + |
| 157 | + # Define paths |
| 158 | + $DirtyFile = $RawRootsPath |
| 159 | + $CleanFile = Join-Path $env:KOKORO_GFILE_DIR "roots_clean.pem" |
| 160 | + $CleanFileForward = $CleanFile -replace '\\', '/' |
| 161 | + |
| 162 | + # Check for the "Poison" (\r) |
| 163 | + $text = [System.IO.File]::ReadAllText($DirtyFile) |
| 164 | + if ($text.Contains("`r")) { |
| 165 | + Write-Host -ForegroundColor Red "[CONFIRMED] 'roots.pem' contains Carriage Returns (\r)." |
| 166 | + Write-Host " Attempting to sanitize and run binary..." |
| 167 | + |
| 168 | + # Create the Antidote (Remove all \r) |
| 169 | + $cleanText = $text.Replace("`r", "") |
| 170 | + [System.IO.File]::WriteAllText($CleanFile, $cleanText) |
| 171 | + Write-Host "Created sanitized file: $CleanFileForward" |
| 172 | + |
| 173 | + # Run the Binary against the CLEAN file |
| 174 | + Write-Host "`nRunning quickstart.exe using CLEAN file..." |
| 175 | + |
| 176 | + # Temporarily override the env var just for this test |
| 177 | + $env:CURL_CA_BUNDLE = $CleanFileForward |
| 178 | + $env:SSL_CERT_FILE = $CleanFileForward |
| 179 | + $env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = $CleanFileForward |
| 180 | + |
| 181 | + # Construct executable path |
| 182 | + $QuickstartExe = Join-Path $bazel_bin "google/cloud/storage/quickstart/quickstart.exe" |
| 183 | + |
| 184 | + try { |
| 185 | + & $QuickstartExe "${env:GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME}" |
| 186 | + if ($LastExitCode -eq 0) { |
| 187 | + Write-Host -ForegroundColor Green "`n[SUCCESS] The binary worked with the clean file!" |
| 188 | + Write-Host -ForegroundColor Green "CONCLUSION: Carriage Returns were the root cause." |
| 189 | + } else { |
| 190 | + Write-Host -ForegroundColor Red "`n[FAILURE] The binary still failed ($LastExitCode) even with the clean file." |
| 191 | + Write-Host -ForegroundColor Red "CONCLUSION: The issue is NOT carriage returns." |
| 192 | + } |
| 193 | + } catch { |
| 194 | + Write-Host "Execution failed: $_" |
| 195 | + } |
| 196 | + |
| 197 | + # Restore Env Vars for standard test flow |
| 198 | + $env:CURL_CA_BUNDLE = $RootsPath |
| 199 | + $env:SSL_CERT_FILE = $RootsPath |
| 200 | + $env:GRPC_DEFAULT_SSL_ROOTS_FILE_PATH = $RootsPath |
| 201 | + } else { |
| 202 | + Write-Host -ForegroundColor Green "[INFO] 'roots.pem' is already clean (No \r). Experiment skipped." |
| 203 | + } |
| 204 | + Write-Host "------------------------------------------------" |
| 205 | + # --- VERIFICATION EXPERIMENT END --- |
| 206 | + |
| 207 | + Invoke-REST-Quickstart $bazel_bin |
| 208 | + Invoke-gRPC-Quickstart $bazel_bin |
91 | 209 | } |
92 | 210 |
|
93 | 211 | # Shutdown the Bazel server to release any locks |
|
0 commit comments