diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 deleted file mode 100644 index 6a07fe355a53d..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/config.ps1 +++ /dev/null @@ -1,59 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -# -# Libraries - 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: -$LIBRARIES_NET_AD_MACHINE = "" #Example: "TESTAD" -$LIBRARIES_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. -$LIBRARIES_NET_IISSERVER_MACHINE = "" #Example: "TESTIIS" -$LIBRARIES_NET_IISSERVER_MACHINEIP = "" #Example: "192.168.0.1" - must be a Static IPv4 address. - -# A Windows Client or Server SKU hosting the runtime repo. This machine will be joined to the Domain. -$LIBRARIES_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 = "libraries-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 = "LIBRARIES_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $LIBRARIES_NET_IISSERVER_MACHINE}, - @{Name = "LIBRARIES_NET_AD_CLIENT"; Script = "setup_activedirectory_client.ps1"; MachineName = $LIBRARIES_NET_CLIENT_MACHINE}, - @{Name = "LIBRARIES_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $LIBRARIES_NET_AD_MACHINE; MachineIP = $LIBRARIES_NET_AD_MACHINEIP} -) - -$script:Roles = @( - @{Name = "LIBRARIES_NET_IISSERVER"; Script = "setup_iisserver.ps1"; MachineName = $LIBRARIES_NET_IISSERVER_MACHINE; MachineIP = $LIBRARIES_NET_IISSERVER_MACHINEIP}, - @{Name = "LIBRARIES_NET_CLIENT"; Script = "setup_client.ps1"; MachineName = $LIBRARIES_NET_CLIENT_MACHINE}, - @{Name = "LIBRARIES_NET_AD_DC"; Script = "setup_activedirectory_domaincontroller.ps1"; MachineName = $LIBRARIES_NET_AD_MACHINE; MachineIP = $LIBRARIES_NET_AD_MACHINEIP} -) diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 deleted file mode 100644 index 26544c6ba0ae0..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup.ps1 +++ /dev/null @@ -1,225 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -Param ( - [switch] $uninstall=$false -) - -# Import configuration. -. .\setup_common.ps1 - -Function TestMachineStatus($role) -{ - try - { - $status = Invoke-Command -ComputerName $role.MachineName -ArgumentList $role.Name -ErrorAction Stop { [Environment]::GetEnvironmentVariable($args[0], "Machine") } - - $role.Reachable = $true - if ($status -eq "Installed") - { - $role.Installed = $true - } - else - { - if (-not [string]::IsNullOrWhiteSpace($status)) - { - Write-Warning "Role $($role.Name) found to have status of: $status." - Write-Warning "The script will try to resume the installation. To manually resume installation, manually run the $($role.Script) on $($role.MachineName) as Administrator." - } - } - } - catch [System.Exception] - { - $role.Reachable = $false - } -} - -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)) - { - Write-Host -ForegroundColor DarkGray "`t" $role.Name - if (-not (Test-Path $role.Script)) - { - throw "Cannot find installation script for $($role.Name): $($role.Script)" - } - - if ([string]::IsNullOrWhiteSpace($role.MachineName)) - { - throw "Please edit config.ps1 and set a valid value name for $($role.Name)_Machine." - } - - TestMachineStatus $role - } - - Write-Host "OK." -} - -Function EnsurePreRebootForCurrentMachine -{ - $machineInfo = Get-WmiObject win32_computersystem - $currentRole = GetPreRebootRoleForMachine($Env:COMPUTERNAME) - - if (($machineInfo.PartOfDomain -eq $true) -and ` - ($machineInfo.Domain -eq $script:domainName) -and ` - ($currentRole.Installed -eq $true)) - { - return $true - } - elseif (($machineInfo.PartOfDomain -eq $true) -and ` - ($machineInfo.Domain -ne $script:domainName)) - { - Write-Error "The current machine is already joiend to the $($machineInfo.Domain) domain." - Write-Error "Either change config.ps1 to use the correct domain information, select a different machine or remove the machine from the current domain." - throw "Cannot use the current machine: already joined to a domain." - } - - & (".\" + $currentRole.Script) -} - -Function CreateDestinationPath($s) -{ - return Invoke-Command -Session $s ` - { - $destPath = Join-Path $env:SystemDrive "LIBRARIES_NET_SCRIPTS" - mkdir $destPath -ErrorAction SilentlyContinue | Out-Null - return $destPath - } -} - -Function CopyScripts($s, $remotePath) -{ - Copy-Item -Recurse -Force -Path ".\*" -Destination $remotePath -ToSession $s -ErrorAction Stop -} - -Function InstallRoles -{ - Write-Host -ForegroundColor Cyan "Remotely installing all roles." - - foreach ($role in $script:Roles) - { - Write-Host -ForegroundColor DarkCyan "Installing role [$($role.Name)]: $($role.MachineName)" - - Write-Host -ForegroundColor DarkGray "`tConnecting" - $s = New-PSSession -ComputerName $role.MachineName - - Write-Host -ForegroundColor DarkGray "`tCopying scripts" - # Copy scripts - $remotePath = CreateDestinationPath $s - CopyScripts $s $remotePath - - Write-Host -ForegroundColor DarkGray "`tInstalling" - # Run remote scripts - Invoke-Command -Session $s -ArgumentList $remotePath, $role.Script ` - { - $path = $args[0] - $script = $args[1] - - cd $path - & (".\" + $script) - } - - Write-Host -ForegroundColor DarkCyan "Role [$($role.Name)]: $($role.MachineName) installation complete." - Write-Host - Write-Host - } -} - -Function Install -{ - Write-Host -ForegroundColor Cyan "Install/Update Libraries Networking multi-machine prerequisites" - Write-Host - CheckRoles - - EnsurePreRebootForCurrentMachine - - if (($script:Roles | where {$_.Reachable -ne $true}).Count -ne 0) - { - Write-Warning "Not all roles are reachable from this host." - Write-Host "- If all machines are joined to the Domain, make sure you are logged on as $($script:domainNetbios)\Administrator and not as a local Administrator." - Write-Host "- If not all machines are joined to the Domain: Log-on to the following machines, copy all scripts and run .\setup.ps1 as Administrator:" - $script:Roles | where {$_.Reachable -ne $true} - Write-Host -ForegroundColor Cyan "Rerun this command after all machines have been started and joined to the $($script:domainNetBios) domain." - return - } - - InstallRoles - - Write-Host -ForegroundColor Cyan "Role installation complete." -} - -Function UnistallMachines -{ - Write-Host -ForegroundColor Cyan "Remotely uninstalling roles." - - foreach ($role in $script:Roles) - { - Write-Host -ForegroundColor DarkCyan "Uninstalling role [$($role.Name)]: $($role.MachineName)" - - Write-Host -ForegroundColor DarkGray "`tConnecting" - $s = New-PSSession -ComputerName $role.MachineName - - Write-Host -ForegroundColor DarkGray "`tCopying scripts" - # Copy scripts - $remotePath = CreateDestinationPath $s - CopyScripts $s $remotePath - - $preRebootRole = GetPreRebootRoleForMachine $role.MachineName - - Write-Host -ForegroundColor DarkGray "`tUninstalling" - # Run remote scripts - Invoke-Command -Session $s -ArgumentList $remotePath, $role.Script, $preRebootRole.Script ` - { - $path = $args[0] - $script = $args[1] - $preRebootScript = $args[2] - - cd $path - & (".\" + $script) -uninstall - & (".\" + $preRebootScript) -uninstall - } - - Write-Host -ForegroundColor DarkCyan "Role [$($role.Name)]: $($role.MachineName) uninstall complete." - Write-Host - Write-Host - } -} - -Function Uninstall -{ - Write-Host -ForegroundColor Cyan "Uninstall Libraries Networking multi-machine prerequisites" - Write-Host - CheckRoles - Write-Host - - Write-Warning "Some of the installed components may have existed before or got changes outside of this setup script." - Write-Warning "The scripts will attempt to remove all components regardless of these changes." - $continue = Read-Host "Do you want to continue? [Y/N]" - - if ($continue.ToUpper() -ne "Y") - { - Write-Warning "Aborted by user." - return - } - - UnistallMachines -} - -if ($uninstall) -{ - Uninstall -} -else -{ - Install -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_client.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_client.ps1 deleted file mode 100644 index 7a7df93b18517..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_client.ps1 +++ /dev/null @@ -1,86 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -# -# Run this script on all Active Directory client machines. -# Tested on Windows 2016 TP5 and Windows 10. -# -Param ( - [switch] $uninstall=$false -) - -# Imports: -. .\setup_common.ps1 - -$script:LIBRARIES_ROLE_NAME = "LIBRARIES_NET_AD_CLIENT" - -Function ConfigureDNS -{ - Write-Host -ForegroundColor Cyan "Configuring DNS" - - $dcRole = GetRole "LIBRARIES_NET_AD_DC" - - if (-not (Test-Connection $dcRole.MachineIP)) - { - throw "The local machine cannot ping the Domain Controller/DNS Server at $($dcRole.MachineIP).`n" + ` - "Ensure that the setup was completed on the machine then try re-running the script on this machine again." - } - - $ipv4DnsInterfaces = Get-DnsClientServerAddress | where {($_.AddressFamily -eq 2) -and ($_.InterfaceAlias -eq "Ethernet")} - if ($ipv4DnsInterfaces.Count -eq 0) - { - throw "The setup script cannot find a network adapter named 'Ethernet' that has IPv4 configured." - } - - $ifIndex = $ipv4DnsInterfaces[0].InterfaceIndex - - Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ServerAddresses ($dcRole.MachineIP) -} - -Function EnableAD -{ - Write-Host -ForegroundColor Cyan "Adding computer to domain. Please use the domain administrator password for the $($script:domainNetbios) domain." - Add-Computer -DomainName $script:domainNetbios -} - -Function Install -{ - Write-Host -ForegroundColor Cyan "Installing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)" - - CheckPreRebootMachineInfo - ConfigureDNS - EnableAD - Enable-PSRemoting - EnvironmentSetRebootPendingRoleStatus - Write-Host -ForegroundColor Cyan "Please re-start one instance of the script on any of the machines after reboot to resume the installation." - Read-Host "[Press ENTER to reboot.]" - Restart-Computer - EnvironmentSetInstalledRoleStatus -} - -Function Uninstall -{ - Write-Host -ForegroundColor Cyan "Removing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)." - - EnvironmentCheckUninstallRoleStatus - - Remove-Computer - EnvironmentRemoveRoleStatus - - Write-Warning "Current DNS configuration:" - Get-DnsClientServerAddress - Write-Warning "To complete the uninstallation, you may need to change the DNS client address configuration." - Read-Host "[Press ENTER to reboot.]" - Restart-Computer -} - -if ($uninstall) -{ - Uninstall -} -else -{ - Install -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 deleted file mode 100644 index 2687ea5fb27b1..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_activedirectory_domaincontroller.ps1 +++ /dev/null @@ -1,94 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -# -# Run this script on the Active Directory Domain Controller machine. -# Tested on Windows 2016 TP5 -# - -Param ( - [switch] $uninstall=$false -) - -# Import configuration. -. .\setup_common.ps1 - -$script:LIBRARIES_ROLE_NAME = "LIBRARIES_NET_AD_DC" - -Function EnableAD -{ - Write-Host -ForegroundColor Cyan "Installing Active Directory." - CheckPreRebootMachineInfo - - # From https://technet.microsoft.com/en-us/library/hh472162.aspx - Install-Windowsfeature -name AD-Domain-Services -IncludeManagementTools - - # Will prompt for SafeModeAdministratorPassword: - Install-ADDSForest -domainname $script:domainName -DomainNetbiosName $script:domainNetbios -NoRebootOnCompletion -} - -Function AddUser -{ - Write-Host -ForegroundColor Cyan "Creating domain user." - Remove-ADUser $script:domainUserName -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - New-ADUser $script:domainUserName -Enabled $true -PasswordNeverExpires $true -AccountPassword (ConvertTo-SecureString $script:domainUserPassword -AsPlainText -force) -} - -Function ConfigureDNS -{ - Write-Host -ForegroundColor Cyan "Configuring DNS." - - $iisServer = GetRole "LIBRARIES_NET_IISSERVER" - - $serverName = ($script:iisServerFQDN).Split('.')[0]; - $zoneName = ($script:iisServerFQDN).Substring($serverName.Length + 1) - - Remove-DnsServerZone -Name $zoneName -Force -ErrorAction SilentlyContinue | Out-Null - Add-DnsServerPrimaryZone -Name $zoneName -ReplicationScope "Forest" - Add-DnsServerResourceRecordA -Name $serverName -ZoneName $zoneName -AllowUpdateAny -IPv4Address $iisServer.MachineIP -TimeToLive 01:00:00 -} - -Function Install -{ - Write-Host -ForegroundColor Cyan "Installing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)." - - if ((-not (EnvironmentIsRoleInstalled)) -and (-not (EnvironmentIsRoleRebootPending))) - { - EnableAD - EnvironmentSetRebootPendingRoleStatus - Write-Host -ForegroundColor Cyan "Please re-start the script after the machine reboots." - Read-Host "[Press ENTER to reboot.]" - Restart-Computer - } - else - { - AddUser - ConfigureDNS - Enable-PSRemoting - EnvironmentSetInstalledRoleStatus - Write-Host -ForegroundColor Cyan "Prerequisites installed for $($script:LIBRARIES_ROLE_NAME)." - Write-Host - } -} - -Function Uninstall -{ - Write-Host -ForegroundColor Cyan "Removing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)." - - EnvironmentCheckUninstallRoleStatus - EnvironmentRemoveRoleStatus - - # Will reboot. - Uninstall-ADDSDomainController -LastDomainControllerInDomain -RemoveApplicationPartitions -IgnoreLastDNSServerForZone -} - -if ($uninstall) -{ - Uninstall -} -else -{ - Install -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_certificates.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_certificates.ps1 deleted file mode 100644 index 3a52a66720e43..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_certificates.ps1 +++ /dev/null @@ -1,128 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -# Certificate configuration - -$script:testDataUri = "https://github.com/dotnet/runtime-assets/archive/main.zip" -$script:testData = "runtime-assets" -$script:certificatePath = "$($script:testData)\src\System.Net.TestData\TestDataCertificates" - -$script:clientPrivateKeyPath = Join-Path $script:certificatePath "testclient1_at_contoso.com.pfx" -$script:clientPrivateKeyPassword = "PLACEHOLDER" - -$script:serverPrivateKeyPath = Join-Path $script:certificatePath "contoso.com.pfx" -$script:serverPrivateKeyPassword = "PLACEHOLDER" - -Function GetFullPath($relativePath) -{ - return (Get-Item $relativePath).FullName -} - -Function DeleteTestData -{ - if (Test-Path $script:testData) - { - rmdir $script:testData -Recurse -Force - } - - del ($testData + ".zip") -ErrorAction SilentlyContinue -} - -Function DownloadTestData -{ - DeleteTestData - DownloadFile $script:testDataUri ($testData + ".zip") - Expand-Archive ($testData + ".zip") -} - -Function LoadCertificateAndRoot($fileName, $password) -{ - $privateCerts = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection - $fullPath = GetFullPath $fileName - - $privateCerts.Import($fullPath, $password, ("MachineKeySet", "PersistKeySet", "Exportable")) - - $privateKeyCert = $null - foreach ($cert in $privateCerts) - { - if ($privateKeyCert -eq $null -and $cert.HasPrivateKey) - { - $privateKeyCert = $cert - } - } - - $rootCACert = $privateCerts | where {$_.Subject -eq $privateKeyCert.Issuer} - - return ($privateKeyCert, $rootCACert) -} - -Function AddCertificateToStore($certificate, $storeName, $storeLocation) -{ - $rootStore = New-Object System.Security.Cryptography.X509Certificates.X509Store($storeName, $storeLocation) - $rootStore.Open("ReadWrite") - $rootStore.Add($certificate) - $rootStore.Close() -} - -Function InstallCertificates($fileName, $password) -{ - Write-Host "Acquiring test data." - DownloadTestData - - Write-Host "Adding certificates" - ($private, $root) = LoadCertificateAndRoot $fileName $password - - Write-Host -ForegroundColor DarkGray "`tAdding root certificate: $($root.Subject)" - AddCertificateToStore $root "Root" "LocalMachine" - - Write-Host -ForegroundColor DarkGray "`tAdding private key certificate: $($private.Subject)" - AddCertificateToStore $private "My" "LocalMachine" - - Write-Host "Removing temporary files" - DeleteTestData -} - -Function InstallClientCertificates -{ - Write-Host -ForegroundColor Cyan "Installing Client Certificates" - InstallCertificates $script:clientPrivateKeyPath $script:clientPrivateKeyPassword -} - -Function InstallServerCertificates -{ - Write-Host -ForegroundColor Cyan "Installing Server Certificates" - InstallCertificates $script:serverPrivateKeyPath $script:serverPrivateKeyPassword -} - -Function GetServerCertificate -{ - return dir Cert:\LocalMachine\My | where { $_.DnsNameList | where{$_.Punycode -eq $script:iisServerFQDN} } -} - -Function RemoveCertificates($filename, $password) -{ - Write-Host "Acquiring test data." - DownloadTestData - ($private, $root) = LoadCertificateAndRoot $fileName $password - - Write-Host -ForegroundColor DarkGray "`tRemoving root certificate: $($root.Subject)" - dir Cert:\LocalMachine\Root | where {$_.Subject -eq $root.Subject} | foreach { rm (Join-Path Cert:\LocalMachine\Root $_.Thumbprint) } - Write-Host -ForegroundColor DarkGray "`tRemoving private key certificate: $($private.Subject)" - dir Cert:\LocalMachine\My | where {$_.Subject -eq $private.Subject} | foreach { rm (Join-Path Cert:\LocalMachine\My $_.Thumbprint) -DeleteKey } - - DeleteTestData -} - -Function RemoveClientCertificates -{ - Write-Host -ForegroundColor Cyan "Removing Client Certificates" - RemoveCertificates $script:clientPrivateKeyPath $script:clientPrivateKeyPassword -} - -Function RemoveServerCertificates -{ - Write-Host -ForegroundColor Cyan "Removing Server Certificates" - RemoveCertificates $script:serverPrivateKeyPath $script:serverPrivateKeyPassword -} \ No newline at end of file diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_client.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_client.ps1 deleted file mode 100644 index d605ca59ab287..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_client.ps1 +++ /dev/null @@ -1,63 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -Param ( - [switch] $uninstall=$false -) - -# Imports: -. .\setup_common.ps1 -. .\setup_certificates.ps1 - -$script:LIBRARIES_ROLE_NAME = "LIBRARIES_NET_CLIENT" - -Function InstallClientEnvironmentConfiguration -{ - Write-Host -ForegroundColor Cyan "Installing client configuration." - - foreach ($configEntry in $script:ClientConfiguration) - { - [Environment]::SetEnvironmentVariable($configEntry.Name, $configEntry.Value, "Machine") - } -} - -Function UninstallClientEnvironmentConfiguration -{ - Write-Host -ForegroundColor Cyan "Removing client configuration." - - foreach ($configEntry in $script:ClientConfiguration) - { - [Environment]::SetEnvironmentVariable($configEntry.Name, $null, "Machine") - } -} - -Function Install -{ - Write-Host -ForegroundColor Cyan "Installing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)." - CheckMachineInfo - - InstallClientCertificates - InstallClientEnvironmentConfiguration - - EnvironmentSetInstalledRoleStatus -} - -Function Uninstall -{ - Write-Host -ForegroundColor Cyan "Removing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)." - EnvironmentCheckUninstallRoleStatus - - RemoveClientCertificates - UninstallClientEnvironmentConfiguration - - EnvironmentRemoveRoleStatus -} - -if ($uninstall) -{ - Uninstall -} -else -{ - Install -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 deleted file mode 100644 index 995b931581567..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_common.ps1 +++ /dev/null @@ -1,149 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -. .\config.ps1 - -# The following variable names should match the ones read by Configuration.*.cs code. -$script:ClientConfiguration = @( - - # Configuration.Http: - @{Name = "DOTNET_TEST_HTTPHOST"; Value = $script:iisServerFQDN}, - @{Name = "DOTNET_TEST_SECUREHTTPHOST"; Value = $script:iisServerFQDN}, - @{Name = "DOTNET_TEST_HTTP2HOST"; Value = $script:iisServerFQDN}, # Requires Windows 10 and above. - @{Name = "DOTNET_TEST_DOMAINJOINED_HTTPHOST"; Value = $script:iisServerFQDN}, - @{Name = "DOTNET_TEST_DOMAINJOINED_PROXYHOST"; Value = $null}, - @{Name = "DOTNET_TEST_DOMAINJOINED_PROXYPORT"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_SSL2"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_SSL3"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_TLS10"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_TLS11"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_TLS12"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_EXPIREDCERT"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_WRONGHOSTNAME"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_SELFSIGNEDCERT"; Value = $null}, - @{Name = "DOTNET_TEST_HTTPHOST_REVOKEDCERT"; Value = $null}, - @{Name = "DOTNET_TEST_STRESS_HTTP"; Value = "1"}, - - # Configuration.WebSockets: - @{Name = "DOTNET_TEST_WEBSOCKETHOST"; Value = $script:iisServerFQDN}, - @{Name = "DOTNET_TEST_SECUREWEBSOCKETHOST"; Value = $script:iisServerFQDN}, - - # Configuration.Security: - @{Name = "DOTNET_TEST_NET_AD_DOMAINNAME"; Value = $script:domainNetbios}, - @{Name = "DOTNET_TEST_NET_AD_USERNAME"; Value = $script:domainUserName}, - @{Name = "DOTNET_TEST_NET_AD_PASSWORD"; Value = $script:domainUserPassword}, - @{Name = "DOTNET_TEST_NET_SECURITY_NEGOSERVERURI"; Value = "http://$($script:iisServerFQDN)"}, - @{Name = "DOTNET_TEST_NET_SECURITY_TLSSERVERURI"; Value = "https://$($script:iisServerFQDN)"}, - - @{Name = "DOTNET_TEST_NET_SOCKETS_SERVERURI"; Value = "http://$($script:iisServerFQDN)"} -) - -Function GetRoleForMachine($machineName) -{ - return $script:Roles | where {$_.MachineName.ToUpper() -eq $machineName.ToUpper()} -} - -Function GetPreRebootRoleForMachine($machineName) -{ - return $script:PreRebootRoles | where {$_.MachineName.ToUpper() -eq $machineName.ToUpper()} -} - -Function GetRole($roleName) -{ - return $script:Roles | where {$_.Name.ToUpper() -eq $roleName.ToUpper()} -} - -Function CheckPreRebootMachineInfo -{ - $role = GetPreRebootRoleForMachine $Env:COMPUTERNAME - - if ($role.Name -ne $script:DOTNET_TEST_ROLE_NAME) - { - throw "This script needs to run on machines part of the $($role.Name) role." - } - - if ((-not [string]::IsNullOrWhiteSpace($role.MachineIP)) -and ((Get-NetIPAddress | where {$_.IPAddress -eq $role.MachineIP}).Count -eq 0)) - { - throw "The current machine doesn't have the expected Static IP address: $($role.MachineIP)" - } -} - -Function CheckMachineInfo -{ - $role = GetRoleForMachine $Env:COMPUTERNAME - - if ($role.Name -ne $script:DOTNET_TEST_ROLE_NAME) - { - throw "This script needs to run on machines part of the $($role.Name) role." - } - - if ((-not [string]::IsNullOrWhiteSpace($role.MachineIP)) -and ((Get-NetIPAddress | where {$_.IPAddress -eq $role.MachineIP}).Count -eq 0)) - { - throw "The current machine doesn't have the expected Static IP address: $($role.MachineIP)" - } -} - -Function EnvironmentAddRoleStatus($status) -{ - [Environment]::SetEnvironmentVariable($script:DOTNET_TEST_ROLE_NAME, $status, "Machine") -} - -Function EnvironmentSetInstalledRoleStatus -{ - EnvironmentAddRoleStatus "Installed" -} - -Function EnvironmentSetRebootPendingRoleStatus -{ - EnvironmentAddRoleStatus "PendingReboot" -} - -Function EnvironmentRemoveRoleStatus -{ - [Environment]::SetEnvironmentVariable($script:DOTNET_TEST_ROLE_NAME, $null, "Machine") -} - -Function EnvironmentCheckUninstallRoleStatus -{ - if ([Environment]::GetEnvironmentVariable($script:DOTNET_TEST_ROLE_NAME, "Machine") -ne "Installed") - { - Write-Warning "The machine doesn't appear to be in the $($script:DOTNET_TEST_ROLE_NAME) role." - $continue = Read-Host "Do you want to continue? [Y/N]" - if ($continue.ToUpper() -ne "Y") - { - Write-Warning "Aborted by user." - exit - } - } -} - -Function EnvironmentIsRoleRebootPending -{ - return [Environment]::GetEnvironmentVariable($script:DOTNET_TEST_ROLE_NAME, "Machine") -eq "PendingReboot" -} - -Function EnvironmentIsRoleInstalled -{ - return [Environment]::GetEnvironmentVariable($script:DOTNET_TEST_ROLE_NAME, "Machine") -eq "Installed" -} - -Function DownloadFile($source, $destination) -{ - # BITS remoting doesn't work on systems <= TH2. - if ([System.Environment]::OSVersion.Version -gt (new-object 'Version' 10,0,10586,0)) - { - Start-BitsTransfer -Source $source -Destination $destination - } - else - { - # BUG: taking very long: Invoke-WebRequest $source -OutFile $destination - $fqDestination = Join-Path (pwd) $destination - $wc = New-Object System.Net.WebClient - $wc.Downloadfile($source, $fqDestination.ToString()) - } -} - -Function GetIISCodePath -{ - return ".\IISApplications" -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_firewall.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_firewall.ps1 deleted file mode 100644 index a1db4f5fad21e..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_firewall.ps1 +++ /dev/null @@ -1,31 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -# Firewall configuration -$script:firewallGroup = "Libraries Testing" -$script:firewallRules = @( - @{Name = "LibrariesNet - HTTP 80"; Port = 80}, - @{Name = "LibrariesNet - HTTP 443"; Port = 443} -) - -Function InstallServerFirewall -{ - Write-Host -ForegroundColor Cyan "Installing Firewall rules." - foreach ($rule in $script:firewallRules) - { - Write-Host -ForegroundColor DarkGray "`t" $rule.Name - New-NetFirewallRule -DisplayName $rule.Name -Group $script:firewallGroup -Direction Inbound -Protocol TCP -LocalPort $rule.Port -Action Allow | Out-Null - } -} - -Function RemoveServerFirewall -{ - Write-Host -ForegroundColor Cyan "Removing Firewall rules." - foreach ($rule in $script:firewallRules) - { - Write-Host -ForegroundColor DarkGray "`t" $rule.Name - Remove-NetFirewallRule -DisplayName $rule.Name | Out-Null - } -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 b/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 deleted file mode 100644 index 07a4dcbb4011f..0000000000000 --- a/src/libraries/Common/tests/System/Net/Prerequisites/Deployment/setup_iisserver.ps1 +++ /dev/null @@ -1,199 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the MIT license. - -#Requires -RunAsAdministrator - -# -# Run this script on the IIS server machine. -# Tested on Windows 2016 TP5 -# - -Param ( - [switch] $uninstall=$false -) - -# Imports: -. .\setup_common.ps1 -. .\setup_certificates.ps1 -. .\setup_firewall.ps1 - -# Server application configuration -$script:iisWwwRoot = "$env:systemdrive\inetpub\wwwroot" -$script:defaultWebSite = "Default Web Site" - -$script:webApps = @( - @{Name = "NoAuth"; - IISRelativePath = ""; - SourceRelativePath = ".\"; - - Configuration = @() - }, - - @{Name = "BasicAuth"; - IISRelativePath = "BasicAuth"; - SourceRelativePath = "\"; - Configuration = @( - @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } - @{ Path = "/system.webServer/security/authentication/basicAuthentication"; Name = "Enabled"; Value = "True" } - ); - UserAccess = @( $script:basicUserName ) - }, - - @{Name = "DigestAuth"; - IISRelativePath = "DigestAuth"; - SourceRelativePath = "\"; - Configuration = @( - @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } - @{ Path = "/system.webServer/security/authentication/digestAuthentication"; Name = "Enabled"; Value = "True" } - ); - UserAccess = @( $script:basicUserName ) - }, - - @{Name = "WindowsAuth"; - IISRelativePath = "WindowsAuth"; - SourceRelativePath = "\"; - Configuration = @( - @{ Path = "/system.webServer/security/authentication/anonymousAuthentication"; Name = "Enabled"; Value = "False" } - @{ Path = "/system.webServer/security/authentication/windowsAuthentication"; Name = "Enabled"; Value = "True" } - ); - UserAccess = @( "$($script:domainNetbios)\$($script:domainUserName)" ) - } -) - -$script:LIBRARIES_ROLE_NAME = "LIBRARIES_NET_IISSERVER" - -Function InstallIIS -{ - Write-Host -ForegroundColor Cyan "Installing IIS components." - Install-WindowsFeature -Name Web-Server,Web-Basic-Auth,Web-Digest-Auth,Web-Windows-Auth,Web-Cert-Auth,Web-Asp-Net45,Web-WebSockets -IncludeManagementTools -ErrorAction Stop | Out-Null -} - -Function RemoveIIS -{ - Write-Host -ForegroundColor Cyan "Removing IIS components." - Uninstall-WindowsFeature -Name Web-Server -IncludeManagementTools -} - -Function CreateLocalUser -{ - # A local user is required to allow Basic and Digest authentication. (WDigest not supported.) - Write-Host -ForegroundColor Cyan "Creating local user account." - Remove-LocalUser $script:basicUserName -Confirm:$false -ErrorAction SilentlyContinue - New-LocalUser $script:basicUserName -PasswordNeverExpires -Password (ConvertTo-SecureString $script:basicUserPassword -AsPlainText -force) | Out-Null -} - -Function RemoveLocalUser -{ - Write-Host -ForegroundColor Cyan "Removing local user account." - Remove-LocalUser $script:basicUserName -Confirm:$false -} - -Function ConfigureWebSites -{ - Write-Host -ForegroundColor Cyan "Configuring IIS websites." - - # SSL Bindings - $sslCert = GetServerCertificate - - Get-WebBinding -Port 443 -Name $script:defaultWebSite | Remove-WebBinding - New-WebBinding -Name $script:defaultWebSite -Protocol https -Port 443 - - Remove-Item -Path "IIS:\SslBindings\*" - New-Item -Path "IIS:\SslBindings\0.0.0.0!443" -Value $sslCert -Force | Out-Null -} - -Function GrantUserAccess($path, $userAccess) -{ - foreach ($user in $userAccess) - { - $acl = Get-Acl $path - $ar = New-Object System.Security.AccessControl.FileSystemAccessRule($user, "ReadAndExecute", "Allow") - $acl.SetAccessRule($ar) - Set-Acl $path $acl - } -} - -Function InstallServerCode -{ - Write-Host -ForegroundColor Cyan "Installing applications." - $serverCodeRootPath = GetIISCodePath - - foreach ($app in $script:webApps) - { - Write-Host -ForegroundColor DarkGray "`tInstalling webApp: $($app.Name)" - - $appPath = Join-Path $script:iisWwwRoot $app.IISRelativePath - - if ($(Get-WebApplication $app.Name) -ne $null) - { - Write-Host "`tRemoving $($app.Name)" - Remove-WebApplication -Site $script:defaultWebSite -Name $app.Name - Remove-Item ($appPath + "\*") -Recurse -Force -ErrorAction SilentlyContinue - } - - Write-Host "`tAdding $($app.Name)" - - $tempPath = Join-Path $serverCodeRootPath $app.SourceRelativePath - mkdir $appPath -ErrorAction SilentlyContinue | Out-Null - Copy-Item ($tempPath + "\*") $appPath -Recurse -ErrorAction Stop - - New-WebApplication -Site $script:defaultWebSite -Name $app.Name -PhysicalPath $appPath | Out-Null - - foreach ($config in $app.Configuration) - { - Set-WebConfigurationProperty -Filter $config.Path -Name $config.Name -Value $config.Value -PSPath IIS:\ -location "$($script:defaultWebSite)/$($app.Name)" -ErrorAction Stop - } - - GrantUserAccess $appPath $app.UserAccess - } -} - -Function RemoveServerCode -{ - Write-Host -ForegroundColor Cyan "Removing server code." - foreach ($app in $script:webApps) - { - Write-Host -ForegroundColor DarkGray "`tRemoving webApp files: $($app.Name)" - $appPath = Join-Path $script:iisWwwRoot $app.IISRelativePath - rmdir -Recurse -Force $appPath -ErrorAction SilentlyContinue - } -} - -Function Install -{ - Write-Host -ForegroundColor Cyan "Installing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)" - CheckMachineInfo - - InstallIIS - InstallServerCertificates - CreateLocalUser - ConfigureWebSites - InstallServerCode - InstallServerFirewall - - EnvironmentSetInstalledRoleStatus -} - -Function Uninstall -{ - Write-Host -ForegroundColor Cyan "Removing prerequisites for test role: $($script:LIBRARIES_ROLE_NAME)" - - EnvironmentCheckUninstallRoleStatus - - RemoveServerFirewall - RemoveIIS - RemoveServerCertificates - RemoveLocalUser - RemoveServerCode - - EnvironmentRemoveRoleStatus -} - -if ($uninstall) -{ - Uninstall -} -else -{ - Install -} diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/README.md b/src/libraries/Common/tests/System/Net/Prerequisites/README.md index a1f766b07fe55..7b0eff9c89e99 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/README.md +++ b/src/libraries/Common/tests/System/Net/Prerequisites/README.md @@ -1,40 +1,2 @@ # 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 main branch. - -### Build the server applications - -Prepare the $DOTNET_TEST_NET_CLIENT_Machine as any Dev station following the instructions at https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md. Ensure that you can build and test CoreFX on this machine. -In addition, you will also need to install the _Azure development_ workload for Visual Studio 2017. - -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 any of the machines within the environment. -The script will use WinRM to connect and update all other roles.