From 77da2eba3ed72b833a1b1b4eaaa8e9e031c764e5 Mon Sep 17 00:00:00 2001 From: asranja Date: Wed, 1 Mar 2017 15:55:14 +0530 Subject: [PATCH] Added L0 tests for IIS Web App Manage task --- .../resources.resjson/en-US/resources.resjson | 4 +- .../Tests/L0.ts | 95 ++++++++ .../Tests/L0AppcmdAddUpdateAppPool.ps1 | 62 ++++++ .../Tests/L0AppcmdAddUpdateApplication.ps1 | 62 ++++++ .../Tests/L0AppcmdAddUpdateVDir.ps1 | 44 ++++ .../Tests/L0AppcmdAddUpdateWebsite.ps1 | 121 ++++++++++ .../Tests/L0AppcmdAdditionalActions.ps1 | 70 ++++++ .../Tests/L0AppcmdExecuteMain.ps1 | 207 ++++++++++++++++++ .../Tests/L0AppcmdTestApplicationExists.ps1 | 50 +++++ .../L0AppcmdTestApplicationPoolExists.ps1 | 48 ++++ .../Tests/L0AppcmdTestBinding.ps1 | 76 +++++++ .../Tests/L0AppcmdTestSSLandSNI.ps1 | 121 ++++++++++ .../Tests/L0AppcmdTestVirtualDirExists.ps1 | 51 +++++ .../Tests/L0AppcmdTestWebsiteExists.ps1 | 51 +++++ .../Tests/L0UtilityManageApp.ps1 | 65 ++++++ .../Tests/L0UtilityManageAppPool.ps1 | 93 ++++++++ .../Tests/L0UtilityManageVDir.ps1 | 51 +++++ .../Tests/L0UtilityManageWebsite.ps1 | 147 +++++++++++++ .../Tests/MockHelpers.ps1 | 15 ++ .../Utility.ps1 | 39 +++- .../task.json | 8 +- .../task.loc.json | 8 +- .../tsconfig.json | 6 + 23 files changed, 1476 insertions(+), 18 deletions(-) create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0.ts create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateAppPool.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateApplication.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateVDir.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateWebsite.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAdditionalActions.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdExecuteMain.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationExists.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationPoolExists.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestBinding.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestSSLandSNI.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestVirtualDirExists.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestWebsiteExists.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageApp.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageAppPool.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageVDir.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageWebsite.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/Tests/MockHelpers.ps1 create mode 100644 Tasks/IISWebAppManagementOnMachineGroup/tsconfig.json diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Strings/resources.resjson/en-US/resources.resjson b/Tasks/IISWebAppManagementOnMachineGroup/Strings/resources.resjson/en-US/resources.resjson index ca755ea698f0..d8cd52ceb24c 100644 --- a/Tasks/IISWebAppManagementOnMachineGroup/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/IISWebAppManagementOnMachineGroup/Strings/resources.resjson/en-US/resources.resjson @@ -114,5 +114,7 @@ "loc.input.help.AppCmdCommands": "Enter additional AppCmd.exe commands. For more than one command use a line separator, like
list apppools
list sites
recycle apppool /apppool.name:ExampleAppPoolName", "loc.messages.InvalidSslThumbprint": "Invalid thumbprint. Length is not 40 characters or contains invalid characters.", "loc.messages.InvalidVirtualPath": "Virtual path should begin with a /", - "loc.messages.InvalidIISDeploymentType": "Invalid IIS Deployment Type : {0}" + "loc.messages.InvalidIISDeploymentType": "Invalid IIS Deployment Type : {0}", + "loc.messages.InvalidActionIISWebsite": "Invalid action '{0}' selected for the IIS Website.", + "loc.messages.InvalidActionIISAppPool": "Invalid action '{0}' selected for the IIS Application Pool." } \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0.ts b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0.ts new file mode 100644 index 000000000000..7f518868704e --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0.ts @@ -0,0 +1,95 @@ +/// +/// +/// + +import Q = require('q'); +import assert = require('assert'); +var path = require('path'); +var psm = require('../../../Tests/lib/psRunner'); +var shell = require('shelljs'); +var ps = shell.which('powershell.exe'); +var psr = null; + +describe('IISWebAppManagementOnMachineGroup Suite', function () { + this.timeout(20000); + + before((done) => { + if (ps) { + psr = new psm.PSRunner(); + psr.start(); + } + + done(); + }); + + after(function () { + psr.kill(); + }); + + if (ps) { + + it('test website exists', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestWebsiteExists.ps1'), done); + }) + + it('test add and update website', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdAddUpdateWebsite.ps1'), done); + }) + + it('test website add binding', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestBinding.ps1'), done); + }) + + it('test sni and sslcert addition', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestSSLandSNI.ps1'), done); + }) + + it('test application pool exists', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestApplicationPoolExists.ps1'), done); + }) + + it('test add and update appPool', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdAddUpdateAppPool.ps1'), done); + }) + + it('test application exists', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestApplicationExists.ps1'), done); + }) + + it('test add and update application function', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdAddUpdateApplication.ps1'), done); + }) + + it('test virtual directory exists function', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdTestVirtualDirExists.ps1'), done); + }) + + it('test add and update virtual directory function', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdAddUpdateVDir.ps1'), done); + }) + + it('test additional actions', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdAdditionalActions.ps1'), done); + }) + + it('test execute-main function', (done) => { + psr.run(path.join(__dirname, 'L0AppcmdExecuteMain.ps1'), done); + }) + + it('test iis manage utility - manage virtual directory', (done) => { + psr.run(path.join(__dirname, 'L0UtilityManageVDir.ps1'), done); + }) + + it('test iis manage utility - manage application', (done) => { + psr.run(path.join(__dirname, 'L0UtilityManageApp.ps1'), done); + }) + + it('test iis manage utility - manage application pool', (done) => { + psr.run(path.join(__dirname, 'L0UtilityManageAppPool.ps1'), done); + }) + + it('test iis manage utility - manage website', (done) => { + psr.run(path.join(__dirname, 'L0UtilityManageWebsite.ps1'), done); + }) + } +}); \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateAppPool.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateAppPool.ps1 new file mode 100644 index 000000000000..eaadb54ffda5 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateAppPool.ps1 @@ -0,0 +1,62 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$appPoolName = "Sample App Pool" +$dotNetVersion = "v4.0" +$pipeLineMode = "Integrated" +$appPoolIdentity = "ApplicationPoolIdentity" +$appPoolCredentials = $null + +#Test 1 : App pool doesn't exist. Create and update the app pool + +Register-Mock Test-AppPoolExist { return $false } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-AppPool -appPoolName $appPoolName -clrVersion $dotNetVersion -pipeLineMode $pipeLineMode -identity $appPoolIdentity -appPoolCredentials $appPoolCredentials + +Assert-WasCalled Test-AppPoolExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " add apppool /name:`"Sample App Pool`"" -RequireExitCodeZero +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set apppool /apppool.name:`"Sample App Pool`" -managedRuntimeVersion:v4.0 -managedPipelineMode:Integrated -processModel.identityType:ApplicationPoolIdentity" -RequireExitCodeZero + +#Test 2 : App pool exists. Update the app pool + +$pipeLineMode = "Classic" +$dotNetVersion = "No Managed Code" +$appPoolIdentity = "NetworkService" + +Unregister-Mock Test-AppPoolExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-AppPoolExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-AppPool -appPoolName $appPoolName -clrVersion $dotNetVersion -pipeLineMode $pipeLineMode -identity $appPoolIdentity -appPoolCredentials $appPoolCredentials + +Assert-WasCalled Test-AppPoolExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set apppool /apppool.name:`"Sample App Pool`" -managedRuntimeVersion: -managedPipelineMode:Classic -processModel.identityType:NetworkService" -RequireExitCodeZero + +#Test 3: Applicatin pool exists and updating the app pool identity for specific user + +$pipeLineMode = "Classic" +$dotNetVersion = "v2.0" +$appPoolIdentity = "SpecificUser" +$appPoolCredentials = Get-MockCredentials + +Unregister-Mock Test-AppPoolExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-AppPoolExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-AppPool -appPoolName $appPoolName -clrVersion $dotNetVersion -pipeLineMode $pipeLineMode -identity $appPoolIdentity -appPoolCredentials $appPoolCredentials + +Assert-WasCalled Test-AppPoolExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set apppool /apppool.name:`"Sample App Pool`" -managedRuntimeVersion:v2.0 -managedPipelineMode:Classic -processModel.identityType:SpecificUser -processModel.userName:`"domain\name`" -processModel.password:`"random!123```"`$password`"" -RequireExitCodeZero \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateApplication.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateApplication.ps1 new file mode 100644 index 000000000000..98fbd38b4667 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateApplication.ps1 @@ -0,0 +1,62 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$websiteName = "Sample Web Site" +$virtualPath = "/Application" +$physicalPath = "Drive:/Physical Path" +$appPoolName = "" +$physicalPathAuth = "ApplicationUserPassThrough" +$physicalPathAuthCredentials = $null + +Register-Mock Test-Path { return $true } -ParametersEvaluator { $Path -eq $physicalPath } + +# Test 1 : Application doesn't exist + +Register-Mock Test-ApplicationExist { return $false } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Application -siteName $websiteName -virtualPath $virtualPath -physicalPath $physicalPath -applicationPool $appPoolName -physicalPathAuthentication $physicalPathAuth -physicalPathAuthenticationCredentials $physicalPathAuthCredentials + +Assert-WasCalled Test-ApplicationExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " add app /site.name:`"Sample Web Site`" /path:`"/Application`" /physicalPath:`"Drive:/Physical Path`"" -RequireExitCodeZero +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set app /app.name:`"Sample Web Site/Application`" -[path='/'].physicalPath:`"Drive:/Physical Path`" -[path='/'].userName: -[path='/'].password:" -RequireExitCodeZero + +# Test 2 : Application Exists. Updating properties + +$physicalPath = "Drive:/New Physical Path" +$appPoolName = "Sample App Pool" + +Unregister-Mock Test-ApplicationExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-ApplicationExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Application -siteName $websiteName -virtualPath $virtualPath -physicalPath $physicalPath -applicationPool $appPoolName -physicalPathAuthentication $physicalPathAuth -physicalPathAuthenticationCredentials $physicalPathAuthCredentials + +Assert-WasCalled Test-ApplicationExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set app /app.name:`"Sample Web Site/Application`" -applicationPool:`"Sample App Pool`" -[path='/'].physicalPath:`"Drive:/New Physical Path`" -[path='/'].userName: -[path='/'].password:" -RequireExitCodeZero + +# Test 3 : Updating the application's physical path authentication + +$physicalPathAuth = "ApplicationWindowsAuth" +$physicalPathAuthCredentials = Get-MockCredentials + +Unregister-Mock Test-ApplicationExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-ApplicationExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Application -siteName $websiteName -virtualPath $virtualPath -physicalPath $physicalPath -applicationPool $appPoolName -physicalPathAuthentication $physicalPathAuth -physicalPathAuthenticationCredentials $physicalPathAuthCredentials + +Assert-WasCalled Test-ApplicationExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set app /app.name:`"Sample Web Site/Application`" -applicationPool:`"Sample App Pool`" -[path='/'].physicalPath:`"Drive:/New Physical Path`" -[path='/'].userName:`"domain\name`" -[path='/'].password:`"random!123```"`$password`"" -RequireExitCodeZero diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateVDir.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateVDir.ps1 new file mode 100644 index 000000000000..1b8bd500af5b --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateVDir.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$websiteName = "Sample Web Site" +$virtualPath = "/Applcation/VDir" +$physicalPath = "Drive:/Physical Path" +$physicalPathAuth = "VDUserPassThrough" +$physicalPathAuthCredentials = $null + +Register-Mock Test-Path { return $true } -ParametersEvaluator { $Path -eq $physicalPath } + +#Test 1 : Virtual Directory doesn't exist. Create new + +Register-Mock Test-VirtualDirectoryExist { return $false } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-VirtualDirectory -siteName $websiteName -virtualPath $virtualPath -physicalPath $physicalPath -physicalPathAuthentication $physicalPathAuth -physicalPathAuthenticationCredentials $physicalPathAuthCredentials + +Assert-WasCalled Test-VirtualDirectoryExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " add vdir /app.name:`"Sample Web Site/Applcation`" /path:`"/VDir`" /physicalPath:`"Drive:/Physical Path`"" -RequireExitCodeZero +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set vdir /vdir.name:`"Sample Web Site/Applcation/VDir`" -physicalPath:`"Drive:/Physical Path`" -userName: -password:" -RequireExitCodeZero + +# Test 2 : Virtual Directory exists. Updating + +$physicalPathAuth = "VDWindowsAuth" +$physicalPathAuthCredentials = Get-MockCredentials + +Unregister-Mock Test-VirtualDirectoryExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-VirtualDirectoryExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-VirtualDirectory -siteName $websiteName -virtualPath $virtualPath -physicalPath $physicalPath -physicalPathAuthentication $physicalPathAuth -physicalPathAuthenticationCredentials $physicalPathAuthCredentials + +Assert-WasCalled Test-VirtualDirectoryExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set vdir /vdir.name:`"Sample Web Site/Applcation/VDir`" -physicalPath:`"Drive:/Physical Path`" -userName:`"domain\name`" -password:`"random!123```"`$password`"" -RequireExitCodeZero diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateWebsite.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateWebsite.ps1 new file mode 100644 index 000000000000..5b27c887c6a3 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAddUpdateWebsite.ps1 @@ -0,0 +1,121 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$siteName = "Sample Web Site" +$appPoolName = "" +$physicalPath = "Drive:/RandomPath" +$authType = "WebsiteUserPassThrough" +$websitePhysicalPathAuthCredentials = $null +$addBinding = "false" +$protocol = "http" +$ipAddress = "All Unassigned" +$port = "8080" +$hostname = $null + +# Test 1 : Website exists and without add binding input + +Register-Mock Test-WebsiteExist { return $true } +Register-Mock Test-Path { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Website -siteName $siteName -appPoolName $appPoolName -physicalPath $physicalPath -authType $authType ` + -websitePhysicalPathAuthCredentials $websitePhysicalPathAuthCredentials -addBinding $addBinding -protocol $protocol ` + -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Test-WebsiteExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 + +# Test 2 : Website does not exist and add binding input is enabled and binding does not exist for any site + +$addBinding = "true" + +Unregister-Mock Test-WebsiteExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-WebsiteExist { return $false } +Register-Mock Test-BindingExist { return $false } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Website -siteName $siteName -appPoolName $appPoolName -physicalPath $physicalPath -authType $authType ` + -websitePhysicalPathAuthCredentials $websitePhysicalPathAuthCredentials -addBinding $addBinding -protocol $protocol ` + -ipAddress $ipAddress -port $port -hostname $hostname + + +Assert-WasCalled Test-WebsiteExist -Times 1 +Assert-WasCalled Test-BindingExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " add site /name:`"Sample Web Site`" /physicalPath:`"Drive:/RandomPath`"" -RequireExitCodeZero +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set site /site.name:`"Sample Web Site`" -[path='/'].[path='/'].physicalPath:`"Drive:/RandomPath`" -[path='/'].[path='/'].userName: -[path='/'].[path='/'].password: /+bindings.[protocol='http',bindingInformation='*:8080:']" -RequireExitCodeZero + +# Test 3 : Website exists and update app pool is enabled and binding already exists for the current site + +$appPoolName = "Sample App Pool" +$addBinding = "true" + +Unregister-Mock Test-WebsiteExist +Unregister-Mock Test-BindingExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-WebsiteExist { return $true } +Register-Mock Test-BindingExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Website -siteName $siteName -appPoolName $appPoolName -physicalPath $physicalPath -authType $authType ` + -websitePhysicalPathAuthCredentials $websitePhysicalPathAuthCredentials -addBinding $addBinding -protocol $protocol ` + -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Test-WebsiteExist -Times 1 +Assert-WasCalled Test-BindingExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set site /site.name:`"Sample Web Site`" -applicationDefaults.applicationPool:`"Sample App Pool`" -[path='/'].[path='/'].physicalPath:`"Drive:/RandomPath`" -[path='/'].[path='/'].userName: -[path='/'].[path='/'].password:" -RequireExitCodeZero + +# Test 4 : Add binding with specific ip address and hostname + +$appPoolName = "" +$addBinding = "true" +$ipAddress = "127.0.0.1" +$hostname = "somehost" + +Unregister-Mock Test-WebsiteExist +Unregister-Mock Test-BindingExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-WebsiteExist { return $true } +Register-Mock Test-BindingExist { return $false } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Website -siteName $siteName -appPoolName $appPoolName -physicalPath $physicalPath -authType $authType ` + -websitePhysicalPathAuthCredentials $websitePhysicalPathAuthCredentials -addBinding $addBinding -protocol $protocol ` + -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Test-WebsiteExist -Times 1 +Assert-WasCalled Test-BindingExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set site /site.name:`"Sample Web Site`" -[path='/'].[path='/'].physicalPath:`"Drive:/RandomPath`" -[path='/'].[path='/'].userName: -[path='/'].[path='/'].password: /+bindings.[protocol='http',bindingInformation='127.0.0.1:8080:somehost']" -RequireExitCodeZero + +# Test 5 : Physical path authentication input is enabled + +$authType = "WebsiteWindowsAuth" +$websitePhysicalPathAuthCredentials = Get-MockCredentials + +Unregister-Mock Test-WebsiteExist +Unregister-Mock Test-BindingExist +Unregister-Mock Invoke-VstsTool + +Register-Mock Test-WebsiteExist { return $true } +Register-Mock Test-BindingExist { return $true } +Register-Mock Invoke-VstsTool { } + +Add-And-Update-Website -siteName $siteName -appPoolName $appPoolName -physicalPath $physicalPath -authType $authType ` + -websitePhysicalPathAuthCredentials $websitePhysicalPathAuthCredentials -addBinding $addBinding -protocol $protocol ` + -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Test-WebsiteExist -Times 1 +Assert-WasCalled Test-BindingExist -Times 1 +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " set site /site.name:`"Sample Web Site`" -[path='/'].[path='/'].physicalPath:`"Drive:/RandomPath`" -[path='/'].[path='/'].userName:`"domain\name`" -[path='/'].[path='/'].password:`"random!123```"`$password`"" -RequireExitCodeZero diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAdditionalActions.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAdditionalActions.ps1 new file mode 100644 index 000000000000..ce486cc6cb7f --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdAdditionalActions.ps1 @@ -0,0 +1,70 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$sitename = "Sample Web Site" +$appPoolName = "Sample App Pool" + +# Test 1 : Start Website + +$action = "start" + +Register-Mock Invoke-VstsTool { } + +Start-Stop-Website -sitename $sitename -action $action + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments "start site /site.name:`"Sample Web Site`"" -RequireExitCodeZero + +# Test 2 : Stop Website + +$action = "stop" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { } + +Start-Stop-Website -sitename $sitename -action $action + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments "stop site /site.name:`"Sample Web Site`"" -RequireExitCodeZero + +# Test 3 : Start Application Pool + +$action = "start" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { } + +Start-Stop-Recycle-ApplicationPool -appPoolName $appPoolName -action $action + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments "start apppool /apppool.name:`"Sample App Pool`"" -RequireExitCodeZero + +# Test 4 : Stop Application Pool + +$action = "stop" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { } + +Start-Stop-Recycle-ApplicationPool -appPoolName $appPoolName -action $action + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments "stop apppool /apppool.name:`"Sample App Pool`"" -RequireExitCodeZero + +# Test 5 : Recycle Application Pool + +$action = "recycle" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { } + +Start-Stop-Recycle-ApplicationPool -appPoolName $appPoolName -action $action + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments "recycle apppool /apppool.name:`"Sample App Pool`"" -RequireExitCodeZero + diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdExecuteMain.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdExecuteMain.ps1 new file mode 100644 index 000000000000..057d4e246ad5 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdExecuteMain.ps1 @@ -0,0 +1,207 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$createVirtualDirectory = "" +$createApplication = "false" + +$actionIISWebsite = "CreateOrUpdateWebsite" +$actionIISApplicationPool = "" + +$virtualPath = "" + +$websiteName = "Sample Web Site" +$physicalPath = "Drive:/Physical path" +$physicalPathAuth = "WebsiteUserPassThrough" +$physicalPathAuthCredentials = $null + +$addBinding = "false" +$protocol = "http" +$ipAddress = "All Unassigned" +$port = "8080" +$hostNameWithOutSNI = "" +$hostNameWithHttp = "" +$hostNameWithSNI = "" +$serverNameIndication = "false" +$sslCertThumbPrint = "" + +$appPoolName = "" +$dotNetVersion = "" +$pipeLineMode = "" +$appPoolIdentity = "" +$appPoolCredentials = $null + +$appCmdCommands = "" + +# Test 1 + +Register-Mock Test-Path { return $true } +Register-Mock Add-And-Update-Website { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Add-And-Update-Website -Times 1 +Assert-WasCalled Add-And-Update-Website -- -siteName "Sample Web Site" -appPoolName "" -physicalPath "Drive:/Physical path" -authType "WebsiteUserPassThrough" -websitePhysicalPathAuthCredentials $null -addBinding "false" -protocol "http" -ipAddress "All Unassigned" -port "8080" -hostname "" + +# Test 2 + +$actionIISApplicationPool = "CreateOrUpdateAppPool" + +Unregister-Mock Add-And-Update-Website + +Register-Mock Add-And-Update-Website { } +Register-Mock Add-And-Update-AppPool { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Add-And-Update-AppPool -Times 1 +Assert-WasCalled Add-And-Update-Website -Times 1 + +# Test 3 + +$addBinding = "true" +$protocol = "https" + +Unregister-Mock Add-And-Update-Website +Unregister-Mock Add-And-Update-AppPool + +Register-Mock Add-And-Update-AppPool { } +Register-Mock Add-And-Update-Website { } +Register-Mock Add-SslCert { } +Register-Mock Enable-SNI { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Add-And-Update-AppPool -Times 1 +Assert-WasCalled Add-And-Update-Website -Times 1 +Assert-WasCalled Add-SslCert -Times 1 +Assert-WasCalled Enable-SNI -Times 1 + +# Test 4 + +$actionIISWebsite = "StartWebsite" +Register-Mock Start-Stop-Website { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Start-Stop-Website -- -siteName "Sample Web Site" -action "Start" + +# Test 5 + +$actionIISWebsite = "StopWebsite" +Unregister-Mock Start-Stop-Website +Register-Mock Start-Stop-Website { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Start-Stop-Website -- -siteName "Sample Web Site" -action "Stop" + +# Test 6 + +$appPoolName = "Sample App Pool" +$actionIISApplicationPool = "StartAppPool" + +Register-Mock Start-Stop-Recycle-ApplicationPool { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Start-Stop-Recycle-ApplicationPool -- -appPoolName "Sample App Pool" -action "Start" + +# Test 7 + +$appPoolName = "Sample App Pool" +$actionIISApplicationPool = "StopAppPool" + +Unregister-Mock Start-Stop-Recycle-ApplicationPool +Register-Mock Start-Stop-Recycle-ApplicationPool { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Start-Stop-Recycle-ApplicationPool -- -appPoolName "Sample App Pool" -action "Stop" + +# Test 8 + +$appPoolName = "Sample App Pool" +$actionIISApplicationPool = "RecycleAppPool" + +Unregister-Mock Start-Stop-Recycle-ApplicationPool +Register-Mock Start-Stop-Recycle-ApplicationPool { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Start-Stop-Recycle-ApplicationPool -- -appPoolName "Sample App Pool" -action "Recycle" + +# Test 9 + +$CreateApplication = "true" + +Register-Mock Add-And-Update-Application { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Add-And-Update-Application -Times 1 + +# Test 10 + +$CreateVirtualDirectory = "true" + +Register-Mock Add-And-Update-VirtualDirectory { } + +Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $websiteName -virtualPath $virtualPath -actionIISApplicationPool $actionIISApplicationPool -createVirtualDirectory $createVirtualDirectory -createApplication $createApplication -PhysicalPath $physicalPath -PhysicalPathAuth $physicalPathAuth ` + -PhysicalPathAuthCredentials $physicalPathAuthCredentials -AddBinding $addBinding -Protocol $protocol -IpAddress $ipAddress ` + -Port $port -HostNameWithOutSNI $hostNameWithOutSNI -HostNameWithHttp $hostNameWithHttp -HostNameWithSNI $hostNameWithSNI ` + -ServerNameIndication $serverNameIndication -SslCertThumbPrint $sslCertThumbPrint ` + -AppPoolName $appPoolName -DotNetVersion $dotNetVersion -PipeLineMode $pipeLineMode ` + -AppPoolIdentity $appPoolIdentity -AppPoolCredentials $appPoolCredentials -AppCmdCommands $appCmdCommands + +Assert-WasCalled Add-And-Update-VirtualDirectory -Times 1 + diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationExists.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationExists.ps1 new file mode 100644 index 000000000000..ab49d7ec0121 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationExists.ps1 @@ -0,0 +1,50 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$applicationName = "Sample Web Site/Application" + +# Test 1 : Application does not exist +Register-Mock Invoke-VstsTool { + return $null +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list app `"Sample Web Site/Application`"" } + +$result = Test-ApplicationExist -applicationName $applicationName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list app `"Sample Web Site/Application`"" +Assert-AreEqual $false $result + +# Test 2 : Application already exists + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return "APP `"Sample Web Site/Application`" (applicationPool:DefaultAppPool)" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list app `"Sample Web Site/Application`"" } + +$result = Test-ApplicationExist -applicationName $applicationName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list app `"Sample Web Site/Application`"" +Assert-AreEqual $true $result + +# Test 3 : Return false if appcmd throws error + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + Write-Verbose "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" + return "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list app `"Sample Web Site/Application`"" } + +$result = Test-ApplicationExist -applicationName $applicationName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list app `"Sample Web Site/Application`"" +Assert-AreEqual $false $result \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationPoolExists.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationPoolExists.ps1 new file mode 100644 index 000000000000..298b86289a2e --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestApplicationPoolExists.ps1 @@ -0,0 +1,48 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$appPoolName = "Sample App Pool" + +# Test 1 : Application pool does not exist + +Register-Mock Invoke-VstsTool { return $null } + +$result = Test-AppPoolExist -appPoolName $appPoolName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list apppool /name:`"Sample App Pool`"" +Assert-AreEqual $false $result + +# Test 2 : Application pool already exists + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return "apppool /name:`"Sample App Pool`" (applicationPool:DefaultAppPool)" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list apppool /name:`"Sample App Pool`"" } + +$result = Test-AppPoolExist -appPoolName $appPoolName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list apppool /name:`"Sample App Pool`"" +Assert-AreEqual $true $result + +# Test 3 : Return false if appcmd throws error + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + Write-Verbose "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" + return "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list apppool /name:`"Sample App Pool`"" } + +$result = Test-AppPoolExist -appPoolName $appPoolName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list apppool /name:`"Sample App Pool`"" +Assert-AreEqual $false $result \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestBinding.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestBinding.ps1 new file mode 100644 index 000000000000..50ce30fdaa63 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestBinding.ps1 @@ -0,0 +1,76 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$siteName = "Sample Web Site" +$protocol = "http" +$ipAddress = "*" +$port = "8080" +$hostname = "" + +$binding1 = [string]::Format("{0}/{1}:{2}:{3}", "http", $ipAddress, "80", "") +$binding2 = [string]::Format("{0}/{1}:{2}:{3}", "http", $ipAddress, "90", "localhost") +$binding3 = [string]::Format("{0}/{1}:{2}:{3}", "https", "$ipAddress", "100", "") + +# Test 1 : Binding doesn't exist for any site + +Register-Mock Invoke-VstsTool { + return @("SITE `"Sample Site1`" (id:1,bindings:$binding1,state:Started)", + "SITE `"Sample Site2`" (id:2,bindings:$binding2,state:Started))", + "SITE `"Test Web Site`" (id:3,bindings:$binding3,state:Unknown))" + ) + +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list sites" } + +$result = Test-BindingExist -siteName $siteName -protocol $protocol -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-AreEqual $false $result + +# Test 2 : Binding already exists for the current site + +$protocol = "https" +$port = "100" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return @("SITE `"Sample Site1`" (id:1,bindings:$binding1,state:Started)", + "SITE `"Sample Site2`" (id:2,bindings:$binding2,state:Started))", + "SITE `"Sample Web Site`" (id:3,bindings:$binding3,state:Started))" + ) + +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list sites" } + +$result = Test-BindingExist -siteName $siteName -protocol $protocol -ipAddress $ipAddress -port $port -hostname $hostname + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-AreEqual $true $result + +# Test 3 : Binding exists for a different website + +$protocol = "http" +$port = "90" +$hostname = "localhost" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return @("SITE `"Sample Site1`" (id:1,bindings:$binding1,state:Started)", + "SITE `"Sample Site2`" (id:2,bindings:$binding2,state:Started))", + "SITE `"Sample Web Site`" (id:3,bindings:$binding3,state:Started))" + ) + +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list sites" } + +Assert-Throws { + Test-BindingExist -siteName $siteName -protocol $protocol -ipAddress $ipAddress -port $port -hostname $hostname +} -MessagePattern "Given binding already exists for a different website*" + +Assert-WasCalled Invoke-VstsTool -Times 1 + diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestSSLandSNI.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestSSLandSNI.ps1 new file mode 100644 index 000000000000..f89f7f760a86 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestSSLandSNI.ps1 @@ -0,0 +1,121 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +# Test 1 : SNI is not enabled if SNI input is not set + +$WebsiteName = "Sample Web Site" +$ServerNameIndication = "false" +$IpAddress = "All Unassigned" +$Port = "8080" +$HostName = "somehost" + +Register-Mock Invoke-VstsTool { } + +Enable-SNI -siteName $WebsiteName -sni $ServerNameIndication -ipAddress $IpAddress -port $Port -hostname $HostName + +Assert-WasCalled Invoke-VstsTool -Times 0 + +# Test 2 : SNI input is set + +$ServerNameIndication = "true" + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { } + +Enable-SNI -siteName $WebsiteName -sni $ServerNameIndication -ipAddress $IpAddress -port $Port -hostname $HostName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "appcmdPath" -Arguments " set site /site.name:`"Sample Web Site`" /bindings.[protocol='https',bindingInformation='*:8080:somehost'].sslFlags:`"1`"" -RequireExitCodeZero + +# Test 3 : Add-SslCert with certifcate not already present + +$Port = "8080" +$IpAddress = "All Unassigned" +$SslCertThumbPrint = "asdfghjklqwertyuiopzxcvbnmqazwsxedcrfvtg" +$HostName = "somehost" +$ServerNameIndication = "false" +$iisVersion = 8 + +Unregister-Mock Invoke-VstsTool + +Register-Mock Invoke-VstsTool { + return @( + "`n", + "SSL Certificate bindings:", + "-------------------------", + "`n", + "The system cannot find the file specified.", + "`n" + ) +} -ParametersEvaluator { $Arguments -eq "http show sslcert ipport=0.0.0.0:8080"} + +Add-SslCert -ipAddress $IpAddress -port $Port -certhash $SslCertThumbPrint -hostname $HostName -sni $ServerNameIndication -iisVersion $iisVersion + +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -Filename "netsh" -Arguments "http show sslcert ipport=0.0.0.0:8080" +Assert-WasCalled Invoke-VstsTool -ParametersEvaluator { + $Arguments -like "http add sslcert ipport=0.0.0.0:8080 certhash=asdfghjklqwertyuiopzxcvbnmqazwsxedcrfvtg appid={*} certstorename=MY" +} + +# Test 4 : Add-SslCert with certifcate already present + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return @( + "`n", + "SSL Certificate bindings:", + "-------------------------", + "`n", + " IP:port : 0.0.0.0:8080", + " Certificate Hash : asdfghjklqwertyuiopzxcvbnmqazwsxedcrfvtg", + " Application ID : {randomClientGuid}", + " Certificate Store Name : My", + " Verify Client Certificate Revocation : Enabled", + " Verify Revocation Using Cached Client Certificate Only : Disabled" + " Usage Check : Enabled", + " Revocation Freshness Time : 0", + " URL Retrieval Timeout : 0", + " Ctl Identifier : (null)", + " Ctl Store Name : (null)", + " DS Mapper Usage : Disabled", + " Negotiate Client Certificate : Disabled", + " Reject Connections : Disabled" + ) +} -ParametersEvaluator { $Arguments -eq "http show sslcert ipport=0.0.0.0:8080"} + +Add-SslCert -ipAddress $IpAddress -port $Port -certhash $SslCertThumbPrint -hostname $HostName -sni $ServerNameIndication -iisVersion $iisVersion + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -Filename "netsh" -Arguments "http show sslcert ipport=0.0.0.0:8080" + +# Test 5 : Add-SslCert with SNI enabled and certificate not present + +$ServerNameIndication = "true" + +Unregister-Mock Invoke-VstsTool + +Register-Mock Invoke-VstsTool { + return @( + "`n", + "SSL Certificate bindings:", + "-------------------------", + "`n", + "The system cannot find the file specified.", + "`n" + ) +} -ParametersEvaluator { $Arguments -eq "http show sslcert hostnameport=somehost:8080"} + +Add-SslCert -ipAddress $IpAddress -port $Port -certhash $SslCertThumbPrint -hostname $HostName -sni $ServerNameIndication -iisVersion $iisVersion + +Assert-WasCalled Invoke-VstsTool -Times 2 +Assert-WasCalled Invoke-VstsTool -- -Filename "netsh" -Arguments "http show sslcert hostnameport=somehost:8080" +Assert-WasCalled Invoke-VstsTool -ParametersEvaluator { + $Arguments -like "http add sslcert hostnameport=somehost:8080 certhash=asdfghjklqwertyuiopzxcvbnmqazwsxedcrfvtg appid={*} certstorename=MY" +} + + diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestVirtualDirExists.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestVirtualDirExists.ps1 new file mode 100644 index 000000000000..6fcecb946921 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestVirtualDirExists.ps1 @@ -0,0 +1,51 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$virtualDirectoryName = "Sample Web Site/Application/VirtualDir" + +# Test 1 : Virtual directory does not exist + +Register-Mock Invoke-VstsTool { + return $null +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" } + +$result = Test-VirtualDirectoryExist -virtualDirectoryName $virtualDirectoryName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" +Assert-AreEqual $false $result + +# Test 2 : Virtual directory already exist + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return "vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`" (applicationPool:Defaultvdir)" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" } + +$result = Test-VirtualDirectoryExist -virtualDirectoryName $virtualDirectoryName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" +Assert-AreEqual $true $result + +# Test 3 : Return false if appcmd throws error + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + Write-Verbose "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" + return "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" } + +$result = Test-VirtualDirectoryExist -virtualDirectoryName $virtualDirectoryName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list vdir -vdir.name:`"Sample Web Site/Application/VirtualDir`"" +Assert-AreEqual $false $result \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestWebsiteExists.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestWebsiteExists.ps1 new file mode 100644 index 000000000000..8f56223023be --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0AppcmdTestWebsiteExists.ps1 @@ -0,0 +1,51 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\ps_modules\TaskModuleIISManageUtility\AppCmdOnTargetMachines.ps1 + +$siteName = "Sample Web Site" + +# Test 1 : Returns false if website does not exist +Register-Mock Invoke-VstsTool { + return $null +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list site /name:`"Sample Web Site`"" } + +$result = Test-WebsiteExist -siteName $siteName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list site /name:`"Sample Web Site`"" +Assert-AreEqual $false $result + +# Test 2 : Returns true if website already exists + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + return "SITE `"Sample Web Site`" (id:1,bindings:http/*:80:,state:Started)" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list site /name:`"Sample Web Site`"" } + +$result = Test-WebsiteExist -siteName $siteName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list site /name:`"Sample Web Site`"" +Assert-AreEqual $true $result + +# Test 3 : Returns false if appcmd.exe throws error + +Unregister-Mock Invoke-VstsTool +Register-Mock Invoke-VstsTool { + Write-Verbose "Invoking stubbed tool" + Write-Verbose "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" + return "ERROR ( message:Configuration error`nFilename: redirection.config`nLine Number: 0`nDescription: Cannot read configuration file due to insufficient permissions. )" +} -ParametersEvaluator { $FileName -eq "appcmdPath" -and + $Arguments -eq " list site /name:`"Sample Web Site`"" } + +$result = Test-WebsiteExist -siteName $siteName + +Assert-WasCalled Invoke-VstsTool -Times 1 +Assert-WasCalled Invoke-VstsTool -- -FileName "appcmdPath" -Arguments " list site /name:`"Sample Web Site`"" +Assert-AreEqual $false $result \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageApp.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageApp.ps1 new file mode 100644 index 000000000000..ec2afad12b31 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageApp.ps1 @@ -0,0 +1,65 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\Utility.ps1 + +$parentWebsiteNameForApplication = "Sample Web Site" +$virtualPathForApplication = "/Application" +$physicalPathForApplication = "Drive:/Physical Path" +$applicationPhysicalPathAuth = "ApplicationUserPassThrough" +$applicationAuthUserName = "" +$applicationAuthUserPassword = "" + +$createOrUpdateAppPoolForApplication = "false" +$appPoolNameForApplication = "Sample App Pool" +$dotNetVersionForApplication = "v4.0" +$pipeLineModeForApplication = "Integrated" +$appPoolIdentityForApplication = "ApplicationPoolIdentity" +$appPoolUsernameForApplication = "" +$appPoolPasswordForApplication = "" +$appCmdCommands = "" + +# Test 1 + +Register-Mock Execute-Main { } + +Manage-IISWebApplication -parentWebsiteName $parentWebsiteNameForApplication -virtualPath $virtualPathForApplication -physicalPath $physicalPathForApplication -physicalPathAuth $applicationPhysicalPathAuth -physicalPathAuthUserName $applicationAuthUserName -physicalPathAuthUserPassword $applicationAuthUserPassword ` + -createOrUpdateAppPool $createOrUpdateAppPoolForApplication -appPoolName $appPoolNameForApplication -dotNetVersion $dotNetVersionForApplication -pipeLineMode $pipeLineModeForApplication -appPoolIdentity $appPoolIdentityForApplication -appPoolUsername $appPoolUsernameForApplication -appPoolPassword $appPoolPasswordForApplication ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -CreateApplication "True" -WebsiteName "Sample Web Site" -VirtualPath "/Application" -PhysicalPath "Drive:/Physical Path" -PhysicalPathAuth "ApplicationUserPassThrough" -PhysicalPathAuthCredentials $null -AppCmdCommands "" + +# Test 2 + +$applicationPhysicalPathAuth = "ApplicationWindowsAuth" +$createOrUpdateAppPoolForApplication = "true" +$appPoolIdentityForApplication = "SpecificUser" +$appPoolUsernameForApplication = "" +$appPoolPasswordForApplication = "" + +Unregister-Mock Execute-Main + +Register-Mock Execute-Main { } +Register-Mock Get-CustomCredentials { return "CustomCredentialsObject" } + +Manage-IISWebApplication -parentWebsiteName $parentWebsiteNameForApplication -virtualPath $virtualPathForApplication -physicalPath $physicalPathForApplication -physicalPathAuth $applicationPhysicalPathAuth -physicalPathAuthUserName $applicationAuthUserName -physicalPathAuthUserPassword $applicationAuthUserPassword ` + -createOrUpdateAppPool $createOrUpdateAppPoolForApplication -appPoolName $appPoolNameForApplication -dotNetVersion $dotNetVersionForApplication -pipeLineMode $pipeLineModeForApplication -appPoolIdentity $appPoolIdentityForApplication -appPoolUsername $appPoolUsernameForApplication -appPoolPassword $appPoolPasswordForApplication ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Get-CustomCredentials -Times 2 +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -CreateApplication "True" -WebsiteName "Sample Web Site" -VirtualPath "/Application" -PhysicalPath "Drive:/Physical Path" -PhysicalPathAuth "ApplicationWindowsAuth" -PhysicalPathAuthCredentials "CustomCredentialsObject" -ActionIISApplicationPool "CreateOrUpdateAppPool" -AppPoolName "Sample App Pool" -DotNetVersion "v4.0" -PipeLineMode "Integrated" -AppPoolIdentity "SpecificUser" -AppPoolCredentials "CustomCredentialsObject" -AppCmdCommands "" + +# Test 3 + +$virtualPathForApplication = "Application" + +Assert-Throws { + Manage-IISWebApplication -parentWebsiteName $parentWebsiteNameForApplication -virtualPath $virtualPathForApplication -physicalPath $physicalPathForApplication -physicalPathAuth $applicationPhysicalPathAuth -physicalPathAuthUserName $applicationAuthUserName -physicalPathAuthUserPassword $applicationAuthUserPassword ` + -createOrUpdateAppPool $createOrUpdateAppPoolForApplication -appPoolName $appPoolNameForApplication -dotNetVersion $dotNetVersionForApplication -pipeLineMode $pipeLineModeForApplication -appPoolIdentity $appPoolIdentityForApplication -appPoolUsername $appPoolUsernameForApplication -appPoolPassword $appPoolPasswordForApplication ` + -appCmdCommands $appCmdCommands +} -MessagePattern "InvalidVirtualPath" \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageAppPool.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageAppPool.ps1 new file mode 100644 index 000000000000..1bbcaed35cdc --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageAppPool.ps1 @@ -0,0 +1,93 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\Utility.ps1 + +$actionIISApplicationPool = "CreateOrUpdateAppPool" +$appPoolName = "Sample App Pool" +$startStopRecycleAppPoolName = "" +$dotNetVersion = "v4.0" +$pipeLineMode = "Classic" +$appPoolIdentity = "ApplicationPoolIdentity" +$appPoolUsername = "" +$appPoolPassword = "" +$appCmdCommands = "" + +# Test 1 + +Register-Mock Execute-Main { } + +Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISApplicationPool "CreateOrUpdateAppPool" -AppPoolName "Sample App Pool" -DotNetVersion "v4.0" -PipeLineMode "Classic" -AppPoolIdentity "ApplicationPoolIdentity" -AppPoolCredentials $null -AppCmdCommands "" + +# Test 2 + +$appPoolIdentity = "SpecificUser" + +Unregister-Mock Execute-Main + +Register-Mock Execute-Main { } +Register-Mock Get-CustomCredentials { return "CustomCredentialsObject" } + +Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISApplicationPool "CreateOrUpdateAppPool" -AppPoolName "Sample App Pool" -DotNetVersion "v4.0" -PipeLineMode "Classic" -AppPoolIdentity "SpecificUser" -AppPoolCredentials "CustomCredentialsObject" -AppCmdCommands "" + +# Test 3 + +$actionIISApplicationPool = "StartAppPool" +$startStopRecycleAppPoolName = "Sample App Pool" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISApplicationPool "StartAppPool" -AppPoolName "Sample App Pool" -AppCmdCommands "" + +# Test 4 + +$actionIISApplicationPool = "StopAppPool" +$startStopRecycleAppPoolName = "Sample App Pool" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISApplicationPool "StopAppPool" -AppPoolName "Sample App Pool" -AppCmdCommands "" + +# Test 5 + +$actionIISApplicationPool = "RecycleAppPool" +$startStopRecycleAppPoolName = "Sample App Pool" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISApplicationPool "RecycleAppPool" -AppPoolName "Sample App Pool" -AppCmdCommands "" + +# Test 6 + +$actionIISApplicationPool = "InvalidOption" + +Assert-Throws { + Manage-IISApplicationPool -actionIISApplicationPool $actionIISApplicationPool -appPoolName $appPoolName -startStopRecycleAppPoolName $startStopRecycleAppPoolName -dotNetVersion $dotNetVersion ` + -pipeLineMode $pipeLineMode -appPoolIdentity $appPoolIdentity -appPoolUsername $appPoolUsername -appPoolPassword $appPoolPassword -appCmdCommands $appCmdCommands +} -MessagePattern "InvalidActionIISAppPool InvalidOption" \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageVDir.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageVDir.ps1 new file mode 100644 index 000000000000..0d39cf8ee459 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageVDir.ps1 @@ -0,0 +1,51 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\Utility.ps1 + +$parentWebsiteNameForVD = "Sample Web Site" +$virtualPathForVD = "/App/Vdir" +$physicalPathForVD = "Drive:/Physical path" +$vdPhysicalPathAuth = "VDUserPassThrough" +$vdAuthUserName = "" +$vdAuthUserPassword = "" +$appCmdCommands = "" + +# Test 1 + +Register-Mock Execute-Main { } + +Manage-IISVirtualDirectory -parentWebsiteName $parentWebsiteNameForVD -virtualPath $virtualPathForVD -physicalPath $physicalPathForVD -PhysicalPathAuth $vdPhysicalPathAuth ` + -physicalPathAuthUserName $vdAuthUserName -physicalPathAuthUserPassword $vdAuthUserPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -CreateVirtualDirectory "True" -WebsiteName "Sample Web Site" -VirtualPath "/App/Vdir" -PhysicalPath "Drive:/Physical path" -PhysicalPathAuth "VDUserPassThrough" -PhysicalPathAuthCredentials $null -AppCmdCommands "" + +# Test 2 + +$virtualPathForVD = "App/Vdir" +Assert-Throws { + Manage-IISVirtualDirectory -parentWebsiteName $parentWebsiteNameForVD -virtualPath $virtualPathForVD -physicalPath $physicalPathForVD -PhysicalPathAuth $vdPhysicalPathAuth ` + -physicalPathAuthUserName $vdAuthUserName -physicalPathAuthUserPassword $vdAuthUserPassword -appCmdCommands $appCmdCommands +} -MessagePattern "InvalidVirtualPath" + +# Test 3 + +$virtualPathForVD = "/App/Vdir" +$vdPhysicalPathAuth = "VDWindowsAuth" +$vdAuthUserName = "name" +$vdAuthUserPassword = "pass" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Register-Mock Get-CustomCredentials { return "CustomCredentialsObject" } + +Manage-IISVirtualDirectory -parentWebsiteName $parentWebsiteNameForVD -virtualPath $virtualPathForVD -physicalPath $physicalPathForVD -PhysicalPathAuth $vdPhysicalPathAuth ` + -physicalPathAuthUserName $vdAuthUserName -physicalPathAuthUserPassword $vdAuthUserPassword -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -CreateVirtualDirectory "True" -WebsiteName "Sample Web Site" -VirtualPath "/App/Vdir" -PhysicalPath "Drive:/Physical path" -PhysicalPathAuth "VDWindowsAuth" -PhysicalPathAuthCredentials "CustomCredentialsObject" -AppCmdCommands "" \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageWebsite.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageWebsite.ps1 new file mode 100644 index 000000000000..3c77411484b4 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/L0UtilityManageWebsite.ps1 @@ -0,0 +1,147 @@ +[CmdletBinding()] +param() + +. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1 +. $PSScriptRoot\MockHelpers.ps1 + +. $PSScriptRoot\..\Utility.ps1 + +$actionIISWebsite = "CreateOrUpdateWebsite" +$websiteName = "Sample Web Site" +$startStopWebsiteName = "" +$websitePhysicalPath = "Drive:\Physical Path" +$websitePhysicalPathAuth = "WebsiteUserPassThrough" +$websiteAuthUserName = "" +$websiteAuthUserPassword = "" +$addBinding = "true" +$protocol = "http" +$ipAddress = "All Unassigned" +$port = "8080" +$serverNameIndication = "false" +$hostNameWithOutSNI = "" +$hostNameWithHttp = "" +$hostNameWithSNI = "" +$sslCertThumbPrint = "" +$createOrUpdateAppPoolForWebsite = "false" +$appPoolNameForWebsite = "Sample App Pool" +$dotNetVersionForWebsite = "v4.0" +$pipeLineModeForWebsite = "Integrated" +$appPoolIdentityForWebsite = "ApplicationPoolIdentity" +$appPoolUsernameForWebsite = "" +$appPoolPasswordForWebsite = "" +$appCmdCommands = "" + +# Test 1 + +Register-Mock Execute-Main { } + +Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISWebsite "CreateOrUpdateWebsite" -WebsiteName "Sample Web Site" -PhysicalPath "Drive:\Physical Path" -PhysicalPathAuth "WebsiteUserPassThrough" -PhysicalPathAuthCredentials $null -AddBinding "true" -Protocol "http" -IpAddress "All Unassigned" -Port "8080" -HostNameWithOutSNI "" -HostNameWithHttp "" -HostNameWithSNI "" -ServerNameIndication "false" -SslCertThumbPrint "" -AppCmdCommands "" + +# Test 2 + +$createOrUpdateAppPoolForWebsite = "true" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISWebsite "CreateOrUpdateWebsite" -WebsiteName "Sample Web Site" -PhysicalPath "Drive:\Physical Path" -PhysicalPathAuth "WebsiteUserPassThrough" -PhysicalPathAuthCredentials $null -AddBinding "true" -Protocol "http" -IpAddress "All Unassigned" -Port "8080" -HostNameWithOutSNI "" -HostNameWithHttp "" -HostNameWithSNI "" -ServerNameIndication "false" -SslCertThumbPrint "" -ActionIISApplicationPool "CreateOrUpdateAppPool" -AppPoolName "Sample App Pool" -DotNetVersion "v4.0" -PipeLineMode "Integrated" -AppPoolIdentity "ApplicationPoolIdentity" -AppPoolCredentials $null -AppCmdCommands "" + +# Test 3 + +$websitePhysicalPathAuth = "WebsiteWindowsAuth" +$websiteAuthUserName = "name" +$websiteAuthUserPassword = "pass" + +$appPoolIdentityForWebsite = "SpecificUser" +$appPoolUsernameForWebsite = "name" +$appPoolPasswordForWebsite = "pass" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Register-Mock Get-CustomCredentials { return "CustomCredentialsObject" } + +Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Get-CustomCredentials -Times 2 +Assert-WasCalled Execute-Main -- -ActionIISWebsite "CreateOrUpdateWebsite" -WebsiteName "Sample Web Site" -PhysicalPath "Drive:\Physical Path" -PhysicalPathAuth "WebsiteWindowsAuth" -PhysicalPathAuthCredentials "CustomCredentialsObject" -AddBinding "true" -Protocol "http" -IpAddress "All Unassigned" -Port "8080" -HostNameWithOutSNI "" -HostNameWithHttp "" -HostNameWithSNI "" -ServerNameIndication "false" -SslCertThumbPrint "" -ActionIISApplicationPool "CreateOrUpdateAppPool" -AppPoolName "Sample App Pool" -DotNetVersion "v4.0" -PipeLineMode "Integrated" -AppPoolIdentity "SpecificUser" -AppPoolCredentials "CustomCredentialsObject" -AppCmdCommands "" + +# Test 4 + +$actionIISWebsite = "StartWebsite" +$startStopWebsiteName = "Sample Web Site" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISWebsite "StartWebsite" -WebsiteName "Sample Web Site" -AppCmdCommands "" + +# Test 5 + +$actionIISWebsite = "StopWebsite" +$startStopWebsiteName = "Sample Web Site" + +Unregister-Mock Execute-Main +Register-Mock Execute-Main { } + +Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands + +Assert-WasCalled Execute-Main -Times 1 +Assert-WasCalled Execute-Main -- -ActionIISWebsite "StopWebsite" -WebsiteName "Sample Web Site" -AppCmdCommands "" + +# Test 6 + +$actionIISWebsite = "CreateOrUpdateWebsite" +$addBinding = "true" +$protocol = "https" +$sslCertThumbPrint = "lessthan40charsstring" + +Assert-Throws { + Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands +} -MessagePattern "InvalidSslThumbprint" + +# Test 7 + +$actionIISWebsite = "InvalidOption" + +Assert-Throws { + Manage-IISWebsite -actionIISWebsite $actionIISWebsite -websiteName $websiteName -startStopWebsiteName $startStopWebsiteName -physicalPath $websitePhysicalPath -physicalPathAuth $websitePhysicalPathAuth -physicalPathAuthUserName $websiteAuthUserName -physicalPathAuthUserPassword $websiteAuthUserPassword ` + -addBinding $addBinding -protocol $protocol -ipAddress $ipAddress -port $port -serverNameIndication $serverNameIndication ` + -hostNameWithOutSNI $hostNameWithOutSNI -hostNameWithHttp $hostNameWithHttp -hostNameWithSNI $hostNameWithSNI -sslCertThumbPrint $sslCertThumbPrint ` + -createOrUpdateAppPool $createOrUpdateAppPoolForWebsite -appPoolName $appPoolNameForWebsite -dotNetVersion $dotNetVersionForWebsite -pipeLineMode $pipeLineModeForWebsite -appPoolIdentity $appPoolIdentityForWebsite -appPoolUsername $appPoolUsernameForWebsite -appPoolPassword $appPoolPasswordForWebsite ` + -appCmdCommands $appCmdCommands +} -MessagePattern "InvalidActionIISWebsite InvalidOption" \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Tests/MockHelpers.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Tests/MockHelpers.ps1 new file mode 100644 index 000000000000..798f3601a522 --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/Tests/MockHelpers.ps1 @@ -0,0 +1,15 @@ +## Helper for global mock functions + +Register-Mock Get-AppCmdLocation { + return "appcmdPath", 8 +} + +function Get-MockCredentials { + $username = "domain\name" + $password = 'random!123`"$password' + + $securePass = New-Object System.Security.SecureString + ForEach ($ch in $password.ToCharArray()) { $securePass.appendChar($ch) } + $authCredentials = New-Object System.Management.Automation.PSCredential($username, $securePass) + return $authCredentials +} \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/Utility.ps1 b/Tasks/IISWebAppManagementOnMachineGroup/Utility.ps1 index cbb69ee8fe3b..05549752e4bd 100644 --- a/Tasks/IISWebAppManagementOnMachineGroup/Utility.ps1 +++ b/Tasks/IISWebAppManagementOnMachineGroup/Utility.ps1 @@ -1,6 +1,5 @@ Import-Module $PSScriptRoot\ps_modules\TaskModuleIISManageUtility -## add appcmd parameter function Manage-IISWebSite { param ( @@ -29,16 +28,17 @@ function Manage-IISWebSite [string] $pipeLineMode, [string] $appPoolIdentity, [string] $appPoolUsername, - [string] $appPoolPassword + [string] $appPoolPassword, + [string] $appCmdCommands ) - Trim-Inputs -siteName ([ref]$websiteName) -physicalPath ([ref]$physicalPath) -poolName ([ref]$appPoolName) -physicalPathAuthuser ([ref]$physicalPathAuthUserName) -appPoolUser ([ref]$appPoolUsername) -sslCertThumbPrint ([ref]$sslCertThumbPrint) - Validate-Inputs -sslCertThumbPrint $sslCertThumbPrint - switch ($actionIISWebsite) { "CreateOrUpdateWebsite" { + Trim-Inputs -siteName ([ref]$websiteName) -physicalPath ([ref]$physicalPath) -poolName ([ref]$appPoolName) -physicalPathAuthuser ([ref]$physicalPathAuthUserName) -appPoolUser ([ref]$appPoolUsername) -sslCertThumbPrint ([ref]$sslCertThumbPrint) + Validate-Inputs -sslCertThumbPrint $sslCertThumbPrint -protocol $protocol -addBinding $addBinding + if($physicalPathAuth -ieq "WebsiteWindowsAuth") { $physicalPathAuthCredentials = Get-CustomCredentials -username $physicalPathAuthUserName -password $physicalPathAuthUserPassword @@ -62,8 +62,14 @@ function Manage-IISWebSite } {($_ -eq "StartWebsite") -or ($_ -eq "StopWebsite")} { + Trim-Inputs -siteName ([ref]$startStopWebsiteName) + Execute-Main -ActionIISWebsite $actionIISWebsite -WebsiteName $startStopWebsiteName -AppCmdCommands $appCmdCommands } + default + { + throw (Get-VstsLocString -Key "InvalidActionIISWebsite" -ArgumentList $actionIISWebsite) + } } } @@ -75,7 +81,8 @@ function Manage-IISVirtualDirectory [string] $physicalPath, [string] $PhysicalPathAuth, [string] $physicalPathAuthUserName, - [string] $physicalPathAuthUserPassword + [string] $physicalPathAuthUserPassword, + [string] $appCmdCommands ) Trim-Inputs -siteName ([ref]$parentWebsiteName) -virtualPath ([ref]$virtualPath) -physicalPath ([ref]$physicalPath) -physicalPathAuthuser ([ref]$physicalPathAuthUserName) @@ -106,7 +113,8 @@ function Manage-IISWebApplication [string] $pipeLineMode, [string] $appPoolIdentity, [string] $appPoolUsername, - [string] $appPoolPassword + [string] $appPoolPassword, + [string] $appCmdCommands ) Trim-Inputs -siteName ([ref]$parentWebsiteName) -virtualPath ([ref]$virtualPath) -physicalPath ([ref]$physicalPath) -physicalPathAuthuser ([ref]$physicalPathAuthUserName) -poolName ([ref]$appPoolName) -appPoolUser ([ref]$appPoolUsername) @@ -144,15 +152,16 @@ function Manage-IISApplicationPool [string] $pipeLineMode, [string] $appPoolIdentity, [string] $appPoolUsername, - [string] $appPoolPassword + [string] $appPoolPassword, + [string] $appCmdCommands ) - Trim-Inputs -poolName ([ref]$appPoolName) -appPoolUser ([ref]$appPoolUsername) - switch ($actionIISApplicationPool) { "CreateOrUpdateAppPool" { + Trim-Inputs -poolName ([ref]$appPoolName) -appPoolUser ([ref]$appPoolUsername) + if($appPoolIdentity -ieq "SpecificUser") { $appPoolCredentials = Get-CustomCredentials -username $appPoolUsername -password $appPoolPassword @@ -163,8 +172,14 @@ function Manage-IISApplicationPool } {($_ -eq "StartAppPool") -or ($_ -eq "StopAppPool") -or ($_ -eq "RecycleAppPool")} { + Trim-Inputs -poolName ([ref]$startStopRecycleAppPoolName) + Execute-Main -ActionIISApplicationPool $actionIISApplicationPool -AppPoolName $startStopRecycleAppPoolName -AppCmdCommands $appCmdCommands } + default + { + throw (Get-VstsLocString -Key "InvalidActionIISAppPool" -ArgumentList $actionIISApplicationPool) + } } } @@ -219,7 +234,9 @@ function Validate-Inputs { param ( [string] $virtualPath, - [string] $sslCertThumbPrint + [string] $sslCertThumbPrint, + [string] $protocol, + [string] $addBinding ) if((-not [string]::IsNullOrWhiteSpace($sslCertThumbPrint)) -and ($protocol -ieq "https") -and ($addBinding -ieq "true")) diff --git a/Tasks/IISWebAppManagementOnMachineGroup/task.json b/Tasks/IISWebAppManagementOnMachineGroup/task.json index fc50ac5d921c..04f9433e0347 100644 --- a/Tasks/IISWebAppManagementOnMachineGroup/task.json +++ b/Tasks/IISWebAppManagementOnMachineGroup/task.json @@ -15,8 +15,8 @@ "demands": [], "version": { "Major": 0, - "Minor": 1, - "Patch": 2 + "Minor": 2, + "Patch": 0 }, "minimumAgentVersion": "2.111.0", "instanceNameFormat": "Manage $(IISDeploymentType)", @@ -625,7 +625,9 @@ "messages": { "InvalidSslThumbprint": "Invalid thumbprint. Length is not 40 characters or contains invalid characters.", "InvalidVirtualPath": "Virtual path should begin with a /", - "InvalidIISDeploymentType": "Invalid IIS Deployment Type : {0}" + "InvalidIISDeploymentType": "Invalid IIS Deployment Type : {0}", + "InvalidActionIISWebsite": "Invalid action '{0}' selected for the IIS Website.", + "InvalidActionIISAppPool": "Invalid action '{0}' selected for the IIS Application Pool." } } \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/task.loc.json b/Tasks/IISWebAppManagementOnMachineGroup/task.loc.json index bd65ac82fdcd..3a0a8cfc464f 100644 --- a/Tasks/IISWebAppManagementOnMachineGroup/task.loc.json +++ b/Tasks/IISWebAppManagementOnMachineGroup/task.loc.json @@ -15,8 +15,8 @@ "demands": [], "version": { "Major": 0, - "Minor": 1, - "Patch": 2 + "Minor": 2, + "Patch": 0 }, "minimumAgentVersion": "2.111.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", @@ -625,6 +625,8 @@ "messages": { "InvalidSslThumbprint": "ms-resource:loc.messages.InvalidSslThumbprint", "InvalidVirtualPath": "ms-resource:loc.messages.InvalidVirtualPath", - "InvalidIISDeploymentType": "ms-resource:loc.messages.InvalidIISDeploymentType" + "InvalidIISDeploymentType": "ms-resource:loc.messages.InvalidIISDeploymentType", + "InvalidActionIISWebsite": "ms-resource:loc.messages.InvalidActionIISWebsite", + "InvalidActionIISAppPool": "ms-resource:loc.messages.InvalidActionIISAppPool" } } \ No newline at end of file diff --git a/Tasks/IISWebAppManagementOnMachineGroup/tsconfig.json b/Tasks/IISWebAppManagementOnMachineGroup/tsconfig.json new file mode 100644 index 000000000000..0438b79f69ac --- /dev/null +++ b/Tasks/IISWebAppManagementOnMachineGroup/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "commonjs" + } +} \ No newline at end of file