TestBoundaryChildProcessSkipsCheck verifies that when CHILD=true, the license check is skipped. This simulates boundary re-executing itself to run the target process. We use a proxy that would fail the license check to verify it's skipped.
(t *testing.T)
| 238 | // target process. We use a proxy that would fail the license check to verify |
| 239 | // it's skipped. |
| 240 | func TestBoundaryChildProcessSkipsCheck(t *testing.T) { |
| 241 | // Cannot use t.Parallel() with t.Setenv(). |
| 242 | client, _ := coderdenttest.New(t, &coderdenttest.Options{ |
| 243 | LicenseOptions: &coderdenttest.LicenseOptions{ |
| 244 | Features: license.Features{ |
| 245 | // No FeatureBoundary - would normally fail |
| 246 | }, |
| 247 | }, |
| 248 | }) |
| 249 | |
| 250 | proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 251 | if r.URL.Path == "/api/v2/entitlements" { |
| 252 | // Return not entitled for boundary - this would normally cause failure. |
| 253 | res := codersdk.Entitlements{ |
| 254 | Features: map[codersdk.FeatureName]codersdk.Feature{}, |
| 255 | Warnings: []string{}, |
| 256 | Errors: []string{}, |
| 257 | HasLicense: true, |
| 258 | Trial: false, |
| 259 | RequireTelemetry: false, |
| 260 | } |
| 261 | for _, feature := range codersdk.FeatureNames { |
| 262 | if feature == codersdk.FeatureBoundary { |
| 263 | res.Features[feature] = codersdk.Feature{ |
| 264 | Entitlement: codersdk.EntitlementNotEntitled, |
| 265 | Enabled: false, |
| 266 | } |
| 267 | } else { |
| 268 | res.Features[feature] = codersdk.Feature{ |
| 269 | Entitlement: codersdk.EntitlementEntitled, |
| 270 | Enabled: true, |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | httpapi.Write(r.Context(), w, http.StatusOK, res) |
| 275 | return |
| 276 | } |
| 277 | |
| 278 | // Otherwise, proxy the request to the real API server. |
| 279 | rp := httputil.NewSingleHostReverseProxy(client.URL) |
| 280 | tp := &http.Transport{} |
| 281 | defer tp.CloseIdleConnections() |
| 282 | rp.Transport = tp |
| 283 | rp.ServeHTTP(w, r) |
| 284 | })) |
| 285 | defer proxy.Close() |
| 286 | |
| 287 | proxyURL, err := url.Parse(proxy.URL) |
| 288 | require.NoError(t, err) |
| 289 | proxyClient := codersdk.New(proxyURL, codersdk.WithHTTPClient(coderdtest.NewIsolatedHTTPClient(proxyURL))) |
| 290 | proxyClient.SetSessionToken(client.SessionToken()) |
| 291 | t.Cleanup(proxyClient.HTTPClient.CloseIdleConnections) |
| 292 | |
| 293 | inv, conf := newCLI(t, "boundary", "--version") |
| 294 | clitest.SetupConfig(t, proxyClient, conf) |
| 295 | |
| 296 | // Set CHILD=true to simulate boundary re-execution. This should skip the |
| 297 | // license check, so the command should succeed even though the proxy would |
nothing calls this directly
no test coverage detected