Skip to content

Commit

Permalink
Added L0 tests for IIS Web App Manage task (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
asranja authored Mar 2, 2017
1 parent a74630b commit d37575e
Show file tree
Hide file tree
Showing 23 changed files with 1,476 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@
"loc.input.help.AppCmdCommands": "Enter additional AppCmd.exe commands. For more than one command use a line separator, like <br/> list apppools <br/> list sites<br/> 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."
}
95 changes: 95 additions & 0 deletions Tasks/IISWebAppManagementOnMachineGroup/Tests/L0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/// <reference path="../../../definitions/mocha.d.ts"/>
/// <reference path="../../../definitions/node.d.ts"/>
/// <reference path="../../../definitions/Q.d.ts"/>

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);
})
}
});
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d37575e

Please sign in to comment.