|
1 | | -using System.Diagnostics; |
2 | 1 | using System.IO.Compression; |
3 | 2 | using System.Text; |
4 | 3 | using CHttp.Abstractions; |
@@ -350,6 +349,86 @@ public async Task Diff_FunctionalTest() |
350 | 349 | Assert.Contains("probability, the base session's true mean latency is", console.Text); |
351 | 350 | } |
352 | 351 |
|
| 352 | + [Fact] |
| 353 | + public async Task CertificateValidationError_WithProposedSuggestion() |
| 354 | + { |
| 355 | + using var host = HttpServer.CreateHostBuilder(context => context.Response.WriteAsync("test"), HttpProtocols.Http2); |
| 356 | + await host.StartAsync(TestContext.Current.CancellationToken); |
| 357 | + var console = new TestConsolePerWrite(); |
| 358 | + var writer = new SilentConsoleWriter(new TextBufferedProcessor(), console); |
| 359 | + |
| 360 | + var client = await CommandFactory.CreateRootCommand(writer) |
| 361 | + .Parse("--method GET --uri https://localhost:5011 -v 2") |
| 362 | + .InvokeAsync(cancellationToken: TestContext.Current.CancellationToken); |
| 363 | + |
| 364 | + await writer.CompleteAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); |
| 365 | + Assert.Contains("Enable flag --no-certificate-validation true'. SSL error: The remote certificate is invalid because of errors in the certificate chain", console.Text); |
| 366 | + } |
| 367 | + |
| 368 | + [Fact] |
| 369 | + public async Task CertificateValidationError_HttpsServer_HttpRequest_H2() |
| 370 | + { |
| 371 | + using var host = HttpServer.CreateHostBuilder(context => context.Response.WriteAsync("test"), HttpProtocols.Http2); |
| 372 | + await host.StartAsync(TestContext.Current.CancellationToken); |
| 373 | + var console = new TestConsolePerWrite(); |
| 374 | + var writer = new SilentConsoleWriter(new TextBufferedProcessor(), console); |
| 375 | + |
| 376 | + var client = await CommandFactory.CreateRootCommand(writer) |
| 377 | + .Parse("--method GET --uri http://localhost:5011 -v 2") |
| 378 | + .InvokeAsync(cancellationToken: TestContext.Current.CancellationToken); |
| 379 | + |
| 380 | + await writer.CompleteAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); |
| 381 | + Assert.Contains("Invalid http(s) schema: An HTTP/2 connection could not be established", console.Text); |
| 382 | + } |
| 383 | + |
| 384 | + [Fact] |
| 385 | + public async Task CertificateValidationError_HttpsServer_HttpRequest_H3() |
| 386 | + { |
| 387 | + using var host = HttpServer.CreateHostBuilder(context => context.Response.WriteAsync("test"), HttpProtocols.Http3); |
| 388 | + await host.StartAsync(TestContext.Current.CancellationToken); |
| 389 | + var console = new TestConsolePerWrite(); |
| 390 | + var writer = new SilentConsoleWriter(new TextBufferedProcessor(), console); |
| 391 | + |
| 392 | + var client = await CommandFactory.CreateRootCommand(writer) |
| 393 | + .Parse("--method GET --uri http://localhost:5011 -v 3") |
| 394 | + .InvokeAsync(cancellationToken: TestContext.Current.CancellationToken); |
| 395 | + |
| 396 | + await writer.CompleteAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); |
| 397 | + Assert.Contains("Requesting HTTP version 3.0 with version policy RequestVersionExact while unable to establish HTTP/3 connection.", console.Text); |
| 398 | + } |
| 399 | + |
| 400 | + [Fact] |
| 401 | + public async Task CertificateValidationError_HttpsServer_HttpRequest_H1() |
| 402 | + { |
| 403 | + using var host = HttpServer.CreateHostBuilder(context => context.Response.WriteAsync("test"), HttpProtocols.Http1); |
| 404 | + await host.StartAsync(TestContext.Current.CancellationToken); |
| 405 | + var console = new TestConsolePerWrite(); |
| 406 | + var writer = new SilentConsoleWriter(new TextBufferedProcessor(), console); |
| 407 | + |
| 408 | + var client = await CommandFactory.CreateRootCommand(writer) |
| 409 | + .Parse("--method GET --uri http://localhost:5011 -v 1.1") |
| 410 | + .InvokeAsync(cancellationToken: TestContext.Current.CancellationToken); |
| 411 | + |
| 412 | + await writer.CompleteAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); |
| 413 | + Assert.Contains("Invalid http(s) schema: The response ended prematurely.", console.Text); |
| 414 | + } |
| 415 | + |
| 416 | + [Fact] |
| 417 | + public async Task CertificateValidationError_HttpServer_HttpsRequest() |
| 418 | + { |
| 419 | + using var host = HttpServer.CreateHostBuilder(context => context.Response.WriteAsync("test"), HttpProtocols.Http1, withHttps: false); |
| 420 | + await host.StartAsync(TestContext.Current.CancellationToken); |
| 421 | + var console = new TestConsolePerWrite(); |
| 422 | + var writer = new SilentConsoleWriter(new TextBufferedProcessor(), console); |
| 423 | + |
| 424 | + var client = await CommandFactory.CreateRootCommand(writer) |
| 425 | + .Parse("--method GET --uri https://localhost:5011 -v 1.1") |
| 426 | + .InvokeAsync(cancellationToken: TestContext.Current.CancellationToken); |
| 427 | + |
| 428 | + await writer.CompleteAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); |
| 429 | + Assert.Contains("Invalid http(s) schema: Cannot determine the frame size or a corrupted frame was received.", console.Text); |
| 430 | + } |
| 431 | + |
353 | 432 | private class Request |
354 | 433 | { |
355 | 434 | public string? Data { get; set; } |
|
0 commit comments