PowerShell/test/tools/WebListener/Program.cs

87 lines
4.4 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Https;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace mvc
{
public class Program
{
public static void Main(string[] args)
{
if (args.Length != 7)
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
{
System.Console.WriteLine("Required: <CertificatePath> <CertificatePassword> <HTTPPortNumber> <HTTPSPortNumberTls12> <HTTPSPortNumberTls11> <HTTPSPortNumberTls> <HTTPSPortNumberTls12>");
Environment.Exit(1);
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder()
.UseStartup<Startup>().UseKestrel(options =>
{
options.AllowSynchronousIO = true;
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
options.Listen(IPAddress.Loopback, int.Parse(args[2]));
options.Listen(IPAddress.Loopback, int.Parse(args[3]), listenOptions =>
{
var certificate = new X509Certificate2(args[0], args[1]);
HttpsConnectionAdapterOptions httpsOption = new HttpsConnectionAdapterOptions();
httpsOption.SslProtocols = SslProtocols.Tls12;
httpsOption.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
httpsOption.ClientCertificateValidation = (inCertificate, inChain, inPolicy) => { return true; };
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
httpsOption.CheckCertificateRevocation = false;
httpsOption.ServerCertificate = certificate;
listenOptions.UseHttps(httpsOption);
});
options.Listen(IPAddress.Loopback, int.Parse(args[4]), listenOptions =>
{
var certificate = new X509Certificate2(args[0], args[1]);
HttpsConnectionAdapterOptions httpsOption = new HttpsConnectionAdapterOptions();
httpsOption.SslProtocols = SslProtocols.Tls11;
httpsOption.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
httpsOption.ClientCertificateValidation = (inCertificate, inChain, inPolicy) => { return true; };
httpsOption.CheckCertificateRevocation = false;
httpsOption.ServerCertificate = certificate;
listenOptions.UseHttps(httpsOption);
});
options.Listen(IPAddress.Loopback, int.Parse(args[5]), listenOptions =>
{
var certificate = new X509Certificate2(args[0], args[1]);
HttpsConnectionAdapterOptions httpsOption = new HttpsConnectionAdapterOptions();
httpsOption.SslProtocols = SslProtocols.Tls;
httpsOption.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
httpsOption.ClientCertificateValidation = (inCertificate, inChain, inPolicy) => { return true; };
httpsOption.CheckCertificateRevocation = false;
httpsOption.ServerCertificate = certificate;
listenOptions.UseHttps(httpsOption);
});
options.Listen(IPAddress.Loopback, int.Parse(args[6]), listenOptions =>
{
var certificate = new X509Certificate2(args[0], args[1]);
HttpsConnectionAdapterOptions httpsOption = new HttpsConnectionAdapterOptions();
httpsOption.SslProtocols = SslProtocols.Tls13;
httpsOption.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
httpsOption.ClientCertificateValidation = (inCertificate, inChain, inPolicy) => { return true; };
httpsOption.CheckCertificateRevocation = false;
httpsOption.ServerCertificate = certificate;
listenOptions.UseHttps(httpsOption);
});
Add test WebListener module and tests for Web Cmdlet Certificate Authentication (#4622) Introduce new test module 'WebListener.psm1'. Now web HTTPS tests can use it to exclude using external sites. PowerShell/PowerShell#4609 * [Feature] Add Tests for Web Cmdlet Certificate Authentication PowerShell/PowerShell#4609 * [feature] Add new app to Publish-PSTestTools refactor tests also add ASP.NET to .spelling * [feature] spelling fix * [feature] revert badssl changes * [feature] Impliment suggestions * [feature] Spelling, var rename, port 8443 to 8083 rebase fix conflict * [feature] Rename to HttpsListener and Module-ize . * [feature] password protect ClientCert to fix macOS import issue * [feature] Rename to WebListener * Rename HttpsListener to WebListener * Switch Listener from Razor pages to MVC * Address PR feedback * Adjust tests * [feature] Address PR feedback * [feature] Replace missing smeicolons * [feature] Address PR Feedback * [feature] Cleanup and minor fix * Enum was not used * GetStatus() was not accessing the correct property chain * Added -Test param to make URL generation smoother in test code and to fix double / issues * [feature] More minor fixes * Https when it matters. * Expand property... not exclude.. * Remove superfluous and outdated ToString() override * [Feature] Move ClientCeret.pfx to WebListener Module * Move the cert * Adjust Get-WebListenerClientCertificate * Remove cert from csproj * ActionResult -> JsonResult (was mistakenly left as ActionResult during testing).. * [Feature] Move ServerCert.pfx to Module * Move cert * Upate csproj * Update module * Add/Update README.md's CI Retest.
2017-08-31 11:30:35 +02:00
})
.Build();
}
}