From ba43904a935cf34ca3d5a70aca514d7595b9e903 Mon Sep 17 00:00:00 2001 From: Cristian Pop Date: Tue, 5 Jul 2016 16:44:19 -0700 Subject: [PATCH] Adding server code. Fixing IIS application deployment. Commit migrated from https://github.com/dotnet/corefx/commit/cb0becbb7e546ffa5f265f862e76bc0fa445ec50 --- .../Common/tests/Scripts/Prerequisites/config.ps1 | 96 ---------- .../System/Net/Prerequisites/Deployment/config.ps1 | 60 ++++++ .../Net/Prerequisites/Deployment}/setup.ps1 | 12 +- .../Deployment}/setup_activedirectory_client.ps1 | 0 .../setup_activedirectory_domaincontroller.ps1 | 1 - .../Deployment}/setup_certificates.ps1 | 0 .../Net/Prerequisites/Deployment}/setup_client.ps1 | 0 .../Net/Prerequisites/Deployment}/setup_common.ps1 | 40 ++++ .../Prerequisites/Deployment}/setup_firewall.ps1 | 0 .../Prerequisites/Deployment}/setup_iisserver.ps1 | 39 +--- .../tests/System/Net/Prerequisites/README.md | 44 +++++ .../CoreFxNetCloudService.sln | 28 +++ .../CoreFxNetCloudService.ccproj | 62 ++++++ .../ServiceConfiguration.Cloud.cscfg | 18 ++ .../ServiceConfiguration.Local.cscfg | 18 ++ .../CoreFxNetCloudService/ServiceDefinition.csdef | 27 +++ .../WebServerContent/diagnostics.wadcfgx | 39 ++++ .../ecf/WebServerContent/diagnostics.wadcfgx | 39 ++++ .../WebServer/AuthenticationHelper.cs | 122 ++++++++++++ .../WebServer/ContentHelper.cs | 54 ++++++ .../CoreFxNetCloudService/WebServer/Deflate.ashx | 1 + .../WebServer/Deflate.ashx.cs | 36 ++++ .../CoreFxNetCloudService/WebServer/Echo.ashx | 1 + .../CoreFxNetCloudService/WebServer/Echo.ashx.cs | 54 ++++++ .../WebServer/EmptyContent.ashx | 1 + .../WebServer/EmptyContent.ashx.cs | 31 +++ .../CoreFxNetCloudService/WebServer/GZip.ashx | 1 + .../CoreFxNetCloudService/WebServer/GZip.ashx.cs | 36 ++++ .../WebServer/NameValueCollectionConverter.cs | 77 ++++++++ .../WebServer/Properties/AssemblyInfo.cs | 39 ++++ .../IIS_PublishToLocalPath_CHK.pubxml | 17 ++ .../IIS_PublishToLocalPath_RET.pubxml | 17 ++ .../CoreFxNetCloudService/WebServer/Redirect.ashx | 1 + .../WebServer/Redirect.ashx.cs | 89 +++++++++ .../WebServer/RequestHelper.cs | 44 +++++ .../WebServer/RequestInformation.cs | 87 +++++++++ .../WebServer/StatusCode.ashx | 1 + .../WebServer/StatusCode.ashx.cs | 40 ++++ .../CoreFxNetCloudService/WebServer/Test.ashx | 1 + .../CoreFxNetCloudService/WebServer/Test.ashx.cs | 46 +++++ .../WebServer/VerifyUpload.ashx | 1 + .../WebServer/VerifyUpload.ashx.cs | 83 ++++++++ .../WebServer/Web.Debug.config | 30 +++ .../WebServer/Web.Release.config | 31 +++ .../CoreFxNetCloudService/WebServer/Web.config | 60 ++++++ .../CoreFxNetCloudService/WebServer/WebRole.cs | 24 +++ .../WebServer/WebServer.csproj | 209 +++++++++++++++++++++ .../WebServer/WebSocket/Default.htm | 14 ++ .../WebServer/WebSocket/EchoWebSocket.ashx | 1 + .../WebServer/WebSocket/EchoWebSocket.ashx.cs | 165 ++++++++++++++++ .../WebServer/WebSocket/EchoWebSocketHeaders.ashx | 1 + .../WebSocket/EchoWebSocketHeaders.ashx.cs | 90 +++++++++ .../CoreFxNetCloudService/WebServer/index.html | 11 ++ .../WebServer/packages.config | 12 ++ .../Net/Prerequisites/Servers/buildAndPackage.ps1 | 33 ++++ .../FunctionalTests/DefaultCredentialsTest.cs | 52 ++--- .../System.Net.Http.Functional.Tests.csproj | 3 + 57 files changed, 1984 insertions(+), 155 deletions(-) delete mode 100644 src/libraries/Common/tests/Scripts/Prerequisites/config.ps1 create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup.ps1 (94%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_activedirectory_client.ps1 (100%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_activedirectory_domaincontroller.ps1 (98%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_certificates.ps1 (100%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_client.ps1 (100%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_common.ps1 (63%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_firewall.ps1 (100%) rename src/libraries/Common/tests/{Scripts/Prerequisites => System/Net/Prerequisites/Deployment}/setup_iisserver.ps1 (84%) create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/README.md create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService.sln create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/CoreFxNetCloudService.ccproj create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Cloud.cscfg create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Local.cscfg create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceDefinition.csdef create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/WebServerContent/diagnostics.wadcfgx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ecf/WebServerContent/diagnostics.wadcfgx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/AuthenticationHelper.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/ContentHelper.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/NameValueCollectionConverter.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/AssemblyInfo.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_CHK.pubxml create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_RET.pubxml create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestHelper.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestInformation.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Debug.config create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Release.config create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.config create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebRole.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebServer.csproj create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/Default.htm create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx.cs create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/index.html create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/packages.config create mode 100644 src/libraries/Common/tests/System/Net/Prerequisites/Servers/buildAndPackage.ps1 diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/config.ps1 b/src/libraries/Common/tests/Scripts/Prerequisites/config.ps1 deleted file mode 100644 index a608206..0000000 --- a/src/libraries/Common/tests/Scripts/Prerequisites/config.ps1 +++ /dev/null @@ -1,96 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. -# See the LICENSE file in the project root for more information. - -# -# CoreFX - Net configuration -# - -# -- Machine selection - -# You can find the host name by logging on to the target machine and typing "hostname" in a cmd console. -# You can find the IP address by logging on to the target machine and typing "ipconfig" in a cmd console. -# Requirements: -# - The machines below should be within the same LAN network. -# - All machines must have Powershell >3.0 installed. - -# IMPORTANT: -# The state for the following machines will be changed irreversably. -# The uninstall step will remove the installed components regardless if it existed before the deployment or -# was altered/customized after deployment. -# - -# A Windows Server SKU hosting Active Directory services. This machine will become the Domain Controller: -$COREFX_NET_AD_Machine = "" #Example: "TESTAD" -$COREFX_NET_AD_MachineIP = "" #Example: "192.168.0.1" - must be a Static IPv4 address. - -# A Windows Client or Server SKU hosting the IIS Server. This machine will be joined to the Domain. -$COREFX_NET_IISSERVER_Machine = "" #Example: "TESTIIS" -$COREFX_NET_IISSERVER_MachineIP = "" #Example: "192.168.0.1" - must be a Static IPv4 address. - -# A Windows Client or Server SKU hosting the corefx enlistment. This machine will be joined to the Domain. -$COREFX_NET_CLIENT_Machine = "" #Example: "TESTCLIENT" - -# -- Test parameters - -# For security reasons, it's advisable that the default username/password pairs below are changed regularly. - -$script:domainName = "corp.contoso.com" -$script:domainNetbios = "corefx-net-ad" - -$script:domainUserName = "testaduser" -$script:domainUserPassword = "Test-ADPassword" - -$script:basicUserName = "testbasic" -$script:basicUserPassword = "Test-Basic" - -# Changing the IISServer FQDN may require changing certificates. -$script:iisServerFQDN = "testserver.contoso.com" - -$script:PreRebootRoles = @( - @{Name = "COREFX_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $COREFX_NET_IISSERVER_Machine}, - @{Name = "COREFX_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $COREFX_NET_CLIENT_Machine}, - @{Name = "COREFX_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $COREFX_NET_AD_Machine; MachineIP = $COREFX_NET_AD_MachineIP} -) - -$script:Roles = @( - @{Name = "COREFX_NET_IISSERVER"; Script = "setup_iisserver.ps1"; MachineName = $COREFX_NET_IISSERVER_Machine; MachineIP = $COREFX_NET_IISSERVER_MachineIP}, - @{Name = "COREFX_NET_CLIENT"; Script = "setup_client.ps1"; MachineName = $COREFX_NET_CLIENT_Machine}, - @{Name = "COREFX_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $COREFX_NET_AD_Machine; MachineIP = $COREFX_NET_AD_MachineIP} -) - -# The following variable names should match the ones read by Configuration.*.cs code. -$script:ClientConfiguration = @( - -# TODO #9048: - # Configuration.Http: -# @{Name = "COREFX_HTTPHOST"; Value = $script:iisServerFQDN}, -# @{Name = "COREFX_SECUREHTTPHOST"; Value = $script:iisServerFQDN}, -# @{Name = "COREFX_HTTP2HOST"; Value = $script:iisServerFQDN}, # Requires Windows 10 and above. -# @{Name = "COREFX_DOMAINJOINED_HTTPHOST"; Value = $script:iisServerFQDN}, -# @{Name = "COREFX_DOMAINJOINED_PROXYHOST"; Value = $null}, # TODO 9048: Install & configure ISA/TMG or Squid -# @{Name = "COREFX_DOMAINJOINED_PROXYPORT"; Value = $null}, # TODO 9048: Install & configure ISA/TMG or Squid -# @{Name = "COREFX_HTTPHOST_SSL2"; Value = $null}, # TODO 9048: move to a localhost server or configure these websites. -# @{Name = "COREFX_HTTPHOST_SSL3"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_TLS10"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_TLS11"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_TLS12"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_EXPIREDCERT"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_WRONGHOSTNAME"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_SELFSIGNEDCERT"; Value = $null}, -# @{Name = "COREFX_HTTPHOST_REVOKEDCERT"; Value = $null}, -# @{Name = "COREFX_STRESS_HTTP"; Value = "1"}, - - # Configuration.WebSockets: -# @{Name = "COREFX_WEBSOCKETHOST"; Value = $script:domainNetbios}, -# @{Name = "COREFX_SECUREWEBSOCKETHOST"; Value = $script:domainNetbios}, - - # Configuration.Security: - @{Name = "COREFX_NET_AD_DOMAINNAME"; Value = $script:domainNetbios}, - @{Name = "COREFX_NET_AD_USERNAME"; Value = $script:domainUserName}, - @{Name = "COREFX_NET_AD_PASSWORD"; Value = $script:domainUserPassword}, - @{Name = "COREFX_NET_SECURITY_NEGOSERVERURI"; Value = "http://$($script:iisServerFQDN)"}, - @{Name = "COREFX_NET_SECURITY_TLSSERVERURI"; Value = "https://$($script:iisServerFQDN)"}, - - @{Name = "COREFX_NET_SOCKETS_SERVERURI"; Value = "http://$($script:iisServerFQDN)"} -) diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 new file mode 100644 index 0000000..04a2243 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 @@ -0,0 +1,60 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +# +# CoreFX - Net configuration +# + +# -- Machine Information + +# You can find the host name by logging on to the target machine and typing "hostname" in a cmd console. +# You can find the IP address by logging on to the target machine and typing "ipconfig" in a cmd console. +# Requirements: +# - The machines below should be within the same LAN network. +# - All machines must have Powershell >3.0 installed. + +# IMPORTANT: +# The state for the following machines will be changed irreversably. +# The uninstall step will remove the installed components regardless if it existed before the deployment or +# was altered/customized after deployment. +# + +# A Windows Server SKU hosting Active Directory services. This machine will become the Domain Controller: +$COREFX_NET_AD_Machine = "" #Example: "TESTAD" +$COREFX_NET_AD_MachineIP = "" #Example: "192.168.0.1" - must be a Static IPv4 address. + +# A Windows Client or Server SKU hosting the IIS Server. This machine will be joined to the Domain. +$COREFX_NET_IISSERVER_Machine = "" #Example: "TESTIIS" +$COREFX_NET_IISSERVER_MachineIP = "" #Example: "192.168.0.1" - must be a Static IPv4 address. + +# A Windows Client or Server SKU hosting the corefx enlistment. This machine will be joined to the Domain. +$COREFX_NET_CLIENT_Machine = "" #Example: "TESTCLIENT" + +# -- Test Parameters + +# For security reasons, it's advisable that the default username/password pairs below are changed regularly. + +$script:domainName = "corp.contoso.com" +$script:domainNetbios = "corefx-net-ad" + +$script:domainUserName = "testaduser" +$script:domainUserPassword = "Test-ADPassword" + +$script:basicUserName = "testbasic" +$script:basicUserPassword = "Test-Basic" + +# Changing the IISServer FQDN may require changing certificates. +$script:iisServerFQDN = "testserver.contoso.com" + +$script:PreRebootRoles = @( + @{Name = "COREFX_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $COREFX_NET_IISSERVER_Machine}, + @{Name = "COREFX_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $COREFX_NET_CLIENT_Machine}, + @{Name = "COREFX_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $COREFX_NET_AD_Machine; MachineIP = $COREFX_NET_AD_MachineIP} +) + +$script:Roles = @( + @{Name = "COREFX_NET_IISSERVER"; Script = "setup_iisserver.ps1"; MachineName = $COREFX_NET_IISSERVER_Machine; MachineIP = $COREFX_NET_IISSERVER_MachineIP}, + @{Name = "COREFX_NET_CLIENT"; Script = "setup_client.ps1"; MachineName = $COREFX_NET_CLIENT_Machine}, + @{Name = "COREFX_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $COREFX_NET_AD_Machine; MachineIP = $COREFX_NET_AD_MachineIP} +) diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 similarity index 94% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 index 961e024..ffe440d 100644 --- a/src/libraries/Common/tests/Scripts/Prerequisites/setup.ps1 +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 @@ -39,6 +39,13 @@ Function TestMachineStatus($role) Function CheckRoles { + Write-Host "Verifying server applications:" + $iisApplications = GetIISCodePath + if (-not (Test-Path (Join-Path $iisApplications "index.html"))) + { + throw "Cannot find index.html within the $iisApplications path. Make sure that you have built and copied the Server code before running this script." + } + Write-Host "Verifying roles:" foreach ($role in ($script:Roles + $script:PreRebootRoles)) { @@ -93,10 +100,7 @@ Function CreateDestinationPath($s) Function CopyScripts($s, $remotePath) { - foreach ($file in (dir *.ps1)) - { - Copy-Item -Force -Path $file -Destination $remotePath -ToSession $s -ErrorAction Stop - } + Copy-Item -Recurse -Force -Path ".\*" -Destination $remotePath -ToSession $s -ErrorAction Stop } Function InstallRoles diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_activedirectory_client.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_client.ps1 similarity index 100% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_activedirectory_client.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_client.ps1 diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_activedirectory_domaincontroller.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 similarity index 98% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_activedirectory_domaincontroller.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 index 4c108ce..ddcc22c 100644 --- a/src/libraries/Common/tests/Scripts/Prerequisites/setup_activedirectory_domaincontroller.ps1 +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 @@ -41,7 +41,6 @@ Function ConfigureDNS { Write-Host -ForegroundColor Cyan "Configuring DNS." - # TODO: Extract IIS Machine IP from Config. $iisServer = GetRole "COREFX_NET_IISSERVER" $serverName = ($script:iisServerFQDN).Split('.')[0]; diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_certificates.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_certificates.ps1 similarity index 100% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_certificates.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_certificates.ps1 diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_client.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_client.ps1 similarity index 100% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_client.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_client.ps1 diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_common.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 similarity index 63% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_common.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 index 63483fc6..9a28524 100644 --- a/src/libraries/Common/tests/Scripts/Prerequisites/setup_common.ps1 +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 @@ -4,6 +4,41 @@ . .\config.ps1 +# The following variable names should match the ones read by Configuration.*.cs code. +$script:ClientConfiguration = @( + + # Configuration.Http: + @{Name = "COREFX_HTTPHOST"; Value = $script:iisServerFQDN}, + @{Name = "COREFX_SECUREHTTPHOST"; Value = $script:iisServerFQDN}, + @{Name = "COREFX_HTTP2HOST"; Value = $script:iisServerFQDN}, # Requires Windows 10 and above. + @{Name = "COREFX_DOMAINJOINED_HTTPHOST"; Value = $script:iisServerFQDN}, + @{Name = "COREFX_DOMAINJOINED_PROXYHOST"; Value = $null}, + @{Name = "COREFX_DOMAINJOINED_PROXYPORT"; Value = $null}, + @{Name = "COREFX_HTTPHOST_SSL2"; Value = $null}, + @{Name = "COREFX_HTTPHOST_SSL3"; Value = $null}, + @{Name = "COREFX_HTTPHOST_TLS10"; Value = $null}, + @{Name = "COREFX_HTTPHOST_TLS11"; Value = $null}, + @{Name = "COREFX_HTTPHOST_TLS12"; Value = $null}, + @{Name = "COREFX_HTTPHOST_EXPIREDCERT"; Value = $null}, + @{Name = "COREFX_HTTPHOST_WRONGHOSTNAME"; Value = $null}, + @{Name = "COREFX_HTTPHOST_SELFSIGNEDCERT"; Value = $null}, + @{Name = "COREFX_HTTPHOST_REVOKEDCERT"; Value = $null}, + @{Name = "COREFX_STRESS_HTTP"; Value = "1"}, + + # Configuration.WebSockets: + @{Name = "COREFX_WEBSOCKETHOST"; Value = $script:iisServerFQDN}, + @{Name = "COREFX_SECUREWEBSOCKETHOST"; Value = $script:iisServerFQDN}, + + # Configuration.Security: + @{Name = "COREFX_NET_AD_DOMAINNAME"; Value = $script:domainNetbios}, + @{Name = "COREFX_NET_AD_USERNAME"; Value = $script:domainUserName}, + @{Name = "COREFX_NET_AD_PASSWORD"; Value = $script:domainUserPassword}, + @{Name = "COREFX_NET_SECURITY_NEGOSERVERURI"; Value = "http://$($script:iisServerFQDN)"}, + @{Name = "COREFX_NET_SECURITY_TLSSERVERURI"; Value = "https://$($script:iisServerFQDN)"}, + + @{Name = "COREFX_NET_SOCKETS_SERVERURI"; Value = "http://$($script:iisServerFQDN)"} +) + Function GetRoleForMachine($machineName) { return $script:Roles | where {$_.MachineName.ToUpper() -eq $machineName.ToUpper()} @@ -108,3 +143,8 @@ Function DownloadFile($source, $destination) $wc.Downloadfile($source, $fqDestination.ToString()) } } + +Function GetIISCodePath +{ + return ".\IISApplications" +} diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_firewall.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_firewall.ps1 similarity index 100% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_firewall.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_firewall.ps1 diff --git a/src/libraries/Common/tests/Scripts/Prerequisites/setup_iisserver.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 similarity index 84% rename from src/libraries/Common/tests/Scripts/Prerequisites/setup_iisserver.ps1 rename to src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 index e23f001..8a91726 100644 --- a/src/libraries/Common/tests/Scripts/Prerequisites/setup_iisserver.ps1 +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 @@ -19,23 +19,20 @@ Param ( . .\setup_firewall.ps1 # Server application configuration -$script:serverCodeUri = "https://github.com/davidsh/corefx-net-testservers/archive/master.zip" -$script:serverCodeZip = "serverCode" $script:iisWwwRoot = "$env:systemdrive\inetpub\wwwroot" -$script:serverCodeRootPath = "$($script:serverCodeZip)\corefx-net-testservers-master\CoreFxNetCloudService" $script:defaultWebSite = "Default Web Site" $script:webApps = @( @{Name = "NoAuth"; IISRelativePath = ""; - SourceRelativePath = "WebServer"; + SourceRelativePath = ".\"; Configuration = @() }, @{Name = "BasicAuth"; IISRelativePath = "BasicAuth"; - SourceRelativePath = "WebServer"; + SourceRelativePath = "\"; Configuration = @( @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } @{ Path = "/system.webServer/security/authentication/basicAuthentication"; Name = "Enabled"; Value = "True" } @@ -45,7 +42,7 @@ $script:webApps = @( @{Name = "DigestAuth"; IISRelativePath = "DigestAuth"; - SourceRelativePath = "WebServer"; + SourceRelativePath = "\"; Configuration = @( @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } @{ Path = "/system.webServer/security/authentication/digestAuthentication"; Name = "Enabled"; Value = "True" } @@ -55,7 +52,7 @@ $script:webApps = @( @{Name = "WindowsAuth"; IISRelativePath = "WindowsAuth"; - SourceRelativePath = "WebServer"; + SourceRelativePath = "\"; Configuration = @( @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } @{ Path = "/system.webServer/security/authentication/windowsAuthentication"; Name = "Enabled"; Value = "True" } @@ -92,23 +89,6 @@ Function RemoveLocalUser Remove-LocalUser $script:basicUserName -Confirm:$false } -Function DeleteTemporaryFiles -{ - if (Test-Path $script:serverCodeZip) - { - rmdir $script:serverCodeZip -Recurse -Force - } - - del ($script:serverCodeZip + ".zip") -ErrorAction SilentlyContinue -} - -Function DownloadServerCode -{ - DeleteTemporaryFiles - DownloadFile $script:serverCodeUri ($script:serverCodeZip + ".zip") - Expand-Archive ($script:serverCodeZip + ".zip") -} - Function ConfigureWebSites { Write-Host -ForegroundColor Cyan "Configuring IIS websites." @@ -136,10 +116,8 @@ Function GrantUserAccess($path, $userAccess) Function InstallServerCode { - Write-Host -ForegroundColor Cyan "Acquiring server code." - DownloadServerCode - Write-Host -ForegroundColor Cyan "Installing applications." + $serverCodeRootPath = GetIISCodePath foreach ($app in $script:webApps) { @@ -156,7 +134,7 @@ Function InstallServerCode Write-Host "`tAdding $($app.Name)" - $tempPath = Join-Path $script:serverCodeRootPath $app.SourceRelativePath + $tempPath = Join-Path $serverCodeRootPath $app.SourceRelativePath mkdir $appPath -ErrorAction SilentlyContinue | Out-Null Copy-Item ($tempPath + "\*") $appPath -Recurse -ErrorAction Stop @@ -169,9 +147,6 @@ Function InstallServerCode GrantUserAccess $appPath $app.UserAccess } - - Write-Host "Removing temporary files." - DeleteTemporaryFiles } Function RemoveServerCode @@ -198,8 +173,6 @@ Function Install InstallServerFirewall EnvironmentSetInstalledRoleStatus - # TODO: - # - Grant AD user permissions for all auth methods and sites. } Function Uninstall diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/README.md b/src/libraries/Common/tests/System/Net/Prerequisites/README.md new file mode 100644 index 0000000..568c1c3 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/README.md @@ -0,0 +1,44 @@ +# System.Net Test Prerequisites +Contains source files for the networking test servers in Azure or a private IIS deployment. + +## Deployment Instructions for a private multi-machine environment + +### Configuration + +1. Open .\Deployment\config.ps1 in an editor. +2. Fill in the _Machine Selection_ section with the names and IP addresses of the target machines. In most cases the default options for _Test Parameters_ should be enough. + +Note: the `config.ps1` file has been added to .gitignore to prevent it being updated in the master branch. + +### Build the server applications + +From a Visual Studio command prompt: + +``` + powershell + cd .\Servers + .\buildAndPackage.ps1 +``` + +You should now find a folder named `IISApplications` within the Deployment folder. + +### (only once) Create the Active Directory and join all machines + +Skip this step if previously completed and all machines are already part of a domain to which you have Administrator rights. +This will join all machines to a test Active Directory and enable Windows Remoting. + +1. Copy the Deployment folder to each of the machines. +2. Run the .\setup.ps1 script on the machine designated to become the Domain Controller. Once complete, the machine will reboot. +3. Run the .\setup.ps1 script on all other domain joined machines. Once complete, the machines will reboot. + +### Install or Update the environment + +Running as the Active Directory Administrator, run .\setup.ps1 from the client machine's enlistment. +The script will use WinRM to connect and update all other roles. + +## Deployment Instructions to update the Azure-based environment + +1. Create a _Classic_ Azure WebService role. +2. Create a server certificate and add it to the subscription with the name: `CoreFxNetCertificate` +3. Edit `Servers\CoreFxNetCloudService\CoreFxNetCloudService\ServiceConfiguration.Cloud.cscfg` and ensure that the `CoreFxNetCertificate` `thumbprint` and `thumbprintAlgorithm` are correct. +4. Open the solution in Visual Studio and Run the Azure Publishing wizard to create and deploy the application. diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService.sln b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService.sln new file mode 100644 index 0000000..b905dfa --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "CoreFxNetCloudService", "CoreFxNetCloudService\CoreFxNetCloudService.ccproj", "{57E639CE-BD4D-4CB3-A913-AE51E18CD4A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebServer", "WebServer\WebServer.csproj", "{6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57E639CE-BD4D-4CB3-A913-AE51E18CD4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57E639CE-BD4D-4CB3-A913-AE51E18CD4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57E639CE-BD4D-4CB3-A913-AE51E18CD4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57E639CE-BD4D-4CB3-A913-AE51E18CD4A0}.Release|Any CPU.Build.0 = Release|Any CPU + {6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/CoreFxNetCloudService.ccproj b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/CoreFxNetCloudService.ccproj new file mode 100644 index 0000000..b5c547f --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/CoreFxNetCloudService.ccproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + 2.9 + 57e639ce-bd4d-4cb3-a913-ae51e18cd4a0 + Library + Properties + CoreFxNetCloudService + CoreFxNetCloudService + True + CoreFxNetCloudService + False + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + WebServer + {6acff710-5f63-4e46-b0da-0d1fe36ef4a7} + True + Web + WebServer + True + + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.9\ + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Cloud.cscfg b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Cloud.cscfg new file mode 100644 index 0000000..b86cecd --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Cloud.cscfg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Local.cscfg b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Local.cscfg new file mode 100644 index 0000000..7b9e8a7 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceConfiguration.Local.cscfg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceDefinition.csdef b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceDefinition.csdef new file mode 100644 index 0000000..ca934aa --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ServiceDefinition.csdef @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/WebServerContent/diagnostics.wadcfgx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/WebServerContent/diagnostics.wadcfgx new file mode 100644 index 0000000..4ff2f0a --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/WebServerContent/diagnostics.wadcfgx @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ecf/WebServerContent/diagnostics.wadcfgx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ecf/WebServerContent/diagnostics.wadcfgx new file mode 100644 index 0000000..b85e92a --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/CoreFxNetCloudService/ecf/WebServerContent/diagnostics.wadcfgx @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + devstoreaccount1 + + + + + true + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/AuthenticationHelper.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/AuthenticationHelper.cs new file mode 100644 index 0000000..b495712 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/AuthenticationHelper.cs @@ -0,0 +1,122 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; + +namespace WebServer +{ + public static class AuthenticationHelper + { + public static bool HandleAuthentication(HttpContext context) + { + string authType = context.Request.QueryString["auth"]; + string user = context.Request.QueryString["user"]; + string password = context.Request.QueryString["password"]; + string domain = context.Request.QueryString["domain"]; + + if (string.Equals("basic", authType, StringComparison.OrdinalIgnoreCase)) + { + if (!HandleBasicAuthentication(context, user, password, domain)) + { + context.Response.End(); + return false; + } + } + else if (string.Equals("Negotiate", authType, StringComparison.OrdinalIgnoreCase) || + string.Equals("NTLM", authType, StringComparison.OrdinalIgnoreCase)) + { + if (!HandleChallengeResponseAuthentication(context, authType, user, password, domain)) + { + context.Response.End(); + return false; + } + } + else if (authType != null) + { + context.Response.StatusCode = 501; + context.Response.StatusDescription = "Unsupported auth type: " + authType; + context.Response.End(); + return false; + } + + return true; + } + + private static bool HandleBasicAuthentication(HttpContext context, string user, string password, string domain) + { + const string WwwAuthenticateHeaderValue = "Basic realm=\"corefx-networking\""; + + string authHeader = context.Request.Headers["Authorization"]; + if (authHeader == null) + { + context.Response.StatusCode = 401; + context.Response.Headers.Add("WWW-Authenticate", WwwAuthenticateHeaderValue); + return false; + } + + string[] split = authHeader.Split(new Char[] { ' ' }); + if (split.Length < 2) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Invalid Authorization header: " + authHeader; + return false; + } + + if (!string.Equals("basic", split[0], StringComparison.OrdinalIgnoreCase)) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Unsupported auth type: " + split[0]; + return false; + } + + // Decode base64 username:password. + byte[] bytes = Convert.FromBase64String(split[1]); + string credential = Encoding.ASCII.GetString(bytes); + string[] pair = credential.Split(new Char[] { ':' }); + + // Prefix "domain\" to username if domain is specified. + if (domain != null) + { + user = domain + "\\" + user; + } + + if (pair.Length != 2 || pair[0] != user || pair[1] != password) + { + context.Response.StatusCode = 401; + context.Response.Headers.Add("WWW-Authenticate", WwwAuthenticateHeaderValue); + return false; + } + + // Success. + return true; + } + private static bool HandleChallengeResponseAuthentication( + HttpContext context, + string authType, + string user, + string password, + string domain) + { + string authHeader = context.Request.Headers["Authorization"]; + if (authHeader == null) + { + context.Response.StatusCode = 401; + context.Response.Headers.Add("WWW-Authenticate", authType); + return false; + } + + // We don't fully support this authentication method. + context.Response.StatusCode = 501; + context.Response.StatusDescription = string.Format( + "Attempt to use unsupported challenge/response auth type. {0}: {1}", + authType, + authHeader); + return false; + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/ContentHelper.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/ContentHelper.cs new file mode 100644 index 0000000..f175428 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/ContentHelper.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using System.IO.Compression; +using System.Security.Cryptography; +using System.Text; + +namespace WebServer +{ + public static class ContentHelper + { + public static byte[] GetDeflateBytes(string data) + { + byte[] bytes = Encoding.UTF8.GetBytes(data); + var compressedStream = new MemoryStream(); + + using (var compressor = new DeflateStream(compressedStream, CompressionMode.Compress, true)) + { + compressor.Write(bytes, 0, bytes.Length); + } + + return compressedStream.ToArray(); + } + + public static byte[] GetGZipBytes(string data) + { + byte[] bytes = Encoding.UTF8.GetBytes(data); + var compressedStream = new MemoryStream(); + + using (var compressor = new GZipStream(compressedStream, CompressionMode.Compress, true)) + { + compressor.Write(bytes, 0, bytes.Length); + } + + return compressedStream.ToArray(); + } + + public static byte[] ComputeMD5Hash(string data) + { + return ComputeMD5Hash(Encoding.UTF8.GetBytes(data)); + } + + public static byte[] ComputeMD5Hash(byte[] data) + { + using (MD5 md5 = MD5.Create()) + { + return md5.ComputeHash(data); + } + } + } +} \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx new file mode 100644 index 0000000..2a039a0 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="Deflate.ashx.cs" Class="WebServer.Deflate" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx.cs new file mode 100644 index 0000000..889241a --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Deflate.ashx.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Web; + +namespace WebServer +{ + /// + /// Summary description for Deflate + /// + public class Deflate : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + string responseBody = "Sending DEFLATE compressed"; + + context.Response.Headers.Add("Content-MD5", Convert.ToBase64String(ContentHelper.ComputeMD5Hash(responseBody))); + context.Response.Headers.Add("Content-Encoding", "deflate"); + + context.Response.ContentType = "text/plain"; + + byte[] bytes = ContentHelper.GetDeflateBytes(responseBody); + context.Response.BinaryWrite(bytes); + } + + public bool IsReusable + { + get + { + return true; + } + } + } +} \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx new file mode 100644 index 0000000..05b6037 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="Echo.ashx.cs" Class="WebServer.Echo" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx.cs new file mode 100644 index 0000000..d029666 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Echo.ashx.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Security.Cryptography; +using System.Text; +using System.Web; + +namespace WebServer +{ + public class Echo : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + RequestHelper.AddResponseCookies(context); + + if (!AuthenticationHelper.HandleAuthentication(context)) + { + context.Response.End(); + return; + } + + // Add original request method verb as a custom response header. + context.Response.Headers.Add("X-HttpRequest-Method", context.Request.HttpMethod); + + // Echo back JSON encoded payload. + RequestInformation info = RequestInformation.Create(context.Request); + string echoJson = info.SerializeToJson(); + + // Compute MD5 hash to clients can verify the received data. + using (MD5 md5 = MD5.Create()) + { + byte[] bytes = Encoding.UTF8.GetBytes(echoJson); + byte[] hash = md5.ComputeHash(bytes); + string encodedHash = Convert.ToBase64String(hash); + + context.Response.Headers.Add("Content-MD5", encodedHash); + context.Response.ContentType = "application/json"; + context.Response.Write(echoJson); + } + + context.Response.End(); + } + + public bool IsReusable + { + get + { + return true; + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx new file mode 100644 index 0000000..a647c9a --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="EmptyContent.ashx.cs" Class="WebServer.EmptyContent" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx.cs new file mode 100644 index 0000000..fae32f6 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/EmptyContent.ashx.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace WebServer +{ + /// + /// Summary description for EmptyContent + /// + public class EmptyContent : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + // By default, this empty method sends back a 200 status code with 'Content-Length: 0' response header. + // There are no other entity-body related (i.e. 'Content-Type') headers returned. + } + + public bool IsReusable + { + get + { + return true; + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx new file mode 100644 index 0000000..b6ee5e1 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="GZip.ashx.cs" Class="WebServer.GZip" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx.cs new file mode 100644 index 0000000..157d2f4 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/GZip.ashx.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Web; + +namespace WebServer +{ + /// + /// Summary description for Gzip + /// + public class GZip : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + string responseBody = "Sending GZIP compressed"; + + context.Response.Headers.Add("Content-MD5", Convert.ToBase64String(ContentHelper.ComputeMD5Hash(responseBody))); + context.Response.Headers.Add("Content-Encoding", "gzip"); + + context.Response.ContentType = "text/plain"; + + byte[] bytes = ContentHelper.GetGZipBytes(responseBody); + context.Response.BinaryWrite(bytes); + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/NameValueCollectionConverter.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/NameValueCollectionConverter.cs new file mode 100644 index 0000000..98c70e2 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/NameValueCollectionConverter.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Specialized; + +using Newtonsoft.Json; + +namespace WebServer +{ + public class NameValueCollectionConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var collection = value as NameValueCollection; + if (collection == null) + { + return; + } + + writer.Formatting = Formatting.Indented; + writer.WriteStartObject(); + foreach (var key in collection.AllKeys) + { + writer.WritePropertyName(key); + writer.WriteValue(collection.Get(key)); + } + writer.WriteEndObject(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var nameValueCollection = new NameValueCollection(); + var key = ""; + while (reader.Read()) + { + if (reader.TokenType == JsonToken.StartObject) + { + nameValueCollection = new NameValueCollection(); + } + if (reader.TokenType == JsonToken.EndObject) + { + return nameValueCollection; + } + if (reader.TokenType == JsonToken.PropertyName) + { + key = reader.Value.ToString(); + } + if (reader.TokenType == JsonToken.String) + nameValueCollection.Add(key, reader.Value.ToString()); + } + return nameValueCollection; + } + + public override bool CanConvert(Type objectType) + { + return IsTypeDerivedFromType(objectType, typeof(NameValueCollection)); + } + + private bool IsTypeDerivedFromType(Type childType, Type parentType) + { + Type testType = childType; + while (testType != null) + { + if (testType == parentType) + { + return true; + } + + testType = testType.BaseType; + } + + return false; + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/AssemblyInfo.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7affb0b --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/AssemblyInfo.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WebServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WebServer")] +[assembly: AssemblyCopyright("Copyright \u00A9 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6acff710-5f63-4e46-b0da-0d1fe36ef4a7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_CHK.pubxml b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_CHK.pubxml new file mode 100644 index 0000000..8850922 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_CHK.pubxml @@ -0,0 +1,17 @@ + + + + + FileSystem + Debug + Any CPU + + True + False + .\PublishToIIS + False + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_RET.pubxml b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_RET.pubxml new file mode 100644 index 0000000..15494e5 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Properties/PublishProfiles/IIS_PublishToLocalPath_RET.pubxml @@ -0,0 +1,17 @@ + + + + + FileSystem + Release + Any CPU + + True + False + .\PublishToIIS + False + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx new file mode 100644 index 0000000..819e88e --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="Redirect.ashx.cs" Class="WebServer.Redirect" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx.cs new file mode 100644 index 0000000..e1e0554 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Redirect.ashx.cs @@ -0,0 +1,89 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Web; + +namespace WebServer +{ + /// + /// Summary description for Redirect + /// + public class Redirect : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + int statusCode = 302; + string statusCodeString = context.Request.QueryString["statuscode"]; + if (!string.IsNullOrEmpty(statusCodeString)) + { + try + { + statusCode = int.Parse(statusCodeString); + if (statusCode < 300 || statusCode > 307) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Invalid redirect statuscode: " + statusCodeString; + return; + } + } + catch (Exception) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Error parsing statuscode: " + statusCodeString; + return; + } + } + + string redirectUri = context.Request.QueryString["uri"]; + if (string.IsNullOrEmpty(redirectUri)) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Missing redirection uri"; + return; + } + + string hopsString = context.Request.QueryString["hops"]; + int hops = 1; + if (!string.IsNullOrEmpty(hopsString)) + { + try + { + hops = int.Parse(hopsString); + } + catch (Exception) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Error parsing hops: " + hopsString; + return; + } + } + + RequestHelper.AddResponseCookies(context); + + if (hops <= 1) + { + context.Response.Headers.Add("Location", redirectUri); + } + else + { + context.Response.Headers.Add( + "Location", + string.Format("/Redirect.ashx?uri={0}&hops={1}", + redirectUri, + hops - 1)); + } + + context.Response.StatusCode = statusCode; + } + + public bool IsReusable + { + get + { + return true; + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestHelper.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestHelper.cs new file mode 100644 index 0000000..a470212 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestHelper.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Net; +using System.Web; + +namespace WebServer +{ + public static class RequestHelper + { + public static void AddResponseCookies(HttpContext context) + { + // Turn all 'X-SetCookie' request headers into 'Set-Cookie' response headers. + string headerName; + string headerValue; + for (int i = 0; i < context.Request.Headers.Count; i++) + { + headerName = context.Request.Headers.Keys[i]; + headerValue = context.Request.Headers[i]; + + if (string.Equals(headerName, "X-SetCookie", StringComparison.OrdinalIgnoreCase)) + { + context.Response.Headers.Add("Set-Cookie", headerValue); + } + } + } + + public static CookieCollection GetRequestCookies(HttpRequest request) + { + var cookieCollection = new CookieCollection(); + HttpCookieCollection cookies = request.Cookies; + + for (int i = 0; i < cookies.Count; i++) + { + var cookie = new Cookie(cookies[i].Name, cookies[i].Value); + cookieCollection.Add(cookie); + } + + return cookieCollection; + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestInformation.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestInformation.cs new file mode 100644 index 0000000..b923bef --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/RequestInformation.cs @@ -0,0 +1,87 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Specialized; +using System.IO; +using System.Net; +using System.Web; + +using Newtonsoft.Json; + +namespace WebServer +{ + public class RequestInformation + { + public string Method { get; private set; } + + public string Url { get; private set; } + + public NameValueCollection Headers { get; private set; } + + public NameValueCollection Cookies { get; private set; } + + public string BodyContent { get; private set; } + + public int BodyLength { get; private set; } + + public bool SecureConnection { get; private set; } + + public bool ClientCertificatePresent { get; private set; } + + public HttpClientCertificate ClientCertificate { get; private set; } + + public static RequestInformation Create(HttpRequest request) + { + var info = new RequestInformation(); + info.Method = request.HttpMethod; + info.Url = request.RawUrl; + info.Headers = request.Headers; + + var cookies = new NameValueCollection(); + CookieCollection cookieCollection = RequestHelper.GetRequestCookies(request); + foreach (Cookie cookie in cookieCollection) + { + cookies.Add(cookie.Name, cookie.Value); + } + info.Cookies = cookies; + + Stream stream = request.GetBufferedInputStream(); + using (var reader = new StreamReader(stream)) + { + string body = reader.ReadToEnd(); + info.BodyContent = body; + info.BodyLength = body.Length; + } + + info.SecureConnection = request.IsSecureConnection; + + var cs = request.ClientCertificate; + info.ClientCertificatePresent = cs.IsPresent; + if (cs.IsPresent) + { + info.ClientCertificate = request.ClientCertificate; + } + + return info; + } + + public static RequestInformation DeSerializeFromJson(string json) + { + return (RequestInformation)JsonConvert.DeserializeObject( + json, + typeof(RequestInformation), + new NameValueCollectionConverter()); + } + + public string SerializeToJson() + { + return JsonConvert.SerializeObject(this, new NameValueCollectionConverter()); + } + + private RequestInformation() + { + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx new file mode 100644 index 0000000..ea27244 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="StatusCode.ashx.cs" Class="WebServer.StatusCode" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx.cs new file mode 100644 index 0000000..e491755 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/StatusCode.ashx.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Web; + +namespace WebServer +{ + public class StatusCode : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + string statusCodeString = context.Request.QueryString["statuscode"]; + string statusDescription = context.Request.QueryString["statusdescription"]; + try + { + int statusCode = int.Parse(statusCodeString); + context.Response.StatusCode = statusCode; + if (statusDescription != null) + { + context.Response.StatusDescription = statusDescription; + } + } + catch (Exception) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Error parsing statuscode: " + statusCodeString; + } + } + + public bool IsReusable + { + get + { + return true; + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx new file mode 100644 index 0000000..07bfc94 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="Test.ashx.cs" Class="WebServer.Test" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx.cs new file mode 100644 index 0000000..a26c34b --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Test.ashx.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Net; +using System.Net.Http; +using System.Security.Cryptography; +using System.Text; +using System.Web; + +using Newtonsoft.Json; + +namespace WebServer +{ + public class Test : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + RequestInformation info = RequestInformation.Create(context.Request); + + string echoJson = info.SerializeToJson(); + + // Compute MD5 hash to clients can verify the received data. + MD5 md5 = MD5.Create(); + byte[] bytes = Encoding.ASCII.GetBytes(echoJson); + var hash = md5.ComputeHash(bytes); + string encodedHash = Convert.ToBase64String(hash); + context.Response.Headers.Add("Content-MD5", encodedHash); + + RequestInformation newEcho = RequestInformation.DeSerializeFromJson(echoJson); + context.Response.ContentType = "text/plain"; //"application/json"; + context.Response.Write(echoJson); + } + + public bool IsReusable + { + get + { + return false; + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx new file mode 100644 index 0000000..c50104d --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="VerifyUpload.ashx.cs" Class="WebServer.VerifyUpload" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx.cs new file mode 100644 index 0000000..5d9f507 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/VerifyUpload.ashx.cs @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using System.Security.Cryptography; +using System.Web; + +namespace WebServer +{ + public class VerifyUpload : IHttpHandler + { + public void ProcessRequest(HttpContext context) + { + // Report back original request method verb. + context.Response.Headers.Add("X-HttpRequest-Method", context.Request.HttpMethod); + + // Report back original entity-body related request headers. + string contentLength = context.Request.Headers["Content-Length"]; + if (!string.IsNullOrEmpty(contentLength)) + { + context.Response.Headers.Add("X-HttpRequest-Headers-ContentLength", contentLength); + } + + string transferEncoding = context.Request.Headers["Transfer-Encoding"]; + if (!string.IsNullOrEmpty(transferEncoding)) + { + context.Response.Headers.Add("X-HttpRequest-Headers-TransferEncoding", transferEncoding); + } + + // Get expected MD5 hash of request body. + string expectedHash = context.Request.Headers["Content-MD5"]; + if (string.IsNullOrEmpty(expectedHash)) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Missing 'Content-MD5' request header"; + return; + } + + // Compute MD5 hash of received request body. + string actualHash; + using (MD5 md5 = MD5.Create()) + { + byte[] hash = md5.ComputeHash(ReadAllRequestBytes(context)); + actualHash = Convert.ToBase64String(hash); + } + + if (expectedHash == actualHash) + { + context.Response.StatusCode = 200; + } + else + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = "Request body not verfied"; + } + } + + public bool IsReusable + { + get + { + return true; + } + } + + private static byte[] ReadAllRequestBytes(HttpContext context) + { + Stream requestStream = context.Request.GetBufferedInputStream(); + byte[] buffer = new byte[16 * 1024]; + using (MemoryStream ms = new MemoryStream()) + { + int read; + while ((read = requestStream.Read(buffer, 0, buffer.Length)) > 0) + { + ms.Write(buffer, 0, read); + } + return ms.ToArray(); + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Debug.config b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Debug.config new file mode 100644 index 0000000..2e302f9 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Debug.config @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Release.config b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Release.config new file mode 100644 index 0000000..c3584446 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.Release.config @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.config b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.config new file mode 100644 index 0000000..1474319 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/Web.config @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebRole.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebRole.cs new file mode 100644 index 0000000..6d41a09 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebRole.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.WindowsAzure; +using Microsoft.WindowsAzure.Diagnostics; +using Microsoft.WindowsAzure.ServiceRuntime; + +namespace WebServer +{ + public class WebRole : RoleEntryPoint + { + public override bool OnStart() + { + // For information on handling configuration changes + // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. + + return base.OnStart(); + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebServer.csproj b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebServer.csproj new file mode 100644 index 0000000..d8f66c7 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebServer.csproj @@ -0,0 +1,209 @@ + + + + + + + Debug + AnyCPU + + + 2.0 + {6ACFF710-5F63-4E46-B0DA-0D1FE36EF4A7} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + WebServer + WebServer + v4.5.1 + true + + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + True + + + + ..\packages\Microsoft.Data.Edm.5.6.2\lib\net40\Microsoft.Data.Edm.dll + True + + + ..\packages\Microsoft.Data.OData.5.6.2\lib\net40\Microsoft.Data.OData.dll + True + + + ..\packages\Microsoft.Data.Services.Client.5.6.2\lib\net40\Microsoft.Data.Services.Client.dll + True + + + ..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll + True + + + True + + + False + + + ..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll + True + + + ..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll + True + + + + + ..\packages\System.Spatial.5.6.2\lib\net40\System.Spatial.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + Web.config + + + + + + + Designer + + + + + + + Deflate.ashx + + + Echo.ashx + + + EmptyContent.ashx + + + GZip.ashx + + + + + Redirect.ashx + + + + + StatusCode.ashx + + + Test.ashx + + + VerifyUpload.ashx + + + + EchoWebSocket.ashx + + + EchoWebSocketHeaders.ashx + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 42127 + / + http://localhost:42127/ + False + False + + + False + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/Default.htm b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/Default.htm new file mode 100644 index 0000000..105c4b5 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/Default.htm @@ -0,0 +1,14 @@ + + + + + +

Redirecting to the websocket.org test client in 5 seconds...

+ +

Use the following URIs to test the local endpoint:

+
+    ws://testserver.contoso.com/WebSocket/EchoWebSocket.ashx
+    wss://testserver.contoso.com/WebSocket/EchoWebSocket.ashx
+    
+ + diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx new file mode 100644 index 0000000..411704b --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="EchoWebSocket.ashx.cs" Class="WebServer.EchoWebSocket" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx.cs new file mode 100644 index 0000000..815778b --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocket.ashx.cs @@ -0,0 +1,165 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Net.WebSockets; +using System.Web; +using System.Web.WebSockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace WebServer +{ + public class EchoWebSocket : IHttpHandler + { + private const int MaxBufferSize = 128 * 1024; + + public void ProcessRequest(HttpContext context) + { + string subProtocol = context.Request.QueryString["subprotocol"]; + + if (context.Request.Url.Query == "?delay10sec") + { + Thread.Sleep(10000); + } + + try + { + if (!context.IsWebSocketRequest) + { + context.Response.StatusCode = 200; + context.Response.ContentType = "text/plain"; + context.Response.Write("Not a websocket request"); + + return; + } + + if (!string.IsNullOrEmpty(subProtocol)) + { + var wsOptions = new AspNetWebSocketOptions(); + wsOptions.SubProtocol = subProtocol; + + context.AcceptWebSocketRequest(ProcessWebSocketRequest, wsOptions); + } + else + { + context.AcceptWebSocketRequest(ProcessWebSocketRequest); + } + } + catch (Exception ex) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = ex.Message; + } + } + + public bool IsReusable + { + get + { + return false; + } + } + + private async Task ProcessWebSocketRequest(WebSocketContext wsContext) + { + WebSocket socket = wsContext.WebSocket; + var receiveBuffer = new byte[MaxBufferSize]; + var throwAwayBuffer = new byte[MaxBufferSize]; + + // Stay in loop while websocket is open + while (socket.State == WebSocketState.Open || socket.State == WebSocketState.CloseSent) + { + var receiveResult = await socket.ReceiveAsync(new ArraySegment(receiveBuffer), CancellationToken.None); + if (receiveResult.MessageType == WebSocketMessageType.Close) + { + if (receiveResult.CloseStatus == WebSocketCloseStatus.Empty) + { + await socket.CloseAsync(WebSocketCloseStatus.Empty, null, CancellationToken.None); + } + else + { + await socket.CloseAsync( + receiveResult.CloseStatus.GetValueOrDefault(), + receiveResult.CloseStatusDescription, + CancellationToken.None); + } + + continue; + } + + // Keep reading until we get an entire message. + int offset = receiveResult.Count; + while (receiveResult.EndOfMessage == false) + { + if (offset < MaxBufferSize) + { + receiveResult = await socket.ReceiveAsync( + new ArraySegment(receiveBuffer, offset, MaxBufferSize - offset), + CancellationToken.None); + } + else + { + receiveResult = await socket.ReceiveAsync( + new ArraySegment(throwAwayBuffer), + CancellationToken.None); + } + + offset += receiveResult.Count; + } + + // Close socket if the message was too big. + if (offset > MaxBufferSize) + { + await socket.CloseAsync( + WebSocketCloseStatus.MessageTooBig, + String.Format("{0}: {1} > {2}", WebSocketCloseStatus.MessageTooBig.ToString(), offset, MaxBufferSize), + CancellationToken.None); + + continue; + } + + bool sendMessage = false; + if (receiveResult.MessageType == WebSocketMessageType.Text) + { + string receivedMessage = Encoding.UTF8.GetString(receiveBuffer, 0, offset); + if (receivedMessage == ".close") + { + await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, receivedMessage, CancellationToken.None); + } + if (receivedMessage == ".shutdown") + { + await socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, receivedMessage, CancellationToken.None); + } + else if (receivedMessage == ".abort") + { + socket.Abort(); + } + else if (receivedMessage == ".delay5sec") + { + await Task.Delay(5000); + } + else if (socket.State == WebSocketState.Open) + { + sendMessage = true; + } + } + else + { + sendMessage = true; + } + + if (sendMessage) + { + await socket.SendAsync( + new ArraySegment(receiveBuffer, 0, offset), + receiveResult.MessageType, + true, + CancellationToken.None); + } + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx new file mode 100644 index 0000000..72e742e --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="EchoWebSocketHeaders.ashx.cs" Class="WebServer.EchoWebSocketHeaders" %> diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx.cs b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx.cs new file mode 100644 index 0000000..af86d73 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/WebSocket/EchoWebSocketHeaders.ashx.cs @@ -0,0 +1,90 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Web; +using System.Net.WebSockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace WebServer +{ + public class EchoWebSocketHeaders : IHttpHandler + { + private const int MaxBufferSize = 1024; + + public void ProcessRequest(HttpContext context) + { + try + { + if (!context.IsWebSocketRequest) + { + context.Response.StatusCode = 200; + context.Response.ContentType = "text/plain"; + context.Response.Write("Not a websocket request"); + + return; + } + + context.AcceptWebSocketRequest(ProcessWebSocketRequest); + } + catch (Exception ex) + { + context.Response.StatusCode = 500; + context.Response.StatusDescription = ex.Message; + } + } + + public bool IsReusable + { + get + { + return false; + } + } + + private async Task ProcessWebSocketRequest(WebSocketContext wsContext) + { + WebSocket socket = wsContext.WebSocket; + var receiveBuffer = new byte[MaxBufferSize]; + + // Reflect all headers and cookies + var sb = new StringBuilder(); + sb.AppendLine("Headers:"); + + foreach (string header in wsContext.Headers.AllKeys) + { + sb.Append(header); + sb.Append(":"); + sb.AppendLine(wsContext.Headers[header]); + } + + byte[] sendBuffer = Encoding.UTF8.GetBytes(sb.ToString()); + await socket.SendAsync(new ArraySegment(sendBuffer), WebSocketMessageType.Text, true, new CancellationToken()); + + // Stay in loop while websocket is open + while (socket.State == WebSocketState.Open || socket.State == WebSocketState.CloseSent) + { + var receiveResult = await socket.ReceiveAsync(new ArraySegment(receiveBuffer), CancellationToken.None); + if (receiveResult.MessageType == WebSocketMessageType.Close) + { + if (receiveResult.CloseStatus == WebSocketCloseStatus.Empty) + { + await socket.CloseAsync(WebSocketCloseStatus.Empty, null, CancellationToken.None); + } + else + { + await socket.CloseAsync( + receiveResult.CloseStatus.GetValueOrDefault(), + receiveResult.CloseStatusDescription, + CancellationToken.None); + } + + continue; + } + } + } + } +} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/index.html b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/index.html new file mode 100644 index 0000000..6deebf9 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/index.html @@ -0,0 +1,11 @@ + + + + Networking Test Server + + + +

NetworkingTestServer

+

Networking test server in Azure. Used by dotnet/corefx repo.

+ + diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/packages.config b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/packages.config new file mode 100644 index 0000000..9ca0fb1 --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/CoreFxNetCloudService/WebServer/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Servers/buildAndPackage.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/buildAndPackage.ps1 new file mode 100644 index 0000000..e987a3a --- /dev/null +++ b/src/libraries/Common/tests/System/Net/Prerequisites/Servers/buildAndPackage.ps1 @@ -0,0 +1,33 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +# Requires Visual Studio Command Prompt +# Requires Azure SDK and .Net Framework SDK installed on the build machine. + +$cdir = pwd +$folderName = "CoreFxNetCloudService" +$src = Join-Path $cdir $folderName +$tmp = Join-Path $Env:TEMP $folderName +$tmpOut = Join-Path $tmp "WebServer\PublishToIIS" +$dst = Join-Path $cdir "..\Deployment\IISApplications" + +$nugetSrc = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" + +if (Test-Path $tmp) +{ + rm -Recurse $tmp +} + +copy -Recurse $src $Env:TEMP +Start-BitsTransfer -Source $nugetSrc -Destination $tmp + +cd $tmp + +.\nuget restore +msbuild /p:DeployOnBuild=true /p:PublishProfile=IIS_PublishToLocalPath_RET + +copy -Recurse $tmpOut $dst + +cd $cdir +rm -Recurse $tmp diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs index 4a058ab..72a3ccc 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/DefaultCredentialsTest.cs @@ -16,28 +16,31 @@ namespace System.Net.Http.Functional.Tests { private static string DomainJoinedTestServer => Configuration.Http.DomainJoinedHttpHost; private static bool DomainJoinedTestsEnabled => !string.IsNullOrEmpty(DomainJoinedTestServer); - private static string SpecificUserName = "test"; - private static string SpecificPassword = "Password1"; - private static string SpecificDomain = DomainJoinedTestServer; - private static Uri AuthenticatedServer = + private static bool DomainProxyTestsEnabled => (!string.IsNullOrEmpty(Configuration.Http.DomainJoinedProxyHost)) && DomainJoinedTestsEnabled; + + private static string s_specificUserName = Configuration.Security.ActiveDirectoryUserName; + private static string s_specificPassword = Configuration.Security.ActiveDirectoryUserPassword; + private static string s_specificDomain = Configuration.Security.ActiveDirectoryName; + private static Uri s_authenticatedServer = new Uri($"http://{DomainJoinedTestServer}/test/auth/negotiate/showidentity.ashx"); // This test endpoint offers multiple schemes, Basic and NTLM, in that specific order. This endpoint // helps test that the client will use the stronger of the server proposed auth schemes and // not the first auth scheme. - private static Uri MultipleSchemesAuthenticatedServer = + private static Uri s_multipleSchemesAuthenticatedServer = new Uri($"http://{DomainJoinedTestServer}/test/auth/multipleschemes/showidentity.ashx"); private readonly ITestOutputHelper _output; private readonly NetworkCredential _specificCredential = - new NetworkCredential(SpecificUserName, SpecificPassword, SpecificDomain); + new NetworkCredential(s_specificUserName, s_specificPassword, s_specificDomain); public DefaultCredentialsTest(ITestOutputHelper output) { _output = output; - _output.WriteLine(AuthenticatedServer.ToString()); + _output.WriteLine(s_authenticatedServer.ToString()); } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -47,12 +50,13 @@ namespace System.Net.Http.Functional.Tests handler.UseProxy = useProxy; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(AuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_authenticatedServer)) { Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); } } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -61,12 +65,13 @@ namespace System.Net.Http.Functional.Tests var handler = new HttpClientHandler { UseProxy = useProxy, UseDefaultCredentials = false }; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(AuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_authenticatedServer)) { Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); } } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -75,7 +80,7 @@ namespace System.Net.Http.Functional.Tests var handler = new HttpClientHandler { UseProxy = useProxy, UseDefaultCredentials = true }; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(AuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_authenticatedServer)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -86,6 +91,7 @@ namespace System.Net.Http.Functional.Tests } } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -94,7 +100,7 @@ namespace System.Net.Http.Functional.Tests var handler = new HttpClientHandler { UseProxy = useProxy, UseDefaultCredentials = true }; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(MultipleSchemesAuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_multipleSchemesAuthenticatedServer)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -105,6 +111,7 @@ namespace System.Net.Http.Functional.Tests } } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -116,15 +123,16 @@ namespace System.Net.Http.Functional.Tests Credentials = _specificCredential }; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(AuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_authenticatedServer)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); string responseBody = await response.Content.ReadAsStringAsync(); - VerifyAuthentication(responseBody, true, SpecificDomain + "\\" + SpecificUserName); + VerifyAuthentication(responseBody, true, s_specificDomain + "\\" + s_specificUserName); } } + [ActiveIssue(10041)] [ConditionalTheory(nameof(DomainJoinedTestsEnabled))] [InlineData(false)] [InlineData(true)] @@ -138,7 +146,7 @@ namespace System.Net.Http.Functional.Tests }; using (var client = new HttpClient(handler)) - using (HttpResponseMessage response = await client.GetAsync(AuthenticatedServer)) + using (HttpResponseMessage response = await client.GetAsync(s_authenticatedServer)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -149,7 +157,8 @@ namespace System.Net.Http.Functional.Tests } } - [ConditionalFact(nameof(DomainJoinedTestsEnabled))] + [ActiveIssue(10041)] + [ConditionalFact(nameof(DomainProxyTestsEnabled))] public async Task Proxy_UseAuthenticatedProxyWithNoCredentials_ProxyAuthenticationRequired() { var handler = new HttpClientHandler(); @@ -162,7 +171,8 @@ namespace System.Net.Http.Functional.Tests } } - [ConditionalFact(nameof(DomainJoinedTestsEnabled))] + [ActiveIssue(10041)] + [ConditionalFact(nameof(DomainProxyTestsEnabled))] public async Task Proxy_UseAuthenticatedProxyWithDefaultCredentials_OK() { var handler = new HttpClientHandler(); @@ -174,8 +184,8 @@ namespace System.Net.Http.Functional.Tests Assert.Equal(HttpStatusCode.OK, response.StatusCode); } } - - [ConditionalFact(nameof(DomainJoinedTestsEnabled))] + + [ConditionalFact(nameof(DomainProxyTestsEnabled))] public async Task Proxy_UseAuthenticatedProxyWithWrappedDefaultCredentials_OK() { ICredentials wrappedCreds = new CredentialWrapper @@ -235,13 +245,13 @@ namespace System.Net.Http.Functional.Tests _credentials = credentials; string host = Configuration.Http.DomainJoinedProxyHost; - Assert.False(string.IsNullOrEmpty(host), "TestSettings.Http.DomainJoinedProxyHost must specify proxy hostname"); + Assert.False(string.IsNullOrEmpty(host), "DomainJoinedProxyHost must specify proxy hostname"); string portString = Configuration.Http.DomainJoinedProxyPort; - Assert.False(string.IsNullOrEmpty(portString), "TestSettings.Http.DomainJoinedProxyPort must specify proxy port number"); + Assert.False(string.IsNullOrEmpty(portString), "DomainJoinedProxyPort must specify proxy port number"); int port; - Assert.True(int.TryParse(portString, out port), "TestSettings.Http.DomainJoinedProxyPort must be a valid port number"); + Assert.True(int.TryParse(portString, out port), "DomainJoinedProxyPort must be a valid port number"); _proxyUri = new Uri(string.Format("http://{0}:{1}", host, port)); } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 9fb3261..469be17 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -57,6 +57,9 @@ Common\System\Net\Configuration.Http.cs + + Common\System\Net\Configuration.Security.cs + Common\System\Net\TestWebProxies.cs -- 2.7.4