From b3a42da5409f87453ee0c5ab055ae38a3381a2a1 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 4 Sep 2018 13:26:57 +0200 Subject: [PATCH 001/101] Updated appveyor.yml to v2.6 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a2c4d7949..79208bc25 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.5.0.{build} +version: 2.6.0.{build} install: - git clone https://github.com/PowerShell/DscResource.Tests From 63895e3caa23171ccb8716718c5d0d0ae4a52c28 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Sun, 9 Sep 2018 15:12:38 -0400 Subject: [PATCH 002/101] Fixed issue 867 --- CHANGELOG.md | 4 +++ .../MSFT_SPSearchContentSource.psm1 | 34 ++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03e3bbe0e..e49b4f327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change log for SharePointDsc +## Unreleased +* SPSearchContentSource + * Fixed issue with numerical Content Sources name; + ## 2.5 * SPAppCatalog diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 index e02ca0cf8..3c79aa170 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 @@ -80,8 +80,8 @@ function Get-TargetResource Import-Module -Name $modulePath $source = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName ` - -Identity $params.Name ` - -ErrorAction SilentlyContinue + -ErrorAction SilentlyContinue | ` + Where-Object {$_.Name -eq $params.Name} if ($null -eq $source) { return @{ @@ -340,10 +340,9 @@ function Set-TargetResource $OFS = "," $startAddresses = "$($params.Addresses)" - $source = Get-SPEnterpriseSearchCrawlContentSource ` - -SearchApplication $params.ServiceAppName ` - -Identity $params.Name ` - -ErrorAction SilentlyContinue + $source = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName ` + -ErrorAction SilentlyContinue | ` + Where-Object {$_.Name -eq $params.Name} if ($null -eq $source) { @@ -387,22 +386,19 @@ function Set-TargetResource Write-Verbose -Message ("Content source '$($params.Name)' is not idle, " + ` "stopping current crawls to allow settings to be updated") - $source = Get-SPEnterpriseSearchCrawlContentSource ` - -SearchApplication $params.ServiceAppName ` - -Identity $params.Name + $source = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName | ` + Where-Object {$_.Name -eq $params.Name} $source.StopCrawl() $loopCount = 0 - $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource ` - -SearchApplication $params.ServiceAppName ` - -Identity $params.Name + $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName | ` + Where-Object {$_.Name -eq $params.Name} while ($sourceToWait.CrawlStatus -ne "Idle" -and $loopCount -lt 15) { - $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource ` - -SearchApplication $params.ServiceAppName ` - -Identity $params.Name + $sourceToWait = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $params.ServiceAppName | ` + Where-Object {$_.Name -eq $params.Name} Write-Verbose -Message ("$([DateTime]::Now.ToShortTimeString()) - Waiting " + ` "for content source '$($params.Name)' to be idle " + ` @@ -517,12 +513,12 @@ function Set-TargetResource $incrementalSetArgs.Add("CrawlScheduleRunEveryInterval", $params.IncrementalSchedule.CrawlScheduleRunEveryInterval) } - + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.IncrementalSchedule ` -PropertyName "StartHour" if ($propertyTest -eq $true) { - $incrementalSetArgs.Add("CrawlScheduleStartDateTime", + $incrementalSetArgs.Add("CrawlScheduleStartDateTime", "$($params.IncrementalSchedule.StartHour):$($params.IncrementalSchedule.StartMinute)") } Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @incrementalSetArgs @@ -601,12 +597,12 @@ function Set-TargetResource $fullSetArgs.Add("CrawlScheduleRunEveryInterval", $params.FullSchedule.CrawlScheduleRunEveryInterval) } - + $propertyTest = Test-SPDSCObjectHasProperty -Object $params.FullSchedule ` -PropertyName "StartHour" if ($propertyTest -eq $true) { - $fullSetArgs.Add("CrawlScheduleStartDateTime", + $fullSetArgs.Add("CrawlScheduleStartDateTime", "$($params.FullSchedule.StartHour):$($params.FullSchedule.StartMinute)") } Set-SPEnterpriseSearchCrawlContentSource @allSetArguments @fullSetArgs From 10d2c33fef599710ff02e295ee389ae1329a4218 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Sun, 9 Sep 2018 19:31:41 -0400 Subject: [PATCH 003/101] Updated Tests to include Mock Name --- .../SharePointDsc.SPSearchContentSource.Tests.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 index e63f0609c..02a8926ea 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchContentSource.Tests.ps1 @@ -303,6 +303,7 @@ namespace Microsoft.Office.Server.Search.Administration { } Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -339,6 +340,7 @@ namespace Microsoft.Office.Server.Search.Administration { } Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -405,6 +407,7 @@ namespace Microsoft.Office.Server.Search.Administration { } Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -493,6 +496,7 @@ namespace Microsoft.Office.Server.Search.Administration { } Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "Web" MaxPageEnumerationDepth = [System.Int32]::MaxValue MaxSiteEnumerationDepth = 0 @@ -530,6 +534,7 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "Web" MaxPageEnumerationDepth = [System.Int32]::MaxValue MaxSiteEnumerationDepth = 0 @@ -597,6 +602,7 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "Web" MaxPageEnumerationDepth = 0 MaxSiteEnumerationDepth = 0 @@ -680,6 +686,7 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "File" FollowDirectories = $true StartAddresses = @( @@ -716,6 +723,7 @@ namespace Microsoft.Office.Server.Search.Administration { Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "File" FollowDirectories = $true StartAddresses = @( @@ -780,6 +788,7 @@ namespace Microsoft.Office.Server.Search.Administration { } Mock -CommandName Get-SPEnterpriseSearchCrawlContentSource -MockWith { return @{ + Name = "Example content source" Type = "File" FollowDirectories = $false StartAddresses = @( @@ -839,6 +848,7 @@ namespace Microsoft.Office.Server.Search.Administration { $crawlStatus = "Idle" } $returnval = @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -897,6 +907,7 @@ namespace Microsoft.Office.Server.Search.Administration { $schedule.StartMinute = 0 $schedule.DaysInterval = 1 return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -939,6 +950,7 @@ namespace Microsoft.Office.Server.Search.Administration { $schedule.StartMinute = 0 $schedule.DaysOfWeek = [enum]::Parse([Microsoft.Office.Server.Search.Administration.DaysOfWeek], "Monday, Wednesday, Friday") return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( @@ -986,6 +998,7 @@ namespace Microsoft.Office.Server.Search.Administration { $schedule.StartMinute = 0 $schedule.DaysOfWeek = [enum]::Parse([Microsoft.Office.Server.Search.Administration.DaysOfWeek], "Monday, Wednesday, Friday") return @{ + Name = "Example content source" Type = "SharePoint" SharePointCrawlBehavior = "CrawlVirtualServers" StartAddresses = @( From d4a0952cf2cc37b1cf3490822d259e06334b5d01 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 10 Sep 2018 06:04:15 -0400 Subject: [PATCH 004/101] Header surrounded by blank line --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49b4f327..acd27adf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change log for SharePointDsc ## Unreleased + * SPSearchContentSource * Fixed issue with numerical Content Sources name; From 3daa01824771c87bb653f5341bd7d01a89c4e2e8 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Fri, 14 Sep 2018 16:29:05 +0200 Subject: [PATCH 005/101] Fixed issue #874 and #873 --- CHANGELOG.md | 7 ++- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 50 ++++++++++++++++++- .../MSFT_SPSite/MSFT_SPSite.schema.mof | 1 + .../MSFT_SPUserProfileServiceApp.psm1 | 2 +- .../SharePointDsc.SPSite.Tests.ps1 | 30 ++++++++++- 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acd27adf3..5b90c58c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,12 @@ ## Unreleased * SPSearchContentSource - * Fixed issue with numerical Content Sources name; + * Fixed issue with numerical Content Sources name +* SPSite + * Added the possibility for creating the default site groups +* SPUserProfileServiceApp + * Fixed issue which was introduced in v2.5 where the service application proxy + was not created. ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 56da297a7..f333c68d6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -56,6 +56,10 @@ function Get-TargetResource [System.String] $Template, + [Parameter()] + [System.Boolean] + $CreateDefaultGroups, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -122,6 +126,14 @@ function Get-TargetResource $_.QuotaID -eq $site.Quota.QuotaID }).Name + $CreateDefaultGroups = $true + if ($null -eq $site.RootWeb.AssociatedVisitorsGroup -and + $null -eq $site.RootWeb.AssociatedMemberGroup -and + $null -eq $site.RootWeb.AssociatedOwnersGroup) + { + $CreateDefaultGroups = $false + } + return @{ Url = $site.Url OwnerAlias = $owner @@ -136,6 +148,7 @@ function Get-TargetResource SecondaryEmail = $site.SecondaryContact.Email SecondaryOwnerAlias = $secondaryOwner Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.Configuration)" + CreateDefaultGroups = $CreateDefaultGroups InstallAccount = $params.InstallAccount } } @@ -200,6 +213,10 @@ function Set-TargetResource [System.String] $Template, + [Parameter()] + [System.Boolean] + $CreateDefaultGroups, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -207,6 +224,11 @@ function Set-TargetResource Write-Verbose -Message "Setting site collection $Url" + if ($PSBoundParameters.ContainsKey("CreateDefaultGroups") -eq $false) + { + $PSBoundParameters.CreateDefaultGroups = $true + } + $CurrentValues = Get-TargetResource @PSBoundParameters $result = Invoke-SPDSCCommand -Credential $InstallAccount ` @@ -217,11 +239,21 @@ function Set-TargetResource $params.Remove("InstallAccount") | Out-Null + $CreateDefaultGroups = $params.CreateDefaultGroups + $params.Remove("CreateDefaultGroups") | Out-Null + $site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $site) { - New-SPSite @params | Out-Null + $site = New-SPSite @params + + if ($CreateDefaultGroups -eq $true) + { + $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, + $params.SecondaryOwnerAlias, + $null) + } } else { @@ -258,6 +290,15 @@ function Set-TargetResource Write-Verbose -Message "Updating existing site collection" Set-SPSite @newParams } + + if ($CurrentValues.CreateDefaultGroups -eq $false -and + $CreateDefaultGroups -eq $true) + { + $site = Get-SPSite -Identity $params.Url + $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, + $params.SecondaryOwnerAlias, + $null) + } } } } @@ -320,6 +361,10 @@ function Test-TargetResource [System.String] $Template, + [Parameter()] + [System.Boolean] + $CreateDefaultGroups, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -338,7 +383,8 @@ function Test-TargetResource -ValuesToCheck @("Url", "QuotaTemplate", "OwnerAlias", - "SecondaryOwnerAlias") + "SecondaryOwnerAlias", + "CreateDefaultGroups") } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof index 7b28c3f8d..92b43634c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof @@ -14,6 +14,7 @@ class MSFT_SPSite : OMI_BaseResource [Write, Description("The secondary site collection admin email address")] string SecondaryEmail; [Write, Description("The secondary site collection admin username")] string SecondaryOwnerAlias; [Write, Description("The template to apply to the site collection")] string Template; + [Write, Description("Create the default site groups in the site collection")] boolean CreateDefaultGroups; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index 1552deb9f..b6d99b60d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -402,7 +402,7 @@ function Set-TargetResource $app = $serviceApps | Select-Object -First 1 if ($null -eq $serviceApps) { - New-SPProfileServiceApplication @params | Out-Null + $app = New-SPProfileServiceApplication @params | Out-Null if ($null -ne $app) { New-SPProfileServiceApplicationProxy -Name $pName ` diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index b3596e8ea..60ba0333b 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -19,7 +19,27 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope # Mocks for all contexts - Mock -CommandName New-SPSite -MockWith { } + Mock -CommandName New-SPSite -MockWith { + $rootWeb = @{} + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ + HostHeaderIsSiteName = $true + WebApplication = @{ + Url = $testParams.Url + UseClaimsAuthentication = $false + } + Url = $testParams.Url + Owner = @{ UserLogin = "DEMO\owner" } + SecondaryContact = @{ UserLogin = "DEMO\secondowner" } + Quota = @{ + QuotaId = 1 + } + RootWeb = $rootWeb + } + return $returnval + } Mock -CommandName Get-SPDSCContentService -MockWith { $quotaTemplates = @(@{ Test = @{ @@ -73,7 +93,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPSite -MockWith { - return @{ + $rootWeb = @{} + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ HostHeaderIsSiteName = $true WebApplication = @{ Url = $testParams.Url @@ -85,7 +109,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Quota = @{ QuotaId = 1 } + RootWeb = $rootWeb } + return $returnval } Mock -CommandName Set-SPSite -MockWith {} Mock -CommandName Get-SPDSCContentService -MockWith { From 1182320372b62180d777c3884088d09aafe34a6a Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 14 Sep 2018 13:00:15 -0400 Subject: [PATCH 006/101] Added Managed Property --- .../MSFT_SPSearchManagedProperty.psm1 | 434 ++++++++++++++++++ .../MSFT_SPSearchManagedProperty.schema.mof | 21 + .../MSFT_SPSearchManagedProperty/readme.md | 9 + .../1-EnsureProperty.ps1 | 27 ++ .../SharePointDsc.SPSearchManagedProperty.ps1 | 64 +++ 5 files changed, 555 insertions(+) create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/readme.md create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSearchManagedProperty/1-EnsureProperty.ps1 create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 new file mode 100644 index 000000000..2ed5348cd --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -0,0 +1,434 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [Parameter(Mandatory = $true)] + [ValidateSet("Binary","DateTime","Decimal","Double","Integer","Text","YesNo")] + [System.String] + $PropertyType, + + [Parameter()] + [System.Boolean] + $Searchable, + + [Parameter()] + [System.Boolean] + $Queryable, + + [Parameter()] + [System.Boolean] + $Retrievable, + + [Parameter()] + [System.Boolean] + $HasMultipleValues, + + [Parameter()] + [System.Boolean] + $Refinable, + + [Parameter()] + [System.Boolean] + $Sortable, + + [Parameter()] + [System.Boolean] + $SafeForAnonymous, + + [Parameter()] + [System.String] + $Alias, + + [Parameter()] + [System.Boolean] + $TokenNormalization, + + [Parameter()] + [System.Boolean] + $NoWordBreaker, + + [Parameter()] + [System.Boolean] + $IncludeAllCrawledProperties, + + [Parameter()] + [System.String[]] + $CrawledProperties, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting Managed Property Setting for '$Name'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters) ` + -ScriptBlock { + $params = $args[0] + + $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName + if(!$ssa) + { + throw("The specified Search Service Application {$($params.ServiceAppName)} is ` + invalid. Please make sure you specify the name of an existing service application.") + } + $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa | ` + Where-Object{$_.Name -eq $params.Name} + if ($null -eq $managedProperty) + { + return @{ + Name = $params.Name + ServiceAppName = $params.ServiceAppName + PropertyType = $params.PropertyType + Ensure = "Absent" + } + } + else { + $aliases = $managedProperty.GetAliases() + $alias = "" + if($aliases) + { + $alias = $aliases[0] + } + + $mappedCrawlProperties = $managedProperty.GetMappedCrawledProperties($false) + $includeAllCrawlProperties = $false + if($mappedCrawlProperties) + { + $includeAllCrawlProperties = $true + } + $results = @{ + Name = $params.Name + ServiceAppName = $params.ServiceAppName + PropertyType = $managedProperty.ManagedType + Searchable = $managedProperty.Searchable + Queryable = $managedPRoperty.Queryable + Retrievable = $managedProperty.Retrievable + HasMultipleValues = $managedProperty.HasMultipleValues + Refinable = $managedProperty.Refinable + Sortable = $managedProperty.Sortable + SafeForAnonymous = $managedProperty.SafeForAnonymous + Alias = $alias + TokenNormalization = $managedProperty.TokenNormalization + NoWordBreaker = $managedProperty.NoWordBreaker + IncludeAllCrawledProperties = $includeAllCrawlProperties + Ensure = "Present" + } + + if(!$includeAllCrawlProperties) + { + $crawledProperties = @() + foreach($mappedProperty in $mappedCrawlProperties) + { + $crawledProperties += $mappedProperty.Name + } + $results.Add("CrawledProperties", $crawledProperties) + } + return $results + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [Parameter(Mandatory = $true)] + [ValidateSet("Binary","DateTime","Decimal","Double","Integer","Text","YesNo")] + [System.String] + $PropertyType, + + [Parameter()] + [System.Boolean] + $Searchable, + + [Parameter()] + [System.Boolean] + $Queryable, + + [Parameter()] + [System.Boolean] + $Retrievable, + + [Parameter()] + [System.Boolean] + $HasMultipleValues, + + [Parameter()] + [System.Boolean] + $Refinable, + + [Parameter()] + [System.Boolean] + $Sortable, + + [Parameter()] + [System.Boolean] + $SafeForAnonymous, + + [Parameter()] + [System.String] + $Alias, + + [Parameter()] + [System.Boolean] + $TokenNormalization, + + [Parameter()] + [System.Boolean] + $NoWordBreaker, + + [Parameter()] + [System.Boolean] + $IncludeAllCrawledProperties, + + [Parameter()] + [System.String[]] + $CrawledProperties, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting Managed Property Setting for '$Name'" + + # Obtain information about the current state of the Managed property (if it exists) + $CurrentValues = Get-TargetResource @PSBoundParameters + + # Validate that the specified crawled properties are all valid and existing + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, ` + $CurrentValues) ` + -ScriptBlock { + $params = $args[0] + $CurrentValues = $args[1] + + #region Pre-Validation + # Ensure that if we specified that we don't specify any crawled property mapping if we selected to include + # them all. + if($params.IncludeAllCrawledProperties -and $params.CrawledProperties.Length -gt 0) + { + throw("You cannot specify values for CrawledProperties if the property ` + IncludeAllCrawledProperties is set to True.") + } + + # Ensure that the specified crawled properties exist + foreach($mappedCrawlProperty in $params.CrawledProperties) + { + $currentCrawlProperty = Get-SPEnterpriseSearchMetadataCrawledProperty -Name $mappedCrawlProperty ` + -SearchApplication $params.ServiceAppName + if(!$currentCrawlProperty) + { + throw("The specified crawled property {$($mappedCrawlProperty)} does not exist. ` + Please make sure you specify valid existing crawl properties.") + } + } + #endregion + $needToRecreate = $false + + if ($params.Ensure -eq "Absent" -and $CurrentValues.Ensure -eq "Present" -or ` + ($params.PropertyType -ne $CurrentValues.PropertyType -and ` + $CurrentValues.Ensure -eq "Present")) + { + $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -Identity $params.Name ` + -SearchApplication $params.ServiceAppName + + # In order to delete a Managed PRoperty we need to make sure it doesn't have any crawled properties + # mapped to it first. + $managedProperty.DeleteAllMappings() + + # Remove the existing managed property + Write-Verbose "Removing Managed Property {$($params.Name)}" + Remove-SPEnterpriseSearchMetadataManagedProperty -Identity $params.Name ` + -SearchApplication $params.ServiceAppName ` + -Confirm:$false + + if($params.PropertyType -ne $CurrentValues.PropertyType) + { + Write-Verbose "Detected a change to type from {$($currentPropertyType)} to ` + {$($params.PropertyType)}" + $needToRecreate = $true + } + } + + # Managed Property doesn't exist but should or if we are recreating because of a type change + if (($CurrentValues.Ensure -eq "Absent" -and $params.Ensure -eq "Present") -or $needToRecreate) + { + # Create the new content source and then apply settings to it + $managedTypeID = [Microsoft.Office.Server.Search.Administration.ManagedDataType]::$($params.PropertyType).value__ + + Write-Verbose "Creating a new Managed Property {$($params.Name)}" + New-SPEnterpriseSearchMetadataManagedProperty -Name $params.Name ` + -SearchApplication $params.ServiceAppName ` + -Type $managedTypeID + } + + # Set the specified properties on the Managed Property + $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -Identity $params.Name ` + -SearchApplication $params.ServiceAppName + + Set-SPEnterpriseSearchMetadataManagedProperty -Identity $managedProperty ` + -Retrievable $params.Retrievable ` + -SafeForAnonymous $params.SafeForAnonymous ` + -NoWordBreaker $params.NoWordBreaker + + $managedProperty.HasMultipleValues = $params.HasMultipleValues + $managedProperty.Searchable = $params.Searchable + $managedProperty.Queryable = $params.Queryable + $managedProperty.Refinable = $params.Refinable + $managedProperty.Sortable = $params.Sortable + $managedProperty.TokenNormalization = $params.TokenNormalization + $managedProperty.RespectPriority = !($params.IncludeAllCrawledProperties) + $managedProperty.OverrideValueOfHasMultipleValues = !($params.IncludeAllCrawledProperties) + $managedProperty.Update() + # If alias doesn't already exist, add it + $alias = $managedProperty.GetAliases() | Where-Object{$_ -eq $params.Alias} + if($alias) + { + $managedProperty.AddAlias($params.Alias) + } + + # Generate the Crawled Properties mapping + $listOfMappedCrawlProperty = [Microsoft.Office.Server.Search.Administration.MappingCollection]::new() + foreach($mappedCrawlProperty in $params.CrawledProperties) + { + $currentCrawlProperty = Get-SPEnterpriseSearchMetadataCrawledProperty -Name $mappedCrawlProperty ` + -SearchApplication $params.ServiceAppName + + $mapping = [Microsoft.Office.Server.Search.Administration.Mapping]::new() + $mapping.CrawledPropertyName = $mappedCrawlProperty + $mapping.CrawledPropSet = $currentCrawlProperty.PropSet + $mapping.ManagedPID = $managedProperty.PId + $listOfMappedCrawlProperty.Add($mapping) + } + $managedProperty.SetMappings($listOfMappedCrawlProperty) + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $ServiceAppName, + + [Parameter(Mandatory = $true)] + [ValidateSet("Binary","DateTime","Decimal","Double","Integer","Text","YesNo")] + [System.String] + $PropertyType, + + [Parameter()] + [System.Boolean] + $Searchable, + + [Parameter()] + [System.Boolean] + $Queryable, + + [Parameter()] + [System.Boolean] + $Retrievable, + + [Parameter()] + [System.Boolean] + $HasMultipleValues, + + [Parameter()] + [System.Boolean] + $Refinable, + + [Parameter()] + [System.Boolean] + $Sortable, + + [Parameter()] + [System.Boolean] + $SafeForAnonymous, + + [Parameter()] + [System.String] + $Alias, + + [Parameter()] + [System.Boolean] + $TokenNormalization, + + [Parameter()] + [System.Boolean] + $NoWordBreaker, + + [Parameter()] + [System.Boolean] + $IncludeAllCrawledProperties, + + [Parameter()] + [System.String[]] + $CrawledProperties, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = "Present", + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing Managed Property Setting for '$Name'" + + $PSBoundParameters.Ensure = $Ensure + $CurrentValues = Get-TargetResource @PSBoundParameters + + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Name", + "PropertyType", + "Searchable", + "Refinable", + "NoWordBreaker", + "IncludeAllCrawledProperties", + "Ensure") +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof new file mode 100644 index 000000000..70ca94008 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof @@ -0,0 +1,21 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPSearchManagedProperty")] +class MSFT_SPSearchManagedProperty : OMI_BaseResource +{ + [Key, Description("The name of the managed property")] String Name; + [Key, Description("The name of the search service app that this managed property exists within")] String ServiceAppName; + [Required, Description("The type of managed property - choose between Binary, DateTime, Decimal, Double, Integer, Text, and YesNo"), ValueMap{"Binary","DateTime","Decimal","Double","Integer","Text","YesNo"}, Values{"Binary","DateTime","Decimal","Double","Integer","Text","YesNo"}] String PropertyType; + [Write, Description("Should the property be Searchable")] Boolean Searchable; + [Write, Description("Should the property be Queryable")] Boolean Queryable; + [Write, Description("Should the property be Retrievable")] Boolean Retrievable; + [Write, Description("Should the property allow for multiple values to be selected")] Boolean HasMultipleValues; + [Write, Description("Should the property be Refinable")] Boolean Refinable; + [Write, Description("Should the property be Sortable")] Boolean Sortable; + [Write, Description("Should the property be marked as safe for anonymous access")] Boolean SafeForAnonymous; + [Write, Description("Alias of the managed property")] String Alias; + [Write, Description("Should the property be case sensitive")] Boolean TokenNormalization; + [Write, Description("Should the property only match exact content")] Boolean NoWordBreaker; + [Write, Description("Should the property be mapped to all crawled properties")] Boolean IncludeAllCrawledProperties; + [Write, Description("List of crawled properties that the property is mapped with")] String CrawledProperties[]; + [Write, Description("Present if the source should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/readme.md new file mode 100644 index 000000000..717ed282d --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/readme.md @@ -0,0 +1,9 @@ +# Description + +**Type:** Distributed + +This resource will deploy and configure a managed property in a specified search +service application. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the managed property is created. diff --git a/Modules/SharePointDsc/Examples/Resources/SPSearchManagedProperty/1-EnsureProperty.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSearchManagedProperty/1-EnsureProperty.ps1 new file mode 100644 index 000000000..589793bde --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSearchManagedProperty/1-EnsureProperty.ps1 @@ -0,0 +1,27 @@ +<# +.EXAMPLE + This example shows how create a new Managed Property, using the required parameters +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchManagedProperty MyProperty + { + Name = "MyProperty" + ServiceAppName = "Search Service Application" + PropertyType = "Text" + Searchable = $true + IncludeAllCrawledProperties = $false + CrawledProperties = @("OWS_Notes, Personal:AboutMe") + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 new file mode 100644 index 000000000..9ea7f2244 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 @@ -0,0 +1,64 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSearchManagedProperty" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + $getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" + + # Mocks for all contexts + Mock -CommandName New-SPEnterpriseSearchMetadataManagedProperty -MockWith {} + Mock -CommandName Set-SPEnterpriseSearchMetadataManagedProperty -MockWith {} + Mock -CommandName Remove-SPEnterpriseSearchMetadataManagedProperty -MockWith {} + + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + return @(@{ + Name = "MockManagedProperty" + PID = 0 + PropertyType = "Text" + Searchable = $true + Refinable = $true + Queryable = $true + Sortable = $true + NoWordBreaker = $true + }) + } + + Context -Name "When the property doesn't exist and should" -Fixture { + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + return @({ + Name = "TestParam" + PropertyType = "Text" + Ensure = "Absent" + }) + } + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "Search Service Application" + Ensure = "Present" + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From 1a68dd98c0a0b7904827de5bdb5e7a738f9ea3ba Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 14 Sep 2018 14:16:33 -0400 Subject: [PATCH 007/101] Updated tests, still not fully working --- .../MSFT_SPSearchManagedProperty.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index 2ed5348cd..c9d033ca7 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -300,7 +300,7 @@ function Set-TargetResource $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -Identity $params.Name ` -SearchApplication $params.ServiceAppName - Set-SPEnterpriseSearchMetadataManagedProperty -Identity $managedProperty ` + Set-SPEnterpriseSearchMetadataManagedProperty -Identity $managedProperty.Name ` -Retrievable $params.Retrievable ` -SafeForAnonymous $params.SafeForAnonymous ` -NoWordBreaker $params.NoWordBreaker From b7cff42a9f98e3890017c5ab6be2f9a359c5dfad Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Thu, 20 Sep 2018 13:49:43 +0200 Subject: [PATCH 008/101] Added new resource for managing web application property bag. --- CHANGELOG.md | 2 + .../MSFT_SPWebAppPropertyBag.psm1 | 169 +++++++++++++++++ .../MSFT_SPWebAppPropertyBag.schema.mof | 9 + .../MSFT_SPWebAppPropertyBag/readme.md | 9 + .../1-AddWebAppPropertyBag.ps1 | 27 +++ .../1-RemoveWebAppPropertyBag.ps1 | 26 +++ ...harePointDsc.SPWebAppPropertyBag.Tests.ps1 | 176 ++++++++++++++++++ 7 files changed, 418 insertions(+) create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.schema.mof create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPropertyBag.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index acd27adf3..b96af34f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * SPSearchContentSource * Fixed issue with numerical Content Sources name; +* SPWebAppPropertyBag + * New resource to manage web application property bag ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 new file mode 100644 index 000000000..805fce743 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 @@ -0,0 +1,169 @@ +function Get-TargetResource() +{ + [CmdletBinding()] + [OutputType([System.Collections.HashTable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [Parameter(Mandatory = $true)] + [System.String] + $Key, + + [Parameter()] + [System.String] + $Value, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Looking for SPWebApplication property '$Key'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $spWebApp = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue + + if ($null -eq $spWebApp) + { + $currentValue = $null + $localEnsure = 'Absent' + } + else + { + if ($spWebApp.Properties) + { + if ($spWebApp.Properties.Contains($params.Key) -eq $true) + { + $localEnsure = "Present" + $currentValue = $spWebApp.Properties[$params.Key] + } + else + { + $localEnsure = "Absent" + $currentValue = $null + } + } + } + + return @{ + WebAppUrl = $params.WebAppUrl + Key = $params.Key + Value = $currentValue + Ensure = $localEnsure + } + } + return $result +} + +function Set-TargetResource() +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [Parameter(Mandatory = $true)] + [System.String] + $Key, + + [Parameter()] + [System.String] + $Value, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting SPWebApplication property '$Key'" + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $spWebApp = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue + + if ($params.Ensure -eq 'Present') + { + Write-Verbose -Message "Adding property '$params.Key'='$params.value' to SPWebApplication.Properties" + $spWebApp.Properties[$params.Key] = $params.Value + $spWebApp.Update() + } + else + { + Write-Verbose -Message "Removing property '$params.Key' from SPWebApplication.Properties" + $spWebApp.Properties.Remove($params.Key) + $spWebApp.Update() + } + } +} + +function Test-TargetResource() +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $WebAppUrl, + + [Parameter(Mandatory = $true)] + [System.String] + $Key, + + [Parameter()] + [System.String] + $Value, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing SPWebApplication property '$Key'" + + $CurrentValues = Get-TargetResource @PSBoundParameters + + if($Ensure -eq 'Present') + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @('Ensure','Key', 'Value') + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @('Ensure','Key') + + } + +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.schema.mof new file mode 100644 index 000000000..3d8afd80f --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.schema.mof @@ -0,0 +1,9 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPWebAppPropertyBag")] +class MSFT_SPWebAppPropertyBag : OMI_BaseResource +{ + [Key, Description("The URL of the web application")] string WebAppUrl; + [Key, Description("The key of the SPWebApplication property")] string Key; + [Write, Description("Value of the SPWebApplication property")] String Value; + [Write, Description("Set to present to ensure the SPWebApplication property exists, or absent to ensure it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md new file mode 100644 index 000000000..44bdb5d69 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md @@ -0,0 +1,9 @@ +# Description + +**Type:** Distributed + +This resource is used to work with SharePoint Property Bags at the web application level. +The account that runs this resource must be a farm administrator. + +The default value for the Ensure parameter is Present. When not specifying this +parameter, the property bag is configured. diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 new file mode 100644 index 000000000..29a761d82 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 @@ -0,0 +1,27 @@ +<# +.EXAMPLE + This example shows how add property bag value in a web application. +#> + +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + + Import-DscResource -ModuleName SharePointDsc + + node localhost + { + SPWebAppPropertyBag APPLICATION_APPCodeProperty + { + PsDscRunAsCredential = $SetupAccount + Key = "KeyToAdd" + Value = "ValueToAddOrModify" + Ensure = "Present" + } + } +} diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 new file mode 100644 index 000000000..0ae6b6552 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 @@ -0,0 +1,26 @@ +<# +.EXAMPLE + This example shows how remove a property bag value in a web application. +#> + +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + + Import-DscResource -ModuleName SharePointDsc + + node localhost + { + SPWebAppPropertyBag APPLICATION_APPCodeProperty + { + PsDscRunAsCredential = $SetupAccount + Key = "KeyToRemove" + Ensure = "Absent" + } + } +} diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPropertyBag.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPropertyBag.Tests.ps1 new file mode 100644 index 000000000..36347639f --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppPropertyBag.Tests.ps1 @@ -0,0 +1,176 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPWebAppPropertyBag" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + Mock -CommandName Get-SPWebApplication -MockWith { + $spWebApp = [pscustomobject]@{ + Properties = @{ + PropertyKey = 'PropertyValue' + } + } + $spWebApp = $spWebApp | Add-Member ScriptMethod Update { + $Global:SPDscWebApplicationPropertyUpdated = $true + } -PassThru + $spWebApp = $spWebApp | Add-Member ScriptMethod Remove { + $Global:SPDscWebApplicationPropertyUpdated = $true + } -PassThru + return $spWebApp + } + + Context -Name 'The web application does not exist' -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Key = 'PropertyKey' + Value = 'NewPropertyValue' + } + Mock -CommandName Get-SPWebApplication -MockWith { + return $null + } + + $result = Get-TargetResource @testParams + + It 'Should return absent from the get method' { + $result.Ensure | Should Be 'absent' + } + + It 'Should return null value from the get method' { + $result.Value | Should Be $null + } + } + + Context -Name 'The web application property value does not match' -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Key = 'PropertyKey' + Value = 'NewPropertyValue' + Ensure ='Present' + } + + $result = Get-TargetResource @testParams + + It 'Should return present from the get method' { + $result.Ensure | Should Be 'present' + } + + It 'Should return the same key value as passed as parameter' { + $result.Key | Should Be $testParams.Key + } + + It 'Should return false from the test method' { + Test-TargetResource @testParams | Should Be $false + } + + It 'Should not throw an exception in the set method' { + { Set-TargetResource @testParams } | Should not throw + } + + $Global:SPDscWebApplicationPropertyUpdated = $false + It 'Calls Get-SPWebApplication and update web application property bag from the set method' { + Set-TargetResource @testParams + + $Global:SPDscWebApplicationPropertyUpdated | Should Be $true + } + } + + Context -Name 'The web application property exists, and the value match' -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Key = 'PropertyKey' + Value = 'PropertyValue' + Ensure = 'Present' + } + + $result = Get-TargetResource @testParams + + It 'Should return present from the get method' { + $result.Ensure | Should Be 'present' + } + + It 'Should return the same values as passed as parameters' { + $result.Key | Should Be $testParams.Key + $result.value | Should Be $testParams.value + } + + It 'Should return true from the test method' { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name 'The web application property does not exist, and should be removed' -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Key = 'NonExistingPropertyKey' + Value = 'PropertyValue' + Ensure = 'Absent' + } + + $result = Get-TargetResource @testParams + + It 'Should return absent from the get method' { + $result.Ensure | Should Be 'absent' + } + + It 'Should return the same key as passed as parameter and null value.' { + $result.Key | Should Be $testParams.Key + $result.value | Should Be $null + } + + It 'Should return true from the test method' { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name 'The web application property exists, and should not be' -Fixture { + $testParams = @{ + WebAppUrl = "http://sharepoint.contoso.com" + Key = 'PropertyKey' + Value = 'PropertyValue' + Ensure = 'Absent' + } + + $result = Get-TargetResource @testParams + + It 'Should return Present from the get method' { + $result.Ensure | Should Be 'Present' + } + + It 'Should return the same values as passed as parameters' { + $result.Key | Should Be $testParams.Key + $result.value | Should Be $testParams.Value + } + + It 'Should return false from the test method' { + Test-TargetResource @testParams | Should Be $false + } + + It 'Should not throw an exception in the set method' { + { Set-TargetResource @testParams } | Should not throw + } + + $Global:SPDscWebApplicationPropertyUpdated = $false + It 'Calls Get-SPWebApplication and remove web application property bag from the set method' { + Set-TargetResource @testParams + + $Global:SPDscWebApplicationPropertyUpdated | Should Be $true + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From 396b253d9433e78c140c0137ea107403ea93200e Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 20 Sep 2018 15:10:00 +0200 Subject: [PATCH 009/101] Fix for issue #863 and #887 --- .../MSFT_SPSearchTopology/readme.md | 5 +---- .../MSFT_SPUserProfileServiceApp.psm1 | 21 +++++++++++++++---- ...PointDsc.SPUserProfileServiceApp.Tests.ps1 | 4 ++++ Tests/Unit/UnitTestHelper.psm1 | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/readme.md index b66cb5d14..848b51e36 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/readme.md @@ -7,10 +7,7 @@ current farm. It allows the configuration to dictate the search topology roles that the current server should be running. Any combination of roles can be specified and the topology will be upaded to reflect the current servers new roles. If this is the first server to apply topology to a farm, then at least -one search index must be provided. To this end, the FirstPartitionIndex, -FirstPartitionDirectory and FirstPartitionServers allow configuring where the -first index partition will belong. This will behave the same as the -SPSearchIndexPartition resource. +one search index must be provided. You only need to run the topology resource on a single server in the farm. It will enable the components on each server in the farm, as specified in diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 index b6d99b60d..f45d894f9 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileServiceApp/MSFT_SPUserProfileServiceApp.psm1 @@ -286,8 +286,8 @@ function Set-TargetResource if ($Ensure -eq "Present") { $farmAccount = Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + -Arguments $PSBoundParameters ` + -ScriptBlock { return Get-SPDscFarmAccount } @@ -302,6 +302,7 @@ function Set-TargetResource "Account. Make sure the specified InstallAccount isn't the Farm Account " + ` "and try again") } + $setupAccount = $InstallAccount.UserName } else { @@ -316,6 +317,7 @@ function Set-TargetResource "Account. Make sure the specified PSDSCRunAsCredential isn't the " + ` "Farm Account and try again") } + $setupAccount = $localaccount } } } @@ -342,9 +344,10 @@ function Set-TargetResource } $null = Invoke-SPDSCCommand -Credential $FarmAccount ` - -Arguments $PSBoundParameters ` + -Arguments @($PSBoundParameters, $setupAccount) ` -ScriptBlock { $params = $args[0] + $setupAccount = $args[1] $updateEnableNetBIOS = $false if ($params.ContainsKey("EnableNetBIOS")) @@ -402,7 +405,7 @@ function Set-TargetResource $app = $serviceApps | Select-Object -First 1 if ($null -eq $serviceApps) { - $app = New-SPProfileServiceApplication @params | Out-Null + $app = New-SPProfileServiceApplication @params if ($null -ne $app) { New-SPProfileServiceApplicationProxy -Name $pName ` @@ -410,6 +413,16 @@ function Set-TargetResource -DefaultProxyGroup } + $claimsPrincipal = New-SPClaimsPrincipal -Identity $setupAccount ` + -IdentityType WindowsSamAccountName + + $serviceAppSecurity = Get-SPServiceApplicationSecurity $app + Grant-SPObjectSecurity -Identity $serviceAppSecurity ` + -Principal $claimsPrincipal ` + -Rights "Full Control" + Set-SPServiceApplicationSecurity -Identity $app ` + -ObjectSecurity $serviceAppSecurity + $app = Get-SPServiceApplication -Name $params.Name ` -ErrorAction SilentlyContinue } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 index 3b1e10f34..d59f75e67 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPUserProfileServiceApp.Tests.ps1 @@ -261,6 +261,10 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + Mock -CommandName New-SPClaimsPrincipal -MockWith { return @("") } + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { return @("") } + Mock -CommandName Grant-SPObjectSecurity -MockWith {} + Mock -CommandName Set-SPServiceApplicationSecurity -MockWith {} Mock -CommandName Restart-Service {} diff --git a/Tests/Unit/UnitTestHelper.psm1 b/Tests/Unit/UnitTestHelper.psm1 index 0b380e422..95d2f6d5a 100644 --- a/Tests/Unit/UnitTestHelper.psm1 +++ b/Tests/Unit/UnitTestHelper.psm1 @@ -27,7 +27,7 @@ function New-SPDscUnitTestHelper $moduleRoot = Join-Path -Path $repoRoot -ChildPath "Modules\SharePointDsc" $mainModule = Join-Path -Path $moduleRoot -ChildPath "SharePointDsc.psd1" - Import-Module -Name $mainModule -Global + Import-Module -Name $mainModule -Global -Force if ($PSBoundParameters.ContainsKey("SubModulePath") -eq $true) { @@ -50,7 +50,7 @@ function New-SPDscUnitTestHelper $describeHeader += " [SP Build: $spBuild]" - Import-Module -Name $moduleToLoad -Global + Import-Module -Name $moduleToLoad -Global -Force From 611c434284cb7d0acb0efe76f0478228a8523839 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Thu, 20 Sep 2018 15:26:01 +0200 Subject: [PATCH 010/101] Added missing parameter in examples --- .../SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 | 7 ++++--- .../SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 index 29a761d82..44f5a0823 100644 --- a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1 @@ -19,9 +19,10 @@ Configuration Example SPWebAppPropertyBag APPLICATION_APPCodeProperty { PsDscRunAsCredential = $SetupAccount - Key = "KeyToAdd" - Value = "ValueToAddOrModify" - Ensure = "Present" + WebAppUrl = "https://web.contoso.com" + Key = "KeyToAdd" + Value = "ValueToAddOrModify" + Ensure = "Present" } } } diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 index 0ae6b6552..846289031 100644 --- a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 @@ -19,6 +19,7 @@ Configuration Example SPWebAppPropertyBag APPLICATION_APPCodeProperty { PsDscRunAsCredential = $SetupAccount + WebAppUrl = "https://web.contoso.com" Key = "KeyToRemove" Ensure = "Absent" } From 231a1da5a67254a5e939535e59e6a17340fe3366 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Thu, 20 Sep 2018 15:57:10 +0200 Subject: [PATCH 011/101] Fixed incorrect test method that resulted in the resource to not work --- CHANGELOG.md | 2 + .../MSFT_SPWebAppSuiteBar.psm1 | 17 ++++++-- .../SharePointDsc.SPWebAppSuiteBar.Tests.ps1 | 39 +++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acd27adf3..60b8e8ed4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * SPSearchContentSource * Fixed issue with numerical Content Sources name; +* SPWebAppSuiteBar + * Fixed incorrect test method that resulted in this resource to never apply changes. ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 index a67fa0c2a..79a92b51c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 @@ -243,9 +243,20 @@ function Test-TargetResource return $false } - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Ensure") + $installedVersion = Get-SPDSCInstalledProductVersion + + if($installedVersion.FileMajorPart -eq 15) + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("SuiteBarBrandingElementHtml"); + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("SuiteNavBrandingLogoNavigationUrl", "SuiteNavBrandingLogoTitle", "SuiteNavBrandingLogoUrl", "SuiteNavBrandingText") + } } Export-ModuleMember -Function *-TargetResource diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 index 1d82c1f83..084ca8992 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 @@ -115,6 +115,22 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { Set-TargetResource @testParams } | Should Throw "You need to specify a value for the SuiteBarBrandingElementHtml parameter with SharePoint 2013" } } + Context -Name "Configured values does not match" -Fixture { + $testParams = @{ + WebAppUrl = "http://sites.sharepoint.com" + SuiteBarBrandingElementHtml = "
Test
" + } + + Mock -CommandName Get-SPWebApplication -MockWith { return @(@{ + DisplayName = "Test Web App" + Url = "http://sites.sharepoint.com" + SuiteBarBrandingElementHtml = "
Another Test
" + })} + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } } elseif ($Global:SPDscHelper.CurrentStubBuildNumber.Major -ge 16) { @@ -242,6 +258,29 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { Set-TargetResource @testParams } | Should Throw "You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl and SuiteNavBrandingText with SharePoint 2016" } } + + Context -Name "Configured values does not match" -Fixture { + $testParams = @{ + WebAppUrl = "http://sites.sharepoint.com" + SuiteNavBrandingLogoNavigationUrl = "http://sites.sharepoint.com" + SuiteNavBrandingLogoTitle = "LogoTitle" + SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" + SuiteNavBrandingText = "Suite Bar Text" + } + + Mock -CommandName Get-SPWebApplication -MockWith { return @(@{ + DisplayName = "Test Web App" + Url = "http://sites.sharepoint.com" + SuiteNavBrandingLogoNavigationUrl = "http://anothersite.sharepoint.com" + SuiteNavBrandingLogoTitle = "AnotherLogoTitle" + SuiteNavBrandingLogoUrl = "http://anothersite.sharepoint.com/images/logo.gif" + SuiteNavBrandingText = "Another Suite Bar Text" + })} + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } } } } From 0b1d61a568f58475bcc824b9ed1a67f86db91603 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Thu, 20 Sep 2018 17:32:50 +0200 Subject: [PATCH 012/101] Fixed issue with SPExcelServiceApp, which broke the Pester test --- .../SharePointDsc.SPExcelServiceApp.Tests.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 index b28759f50..e62b5acb4 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPExcelServiceApp.Tests.ps1 @@ -21,19 +21,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Initialize tests $getTypeFullName = "Microsoft.Office.Excel.Server.MossHost.ExcelServerWebServiceApplication" - # Mocks for all contexts - Mock -CommandName Remove-SPServiceApplication -MockWith { } - Mock -CommandName New-SPExcelServiceApplication -MockWith { } - Mock -CommandName Get-SPExcelFileLocation -MockWith { } - Mock -CommandName Set-SPExcelServiceApplication -MockWith { } - Mock -CommandName New-SPExcelFileLocation -MockWith { } - Mock -CommandName Set-SPExcelFileLocation -MockWith { } - Mock -CommandName Remove-SPExcelFileLocation -MockWith { } - # Test contexts switch ($Global:SPDscHelper.CurrentStubBuildNumber.Major) { 15 { + # Mocks for all contexts + Mock -CommandName Remove-SPServiceApplication -MockWith { } + Mock -CommandName New-SPExcelServiceApplication -MockWith { } + Mock -CommandName Get-SPExcelFileLocation -MockWith { } + Mock -CommandName Set-SPExcelServiceApplication -MockWith { } + Mock -CommandName New-SPExcelFileLocation -MockWith { } + Mock -CommandName Set-SPExcelFileLocation -MockWith { } + Mock -CommandName Remove-SPExcelFileLocation -MockWith { } + Context -Name "When no service applications exist in the current farm" -Fixture { $testParams = @{ Name = "Test Excel Services App" From 5554f7defe2eb46b4824da1c3f55a7ef630db943 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Thu, 20 Sep 2018 18:42:34 +0200 Subject: [PATCH 013/101] Renamed example file. Fixed problems with verbose messages not working as expected. Fixed too long lines in the readme.md file. --- .../MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 | 4 ++-- .../DSCResources/MSFT_SPWebAppPropertyBag/readme.md | 3 ++- ...oveWebAppPropertyBag.ps1 => 2-RemoveWebAppPropertyBag.ps1} | 0 3 files changed, 4 insertions(+), 3 deletions(-) rename Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/{1-RemoveWebAppPropertyBag.ps1 => 2-RemoveWebAppPropertyBag.ps1} (100%) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 index 805fce743..f477908d8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.psm1 @@ -105,13 +105,13 @@ function Set-TargetResource() if ($params.Ensure -eq 'Present') { - Write-Verbose -Message "Adding property '$params.Key'='$params.value' to SPWebApplication.Properties" + Write-Verbose -Message "Adding property '$($params.Key)'='$($params.value)' to SPWebApplication.Properties" $spWebApp.Properties[$params.Key] = $params.Value $spWebApp.Update() } else { - Write-Verbose -Message "Removing property '$params.Key' from SPWebApplication.Properties" + Write-Verbose -Message "Removing property '$($params.Key)' from SPWebApplication.Properties" $spWebApp.Properties.Remove($params.Key) $spWebApp.Update() } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md index 44bdb5d69..328501802 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md @@ -2,7 +2,8 @@ **Type:** Distributed -This resource is used to work with SharePoint Property Bags at the web application level. +This resource is used to work with SharePoint Property Bags +at the web application level. The account that runs this resource must be a farm administrator. The default value for the Ensure parameter is Present. When not specifying this diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/2-RemoveWebAppPropertyBag.ps1 similarity index 100% rename from Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-RemoveWebAppPropertyBag.ps1 rename to Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/2-RemoveWebAppPropertyBag.ps1 From 0abb95bb6475c7d8c78cdfd9181d82a15a272594 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Thu, 20 Sep 2018 22:43:18 +0200 Subject: [PATCH 014/101] Removed trailing space from markdown file --- .../DSCResources/MSFT_SPWebAppPropertyBag/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md index 328501802..764caac4a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md @@ -2,7 +2,7 @@ **Type:** Distributed -This resource is used to work with SharePoint Property Bags +This resource is used to work with SharePoint Property Bags at the web application level. The account that runs this resource must be a farm administrator. From e91be51ed3658f46690583b8dd9852e2ed70efef Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Fri, 21 Sep 2018 12:08:40 +0200 Subject: [PATCH 015/101] Removed trailing space in readme.md --- .../DSCResources/MSFT_SPWebAppPropertyBag/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md index 764caac4a..174f83df2 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md @@ -3,7 +3,7 @@ **Type:** Distributed This resource is used to work with SharePoint Property Bags -at the web application level. +at the web application level. The account that runs this resource must be a farm administrator. The default value for the Ensure parameter is Present. When not specifying this From 5819d1d48c2cb5d52585114b6f53af252ccd0b51 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sat, 22 Sep 2018 13:41:31 +0200 Subject: [PATCH 016/101] Changed Find-AzureRmResource to Get-AzureRmResource Shortened VM names as max limit is 15 characters --- Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 | 2 +- Tests/Integration/Azure/template.json | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 b/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 index e42d38a24..9c73aacd0 100644 --- a/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 +++ b/Tests/Integration/Azure/AzureEnvironmentBuilder.psm1 @@ -131,7 +131,7 @@ function New-SPDscAzureLab -Context $mainStorageContext # Get keys for software storage - $storageAccount = Find-AzureRmResource -ResourceNameContains $SoftwareStorageAccountName + $storageAccount = Get-AzureRmResource -ResourceName $SoftwareStorageAccountName $softwareKeys = Get-AzureRmStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName ` -Name $SoftwareStorageAccountName diff --git a/Tests/Integration/Azure/template.json b/Tests/Integration/Azure/template.json index fa213106f..a538865a4 100644 --- a/Tests/Integration/Azure/template.json +++ b/Tests/Integration/Azure/template.json @@ -70,16 +70,17 @@ } }, "variables": { + "vmPrefix": "VM", "networkName": "[concat(resourceGroup().Name, '-network')]", "dcNicName": "[concat(resourceGroup().Name, '-dc-nic')]", - "dcVmName": "[concat(resourceGroup().Name, '-dc')]", + "dcVmName": "[concat(variables('vmPrefix'), '-dc')]", "dcDisk1Name": "[concat(resourceGroup().Name, '-dc-disk-c')]", "sqlNicName": "[concat(resourceGroup().Name, '-sql-nic')]", - "sqlVmName": "[concat(resourceGroup().Name, '-sql')]", + "sqlVmName": "[concat(variables('vmPrefix'), '-sql')]", "sqlDisk1Name": "[concat(resourceGroup().Name, '-sql-disk-c')]", "spIpAddressName": "[concat(resourceGroup().Name, '-sp-ip')]", "spNicName": "[concat(resourceGroup().Name, '-sp-nic')]", - "spVmName": "[concat(resourceGroup().Name, '-sp')]", + "spVmName": "[concat(variables('vmPrefix'), '-sp')]", "spDisk1Name": "[concat(resourceGroup().Name, '-sp-disk-c')]" }, "resources": [ From 43f8cbdac63e5a18919fc8f7e4fd9c02cecfeca3 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 25 Sep 2018 10:38:56 +0200 Subject: [PATCH 017/101] Added AdministrationSiteType property --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 50 ++++++++++++++++--- .../MSFT_SPSite/MSFT_SPSite.schema.mof | 1 + .../SPSite/3-AdministrationSiteType.ps1 | 27 ++++++++++ .../SharePointDsc.SPSite.Tests.ps1 | 18 +++++-- 4 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 56da297a7..6b7f5a40e 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -56,6 +56,11 @@ function Get-TargetResource [System.String] $Template, + [Parameter()] + [ValidateSet("TenantAdministration", "None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -136,6 +141,7 @@ function Get-TargetResource SecondaryEmail = $site.SecondaryContact.Email SecondaryOwnerAlias = $secondaryOwner Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.Configuration)" + AdministrationSiteType = $site.AdministrationSiteType InstallAccount = $params.InstallAccount } } @@ -200,6 +206,11 @@ function Set-TargetResource [System.String] $Template, + [Parameter()] + [ValidateSet("TenantAdministration","None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -253,6 +264,14 @@ function Set-TargetResource } } + if ($params.ContainsKey("AdministrationSiteType") -eq $true) + { + if ($params.AdministrationSiteType -ne $CurrentValues.AdministrationSiteType) + { + $newParams.AdministrationSiteType = $params.AdministrationSiteType + } + } + if ($newParams.Count -gt 1) { Write-Verbose -Message "Updating existing site collection" @@ -320,6 +339,11 @@ function Test-TargetResource [System.String] $Template, + [Parameter()] + [ValidateSet("TenantAdministration","None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -333,12 +357,26 @@ function Test-TargetResource { return $false } - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Url", - "QuotaTemplate", - "OwnerAlias", - "SecondaryOwnerAlias") + + if ($null -eq $AdministrationSiteType) + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", + "QuotaTemplate", + "OwnerAlias", + "SecondaryOwnerAlias") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", + "QuotaTemplate", + "OwnerAlias", + "SecondaryOwnerAlias", + "TenantAdministration") + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof index 7b28c3f8d..29ba72323 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof @@ -14,6 +14,7 @@ class MSFT_SPSite : OMI_BaseResource [Write, Description("The secondary site collection admin email address")] string SecondaryEmail; [Write, Description("The secondary site collection admin username")] string SecondaryOwnerAlias; [Write, Description("The template to apply to the site collection")] string Template; + [Write, Description("The administration site type"), ValueMap{"TenantAdministration","None"}, Values{"TenantAdministration","None"}] string AdministrationSiteType; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 new file mode 100644 index 000000000..5a51c60e0 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 @@ -0,0 +1,27 @@ +<# +.EXAMPLE + This example creates a site collection with the provided details +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSite TeamSite + { + Url = "http://sharepoint.contoso.com" + OwnerAlias = "CONTOSO\ExampleUser" + HostHeaderWebApplication = "http://spsites.contoso.com" + Name = "Team Sites" + Template = "STS#0" + AdministrationSiteType = "TenantAdministration" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index b3596e8ea..e323cc33f 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -66,10 +66,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Context -Name "The site exists, but has incorrect owner alias and quota" -Fixture { $testParams = @{ - Url = "http://site.sharepoint.com" - OwnerAlias = "DEMO\User" - SecondaryOwnerAlias = "DEMO\SecondUser" - QuotaTemplate = "Test" + Url = "http://site.sharepoint.com" + OwnerAlias = "DEMO\User" + SecondaryOwnerAlias = "DEMO\SecondUser" + QuotaTemplate = "Test" + AdministrationSiteType = "TenantAdministration" } Mock -CommandName Get-SPSite -MockWith { @@ -85,9 +86,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Quota = @{ QuotaId = 1 } + AdministrationSiteType = "None" } } - Mock -CommandName Set-SPSite -MockWith {} + Mock -CommandName Set-SPSite -MockWith {} -ParameterFilter { + $OwnerAlias = "DEMO\User" + $SecondaryOwnerAlias = "DEMO\SecondUser" + $QuotaTemplate = "Test" + $AdministrationSiteType -eq "TenantAdministration" + } Mock -CommandName Get-SPDSCContentService -MockWith { $quotaTemplates = @(@{ QuotaId = 1 @@ -112,6 +119,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $result.OwnerAlias | Should Be "DEMO\owner" $result.SecondaryOwnerAlias | Should Be "DEMO\SecondOwner" $result.QuotaTemplate | Should Be "WrongTemplate" + $result.AdministrationSiteType | Should Be "None" } It "Should update owner and quota in the set method" { From 59d93730d415b644b0d1ce83a1d946b56116dcf2 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 25 Sep 2018 15:24:09 +0200 Subject: [PATCH 018/101] Implemented review comment changes --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 62 +++++--- .../DSCResources/MSFT_SPSite/readme.md | 4 + .../SharePointDsc.SPSite.Tests.ps1 | 134 +++++++++++++++++- 3 files changed, 177 insertions(+), 23 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index f333c68d6..6e30b2d56 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -58,7 +58,7 @@ function Get-TargetResource [Parameter()] [System.Boolean] - $CreateDefaultGroups, + $CreateDefaultGroups = $true, [Parameter()] [System.Management.Automation.PSCredential] @@ -77,7 +77,22 @@ function Get-TargetResource if ($null -eq $site) { - return $null + return @{ + Url = $params.Url + OwnerAlias = $null + CompatibilityLevel = $null + ContentDatabase = $null + Description = $null + HostHeaderWebApplication = $null + Language = $null + Name = $null + OwnerEmail = $null + QuotaTemplate = $null + SecondaryEmail = $null + SecondaryOwnerAlias = $null + Template = $null + CreateDefaultGroups = $null + } } else { @@ -127,9 +142,9 @@ function Get-TargetResource }).Name $CreateDefaultGroups = $true - if ($null -eq $site.RootWeb.AssociatedVisitorsGroup -and + if ($null -eq $site.RootWeb.AssociatedVisitorGroup -and $null -eq $site.RootWeb.AssociatedMemberGroup -and - $null -eq $site.RootWeb.AssociatedOwnersGroup) + $null -eq $site.RootWeb.AssociatedOwnerGroup) { $CreateDefaultGroups = $false } @@ -215,7 +230,7 @@ function Set-TargetResource [Parameter()] [System.Boolean] - $CreateDefaultGroups, + $CreateDefaultGroups = $true, [Parameter()] [System.Management.Automation.PSCredential] @@ -254,6 +269,11 @@ function Set-TargetResource $params.SecondaryOwnerAlias, $null) } + else + { + Write-Verbose -Message ("CreateDefaultGroups set to false. The default " + ` + "SharePoint groups will not be created") + } } else { @@ -291,13 +311,20 @@ function Set-TargetResource Set-SPSite @newParams } - if ($CurrentValues.CreateDefaultGroups -eq $false -and - $CreateDefaultGroups -eq $true) + if ($CurrentValues.CreateDefaultGroups -eq $false) { - $site = Get-SPSite -Identity $params.Url - $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, - $params.SecondaryOwnerAlias, - $null) + if ($CreateDefaultGroups -eq $true) + { + $site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue + $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, + $params.SecondaryOwnerAlias, + $null) + } + else + { + Write-Verbose -Message ("CreateDefaultGroups set to false. The default " + ` + "SharePoint groups will not be created") + } } } } @@ -363,7 +390,7 @@ function Test-TargetResource [Parameter()] [System.Boolean] - $CreateDefaultGroups, + $CreateDefaultGroups = $true, [Parameter()] [System.Management.Automation.PSCredential] @@ -374,17 +401,20 @@ function Test-TargetResource $CurrentValues = Get-TargetResource @PSBoundParameters - if ($null -eq $CurrentValues) + if ($CreateDefaultGroups -eq $true) { - return $false + if ($CurrentValues.CreateDefaultGroups -ne $true) + { + return $false + } } + return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Url", "QuotaTemplate", "OwnerAlias", - "SecondaryOwnerAlias", - "CreateDefaultGroups") + "SecondaryOwnerAlias") } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md index d6275a939..7c4f31408 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md @@ -17,3 +17,7 @@ IIS site and prevent the site from listening for the URL of the Host Header Site Collection. If you want to change the IIS website binding settings, please use the xWebsite resource in the xWebAdministration module. + +NOTE2: +The CreateDefaultGroups parameter is only used for creating default site +groups. It will not remove or change the default groups if they already exist. diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index 60ba0333b..f8f5d04b5 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -69,8 +69,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPSite -MockWith { return $null } - It "Should return null from the get method" { - Get-TargetResource @testParams | Should BeNullOrEmpty + It "Should return OwnerAlias=Null from the get method" { + (Get-TargetResource @testParams).OwnerAlias | Should BeNullOrEmpty } It "Should return false from the test method" { @@ -79,7 +79,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should create a new site from the set method" { Set-TargetResource @testParams - Assert-MockCalled New-SPSite } } @@ -157,7 +156,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPSite -MockWith { - return @{ + $rootWeb = @{ + AssociatedVisitorGroup = "Test Visitors" + AssociatedMemberGroup = "Test Members" + AssociatedOwnerGroup = "Test Owners" + } + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ HostHeaderIsSiteName = $true WebApplication = @{ Url = $testParams.Url @@ -165,11 +172,13 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Url = $testParams.Url Owner = @{ UserLogin = "DEMO\owner" } + RootWeb = $rootWeb } + return $returnval } It "Should return the site data from the get method" { - Get-TargetResource @testParams | Should Not BeNullOrEmpty + (Get-TargetResource @testParams).OwnerAlias | Should Be "DEMO\owner" } It "Should return true from the test method" { @@ -177,14 +186,74 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "The site exists and uses claims authentication" -Fixture { + Context -Name "The site exists, but doesn't have default groups configured" -Fixture { $testParams = @{ Url = "http://site.sharepoint.com" OwnerAlias = "DEMO\User" } Mock -CommandName Get-SPSite -MockWith { + $rootWeb = @{ + AssociatedVisitorGroup = $null + AssociatedMemberGroup = $null + AssociatedOwnerGroup = $null + } + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value { + $Global:SPDscGroupsUpdated = $true + } -PassThru + $returnval = @{ + HostHeaderIsSiteName = $false + WebApplication = @{ + Url = $testParams.Url + UseClaimsAuthentication = $true + } + Url = $testParams.Url + Owner = @{ UserLogin = "DEMO\owner" } + Quota = @{ QuotaId = 65000 } + RootWeb = $rootWeb + } + return $returnval + } + + Mock -CommandName New-SPClaimsPrincipal -MockWith { return @{ + Value = $testParams.OwnerAlias + } + } + + It "Should return CreateDefaultGroups=False from the get method" { + (Get-TargetResource @testParams).CreateDefaultGroups | Should Be $false + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + $Global:SPDscGroupsUpdated = $false + It "Should update the groups in the set method" { + Set-TargetResource @testParams + $Global:SPDscGroupsUpdated | Should Be $true + } + } + + Context -Name "The site exists and uses claims authentication" -Fixture { + $testParams = @{ + Url = "http://site.sharepoint.com" + OwnerAlias = "DEMO\User" + } + + Mock -CommandName Get-SPSite -MockWith { + $rootWeb = @{ + AssociatedVisitorGroup = "Test Visitors" + AssociatedMemberGroup = "Test Members" + AssociatedOwnerGroup = "Test Owners" + } + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ HostHeaderIsSiteName = $false WebApplication = @{ Url = $testParams.Url @@ -193,7 +262,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Url = $testParams.Url Owner = @{ UserLogin = "DEMO\owner" } Quota = @{ QuotaId = 65000 } + RootWeb = $rootWeb } + return $returnval } Mock -CommandName New-SPClaimsPrincipal -MockWith { @@ -252,7 +323,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPSite -MockWith { - return @{ + $rootWeb = @{ + AssociatedVisitorGroup = "Test Visitors" + AssociatedMemberGroup = "Test Members" + AssociatedOwnerGroup = "Test Owners" + } + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ HostHeaderIsSiteName = $false WebApplication = @{ Url = $testParams.Url @@ -261,7 +340,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Url = $testParams.Url Owner = @{ UserLogin = "DEMO\owner" } Quota = @{ QuotaId = 65000 } + RootWeb = $rootWeb } + return $returnval } It "Should return the site data from the get method" { @@ -290,6 +371,45 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Get-TargetResource @testParams | Should Not BeNullOrEmpty } } + + Context -Name "CreateDefaultGroups is set to false, don't correct anything" -Fixture { + $testParams = @{ + Url = "http://site.sharepoint.com" + OwnerAlias = "DEMO\owner" + CreateDefaultGroups = $false + } + + Mock -CommandName Get-SPSite -MockWith { + $rootWeb = @{ + AssociatedVisitorGroup = $null + AssociatedMemberGroup = $null + AssociatedOwnerGroup = $null + } + $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value {} -PassThru + $returnval = @{ + HostHeaderIsSiteName = $false + WebApplication = @{ + Url = $testParams.Url + UseClaimsAuthentication = $false + } + Url = $testParams.Url + Owner = @{ UserLogin = "DEMO\owner" } + Quota = @{ QuotaId = 65000 } + RootWeb = $rootWeb + } + return $returnval + } + + It "Should return CreateDefaultGroups=False from the get method" { + (Get-TargetResource @testParams).CreateDefaultGroups | Should Be $false + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } } } From c4e81886190c19c884bd42bd8129883db5eb0b4f Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 23 Sep 2018 21:10:01 +0200 Subject: [PATCH 019/101] Added support for local farm token Fixed multiple issues with SPServiceAppSecurity --- .../MSFT_SPServiceAppSecurity.psm1 | 111 ++-- .../MSFT_SPServiceAppSecurity/readme.md | 4 + .../SPServiceAppSecurity/2-Example.ps1 | 31 ++ ...arePointDsc.SPServiceAppSecurity.Tests.ps1 | 489 +++++++++++++++--- 4 files changed, 544 insertions(+), 91 deletions(-) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 40e7356c7..6f1e5bbe0 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -38,7 +38,7 @@ function Get-TargetResource "MembersToExclude parameters") } - if (!$Members -and !$MembersToInclude -and !$MembersToExclude) + if ($null -eq $Members -and !$MembersToInclude -and !$MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") @@ -76,10 +76,17 @@ function Get-TargetResource $user = $securityEntry.Name if ($user -like "i:*|*" -or $user -like "c:*|*") { - $user = (New-SPClaimsPrincipal -Identity $user -IdentityType EncodedClaim).Value - if ($user -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") + if($user.Chars(3) -eq "%") { - $user = Resolve-SPDscSecurityIdentifier -SID $user + $user = "{LocalFarm}" + } + else + { + $user = (New-SPClaimsPrincipal -Identity $user -IdentityType EncodedClaim).Value + if ($user -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") + { + $user = Resolve-SPDscSecurityIdentifier -SID $user + } } } @@ -143,7 +150,7 @@ function Set-TargetResource "MembersToExclude parameters") } - if (!$Members -and !$MembersToInclude -and !$MembersToExclude) + if ($null -eq $Members -and !$MembersToInclude -and !$MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") @@ -173,20 +180,30 @@ function Set-TargetResource } } + $localFarmEncodedClaim = "c:0%.c|system|$((Get-SPFarm).Id.ToString())" + if ($params.ContainsKey("Members") -eq $true) { foreach($desiredMember in $params.Members) { - $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if($desiredMember.Username -eq "{LocalFarm}") { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName + $claim = New-SPClaimsPrincipal -Identity $localFarmEncodedClaim ` + -IdentityType EncodedClaim } else { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSecurityGroupName + $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username + if ($isUser -eq $true) + { + $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` + -IdentityType WindowsSamAccountName + } + else + { + $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` + -IdentityType WindowsSecurityGroupName + } } if ($CurrentValues.Members.Username -contains $desiredMember.Username) @@ -213,16 +230,24 @@ function Set-TargetResource { if ($params.Members.Username -notcontains $currentMember.Username) { - $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if($currentMember.UserName -eq "{LocalFarm}") { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName + $claim = New-SPClaimsPrincipal -Identity $localFarmEncodedClaim ` + -IdentityType EncodedClaim } else { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSecurityGroupName + $isUser = Test-SPDSCIsADUser -IdentityName $currentMember.Username + if ($isUser -eq $true) + { + $claim = New-SPClaimsPrincipal -Identity $currentMember.Username ` + -IdentityType WindowsSamAccountName + } + else + { + $claim = New-SPClaimsPrincipal -Identity $currentMember.Username ` + -IdentityType WindowsSecurityGroupName + } } Revoke-SPObjectSecurity -Identity $security -Principal $claim } @@ -233,17 +258,26 @@ function Set-TargetResource { foreach($desiredMember in $params.MembersToInclude) { - $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if($desiredMember.Username -eq "{LocalFarm}") { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName + $claim = New-SPClaimsPrincipal -Identity $localFarmEncodedClaim ` + -IdentityType EncodedClaim } else { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSecurityGroupName + $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username + if ($isUser -eq $true) + { + $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` + -IdentityType WindowsSamAccountName + } + else + { + $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` + -IdentityType WindowsSecurityGroupName + } } + if ($CurrentValues.Members.Username -contains $desiredMember.Username) { if (($CurrentValues.Members | Where-Object -FilterScript { @@ -273,16 +307,24 @@ function Set-TargetResource { if ($CurrentValues.Members.Username -contains $excludeMember) { - $isUser = Test-SPDSCIsADUser -IdentityName $desiredMember.Username - if ($isUser -eq $true) + if($excludeMember -eq "{LocalFarm}") { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSamAccountName + $claim = New-SPClaimsPrincipal -Identity $localFarmEncodedClaim ` + -IdentityType EncodedClaim } else { - $claim = New-SPClaimsPrincipal -Identity $desiredMember.Username ` - -IdentityType WindowsSecurityGroupName + $isUser = Test-SPDSCIsADUser -IdentityName $excludeMember + if ($isUser -eq $true) + { + $claim = New-SPClaimsPrincipal -Identity $excludeMember ` + -IdentityType WindowsSamAccountName + } + else + { + $claim = New-SPClaimsPrincipal -Identity $excludeMember ` + -IdentityType WindowsSecurityGroupName + } } Revoke-SPObjectSecurity -Identity $security -Principal $claim } @@ -343,7 +385,7 @@ function Test-TargetResource return $false } - if ($Members) + if ($null -ne $Members) { Write-Verbose -Message "Processing Members parameter" @@ -366,9 +408,14 @@ function Test-TargetResource return $true } } + elseif($Members.Count -eq 0) + { + Write-Verbose -Message "Security list does not match" + return $false + } $differences = Compare-Object -ReferenceObject $CurrentValues.Members.Username ` - -DifferenceObject $Members.Username + -DifferenceObject $Members.Username if ($null -eq $differences) { @@ -422,7 +469,7 @@ function Test-TargetResource Write-Verbose -Message "Processing MembersToExclude parameter" foreach ($member in $MembersToExclude) { - if ($CurrentValues.Members.Username -contains $member.Username) + if ($CurrentValues.Members.Username -contains $member) { Write-Verbose -Message "$member already has access. Set result to false" $result = $false diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md index d87606891..ddb80d839 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md @@ -14,3 +14,7 @@ and all others that are members and who are not in this list will be removed. The "MembersToInclude" and "MembersToExclude" properties will allow you to control a specific set of users to add or remove, without changing any other members that are in the group already that may not be specified here, allowing + +NOTE: +In order to specify Local Farm you can use the token "\{LocalFarm\}" +as the username. The token is case sensitive. \ No newline at end of file diff --git a/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 new file mode 100644 index 000000000..670d94dfa --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 @@ -0,0 +1,31 @@ +<# +.EXAMPLE + This example shows how to use the local farm token to grant + full control permission to the local farm to the + user profile service app's sharing permission. +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + $members = @() + $members += MSFT_SPServiceAppSecurityEntry { + Username = "{LocalFarm}" + AccessLevel = "Full Control" + } + SPServiceAppSecurity UserProfileServiceSecurity + { + ServiceAppName = "User Profile Service Application" + SecurityType = "SharingPermissions" + Members = $members + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 index eedb70767..9dd06c166 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -20,30 +20,36 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Initialize tests - # Mocks for all contexts + # Mocks for all contexts Mock -CommandName Test-SPDSCIsADUser -MockWith { return $true } - + Mock Grant-SPObjectSecurity -MockWith {} Mock Revoke-SPObjectSecurity -MockWith {} Mock -CommandName Set-SPServiceApplicationSecurity -MockWith {} - Mock -CommandName New-SPClaimsPrincipal -MockWith { + Mock -CommandName New-SPClaimsPrincipal -MockWith { return @{ Value = $Identity -replace "i:0#.w\|" } } -ParameterFilter { $IdentityType -eq "EncodedClaim" } - Mock -CommandName New-SPClaimsPrincipal -MockWith { + Mock -CommandName New-SPClaimsPrincipal -MockWith { $Global:SPDscClaimsPrincipalUser = $Identity return ( New-Object -TypeName "Object" | Add-Member -MemberType ScriptMethod ` -Name ToEncodedString ` - -Value { - return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" + -Value { + return "i:0#.w|$($Global:SPDscClaimsPrincipalUser)" } -PassThru ) } -ParameterFilter { $IdentityType -eq "WindowsSamAccountName" } + Mock -CommandName Get-SPFarm -MockWith { + return @{ + Id = [Guid]"02a0cea2-d4e0-4e4e-ba2e-e532a433cfef" + } + } + # Test contexts Context -Name "The service app that security should be applied to does not exist" -Fixture { $testParams = @{ @@ -64,39 +70,39 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { }) ) } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return $null + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null } - + It "Should return empty members list from the get method" { (Get-TargetResource @testParams).Members | Should BeNullOrEmpty } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should throw an exception in the set method" { { Set-TargetResource @testParams } | Should Throw } } - + Context -Name "None of the required members properties are provided" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" SecurityType = "SharingPermissions" } - + It "Should throw an exception from the test method" { { Test-TargetResource @testParams } | Should Throw } - + It "Should throw an exception from the set method" { { Set-TargetResource @testParams } | Should Throw } } - + Context -Name "All of the members properties are provided" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -119,16 +125,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) MembersToExclude = @("CONTOSO\user2") } - + It "Should throw an exception from the test method" { { Test-TargetResource @testParams } | Should Throw } - + It "Should throw an exception from the set method" { { Set-TargetResource @testParams } | Should Throw } } - + Context -Name "The service app exists and a fixed members list is provided that does not match the current settings" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -148,12 +154,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { }) ) } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return @{} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} } - Mock -CommandName Get-SPServiceApplicationSecurity { + Mock -CommandName Get-SPServiceApplicationSecurity { return @{ AccessRules = @( @{ @@ -163,15 +169,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } } - + It "Should return a list of current members from the get method" { (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should call the update cmdlet from the set method" { Set-TargetResource @testParams Assert-MockCalled Grant-SPObjectSecurity @@ -179,7 +185,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Set-SPServiceApplicationSecurity } } - + Context -Name "The service app exists and a fixed members list is provided that does match the current settings" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -199,12 +205,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { }) ) } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return @{} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} } - - Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { return @{ AccessRules = @( @{ @@ -218,16 +224,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } } - + It "Should return a list of current members from the get method" { (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } - + Context -Name "The service app exists and a specific list of members to add and remove is provided, which does not match the desired state" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -242,12 +248,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) MembersToExclude = @("CONTOSO\user2") } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return @{} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} } - - Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { return @{ AccessRules = @( @{ @@ -257,15 +263,15 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } } - + It "Should return a list of current members from the get method" { (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty } - + It "Should return false from the test method" { Test-TargetResource @testParams | Should Be $false } - + It "Should call the update cmdlet from the set method" { Set-TargetResource @testParams Assert-MockCalled Grant-SPObjectSecurity @@ -273,7 +279,44 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Set-SPServiceApplicationSecurity } } - + + Context -Name "The service app exists and a specific list of members to remove is provided, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + MembersToExclude = @("CONTOSO\user2") + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user2" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return a list of current members from the get method" { + (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Revoke-SPObjectSecurity + Assert-MockCalled Set-SPServiceApplicationSecurity + } + } + Context -Name "The service app exists and a specific list of members to add and remove is provided, which does match the desired state" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -288,12 +331,12 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) MembersToExclude = @("CONTOSO\user2") } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return @{} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} } - - Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { return @{ AccessRules = @( @{ @@ -303,16 +346,193 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } } - + It "Should return a list of current members from the get method" { (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty } - + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } + Context -Name "The service app exists and a specific list of members to add is provided with different access level, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + MembersToInclude = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "CONTOSO\user1" + AccessLevel = "Read" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user1" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "The service app exists and a specific list of members is provided with different access level, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "CONTOSO\user1" + AccessLevel = "Read" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user1" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 1 + Assert-MockCalled Revoke-SPObjectSecurity -Times 1 + Assert-MockCalled Set-SPServiceApplicationSecurity -Times 1 + } + } + + Context -Name "The service app exists and a specific list of members to add is provided with different access level, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + MembersToInclude = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "CONTOSO\user1" + AccessLevel = "Read" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user1" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 1 + Assert-MockCalled Revoke-SPObjectSecurity -Times 1 + Assert-MockCalled Set-SPServiceApplicationSecurity -Times 1 + } + } + + Context -Name "The service app exists and an empty list of members is provided, which matches the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @() + } + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 0 + Assert-MockCalled Revoke-SPObjectSecurity -Times 0 + Assert-MockCalled Set-SPServiceApplicationSecurity -Times 1 + } + } + + Context -Name "The service app exists and an empty list of members is provided, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user1" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 0 + Assert-MockCalled Revoke-SPObjectSecurity -Times 1 + Assert-MockCalled Set-SPServiceApplicationSecurity -Times 1 + } + } + Context -Name "The service app exists and a specific list of members to add and remove is provided, which does match the desired state and includes a claims based group" -Fixture { $testParams = @{ ServiceAppName = "Example Service App" @@ -327,11 +547,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) MembersToExclude = @("CONTOSO\user2") } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return @{} + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} } - Mock -CommandName Get-SPServiceApplicationSecurity { + Mock -CommandName Get-SPServiceApplicationSecurity { return @{ AccessRules = @( @{ @@ -341,19 +561,170 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } } - + Mock Resolve-SPDscSecurityIdentifier { return "CONTOSO\user1" } - + It "Should return a list of current members from the get method" { (Get-TargetResource @testParams).Members | Should Not BeNullOrEmpty } - + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "The service app exists and the local farm token is provided in the members list that match the current settings" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "{LocalFarm}" + AccessLevel = "Full Control" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "c:0%.c|system|02a0cea2-d4e0-4e4e-ba2e-e532a433cfef" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return local farm token in the list of current members from the get method" { + $members = (Get-TargetResource @testParams).Members + $members[0].Username | Should Be "{LocalFarm}" + } + It "Should return true from the test method" { Test-TargetResource @testParams | Should Be $true } } + + Context -Name "The service app exists and the local farm token is provided in the members list that does not match the current settings" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "{LocalFarm}" + AccessLevel = "Full Control" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity + Assert-MockCalled Revoke-SPObjectSecurity -Times 0 + Assert-MockCalled Set-SPServiceApplicationSecurity + } + } + + Context -Name "The service app exists and local farm token is included in the specific list of members to add, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + MembersToInclude = @( + (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` + -ClientOnly ` + -Property @{ + Username = "{Local Farm}" + AccessLevel = "Full Control" + }) + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "CONTOSO\user2" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity + Assert-MockCalled Revoke-SPObjectSecurity -Times 0 + Assert-MockCalled Set-SPServiceApplicationSecurity + } + } + + Context -Name "The service app exists and local farm token is included in the specific list of members to remove, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + MembersToExclude = @("{LocalFarm}") + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "c:0%.c|system|02a0cea2-d4e0-4e4e-ba2e-e532a433cfef" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 0 + Assert-MockCalled Revoke-SPObjectSecurity + Assert-MockCalled Set-SPServiceApplicationSecurity + } + } } } From 7132f25de9f4f3e343816f545157f0c8f8ff852f Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 23 Sep 2018 21:14:36 +0200 Subject: [PATCH 020/101] Updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 953cc3640..db9f4a7c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ * Fixed issue with numerical Content Sources name; * SPWebAppSuiteBar * Fixed incorrect test method that resulted in this resource to never apply changes. +* SPServiceAppSecurity + * Added local farm token. + * Fixed issues that prevented the resource to work as expected in many situations. * SPWebAppPropertyBag * New resource to manage web application property bag From 6a5dbc4f18b079a7b5082756d4bed416d1bd08f2 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 23 Sep 2018 21:48:40 +0200 Subject: [PATCH 021/101] Added check for local farm id as farm id claim could be a remote farm --- .../MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 6f1e5bbe0..17b274743 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -76,7 +76,7 @@ function Get-TargetResource $user = $securityEntry.Name if ($user -like "i:*|*" -or $user -like "c:*|*") { - if($user.Chars(3) -eq "%") + if($user.Chars(3) -eq "%" -and $user -ilike "*$((Get-SPFarm).Id.ToString())") { $user = "{LocalFarm}" } From efcd635b1170a1b5f58d3bbeb608f385768d9db7 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 23 Sep 2018 22:41:39 +0200 Subject: [PATCH 022/101] Fixed formatting issues --- .../DSCResources/MSFT_SPServiceAppSecurity/readme.md | 2 +- .../Examples/Resources/SPServiceAppSecurity/2-Example.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md index ddb80d839..17040c746 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/readme.md @@ -17,4 +17,4 @@ members that are in the group already that may not be specified here, allowing NOTE: In order to specify Local Farm you can use the token "\{LocalFarm\}" -as the username. The token is case sensitive. \ No newline at end of file +as the username. The token is case sensitive. diff --git a/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 index 670d94dfa..bfc930f85 100644 --- a/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 +++ b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 @@ -1,7 +1,7 @@ <# .EXAMPLE This example shows how to use the local farm token to grant - full control permission to the local farm to the + full control permission to the local farm to the user profile service app's sharing permission. #> From 060e1d6eb727194abad8bb204bba96f859beeec4 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Mon, 24 Sep 2018 06:38:41 +0200 Subject: [PATCH 023/101] Fixed formatting issues --- .../Examples/Resources/SPServiceAppSecurity/2-Example.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 index bfc930f85..9c21890e8 100644 --- a/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 +++ b/Modules/SharePointDsc/Examples/Resources/SPServiceAppSecurity/2-Example.ps1 @@ -2,7 +2,7 @@ .EXAMPLE This example shows how to use the local farm token to grant full control permission to the local farm to the - user profile service app's sharing permission. + user profile service app's sharing permission. #> Configuration Example From ab95fb47988761a8b44d267ecb947f0f34be184e Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Mon, 24 Sep 2018 09:29:12 +0200 Subject: [PATCH 024/101] Removed unnecessary check for null --- .../MSFT_SPServiceAppSecurity.psm1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 17b274743..01450883b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -389,12 +389,6 @@ function Test-TargetResource { Write-Verbose -Message "Processing Members parameter" - if ($null -eq $CurrentValues.Members) - { - Write-Verbose -Message "Security list does not match" - return $false - } - if ($CurrentValues.Members.Count -eq 0) { if ($Members.Count -gt 0) From e01fb9a8194b77bce7b958e2ee2687a74d19469c Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Mon, 24 Sep 2018 09:29:42 +0200 Subject: [PATCH 025/101] Added unit test Fixed typo in existing unit test --- ...arePointDsc.SPServiceAppSecurity.Tests.ps1 | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 index 9dd06c166..68717ff97 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPServiceAppSecurity.Tests.ps1 @@ -659,7 +659,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { (New-CimInstance -ClassName "MSFT_SPServiceAppSecurityEntry" ` -ClientOnly ` -Property @{ - Username = "{Local Farm}" + Username = "{LocalFarm}" AccessLevel = "Full Control" }) ) @@ -725,6 +725,40 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Assert-MockCalled Set-SPServiceApplicationSecurity } } + + Context -Name "The service app exists and an empty list of members are specified, which does not match the desired state" -Fixture { + $testParams = @{ + ServiceAppName = "Example Service App" + SecurityType = "SharingPermissions" + Members = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return @{} + } + + Mock -CommandName Get-SPServiceApplicationSecurity -MockWith { + return @{ + AccessRules = @( + @{ + Name = "c:0%.c|system|02a0cea2-d4e0-4e4e-ba2e-e532a433cfef" + AllowedRights = "FullControl" + } + ) + } + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update cmdlet from the set method" { + Set-TargetResource @testParams + Assert-MockCalled Grant-SPObjectSecurity -Times 0 + Assert-MockCalled Revoke-SPObjectSecurity + Assert-MockCalled Set-SPServiceApplicationSecurity + } + } } } From af1c43f747af36d80a158d80474eca489b7a23b1 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Wed, 26 Sep 2018 10:25:41 +0200 Subject: [PATCH 026/101] Modified check for missing member parameters to check all three for null --- .../MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 index 01450883b..0e4d25ec8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPServiceAppSecurity/MSFT_SPServiceAppSecurity.psm1 @@ -38,7 +38,7 @@ function Get-TargetResource "MembersToExclude parameters") } - if ($null -eq $Members -and !$MembersToInclude -and !$MembersToExclude) + if ($null -eq $Members -and $null -eq $MembersToInclude -and $null -eq $MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") @@ -150,7 +150,7 @@ function Set-TargetResource "MembersToExclude parameters") } - if ($null -eq $Members -and !$MembersToInclude -and !$MembersToExclude) + if ($null -eq $Members -and $null -eq $MembersToInclude -and $null -eq $MembersToExclude) { throw ("At least one of the following parameters must be specified: Members, " + ` "MembersToInclude, MembersToExclude") From 4337150d8944863b13ced044866a4e94b2c3df7f Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 26 Sep 2018 10:06:55 -0400 Subject: [PATCH 027/101] Ready --- .../MSFT_SPSearchManagedProperty.psm1 | 3 + ...PointDsc.SPSearchManagedProperty.Tests.ps1 | 389 ++++++++++++++++++ .../SharePointDsc.SPSearchManagedProperty.ps1 | 64 --- 3 files changed, 392 insertions(+), 64 deletions(-) create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 delete mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index c9d033ca7..535112870 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -259,6 +259,8 @@ function Set-TargetResource #endregion $needToRecreate = $false + # If the property should not be present and is, or if it should be present bu the current property type + # differs from the desired one. if ($params.Ensure -eq "Absent" -and $CurrentValues.Ensure -eq "Present" -or ` ($params.PropertyType -ne $CurrentValues.PropertyType -and ` $CurrentValues.Ensure -eq "Present")) @@ -313,6 +315,7 @@ function Set-TargetResource $managedProperty.TokenNormalization = $params.TokenNormalization $managedProperty.RespectPriority = !($params.IncludeAllCrawledProperties) $managedProperty.OverrideValueOfHasMultipleValues = !($params.IncludeAllCrawledProperties) + $managedProperty.Update() # If alias doesn't already exist, add it $alias = $managedProperty.GetAliases() | Where-Object{$_ -eq $params.Alias} diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 new file mode 100644 index 000000000..4b3265d7f --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 @@ -0,0 +1,389 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSearchManagedProperty" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + $Script:PropertyCreated = $false + + # Mocks for all contexts + Mock -CommandName New-SPEnterpriseSearchMetadataManagedProperty -MockWith { $Script:PropertyCreated = $true } + Mock -CommandName Set-SPEnterpriseSearchMetadataManagedProperty -MockWith {} + Mock -CommandName Remove-SPEnterpriseSearchMetadataManagedProperty -MockWith {} + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith { + return @( + @{ + Name = "Search Service Application" + } + ) + } + + try { [Microsoft.Office.Server.Search.Administration] } + catch { + try { + Add-Type -TypeDefinition @" + namespace Microsoft.Office.Server.Search.Administration { + public enum ManagedDataType { Text, YesNo, Integer, DateTime, Double }; + } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose "The Type Microsoft.Office.Server.Search.Administration.ManagedDataType was already added." + } + } + + try { [Microsoft.Office.Server.Search.Administration.MappingCollection] } + catch { + try { + Add-Type -TypeDefinition @" + namespace Microsoft.Office.Server.Search.Administration { + public class MappingCollection + { + public void Add(object mapping){} + } + } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose "The Type Microsoft.Office.Server.Search.Administration.MappingCollection was already added." + } + } + + try { [Microsoft.Office.Server.Search.Administration.Mapping] } + catch { + try { + Add-Type -TypeDefinition @" + namespace Microsoft.Office.Server.Search.Administration { + public class Mapping + { + public string CrawledPropertyName{get; set;} + public string CrawledPropSet{get; set;} + public int ManagedPID{get;set;} + } + } +"@ -ErrorAction SilentlyContinue + } + catch { + Write-Verbose "The Type Microsoft.Office.Server.Search.Administration.Mapping was already added." + } + } + + Context -Name "When the property doesn't exist and should" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "Search Service Application" + HasMultipleValues = $false + Alias = "TestAlias" + CrawledProperties = @("CP1", "CP2") + Ensure = "Present" + } + + $Script:PropertyCreated = $false + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + return $null + } -ParameterFilter { $Script:PropertyCreated -eq $false } + + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + $results = @{ + Name = "TestParam" + PID = 1 + ManagedType = "Text" + Searchable = $true + Refinable = $true + Queryable = $true + Sortable = $true + NoWordBreaker = $true + HasMultipleValues = $false + } | Add-Member -MemberType ScriptMethod ` + -Name GetAliases ` + -Value { + @("Alias1", "Alias2") + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name GetMappedCrawledProperties ` + -Value { + return @("Map1") + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name AddAlias ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name SetMappings ` + -Value { + $null + } -PassThru -Force + return $results + + } -ParameterFilter { $Script:PropertyCreated -eq $true } + + Mock -CommandName Get-SPEnterpriseSearchMetadataCrawledProperty -MockWith { + return @{CrawledPropertyName = 'FakeValue';} + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should create the managed property" { + Set-TargetResource @testParams + Assert-MockCalled -CommandName Set-SPEnterpriseSearchMetadataManagedProperty -Exactly 1 + } + + It "Should now return Present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + } + + Context -Name "When the property already exists with the proper type and should" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "Search Service Application" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + $results = @{ + Name = "TestParam" + PID = 1 + ManagedType = "Text" + Searchable = $true + Refinable = $true + Queryable = $true + Sortable = $true + NoWordBreaker = $true + HasMultipleValues = $false + Ensure = "Present" + } | Add-Member -MemberType ScriptMethod ` + -Name GetAliases ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name GetMappedCrawledProperties ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name AddAlias ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name SetMappings ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name DeleteAllMappings ` + -Value { + $null + } -PassThru -Force + return $results + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should do nothing" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchMetadataManagedProperty -Exactly 0 -Scope Context + Assert-MockCalled New-SPEnterpriseSearchMetadataManagedProperty -Exactly 0 -Scope Context + } + } + + Context -Name "When the property already exists, but with the invalid property type" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "Search Service Application" + Ensure = "Present" + } + + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + $results = @{ + Name = "TestParam" + PID = 1 + ManagedType = "Number" + Searchable = $true + Refinable = $true + Queryable = $true + Sortable = $true + NoWordBreaker = $true + HasMultipleValues = $false + Ensure = "Present" + } | Add-Member -MemberType ScriptMethod ` + -Name GetAliases ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name GetMappedCrawledProperties ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name AddAlias ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name SetMappings ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name DeleteAllMappings ` + -Value { + $null + } -PassThru -Force + return $results + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should recreate the property with the proper type" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchMetadataManagedProperty -Exactly 1 -Scope Context + Assert-MockCalled New-SPEnterpriseSearchMetadataManagedProperty -Exactly 1 -Scope Context + } + } + + Context -Name "When the property should not exist" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "Search Service Application" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { + $results = @{ + Name = "TestParam" + PID = 1 + ManagedType = "Text" + Searchable = $true + Refinable = $true + Queryable = $true + Sortable = $true + NoWordBreaker = $true + HasMultipleValues = $false + Ensure = "Present" + } | Add-Member -MemberType ScriptMethod ` + -Name GetAliases ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name GetMappedCrawledProperties ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name AddAlias ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name SetMappings ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name DeleteAllMappings ` + -Value { + $null + } -PassThru -Force + return $results + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should recreate the property with the proper type" { + Set-TargetResource @testParams + Assert-MockCalled Remove-SPEnterpriseSearchMetadataManagedProperty -Exactly 1 -Scope Context + Assert-MockCalled New-SPEnterpriseSearchMetadataManagedProperty -Exactly 0 -Scope Context + } + } + + Context -Name "When specified Service Application does not exist" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "InvalidSSA" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith{ + return $null + } + + It "Should throw an error" { + { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application {InvalidSSA} is ` + invalid. Please make sure you specify the name of an existing service application." + } + } + + Context -Name "When specified Service Application does not exist" -Fixture { + $testParams = @{ + Name = "TestParam" + PropertyType = "Text" + ServiceAppName = "InvalidSSA" + Ensure = "Absent" + } + + Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith{ + return $null + } + + It "Should throw an error" { + { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application {InvalidSSA} is ` + invalid. Please make sure you specify the name of an existing service application." + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 deleted file mode 100644 index 9ea7f2244..000000000 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -[CmdletBinding()] -param( - [Parameter()] - [string] - $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` - -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` - -Resolve) -) - -Import-Module -Name (Join-Path -Path $PSScriptRoot ` - -ChildPath "..\UnitTestHelper.psm1" ` - -Resolve) - -$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` - -DscResource "SPSearchManagedProperty" - -Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { - InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { - Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope - - # Initialize tests - $getTypeFullName = "Microsoft.Office.Server.Search.Administration.SearchServiceApplication" - - # Mocks for all contexts - Mock -CommandName New-SPEnterpriseSearchMetadataManagedProperty -MockWith {} - Mock -CommandName Set-SPEnterpriseSearchMetadataManagedProperty -MockWith {} - Mock -CommandName Remove-SPEnterpriseSearchMetadataManagedProperty -MockWith {} - - Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { - return @(@{ - Name = "MockManagedProperty" - PID = 0 - PropertyType = "Text" - Searchable = $true - Refinable = $true - Queryable = $true - Sortable = $true - NoWordBreaker = $true - }) - } - - Context -Name "When the property doesn't exist and should" -Fixture { - Mock -CommandName Get-SPEnterpriseSearchMetadataManagedProperty -MockWith { - return @({ - Name = "TestParam" - PropertyType = "Text" - Ensure = "Absent" - }) - } - $testParams = @{ - Name = "TestParam" - PropertyType = "Text" - ServiceAppName = "Search Service Application" - Ensure = "Present" - } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - } - } -} - -Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From 6139e181a59eb7901523e329402d44f90481d41f Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 26 Sep 2018 12:38:14 -0400 Subject: [PATCH 028/101] Updated number of Test-Resource Checks --- .../MSFT_SPSearchManagedProperty.psm1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index 535112870..29f86d78f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -427,10 +427,6 @@ function Test-TargetResource -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Name", "PropertyType", - "Searchable", - "Refinable", - "NoWordBreaker", - "IncludeAllCrawledProperties", "Ensure") } From 23e5bf9ecc46a9394f83139eb5db24088235c630 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 26 Sep 2018 13:35:44 -0400 Subject: [PATCH 029/101] Removed Return Types for Set and pu bool for test --- .../MSFT_SPSearchManagedProperty.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index 29f86d78f..3c66267ad 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -149,7 +149,6 @@ function Get-TargetResource function Set-TargetResource { [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] param ( [Parameter(Mandatory = $true)] @@ -344,7 +343,7 @@ function Set-TargetResource function Test-TargetResource { [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] + [OutputType([System.Boolean])] param ( [Parameter(Mandatory = $true)] From 431aaf995958e34a3358a78af92454c7a96b3cda Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 27 Sep 2018 06:49:41 -0400 Subject: [PATCH 030/101] Incorporated comments from review --- CHANGELOG.md | 4 +- .../MSFT_SPSearchManagedProperty.psm1 | 41 ++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acd27adf3..48573faba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## Unreleased * SPSearchContentSource - * Fixed issue with numerical Content Sources name; + * Fixed issue with numerical Content Sources name +* SPSearchMAnagedProperty + * Added a new resource to support Search Managed Properties ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index 3c66267ad..352017874 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -83,9 +83,9 @@ function Get-TargetResource $params = $args[0] $ssa = Get-SPEnterpriseSearchServiceApplication -Identity $params.ServiceAppName - if(!$ssa) + if ($null -eq $ssa) { - throw("The specified Search Service Application {$($params.ServiceAppName)} is ` + throw("The specified Search Service Application $($params.ServiceAppName) is ` invalid. Please make sure you specify the name of an existing service application.") } $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $ssa | ` @@ -99,17 +99,18 @@ function Get-TargetResource Ensure = "Absent" } } - else { + else + { $aliases = $managedProperty.GetAliases() $alias = "" - if($aliases) + if ($aliases) { $alias = $aliases[0] } $mappedCrawlProperties = $managedProperty.GetMappedCrawledProperties($false) $includeAllCrawlProperties = $false - if($mappedCrawlProperties) + if ($mappedCrawlProperties) { $includeAllCrawlProperties = $true } @@ -131,10 +132,10 @@ function Get-TargetResource Ensure = "Present" } - if(!$includeAllCrawlProperties) + if (!$includeAllCrawlProperties) { $crawledProperties = @() - foreach($mappedProperty in $mappedCrawlProperties) + foreach ($mappedProperty in $mappedCrawlProperties) { $crawledProperties += $mappedProperty.Name } @@ -238,20 +239,20 @@ function Set-TargetResource #region Pre-Validation # Ensure that if we specified that we don't specify any crawled property mapping if we selected to include # them all. - if($params.IncludeAllCrawledProperties -and $params.CrawledProperties.Length -gt 0) + if ($params.IncludeAllCrawledProperties -and $params.CrawledProperties.Length -gt 0) { throw("You cannot specify values for CrawledProperties if the property ` IncludeAllCrawledProperties is set to True.") } # Ensure that the specified crawled properties exist - foreach($mappedCrawlProperty in $params.CrawledProperties) + foreach ($mappedCrawlProperty in $params.CrawledProperties) { $currentCrawlProperty = Get-SPEnterpriseSearchMetadataCrawledProperty -Name $mappedCrawlProperty ` -SearchApplication $params.ServiceAppName - if(!$currentCrawlProperty) + if (!$currentCrawlProperty) { - throw("The specified crawled property {$($mappedCrawlProperty)} does not exist. ` + throw("The specified crawled property $($mappedCrawlProperty) does not exist. ` Please make sure you specify valid existing crawl properties.") } } @@ -277,7 +278,7 @@ function Set-TargetResource -SearchApplication $params.ServiceAppName ` -Confirm:$false - if($params.PropertyType -ne $CurrentValues.PropertyType) + if ($params.PropertyType -ne $CurrentValues.PropertyType) { Write-Verbose "Detected a change to type from {$($currentPropertyType)} to ` {$($params.PropertyType)}" @@ -318,14 +319,14 @@ function Set-TargetResource $managedProperty.Update() # If alias doesn't already exist, add it $alias = $managedProperty.GetAliases() | Where-Object{$_ -eq $params.Alias} - if($alias) + if ($alias) { $managedProperty.AddAlias($params.Alias) } # Generate the Crawled Properties mapping $listOfMappedCrawlProperty = [Microsoft.Office.Server.Search.Administration.MappingCollection]::new() - foreach($mappedCrawlProperty in $params.CrawledProperties) + foreach ($mappedCrawlProperty in $params.CrawledProperties) { $currentCrawlProperty = Get-SPEnterpriseSearchMetadataCrawledProperty -Name $mappedCrawlProperty ` -SearchApplication $params.ServiceAppName @@ -426,7 +427,17 @@ function Test-TargetResource -DesiredValues $PSBoundParameters ` -ValuesToCheck @("Name", "PropertyType", - "Ensure") + "Ensure", + "HasMultipleValues", + "Retrievable", + "Searchable", + "Refinable", + "Searchable", + "NoWordBreaker", + "IncludeAllCrawledProperties", + "Alias", + "Sortable", + "SafeForAnonymous") } Export-ModuleMember -Function *-TargetResource From 341c540ca4cca80687b68eed7736be321105e51d Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 27 Sep 2018 07:36:24 -0400 Subject: [PATCH 031/101] Fixed typo in Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48573faba..06593fc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * SPSearchContentSource * Fixed issue with numerical Content Sources name -* SPSearchMAnagedProperty +* SPSearchManagedProperty * Added a new resource to support Search Managed Properties ## 2.5 From 92b6b1f010f002f47bb23562112ded9079c76cbd Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 27 Sep 2018 07:59:16 -0400 Subject: [PATCH 032/101] Fixed output with curly brackets --- .../MSFT_SPSearchManagedProperty.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index 352017874..a077d60b3 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -273,15 +273,15 @@ function Set-TargetResource $managedProperty.DeleteAllMappings() # Remove the existing managed property - Write-Verbose "Removing Managed Property {$($params.Name)}" + Write-Verbose "Removing Managed Property $($params.Name)" Remove-SPEnterpriseSearchMetadataManagedProperty -Identity $params.Name ` -SearchApplication $params.ServiceAppName ` -Confirm:$false if ($params.PropertyType -ne $CurrentValues.PropertyType) { - Write-Verbose "Detected a change to type from {$($currentPropertyType)} to ` - {$($params.PropertyType)}" + Write-Verbose "Detected a change to type from $($currentPropertyType) to ` + $($params.PropertyType)" $needToRecreate = $true } } @@ -292,7 +292,7 @@ function Set-TargetResource # Create the new content source and then apply settings to it $managedTypeID = [Microsoft.Office.Server.Search.Administration.ManagedDataType]::$($params.PropertyType).value__ - Write-Verbose "Creating a new Managed Property {$($params.Name)}" + Write-Verbose "Creating a new Managed Property $($params.Name)" New-SPEnterpriseSearchMetadataManagedProperty -Name $params.Name ` -SearchApplication $params.ServiceAppName ` -Type $managedTypeID From 2a7e58a72c7ef3bb6d696676ef90da073a371565 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 27 Sep 2018 10:41:26 -0400 Subject: [PATCH 033/101] Fixed throw output for tests --- ...PointDsc.SPSearchManagedProperty.Tests.ps1 | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 index 4b3265d7f..762c98e2b 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 @@ -113,29 +113,29 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Name GetAliases ` -Value { @("Alias1", "Alias2") - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name GetMappedCrawledProperties ` -Value { return @("Map1") - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name AddAlias ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name SetMappings ` -Value { $null } -PassThru -Force return $results - + } -ParameterFilter { $Script:PropertyCreated -eq $true } Mock -CommandName Get-SPEnterpriseSearchMetadataCrawledProperty -MockWith { @@ -180,27 +180,27 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Name GetAliases ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name GetMappedCrawledProperties ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name AddAlias ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name SetMappings ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name DeleteAllMappings ` -Value { @@ -244,27 +244,27 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Name GetAliases ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name GetMappedCrawledProperties ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name AddAlias ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name SetMappings ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name DeleteAllMappings ` -Value { @@ -308,27 +308,27 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { -Name GetAliases ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name GetMappedCrawledProperties ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name Update ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name AddAlias ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name SetMappings ` -Value { $null - } -PassThru -Force | + } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name DeleteAllMappings ` -Value { @@ -361,7 +361,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should throw an error" { - { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application {InvalidSSA} is ` + { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application InvalidSSA is ` invalid. Please make sure you specify the name of an existing service application." } } @@ -379,7 +379,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should throw an error" { - { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application {InvalidSSA} is ` + { Get-TargetResource @testParams }| Should Throw "The specified Search Service Application InvalidSSA is ` invalid. Please make sure you specify the name of an existing service application." } } From d24853c3ab9b19c8685396cabd55a388ed35e0ee Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 30 Sep 2018 21:19:12 +0200 Subject: [PATCH 034/101] Added resource for setting client callable settings and proxy libraries --- .../DSCResources/MSFT_SPSite/readme.md | 5 + .../MSFT_SPWebAppClientCallableSettings.psm1 | 628 ++++++++++++++ ..._SPWebAppClientCallableSettings.schema.mof | 24 + .../readme.md | 33 + .../1-Example.ps1 | 31 + .../2-Example.ps1 | 29 + ...c.SPWebAppClientCallableSettings.Tests.ps1 | 776 ++++++++++++++++++ 7 files changed, 1526 insertions(+) create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md index d6275a939..bfbc3f98b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md @@ -17,3 +17,8 @@ IIS site and prevent the site from listening for the URL of the Host Header Site Collection. If you want to change the IIS website binding settings, please use the xWebsite resource in the xWebAdministration module. + +NOTE: +AdministrationSiteType is used in combination with the resource +SPWebAppClientCallableSettings. The required proxy library must be configured +before the administration site type has any effect. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 new file mode 100644 index 000000000..b15ad7f74 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -0,0 +1,628 @@ +Set-StrictMode -Version 2 + +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting web application '$url' client callable settings" + + if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) + { + throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + "ProxyLibrariesToExclude parameters") + } + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters) ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + if ($null -eq $webApplication) + { + return @{ + Url = $null + ProxyLibraries = $null + ProxyLibrariesToInclude = $null + ProxyLibrariesToExclude = $null + MaxResourcesPerRequest = $null + MaxObjectPaths = $null + ExecutionTimeout = $null + RequestXmlMaxDepth = $null + EnableXsdValidation = $null + EnableStackTrace = $null + RequestUsageExecutionTimeThreshold = $null + EnableRequestUsage = $null + LogActionsIfHasRequestException = $null + } + } + + $proxyLibraries = @() + $clientCallableSettings = $webApplication.ClientCallableSettings + $clientCallableSettings.ProxyLibraries | ForEach-Object -Process { + $proxyLibraries += $_ + } + + if($params.ContainsKey("ProxyLibrariesToInclude")) + { + $include = $params.ProxyLibrariesToInclude + } + else + { + $include = $null; + } + + if($params.ContainsKey("ProxyLibrariesToExclude")) + { + $exclude = $params.ProxyLibrariesToExclude + } + else + { + $exclude = $null; + } + + return @{ + Url = $params.Url + ProxyLibraries = $clientCallableSettings.ProxyLibraries #$proxyLibraries + ProxyLibrariesToInclude = $include + ProxyLibrariesToExclude = $exclude + MaxResourcesPerRequest = $clientCallableSettings.MaxResourcesPerRequest + MaxObjectPaths = $clientCallableSettings.MaxObjectPaths + ExecutionTimeout = $clientCallableSettings.ExecutionTimeout.TotalMinutes + RequestXmlMaxDepth = $clientCallableSettings.RequestXmlMaxDepth + EnableXsdValidation = $clientCallableSettings.EnableXsdValidation + EnableStackTrace = $clientCallableSettings.EnableStackTrace + RequestUsageExecutionTimeThreshold = $clientCallableSettings.RequestUsageExecutionTimeThreshold + EnableRequestUsage = $clientCallableSettings.EnableRequestUsage + LogActionsIfHasRequestException = $clientCallableSettings.LogActionsIfHasRequestException + } + } + + return $result +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting web application '$Url' client callable settings" + + if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) + { + throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + "ProxyLibrariesToExclude parameters") + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters) ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + if ($null -eq $webApplication) + { + throw "Web application $($params.Url) was not found" + } + + $clientCallableSettings = $webApplication.ClientCallableSettings + $webApplicationNeedsUpdate = $false + + if ($params.ContainsKey("ProxyLibraries") -eq $true) + { + foreach($desiredProxyLibrary in $params.ProxyLibraries) + { + if ($clientCallableSettings.ProxyLibraries.AssemblyName -contains $desiredProxyLibrary.AssemblyName) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $desiredProxyLibrary.AssemblyName + } | Select-Object -First 1 + + if ($existingProxyLibrary.SupportAppAuthentication -ne $desiredProxyLibrary.SupportAppAuthentication) + { + $existingProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $webApplicationNeedsUpdate = $true + } + } + else + { + $newProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $newProxyLibrary.AssemblyName = $desiredProxyLibrary.AssemblyName + $newProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $clientCallableSettings.ProxyLibraries.Add($newProxyLibrary); + $webApplicationNeedsUpdate = $true + } + } + + $proxyLibrariesToRemove = {}.Invoke() + foreach($currentProxyLibrary in $clientCallableSettings.ProxyLibraries) + { + if ($params.ProxyLibraries.Count -eq 0 -or (-not ($params.ProxyLibraries.AssemblyName -contains $currentProxyLibrary.AssemblyName))) + { + $proxyLibrariesToRemove.Add($currentProxyLibrary); + } + } + + foreach($proxyLibraryToRemove in $proxyLibrariesToRemove) + { + $clientCallableSettings.ProxyLibraries.Remove($proxyLibraryToRemove) + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("ProxyLibrariesToInclude") -eq $true -and $params.ProxyLibrariesToInclude.Count -gt 0) + { + foreach($desiredProxyLibrary in $params.ProxyLibrariesToInclude) + { + if ($clientCallableSettings.ProxyLibraries.AssemblyName -contains $desiredProxyLibrary.AssemblyName) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $desiredProxyLibrary.AssemblyName + } | Select-Object -First 1 + + if ( $existingProxyLibrary.SupportAppAuthentication -ne $desiredProxyLibrary.SupportAppAuthentication) + { + $existingProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $webApplicationNeedsUpdate = $true + } + } + else + { + $newProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $newProxyLibrary.AssemblyName = $desiredProxyLibrary.AssemblyName + $newProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $clientCallableSettings.ProxyLibraries.Add($newProxyLibrary); + $webApplicationNeedsUpdate = $true + } + } + } + + if ($params.ContainsKey("ProxyLibrariesToExclude") -eq $true) + { + foreach($excludeProxyLibrary in $params.ProxyLibrariesToExclude) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $excludeProxyLibrary + } | Select-Object -First 1 + if($null -ne $existingProxyLibrary) + { + $clientCallableSettings.ProxyLibraries.Remove($existingProxyLibrary) + $webApplicationNeedsUpdate = $true + } + } + } + + if ($params.ContainsKey("MaxObjectPaths") -eq $true) + { + if ($params.MaxObjectPaths -ne $clientCallableSettings.MaxObjectPaths) + { + $clientCallableSettings.MaxObjectPaths = $params.MaxObjectPaths + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("MaxResourcesPerRequest") -eq $true) + { + if ($params.MaxResourcesPerRequest -ne $clientCallableSettings.MaxResourcesPerRequest) + { + $clientCallableSettings.MaxResourcesPerRequest = $params.MaxResourcesPerRequest + $webApplicationNeedsUpdate = $true + } + } + + + if ($params.ContainsKey("ExecutionTimeout") -eq $true) + { + if ($params.ExecutionTimeout -ne $clientCallableSettings.ExecutionTimeout.TotalMinutes) + { + $clientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes($params.ExecutionTimeout) + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("RequestXmlMaxDepth") -eq $true) + { + if ($params.RequestXmlMaxDepth -ne $clientCallableSettings.RequestXmlMaxDepth) + { + $clientCallableSettings.RequestXmlMaxDepth = $params.RequestXmlMaxDepth + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableXsdValidation") -eq $true) + { + if ($params.EnableXsdValidation -ne $clientCallableSettings.EnableXsdValidation) + { + $clientCallableSettings.EnableXsdValidation = $params.EnableXsdValidation + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableStackTrace") -eq $true) + { + if ($params.EnableStackTrace -ne $clientCallableSettings.EnableStackTrace) + { + $clientCallableSettings.EnableStackTrace = $params.EnableStackTrace + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("RequestUsageExecutionTimeThreshold") -eq $true) + { + if ($params.RequestUsageExecutionTimeThreshold -ne $clientCallableSettings.RequestUsageExecutionTimeThreshold) + { + $clientCallableSettings.RequestUsageExecutionTimeThreshold = $params.RequestUsageExecutionTimeThreshold + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableRequestUsage") -eq $true) + { + if ($params.EnableRequestUsage -ne $clientCallableSettings.EnableRequestUsage) + { + $clientCallableSettings.EnableRequestUsage = $params.EnableRequestUsage + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("LogActionsIfHasRequestException") -eq $true) + { + if ($params.LogActionsIfHasRequestException -ne $clientCallableSettings.LogActionsIfHasRequestException) + { + $clientCallableSettings.LogActionsIfHasRequestException = $params.LogActionsIfHasRequestException + $webApplicationNeedsUpdate = $true + } + } + + if ($webApplicationNeedsUpdate -eq $true) + { + Write-Verbose -Message "Updating web application" + $webApplication.Update() + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing for web application '$Url' client callable settings" + + $currentValues = Get-TargetResource @PSBoundParameters + + if ($null -eq $currentValues.ProxyLibraries) + { + Write-Verbose -Message "Proxy library list does not have a valid value" + return $false + } + + if ($null -ne $ProxyLibraries) + { + Write-Verbose -Message "Processing ProxyLibraries parameter" + + if ($currentValues.ProxyLibraries.Count -eq 0) + { + if ($ProxyLibraries.Count -gt 0) + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + } + else + { + if ($ProxyLibraries.Count -eq 0) + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + + $differences = Compare-Object -ReferenceObject $currentValues.ProxyLibraries.AssemblyName ` + -DifferenceObject $ProxyLibraries.AssemblyName + + if ($null -eq $differences) + { + Write-Verbose -Message "Proxy library list matches - checking that SupportAppAuthentication match on each object" + foreach($currentProxyLibrary in $currentValues.ProxyLibraries) + { + if ($currentProxyLibrary.SupportAppAuthentication -ne ($ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $currentProxyLibrary.AssemblyName + } | Select-Object -First 1).SupportAppAuthentication) + { + Write-Verbose -Message "$($currentProxyLibrary.AssemblyName) has incorrect SupportAppAuthentication. Test failed." + return $false + } + } + } + else + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + } + } + + if ($ProxyLibrariesToInclude) + { + Write-Verbose -Message "Processing ProxyLibrariesToInclude parameter" + + if ($currentValues.ProxyLibraries.Count -eq 0) + { + if ($ProxyLibrariesToInclude.Count -gt 0) + { + Write-Verbose -Message "Proxy library list to include does not match" + return $false + } + } + + Write-Verbose -Message "Processing ProxyLibrariesToInclude parameter" + foreach ($proxyLibrary in $ProxyLibrariesToInclude) + { + if (-not($currentValues.ProxyLibraries.AssemblyName -contains $proxyLibrary.AssemblyName)) + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) is not registered as a proxy library. Set result to false" + return $false + } + else + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) is already registered as a proxy library. Checking SupportAppAuthentication..." + if ($proxyLibrary.SupportAppAuthentication -ne ($currentValues.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $proxyLibrary.AssemblyName + } | Select-Object -First 1).SupportAppAuthentication) + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) has incorrect SupportAppAuthentication. Test failed." + return $false + } + } + } + } + + if ($ProxyLibrariesToExclude) + { + Write-Verbose -Message "Processing ProxyLibrariesToExclude parameter" + + if ($currentValues.ProxyLibraries.Count -gt 0) + { + foreach ($proxyLibrary in $ProxyLibrariesToExclude) + { + if ($currentValues.ProxyLibraries.AssemblyName -contains $proxyLibrary) + { + Write-Verbose -Message "$proxyLibrary is already registered as proxy library. Set result to false" + return $false + } + else + { + Write-Verbose -Message "$proxyLibrary is not registered as proxy library. Skipping" + } + } + } + } + + $valuesToCheck = {"Url"}.Invoke() + + if($PSBoundParameters.ContainsKey("MaxResourcesPerRequest") -eq $true) + { + $valuesToCheck.Add("MaxResourcesPerRequest") + } + + if($PSBoundParameters.ContainsKey("MaxObjectPaths") -eq $true) + { + $valuesToCheck.Add("MaxObjectPaths") + } + + if($PSBoundParameters.ContainsKey("ExecutionTimeout") -eq $true) + { + $valuesToCheck.Add("ExecutionTimeout") + } + + if($PSBoundParameters.ContainsKey("RequestXmlMaxDepth") -eq $true) + { + $valuesToCheck.Add("RequestXmlMaxDepth") + } + + if($PSBoundParameters.ContainsKey("EnableXsdValidation") -eq $true) + { + $valuesToCheck.Add("EnableXsdValidation") + } + + if($PSBoundParameters.ContainsKey("EnableStackTrace") -eq $true) + { + $valuesToCheck.Add("EnableStackTrace") + } + + if($PSBoundParameters.ContainsKey("RequestUsageExecutionTimeThreshold") -eq $true) + { + $valuesToCheck.Add("RequestUsageExecutionTimeThreshold") + } + + if($PSBoundParameters.ContainsKey("EnableRequestUsage") -eq $true) + { + $valuesToCheck.Add("EnableRequestUsage") + } + + if($PSBoundParameters.ContainsKey("LogActionsIfHasRequestException") -eq $true) + { + $valuesToCheck.Add("LogActionsIfHasRequestException") + } + + return Test-SPDscParameterState -CurrentValues $currentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck $valuesToCheck +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof new file mode 100644 index 000000000..b456130b4 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof @@ -0,0 +1,24 @@ +[ClassVersion("1.0.0.0")] +Class MSFT_SPProxyLibraryEntry +{ + [Required, Description("Name of the account")] String AssemblyName; + [Write, Description("Permission level of the account")] Boolean SupportAppAuthentication; +}; +[ClassVersion("1.0.0"), FriendlyName("SPWebAppClientCallableSettings")] +class MSFT_SPWebAppClientCallableSettings : OMI_BaseResource +{ + [Key, Description("The URL of the web application to set blocked file types for")] string Url; + [write, Description("A list of proxy libraries to set. Those not in this list will be removed"), EmbeddedInstance("MSFT_SPProxyLibraryEntry")] string ProxyLibraries[]; + [write, Description("A list of proxy libraries to add. Proxy libraries not in this list will be kept"), EmbeddedInstance("MSFT_SPProxyLibraryEntry")] string ProxyLibrariesToInclude[]; + [write, Description("A list of proxy libraries to remove. Proxy libraries not in this list will be kept")] string ProxyLibrariesToExclude[]; + [write, Description("Sets the maximum number of internal SPRequest objects that can be included in one request")] UInt32 MaxResourcesPerRequest; + [write, Description("Sets the maximum number of object paths that can be used within one request")] UInt32 MaxObjectPaths; + [write, Description("Sets the execution timeout for the client request in minutes")] UInt32 ExecutionTimeout; + [write, Description("Sets the maximum depth of the request XML that is sent by the client measured in 'tag' count")] UInt32 RequestXmlMaxDepth; + [write, Description("Sets a Boolean value that specifies whether to enable XSD validation against an XML request or not")] Boolean EnableXsdValidation; + [write, Description("Sets a Boolean value that specifies whether the server can send stack trace data to the client")] Boolean EnableStackTrace; + [write, Description("Sets the threshold in milliseconds for logging csom request usage data ")] UInt32 RequestUsageExecutionTimeThreshold; + [write, Description("Sets a Boolean value that specifies whether to log usage data or not")] Boolean EnableRequestUsage; + [write, Description("Sets a Boolean value that specifies whether to log usage data when request has an exception or not")] Boolean LogActionsIfHasRequestException; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] string InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md new file mode 100644 index 000000000..699110b82 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md @@ -0,0 +1,33 @@ +# Description + +**Type:** Distributed + +This resource sets the client callable settings for the web application. +It can set the proxy libraries and specific properties for the client +callable settings. +The resource can for example be used to increase the timeout for client +code, and to enable the tenant administration functionality. + +Tenant administration functionality enables client code to work with +the namespace Microsoft.Online.SharePoint.Client.Tenant from the +assembly with the same name. This enables client code to create site +collection, list all site collections, and more. + +In order to use the tenant administration client code a site collection +within the web application needs to be designated as a tenant +administration site collection. This can be done using the SPSite +resource setting the AdministrationSiteType to TenantAdministration. +Use this site collection when creating a client side connection. + +NOTE: +Proxy library used for enabling tenant administration: + +**SharePoint 2013** (Requires mininum April 2014 Cumulative Update): +Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub +, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + +**SharePoint 2016**: +Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub +, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + +In both version set the SupportAppAuthentication property to true. diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 new file mode 100644 index 000000000..c619eefff --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 @@ -0,0 +1,31 @@ +<# +.EXAMPLE + This example shows how to set the client callable settings for a web application +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPWebAppClientCallableSettings DefaultClientCallableSettings + { + Url = "http://example.contoso.local" + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = 90 + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 new file mode 100644 index 000000000..f8ac1d81f --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to enable tenant administration for a web application in a SharePoint 2013 farm +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + $proxyLibraries = @() + $proxyLibraries += MSFT_SPProxyLibraryEntry { + AssemblyName = "Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" + SupportAppAuthentication = $true + } + + SPWebAppClientCallableSettings TenantAdministration + { + Url = "http://example.contoso.local" + ProxyLibraries = $proxyLibraries + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 new file mode 100644 index 000000000..e4702e7be --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 @@ -0,0 +1,776 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPWebAppClientCallableSettings" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + try + { + [Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public class SPClientCallableProxyLibrary { + public SPClientCallableProxyLibrary() + { + } + public string AssemblyName { get; set; } + public bool SupportAppAuthentication { get; set; } + } +} +"@ + } + + # Mocks for all contexts + + $webAppImplementation = { + $clientCallableSettings = [PSCustomObject] @{ + ProxyLibraries = [System.Collections.ObjectModel.Collection[Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary]]@() + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + } + + $webApp = @{ + ClientCallableSettings = $clientCallableSettings + UpdateCalled = $false + } + + $webApp | Add-Member -MemberType ScriptMethod -Name Update -Value { + $this.UpdateCalled = $true + } + return $webApp + } + + # Test contexts + Context -Name "Client callable settings and a specific proxy library list matches current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = 90 + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary); + $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; + $webApp.ClientCallableSettings.MaxObjectPaths = 256; + $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; + $webApp.ClientCallableSettings.EnableXsdValidation = $true; + $webApp.ClientCallableSettings.EnableStackTrace = $false; + $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; + $webApp.ClientCallableSettings.EnableRequestUsage = $true; + $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return the current data from the get method" { + $result = Get-TargetResource @testParams + $result.Url | Should Be "http://sites.sharepoint.com" + $result.MaxResourcesPerRequest | Should Be 16 + $result.MaxObjectPaths | Should Be 256 + $result.ExecutionTimeout | Should Be 90 + $result.RequestXmlMaxDepth | Should Be 32 + $result.EnableXsdValidation | Should Be $true + $result.EnableStackTrace | Should Be $false + $result.RequestUsageExecutionTimeThreshold | Should Be 800 + $result.EnableRequestUsage | Should Be $true + $result.LogActionsIfHasRequestException | Should Be $true + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + } + } + + Context -Name "Client callable settings does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + MaxResourcesPerRequest = 8 + MaxObjectPaths = 128 + ExecutionTimeout = 45 + RequestXmlMaxDepth = 16 + EnableXsdValidation = $false + EnableStackTrace = $true + RequestUsageExecutionTimeThreshold = 400 + EnableRequestUsage = $false + LogActionsIfHasRequestException = $false + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; + $webApp.ClientCallableSettings.MaxObjectPaths = 256; + $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; + $webApp.ClientCallableSettings.EnableXsdValidation = $true; + $webApp.ClientCallableSettings.EnableStackTrace = $false; + $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; + $webApp.ClientCallableSettings.EnableRequestUsage = $true; + $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return the current data from the get method" { + $result = Get-TargetResource @testParams + $result.Url | Should Be "http://sites.sharepoint.com" + $result.MaxResourcesPerRequest | Should Be 16 + $result.MaxObjectPaths | Should Be 256 + $result.ExecutionTimeout | Should Be 90 + $result.RequestXmlMaxDepth | Should Be 32 + $result.EnableXsdValidation | Should Be $true + $result.EnableStackTrace | Should Be $false + $result.RequestUsageExecutionTimeThreshold | Should Be 800 + $result.EnableRequestUsage | Should Be $true + $result.LogActionsIfHasRequestException | Should Be $true + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 + $Script:SPDscWebApplication.ClientCallableSettings.MaxResourcesPerRequest | Should Be 8 + $Script:SPDscWebApplication.ClientCallableSettings.MaxObjectPaths | Should Be 128 + $Script:SPDscWebApplication.ClientCallableSettings.ExecutionTimeout.TotalMinutes | Should Be 45 + $Script:SPDscWebApplication.ClientCallableSettings.RequestXmlMaxDepth | Should Be 16 + $Script:SPDscWebApplication.ClientCallableSettings.EnableXsdValidation | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.EnableStackTrace | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.RequestUsageExecutionTimeThreshold | Should Be 400 + $Script:SPDscWebApplication.ClientCallableSettings.EnableRequestUsage | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.LogActionsIfHasRequestException | Should Be $false + } + } + + Context -Name "A proxy library does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "A proxy library to include does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "NewAssembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "NewAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Multiple proxy libraries matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly1" + SupportAppAuthentication = $true + }), + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly2" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary1 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary1.AssemblyName = "Assembly1" + $testProxyLibrary1.SupportAppAuthentication = $true + $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary2.AssemblyName = "Assembly2" + $testProxyLibrary2.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary1) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly2" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "Assembly1" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries to include does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "NewAssembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "NewAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy library to include matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method, proxy libraries should not change" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "A proxy library to exclude does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary2.AssemblyName = "AnotherAssembly" + $testProxyLibrary2.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $false + } + } + + Context -Name "Proxy library to exclude matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "AnotherAssembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method, proxy libraries should not change" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries does not match the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "Empty proxy libraries matches the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @() + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Empty proxy libraries does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @() + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method and update proxy libraries" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 + } + } + + Context -Name "Proxy libraries to include does not match the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "Proxy libraries to exclude matches the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "ProxyLibraries and ProxyLibrariesToInclude properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "ProxyLibraries and ProxyLibrariesToExclude properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "All of the proxy libraries properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "The web appliation does not exist" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $null + } + + It "Should return a valid object with null on all properties" { + $result = Get-TargetResource @testParams + $result | Should Not BeNullOrEmpty + $result.Url | Should Be $null + $result.ProxyLibraries | Should Be $null + $result.ProxyLibrariesToInclude | Should Be $null + $result.ProxyLibrariesToExclude | Should Be $null + $result.MaxResourcesPerRequest | Should Be $null + $result.MaxObjectPaths | Should Be $null + $result.ExecutionTimeout | Should Be $null + $result.RequestXmlMaxDepth | Should Be $null + $result.EnableXsdValidation | Should Be $null + $result.EnableStackTrace | Should Be $null + $result.RequestUsageExecutionTimeThreshold | Should Be $null + $result.EnableRequestUsage | Should Be $null + $result.LogActionsIfHasRequestException | Should Be $null + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From fc70fd7e4dd2594906b1cc9744d2f1d0321d1233 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 25 Sep 2018 10:38:56 +0200 Subject: [PATCH 035/101] Added AdministrationSiteType property --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 49 ++++++++++++++++--- .../MSFT_SPSite/MSFT_SPSite.schema.mof | 1 + .../SPSite/3-AdministrationSiteType.ps1 | 27 ++++++++++ .../SharePointDsc.SPSite.Tests.ps1 | 18 +++++-- 4 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 6e30b2d56..307b315f6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -60,6 +60,11 @@ function Get-TargetResource [System.Boolean] $CreateDefaultGroups = $true, + [Parameter()] + [ValidateSet("TenantAdministration", "None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -164,6 +169,7 @@ function Get-TargetResource SecondaryOwnerAlias = $secondaryOwner Template = "$($site.RootWeb.WebTemplate)#$($site.RootWeb.Configuration)" CreateDefaultGroups = $CreateDefaultGroups + AdministrationSiteType = $site.AdministrationSiteType InstallAccount = $params.InstallAccount } } @@ -232,6 +238,11 @@ function Set-TargetResource [System.Boolean] $CreateDefaultGroups = $true, + [Parameter()] + [ValidateSet("TenantAdministration","None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -305,6 +316,14 @@ function Set-TargetResource } } + if ($params.ContainsKey("AdministrationSiteType") -eq $true) + { + if ($params.AdministrationSiteType -ne $CurrentValues.AdministrationSiteType) + { + $newParams.AdministrationSiteType = $params.AdministrationSiteType + } + } + if ($newParams.Count -gt 1) { Write-Verbose -Message "Updating existing site collection" @@ -392,6 +411,11 @@ function Test-TargetResource [System.Boolean] $CreateDefaultGroups = $true, + [Parameter()] + [ValidateSet("TenantAdministration","None")] + [System.String] + $AdministrationSiteType, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -409,12 +433,25 @@ function Test-TargetResource } } - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Url", - "QuotaTemplate", - "OwnerAlias", - "SecondaryOwnerAlias") + if ($null -eq $AdministrationSiteType) + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", + "QuotaTemplate", + "OwnerAlias", + "SecondaryOwnerAlias") + } + else + { + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", + "QuotaTemplate", + "OwnerAlias", + "SecondaryOwnerAlias", + "TenantAdministration") + } } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof index 92b43634c..b8dfc7f0d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.schema.mof @@ -15,6 +15,7 @@ class MSFT_SPSite : OMI_BaseResource [Write, Description("The secondary site collection admin username")] string SecondaryOwnerAlias; [Write, Description("The template to apply to the site collection")] string Template; [Write, Description("Create the default site groups in the site collection")] boolean CreateDefaultGroups; + [Write, Description("The administration site type"), ValueMap{"TenantAdministration","None"}, Values{"TenantAdministration","None"}] string AdministrationSiteType; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 new file mode 100644 index 000000000..5a51c60e0 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSite/3-AdministrationSiteType.ps1 @@ -0,0 +1,27 @@ +<# +.EXAMPLE + This example creates a site collection with the provided details +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSite TeamSite + { + Url = "http://sharepoint.contoso.com" + OwnerAlias = "CONTOSO\ExampleUser" + HostHeaderWebApplication = "http://spsites.contoso.com" + Name = "Team Sites" + Template = "STS#0" + AdministrationSiteType = "TenantAdministration" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index f8f5d04b5..4753c984b 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -85,10 +85,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Context -Name "The site exists, but has incorrect owner alias and quota" -Fixture { $testParams = @{ - Url = "http://site.sharepoint.com" - OwnerAlias = "DEMO\User" - SecondaryOwnerAlias = "DEMO\SecondUser" - QuotaTemplate = "Test" + Url = "http://site.sharepoint.com" + OwnerAlias = "DEMO\User" + SecondaryOwnerAlias = "DEMO\SecondUser" + QuotaTemplate = "Test" + AdministrationSiteType = "TenantAdministration" } Mock -CommandName Get-SPSite -MockWith { @@ -109,10 +110,16 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { QuotaId = 1 } RootWeb = $rootWeb + AdministrationSiteType = "None" } return $returnval } - Mock -CommandName Set-SPSite -MockWith {} + Mock -CommandName Set-SPSite -MockWith {} -ParameterFilter { + $OwnerAlias = "DEMO\User" + $SecondaryOwnerAlias = "DEMO\SecondUser" + $QuotaTemplate = "Test" + $AdministrationSiteType -eq "TenantAdministration" + } Mock -CommandName Get-SPDSCContentService -MockWith { $quotaTemplates = @(@{ QuotaId = 1 @@ -137,6 +144,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $result.OwnerAlias | Should Be "DEMO\owner" $result.SecondaryOwnerAlias | Should Be "DEMO\SecondOwner" $result.QuotaTemplate | Should Be "WrongTemplate" + $result.AdministrationSiteType | Should Be "None" } It "Should update owner and quota in the set method" { From 2ff01ad22cc3f3dce954530248a0328bfcf1deed Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 30 Sep 2018 21:19:12 +0200 Subject: [PATCH 036/101] Added resource for setting client callable settings and proxy libraries --- .../DSCResources/MSFT_SPSite/readme.md | 5 + .../MSFT_SPWebAppClientCallableSettings.psm1 | 628 ++++++++++++++ ..._SPWebAppClientCallableSettings.schema.mof | 24 + .../readme.md | 33 + .../1-Example.ps1 | 31 + .../2-Example.ps1 | 29 + ...c.SPWebAppClientCallableSettings.Tests.ps1 | 776 ++++++++++++++++++ 7 files changed, 1526 insertions(+) create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 create mode 100644 Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md index 7c4f31408..39cd0fbb6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/readme.md @@ -21,3 +21,8 @@ resource in the xWebAdministration module. NOTE2: The CreateDefaultGroups parameter is only used for creating default site groups. It will not remove or change the default groups if they already exist. + +NOTE3: +AdministrationSiteType is used in combination with the resource +SPWebAppClientCallableSettings. The required proxy library must be configured +before the administration site type has any effect. diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 new file mode 100644 index 000000000..b15ad7f74 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -0,0 +1,628 @@ +Set-StrictMode -Version 2 + +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting web application '$url' client callable settings" + + if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) + { + throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + "ProxyLibrariesToExclude parameters") + } + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters) ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + if ($null -eq $webApplication) + { + return @{ + Url = $null + ProxyLibraries = $null + ProxyLibrariesToInclude = $null + ProxyLibrariesToExclude = $null + MaxResourcesPerRequest = $null + MaxObjectPaths = $null + ExecutionTimeout = $null + RequestXmlMaxDepth = $null + EnableXsdValidation = $null + EnableStackTrace = $null + RequestUsageExecutionTimeThreshold = $null + EnableRequestUsage = $null + LogActionsIfHasRequestException = $null + } + } + + $proxyLibraries = @() + $clientCallableSettings = $webApplication.ClientCallableSettings + $clientCallableSettings.ProxyLibraries | ForEach-Object -Process { + $proxyLibraries += $_ + } + + if($params.ContainsKey("ProxyLibrariesToInclude")) + { + $include = $params.ProxyLibrariesToInclude + } + else + { + $include = $null; + } + + if($params.ContainsKey("ProxyLibrariesToExclude")) + { + $exclude = $params.ProxyLibrariesToExclude + } + else + { + $exclude = $null; + } + + return @{ + Url = $params.Url + ProxyLibraries = $clientCallableSettings.ProxyLibraries #$proxyLibraries + ProxyLibrariesToInclude = $include + ProxyLibrariesToExclude = $exclude + MaxResourcesPerRequest = $clientCallableSettings.MaxResourcesPerRequest + MaxObjectPaths = $clientCallableSettings.MaxObjectPaths + ExecutionTimeout = $clientCallableSettings.ExecutionTimeout.TotalMinutes + RequestXmlMaxDepth = $clientCallableSettings.RequestXmlMaxDepth + EnableXsdValidation = $clientCallableSettings.EnableXsdValidation + EnableStackTrace = $clientCallableSettings.EnableStackTrace + RequestUsageExecutionTimeThreshold = $clientCallableSettings.RequestUsageExecutionTimeThreshold + EnableRequestUsage = $clientCallableSettings.EnableRequestUsage + LogActionsIfHasRequestException = $clientCallableSettings.LogActionsIfHasRequestException + } + } + + return $result +} + + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting web application '$Url' client callable settings" + + if ($ProxyLibraries -and (($ProxyLibrariesToInclude) -or ($ProxyLibrariesToExclude))) + { + throw ("Cannot use the ProxyLibraries parameter together with the ProxyLibrariesToInclude or " + ` + "ProxyLibrariesToExclude parameters") + } + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters) ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + if ($null -eq $webApplication) + { + throw "Web application $($params.Url) was not found" + } + + $clientCallableSettings = $webApplication.ClientCallableSettings + $webApplicationNeedsUpdate = $false + + if ($params.ContainsKey("ProxyLibraries") -eq $true) + { + foreach($desiredProxyLibrary in $params.ProxyLibraries) + { + if ($clientCallableSettings.ProxyLibraries.AssemblyName -contains $desiredProxyLibrary.AssemblyName) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $desiredProxyLibrary.AssemblyName + } | Select-Object -First 1 + + if ($existingProxyLibrary.SupportAppAuthentication -ne $desiredProxyLibrary.SupportAppAuthentication) + { + $existingProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $webApplicationNeedsUpdate = $true + } + } + else + { + $newProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $newProxyLibrary.AssemblyName = $desiredProxyLibrary.AssemblyName + $newProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $clientCallableSettings.ProxyLibraries.Add($newProxyLibrary); + $webApplicationNeedsUpdate = $true + } + } + + $proxyLibrariesToRemove = {}.Invoke() + foreach($currentProxyLibrary in $clientCallableSettings.ProxyLibraries) + { + if ($params.ProxyLibraries.Count -eq 0 -or (-not ($params.ProxyLibraries.AssemblyName -contains $currentProxyLibrary.AssemblyName))) + { + $proxyLibrariesToRemove.Add($currentProxyLibrary); + } + } + + foreach($proxyLibraryToRemove in $proxyLibrariesToRemove) + { + $clientCallableSettings.ProxyLibraries.Remove($proxyLibraryToRemove) + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("ProxyLibrariesToInclude") -eq $true -and $params.ProxyLibrariesToInclude.Count -gt 0) + { + foreach($desiredProxyLibrary in $params.ProxyLibrariesToInclude) + { + if ($clientCallableSettings.ProxyLibraries.AssemblyName -contains $desiredProxyLibrary.AssemblyName) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $desiredProxyLibrary.AssemblyName + } | Select-Object -First 1 + + if ( $existingProxyLibrary.SupportAppAuthentication -ne $desiredProxyLibrary.SupportAppAuthentication) + { + $existingProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $webApplicationNeedsUpdate = $true + } + } + else + { + $newProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $newProxyLibrary.AssemblyName = $desiredProxyLibrary.AssemblyName + $newProxyLibrary.SupportAppAuthentication = $desiredProxyLibrary.SupportAppAuthentication + $clientCallableSettings.ProxyLibraries.Add($newProxyLibrary); + $webApplicationNeedsUpdate = $true + } + } + } + + if ($params.ContainsKey("ProxyLibrariesToExclude") -eq $true) + { + foreach($excludeProxyLibrary in $params.ProxyLibrariesToExclude) + { + $existingProxyLibrary = $clientCallableSettings.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $excludeProxyLibrary + } | Select-Object -First 1 + if($null -ne $existingProxyLibrary) + { + $clientCallableSettings.ProxyLibraries.Remove($existingProxyLibrary) + $webApplicationNeedsUpdate = $true + } + } + } + + if ($params.ContainsKey("MaxObjectPaths") -eq $true) + { + if ($params.MaxObjectPaths -ne $clientCallableSettings.MaxObjectPaths) + { + $clientCallableSettings.MaxObjectPaths = $params.MaxObjectPaths + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("MaxResourcesPerRequest") -eq $true) + { + if ($params.MaxResourcesPerRequest -ne $clientCallableSettings.MaxResourcesPerRequest) + { + $clientCallableSettings.MaxResourcesPerRequest = $params.MaxResourcesPerRequest + $webApplicationNeedsUpdate = $true + } + } + + + if ($params.ContainsKey("ExecutionTimeout") -eq $true) + { + if ($params.ExecutionTimeout -ne $clientCallableSettings.ExecutionTimeout.TotalMinutes) + { + $clientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes($params.ExecutionTimeout) + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("RequestXmlMaxDepth") -eq $true) + { + if ($params.RequestXmlMaxDepth -ne $clientCallableSettings.RequestXmlMaxDepth) + { + $clientCallableSettings.RequestXmlMaxDepth = $params.RequestXmlMaxDepth + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableXsdValidation") -eq $true) + { + if ($params.EnableXsdValidation -ne $clientCallableSettings.EnableXsdValidation) + { + $clientCallableSettings.EnableXsdValidation = $params.EnableXsdValidation + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableStackTrace") -eq $true) + { + if ($params.EnableStackTrace -ne $clientCallableSettings.EnableStackTrace) + { + $clientCallableSettings.EnableStackTrace = $params.EnableStackTrace + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("RequestUsageExecutionTimeThreshold") -eq $true) + { + if ($params.RequestUsageExecutionTimeThreshold -ne $clientCallableSettings.RequestUsageExecutionTimeThreshold) + { + $clientCallableSettings.RequestUsageExecutionTimeThreshold = $params.RequestUsageExecutionTimeThreshold + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("EnableRequestUsage") -eq $true) + { + if ($params.EnableRequestUsage -ne $clientCallableSettings.EnableRequestUsage) + { + $clientCallableSettings.EnableRequestUsage = $params.EnableRequestUsage + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("LogActionsIfHasRequestException") -eq $true) + { + if ($params.LogActionsIfHasRequestException -ne $clientCallableSettings.LogActionsIfHasRequestException) + { + $clientCallableSettings.LogActionsIfHasRequestException = $params.LogActionsIfHasRequestException + $webApplicationNeedsUpdate = $true + } + } + + if ($webApplicationNeedsUpdate -eq $true) + { + Write-Verbose -Message "Updating web application" + $webApplication.Update() + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibraries, + + [Parameter()] + [Microsoft.Management.Infrastructure.CimInstance[]] + $ProxyLibrariesToInclude, + + [Parameter()] + [System.String[]] + $ProxyLibrariesToExclude, + + [Parameter()] + [System.UInt32] + $MaxResourcesPerRequest, + + [Parameter()] + [System.UInt32] + $MaxObjectPaths, + + [Parameter()] + [System.UInt32] + $ExecutionTimeout, + + [Parameter()] + [System.UInt32] + $RequestXmlMaxDepth, + + [Parameter()] + [Boolean] + $EnableXsdValidation, + + [Parameter()] + [Boolean] + $EnableStackTrace, + + [Parameter()] + [System.UInt32] + $RequestUsageExecutionTimeThreshold, + + [Parameter()] + [Boolean] + $EnableRequestUsage, + + [Parameter()] + [Boolean] + $LogActionsIfHasRequestException, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing for web application '$Url' client callable settings" + + $currentValues = Get-TargetResource @PSBoundParameters + + if ($null -eq $currentValues.ProxyLibraries) + { + Write-Verbose -Message "Proxy library list does not have a valid value" + return $false + } + + if ($null -ne $ProxyLibraries) + { + Write-Verbose -Message "Processing ProxyLibraries parameter" + + if ($currentValues.ProxyLibraries.Count -eq 0) + { + if ($ProxyLibraries.Count -gt 0) + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + } + else + { + if ($ProxyLibraries.Count -eq 0) + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + + $differences = Compare-Object -ReferenceObject $currentValues.ProxyLibraries.AssemblyName ` + -DifferenceObject $ProxyLibraries.AssemblyName + + if ($null -eq $differences) + { + Write-Verbose -Message "Proxy library list matches - checking that SupportAppAuthentication match on each object" + foreach($currentProxyLibrary in $currentValues.ProxyLibraries) + { + if ($currentProxyLibrary.SupportAppAuthentication -ne ($ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $currentProxyLibrary.AssemblyName + } | Select-Object -First 1).SupportAppAuthentication) + { + Write-Verbose -Message "$($currentProxyLibrary.AssemblyName) has incorrect SupportAppAuthentication. Test failed." + return $false + } + } + } + else + { + Write-Verbose -Message "Proxy library list does not match" + return $false + } + } + } + + if ($ProxyLibrariesToInclude) + { + Write-Verbose -Message "Processing ProxyLibrariesToInclude parameter" + + if ($currentValues.ProxyLibraries.Count -eq 0) + { + if ($ProxyLibrariesToInclude.Count -gt 0) + { + Write-Verbose -Message "Proxy library list to include does not match" + return $false + } + } + + Write-Verbose -Message "Processing ProxyLibrariesToInclude parameter" + foreach ($proxyLibrary in $ProxyLibrariesToInclude) + { + if (-not($currentValues.ProxyLibraries.AssemblyName -contains $proxyLibrary.AssemblyName)) + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) is not registered as a proxy library. Set result to false" + return $false + } + else + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) is already registered as a proxy library. Checking SupportAppAuthentication..." + if ($proxyLibrary.SupportAppAuthentication -ne ($currentValues.ProxyLibraries | Where-Object -FilterScript { + $_.AssemblyName -eq $proxyLibrary.AssemblyName + } | Select-Object -First 1).SupportAppAuthentication) + { + Write-Verbose -Message "$($proxyLibrary.AssemblyName) has incorrect SupportAppAuthentication. Test failed." + return $false + } + } + } + } + + if ($ProxyLibrariesToExclude) + { + Write-Verbose -Message "Processing ProxyLibrariesToExclude parameter" + + if ($currentValues.ProxyLibraries.Count -gt 0) + { + foreach ($proxyLibrary in $ProxyLibrariesToExclude) + { + if ($currentValues.ProxyLibraries.AssemblyName -contains $proxyLibrary) + { + Write-Verbose -Message "$proxyLibrary is already registered as proxy library. Set result to false" + return $false + } + else + { + Write-Verbose -Message "$proxyLibrary is not registered as proxy library. Skipping" + } + } + } + } + + $valuesToCheck = {"Url"}.Invoke() + + if($PSBoundParameters.ContainsKey("MaxResourcesPerRequest") -eq $true) + { + $valuesToCheck.Add("MaxResourcesPerRequest") + } + + if($PSBoundParameters.ContainsKey("MaxObjectPaths") -eq $true) + { + $valuesToCheck.Add("MaxObjectPaths") + } + + if($PSBoundParameters.ContainsKey("ExecutionTimeout") -eq $true) + { + $valuesToCheck.Add("ExecutionTimeout") + } + + if($PSBoundParameters.ContainsKey("RequestXmlMaxDepth") -eq $true) + { + $valuesToCheck.Add("RequestXmlMaxDepth") + } + + if($PSBoundParameters.ContainsKey("EnableXsdValidation") -eq $true) + { + $valuesToCheck.Add("EnableXsdValidation") + } + + if($PSBoundParameters.ContainsKey("EnableStackTrace") -eq $true) + { + $valuesToCheck.Add("EnableStackTrace") + } + + if($PSBoundParameters.ContainsKey("RequestUsageExecutionTimeThreshold") -eq $true) + { + $valuesToCheck.Add("RequestUsageExecutionTimeThreshold") + } + + if($PSBoundParameters.ContainsKey("EnableRequestUsage") -eq $true) + { + $valuesToCheck.Add("EnableRequestUsage") + } + + if($PSBoundParameters.ContainsKey("LogActionsIfHasRequestException") -eq $true) + { + $valuesToCheck.Add("LogActionsIfHasRequestException") + } + + return Test-SPDscParameterState -CurrentValues $currentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck $valuesToCheck +} + +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof new file mode 100644 index 000000000..b456130b4 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.schema.mof @@ -0,0 +1,24 @@ +[ClassVersion("1.0.0.0")] +Class MSFT_SPProxyLibraryEntry +{ + [Required, Description("Name of the account")] String AssemblyName; + [Write, Description("Permission level of the account")] Boolean SupportAppAuthentication; +}; +[ClassVersion("1.0.0"), FriendlyName("SPWebAppClientCallableSettings")] +class MSFT_SPWebAppClientCallableSettings : OMI_BaseResource +{ + [Key, Description("The URL of the web application to set blocked file types for")] string Url; + [write, Description("A list of proxy libraries to set. Those not in this list will be removed"), EmbeddedInstance("MSFT_SPProxyLibraryEntry")] string ProxyLibraries[]; + [write, Description("A list of proxy libraries to add. Proxy libraries not in this list will be kept"), EmbeddedInstance("MSFT_SPProxyLibraryEntry")] string ProxyLibrariesToInclude[]; + [write, Description("A list of proxy libraries to remove. Proxy libraries not in this list will be kept")] string ProxyLibrariesToExclude[]; + [write, Description("Sets the maximum number of internal SPRequest objects that can be included in one request")] UInt32 MaxResourcesPerRequest; + [write, Description("Sets the maximum number of object paths that can be used within one request")] UInt32 MaxObjectPaths; + [write, Description("Sets the execution timeout for the client request in minutes")] UInt32 ExecutionTimeout; + [write, Description("Sets the maximum depth of the request XML that is sent by the client measured in 'tag' count")] UInt32 RequestXmlMaxDepth; + [write, Description("Sets a Boolean value that specifies whether to enable XSD validation against an XML request or not")] Boolean EnableXsdValidation; + [write, Description("Sets a Boolean value that specifies whether the server can send stack trace data to the client")] Boolean EnableStackTrace; + [write, Description("Sets the threshold in milliseconds for logging csom request usage data ")] UInt32 RequestUsageExecutionTimeThreshold; + [write, Description("Sets a Boolean value that specifies whether to log usage data or not")] Boolean EnableRequestUsage; + [write, Description("Sets a Boolean value that specifies whether to log usage data when request has an exception or not")] Boolean LogActionsIfHasRequestException; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] string InstallAccount; +}; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md new file mode 100644 index 000000000..699110b82 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md @@ -0,0 +1,33 @@ +# Description + +**Type:** Distributed + +This resource sets the client callable settings for the web application. +It can set the proxy libraries and specific properties for the client +callable settings. +The resource can for example be used to increase the timeout for client +code, and to enable the tenant administration functionality. + +Tenant administration functionality enables client code to work with +the namespace Microsoft.Online.SharePoint.Client.Tenant from the +assembly with the same name. This enables client code to create site +collection, list all site collections, and more. + +In order to use the tenant administration client code a site collection +within the web application needs to be designated as a tenant +administration site collection. This can be done using the SPSite +resource setting the AdministrationSiteType to TenantAdministration. +Use this site collection when creating a client side connection. + +NOTE: +Proxy library used for enabling tenant administration: + +**SharePoint 2013** (Requires mininum April 2014 Cumulative Update): +Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub +, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + +**SharePoint 2016**: +Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub +, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + +In both version set the SupportAppAuthentication property to true. diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 new file mode 100644 index 000000000..c619eefff --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 @@ -0,0 +1,31 @@ +<# +.EXAMPLE + This example shows how to set the client callable settings for a web application +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPWebAppClientCallableSettings DefaultClientCallableSettings + { + Url = "http://example.contoso.local" + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = 90 + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 new file mode 100644 index 000000000..f8ac1d81f --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to enable tenant administration for a web application in a SharePoint 2013 farm +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + $proxyLibraries = @() + $proxyLibraries += MSFT_SPProxyLibraryEntry { + AssemblyName = "Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" + SupportAppAuthentication = $true + } + + SPWebAppClientCallableSettings TenantAdministration + { + Url = "http://example.contoso.local" + ProxyLibraries = $proxyLibraries + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 new file mode 100644 index 000000000..e4702e7be --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppClientCallableSettings.Tests.ps1 @@ -0,0 +1,776 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPWebAppClientCallableSettings" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Initialize tests + try + { + [Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public class SPClientCallableProxyLibrary { + public SPClientCallableProxyLibrary() + { + } + public string AssemblyName { get; set; } + public bool SupportAppAuthentication { get; set; } + } +} +"@ + } + + # Mocks for all contexts + + $webAppImplementation = { + $clientCallableSettings = [PSCustomObject] @{ + ProxyLibraries = [System.Collections.ObjectModel.Collection[Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary]]@() + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + } + + $webApp = @{ + ClientCallableSettings = $clientCallableSettings + UpdateCalled = $false + } + + $webApp | Add-Member -MemberType ScriptMethod -Name Update -Value { + $this.UpdateCalled = $true + } + return $webApp + } + + # Test contexts + Context -Name "Client callable settings and a specific proxy library list matches current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = 90 + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary); + $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; + $webApp.ClientCallableSettings.MaxObjectPaths = 256; + $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; + $webApp.ClientCallableSettings.EnableXsdValidation = $true; + $webApp.ClientCallableSettings.EnableStackTrace = $false; + $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; + $webApp.ClientCallableSettings.EnableRequestUsage = $true; + $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return the current data from the get method" { + $result = Get-TargetResource @testParams + $result.Url | Should Be "http://sites.sharepoint.com" + $result.MaxResourcesPerRequest | Should Be 16 + $result.MaxObjectPaths | Should Be 256 + $result.ExecutionTimeout | Should Be 90 + $result.RequestXmlMaxDepth | Should Be 32 + $result.EnableXsdValidation | Should Be $true + $result.EnableStackTrace | Should Be $false + $result.RequestUsageExecutionTimeThreshold | Should Be 800 + $result.EnableRequestUsage | Should Be $true + $result.LogActionsIfHasRequestException | Should Be $true + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + } + } + + Context -Name "Client callable settings does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + MaxResourcesPerRequest = 8 + MaxObjectPaths = 128 + ExecutionTimeout = 45 + RequestXmlMaxDepth = 16 + EnableXsdValidation = $false + EnableStackTrace = $true + RequestUsageExecutionTimeThreshold = 400 + EnableRequestUsage = $false + LogActionsIfHasRequestException = $false + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; + $webApp.ClientCallableSettings.MaxObjectPaths = 256; + $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); + $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; + $webApp.ClientCallableSettings.EnableXsdValidation = $true; + $webApp.ClientCallableSettings.EnableStackTrace = $false; + $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; + $webApp.ClientCallableSettings.EnableRequestUsage = $true; + $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return the current data from the get method" { + $result = Get-TargetResource @testParams + $result.Url | Should Be "http://sites.sharepoint.com" + $result.MaxResourcesPerRequest | Should Be 16 + $result.MaxObjectPaths | Should Be 256 + $result.ExecutionTimeout | Should Be 90 + $result.RequestXmlMaxDepth | Should Be 32 + $result.EnableXsdValidation | Should Be $true + $result.EnableStackTrace | Should Be $false + $result.RequestUsageExecutionTimeThreshold | Should Be 800 + $result.EnableRequestUsage | Should Be $true + $result.LogActionsIfHasRequestException | Should Be $true + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 + $Script:SPDscWebApplication.ClientCallableSettings.MaxResourcesPerRequest | Should Be 8 + $Script:SPDscWebApplication.ClientCallableSettings.MaxObjectPaths | Should Be 128 + $Script:SPDscWebApplication.ClientCallableSettings.ExecutionTimeout.TotalMinutes | Should Be 45 + $Script:SPDscWebApplication.ClientCallableSettings.RequestXmlMaxDepth | Should Be 16 + $Script:SPDscWebApplication.ClientCallableSettings.EnableXsdValidation | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.EnableStackTrace | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.RequestUsageExecutionTimeThreshold | Should Be 400 + $Script:SPDscWebApplication.ClientCallableSettings.EnableRequestUsage | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.LogActionsIfHasRequestException | Should Be $false + } + } + + Context -Name "A proxy library does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "A proxy library to include does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "NewAssembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "NewAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Multiple proxy libraries matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly1" + SupportAppAuthentication = $true + }), + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly2" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary1 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary1.AssemblyName = "Assembly1" + $testProxyLibrary1.SupportAppAuthentication = $true + $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary2.AssemblyName = "Assembly2" + $testProxyLibrary2.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary1) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly2" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "Assembly1" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries to include does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "NewAssembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "NewAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy library to include matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method, proxy libraries should not change" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "A proxy library to exclude does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $false + + $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary2.AssemblyName = "AnotherAssembly" + $testProxyLibrary2.SupportAppAuthentication = $false + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method, and set expected values" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $false + } + } + + Context -Name "Proxy library to exclude matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "AnotherAssembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method, proxy libraries should not change" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true + } + } + + Context -Name "Proxy libraries does not match the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "Empty proxy libraries matches the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @() + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "Empty proxy libraries does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @() + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary + $testProxyLibrary.AssemblyName = "Assembly" + $testProxyLibrary.SupportAppAuthentication = $true + + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method and update proxy libraries" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 + } + } + + Context -Name "Proxy libraries to include does not match the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "Proxy libraries to exclude matches the current state of empty proxy libraries" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + $webApp = $webAppImplementation.Invoke() + $webApp.ClientCallableSettings.ProxyLibraries.Clear(); + return $webApp + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "ProxyLibraries and ProxyLibrariesToInclude properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "ProxyLibraries and ProxyLibrariesToExclude properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "All of the proxy libraries properties are provided" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + ProxyLibraries = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToInclude = @( + (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` + -ClientOnly ` + -Property @{ + AssemblyName = "Assembly" + SupportAppAuthentication = $true + }) + ) + ProxyLibrariesToExclude = @("Assembly") + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $webAppImplementation.Invoke() + } + + It "Should throw an exception from the get method" { + { Get-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the test method" { + { Test-TargetResource @testParams } | Should Throw + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + + Context -Name "The web appliation does not exist" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + } + + Mock -CommandName Get-SPWebapplication -MockWith { + return $null + } + + It "Should return a valid object with null on all properties" { + $result = Get-TargetResource @testParams + $result | Should Not BeNullOrEmpty + $result.Url | Should Be $null + $result.ProxyLibraries | Should Be $null + $result.ProxyLibrariesToInclude | Should Be $null + $result.ProxyLibrariesToExclude | Should Be $null + $result.MaxResourcesPerRequest | Should Be $null + $result.MaxObjectPaths | Should Be $null + $result.ExecutionTimeout | Should Be $null + $result.RequestXmlMaxDepth | Should Be $null + $result.EnableXsdValidation | Should Be $null + $result.EnableStackTrace | Should Be $null + $result.RequestUsageExecutionTimeThreshold | Should Be $null + $result.EnableRequestUsage | Should Be $null + $result.LogActionsIfHasRequestException | Should Be $null + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From 7277c499e3ed6d8d4fdb549b046ec47774a23e10 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 2 Oct 2018 09:19:24 +0200 Subject: [PATCH 037/101] Added information about IISReswet requirement. Added links to blog posts explaining tenant administration in details --- .../MSFT_SPWebAppClientCallableSettings/readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md index 699110b82..0f3394f07 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/readme.md @@ -19,6 +19,14 @@ administration site collection. This can be done using the SPSite resource setting the AdministrationSiteType to TenantAdministration. Use this site collection when creating a client side connection. +More information about the tenant can be found in a [blog +post] +(https://blogs.msdn.microsoft.com/vesku/2015/12/04/sharepoint-tenant-csom-object-support-in-sharepoint-2013-and-2016/) +by Vesa Juvonen. In another [blog post] +(https://blogs.msdn.microsoft.com/vesku/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom/) +he goes into more details of +the setup and architecture, and includes sample code for how to use. + NOTE: Proxy library used for enabling tenant administration: @@ -31,3 +39,7 @@ Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub , Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c In both version set the SupportAppAuthentication property to true. + +NOTE2: +An IIS reset needs to be performed on all servers in the farm after +modifying the registered proxy libraries. From c862f7a334f2e07c40d52f77d18f7903689daf5a Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 2 Oct 2018 12:42:33 +0200 Subject: [PATCH 038/101] Renamed example files --- .../{1-Example.ps1 => 1-SetClientCallableSettings.ps1} | 0 .../{2-Example.ps1 => 2-EnableTenantAdministration.ps1} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/{1-Example.ps1 => 1-SetClientCallableSettings.ps1} (100%) rename Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/{2-Example.ps1 => 2-EnableTenantAdministration.ps1} (100%) diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-SetClientCallableSettings.ps1 similarity index 100% rename from Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-Example.ps1 rename to Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/1-SetClientCallableSettings.ps1 diff --git a/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 b/Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-EnableTenantAdministration.ps1 similarity index 100% rename from Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-Example.ps1 rename to Modules/SharePointDsc/Examples/Resources/SPWebAppClientCallableSettings/2-EnableTenantAdministration.ps1 From 31547dae448f33e1e73119a3ef7e36b68b4cc93a Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 2 Oct 2018 12:43:22 +0200 Subject: [PATCH 039/101] Removed unnecessary check in test resource --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 307b315f6..897bb0c1f 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -433,25 +433,13 @@ function Test-TargetResource } } - if ($null -eq $AdministrationSiteType) - { - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Url", - "QuotaTemplate", - "OwnerAlias", - "SecondaryOwnerAlias") - } - else - { - return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Url", - "QuotaTemplate", - "OwnerAlias", - "SecondaryOwnerAlias", - "TenantAdministration") - } + return Test-SPDscParameterState -CurrentValues $CurrentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", + "QuotaTemplate", + "OwnerAlias", + "SecondaryOwnerAlias", + "TenantAdministration") } Export-ModuleMember -Function *-TargetResource From f9d4a37edb38975105f9575d68fa13ea2d1e5623 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 2 Oct 2018 12:53:35 +0200 Subject: [PATCH 040/101] Removed unnecessary checks in the test method. Changed collection creation to be more explicit. adde verbose message when web app is not found. --- .../MSFT_SPWebAppClientCallableSettings.psm1 | 65 ++++--------------- 1 file changed, 14 insertions(+), 51 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 index b15ad7f74..65db2dbac 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -79,6 +79,7 @@ function Get-TargetResource $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue if ($null -eq $webApplication) { + Write-Verbose "Web application $($params.Url) was not found" return @{ Url = $null ProxyLibraries = $null @@ -212,8 +213,8 @@ function Set-TargetResource } Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters) ` - -ScriptBlock { + -Arguments @($PSBoundParameters) ` + -ScriptBlock { $params = $args[0] $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue @@ -251,7 +252,7 @@ function Set-TargetResource } } - $proxyLibrariesToRemove = {}.Invoke() + [System.Collections.ObjectModel.Collection[System.Object]]$proxyLibrariesToRemove = @{} foreach($currentProxyLibrary in $clientCallableSettings.ProxyLibraries) { if ($params.ProxyLibraries.Count -eq 0 -or (-not ($params.ProxyLibraries.AssemblyName -contains $currentProxyLibrary.AssemblyName))) @@ -573,56 +574,18 @@ function Test-TargetResource } } - $valuesToCheck = {"Url"}.Invoke() - - if($PSBoundParameters.ContainsKey("MaxResourcesPerRequest") -eq $true) - { - $valuesToCheck.Add("MaxResourcesPerRequest") - } - - if($PSBoundParameters.ContainsKey("MaxObjectPaths") -eq $true) - { - $valuesToCheck.Add("MaxObjectPaths") - } - - if($PSBoundParameters.ContainsKey("ExecutionTimeout") -eq $true) - { - $valuesToCheck.Add("ExecutionTimeout") - } - - if($PSBoundParameters.ContainsKey("RequestXmlMaxDepth") -eq $true) - { - $valuesToCheck.Add("RequestXmlMaxDepth") - } - - if($PSBoundParameters.ContainsKey("EnableXsdValidation") -eq $true) - { - $valuesToCheck.Add("EnableXsdValidation") - } - - if($PSBoundParameters.ContainsKey("EnableStackTrace") -eq $true) - { - $valuesToCheck.Add("EnableStackTrace") - } - - if($PSBoundParameters.ContainsKey("RequestUsageExecutionTimeThreshold") -eq $true) - { - $valuesToCheck.Add("RequestUsageExecutionTimeThreshold") - } - - if($PSBoundParameters.ContainsKey("EnableRequestUsage") -eq $true) - { - $valuesToCheck.Add("EnableRequestUsage") - } - - if($PSBoundParameters.ContainsKey("LogActionsIfHasRequestException") -eq $true) - { - $valuesToCheck.Add("LogActionsIfHasRequestException") - } - return Test-SPDscParameterState -CurrentValues $currentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck $valuesToCheck + -ValuesToCheck @("Url", + "MaxResourcesPerRequest", + "MaxObjectPaths", + "ExecutionTimeout", + "RequestXmlMaxDepth", + "EnableXsdValidation", + "EnableStackTrace", + "RequestUsageExecutionTimeThreshold", + "LogActionsIfHasRequestException", + "EnableRequestUsage") } Export-ModuleMember -Function *-TargetResource From 32f6f9cb7923d4fcb05a24934851155f3a0a0d03 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Tue, 2 Oct 2018 12:54:38 +0200 Subject: [PATCH 041/101] Removed unnecessary check for empty proxy library to include parameter --- .../MSFT_SPWebAppClientCallableSettings.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 index 65db2dbac..93b6834ea 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -268,7 +268,7 @@ function Set-TargetResource } } - if ($params.ContainsKey("ProxyLibrariesToInclude") -eq $true -and $params.ProxyLibrariesToInclude.Count -gt 0) + if ($params.ContainsKey("ProxyLibrariesToInclude") -eq $true) { foreach($desiredProxyLibrary in $params.ProxyLibrariesToInclude) { From 938b2db2babbb6d63207d8df7fefeff17144f779 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Wed, 3 Oct 2018 13:22:07 +0200 Subject: [PATCH 042/101] Removed Set-StrictMode --- .../MSFT_SPWebAppClientCallableSettings.psm1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 index 93b6834ea..3f0c0e26b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppClientCallableSettings/MSFT_SPWebAppClientCallableSettings.psm1 @@ -1,5 +1,3 @@ -Set-StrictMode -Version 2 - function Get-TargetResource { [CmdletBinding()] From dc5b780fba58f5d9d828f8f38603ee4d54f339a0 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Mon, 1 Oct 2018 11:08:37 +0200 Subject: [PATCH 043/101] Enabled usage of SuiteBarBrandingElementHtml in SharePoiont 2016 --- CHANGELOG.md | 6 ++++ .../MSFT_SPWebAppSuiteBar.psm1 | 31 ++++++++++--------- .../MSFT_SPWebAppSuiteBar.schema.mof | 2 +- .../MSFT_SPWebAppSuiteBar/readme.md | 7 ++--- .../SharePointDsc.SPWebAppSuiteBar.Tests.ps1 | 29 +++++++++++++++-- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f59878768..f346e22a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,9 +25,15 @@ * Fixed issues that prevented the resource to work as expected in many situations. * SPWebAppPropertyBag * New resource to manage web application property bag +<<<<<<< HEAD * SPWebAppClientCallableSettings * New resource to manage web application client callable settings including proxy libraries. +======= +* SPWebAppSuiteBar + * Enable usage of SuiteBarBrandingElementHtml for SharePoint 2016 + (only supported if using a SharePoint 2013 masterpage) +>>>>>>> Enabled usage of SuiteBarBrandingElementHtml in SharePoiont 2016 ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 index 79a92b51c..2f838bb23 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 @@ -44,7 +44,7 @@ function Get-TargetResource -ErrorAction SilentlyContinue $returnval = @{ - WebAppUrl = $wa.Url + WebAppUrl = $null SuiteNavBrandingLogoNavigationUrl = $null SuiteNavBrandingLogoTitle = $null SuiteNavBrandingLogoUrl = $null @@ -57,13 +57,16 @@ function Get-TargetResource return $returnval } + $returnval.WebAppUrl = $wa.Url + $installedVersion = Get-SPDSCInstalledProductVersion - if($installedVersion.FileMajorPart -eq 15) + if($installedVersion.FileMajorPart -ge 15) { $returnval.SuiteBarBrandingElementHtml = $wa.SuiteBarBrandingElementHtml } - elseif($installedVersion.FileMajorPart -ge 16) + + if($installedVersion.FileMajorPart -ge 16) { $returnval.SuiteNavBrandingLogoNavigationUrl = $wa.SuiteNavBrandingLogoNavigationUrl $returnval.SuiteNavBrandingLogoTitle = $wa.SuiteNavBrandingLogoTitle @@ -139,23 +142,22 @@ function Set-TargetResource } 16 { - <# Exception: The SP2013 specific SuiteBarBrandingElementHtml parameter was passed with SP2016. #> if($PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { - throw ("Cannot specify SuiteBarBrandingElementHtml with SharePoint 2016. Instead," + ` - " use the SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, " + ` - "SuiteNavBrandingLogoUrl and SuiteNavBrandingText parameters") + Write-Verbose "SuiteBarBrandingElementHtml with SharePoint 2016 only works if using a " + ` + "SharePoint 2016 masterpage" } <# Exception: All the optional parameters are null for SP2016. #> if(!$PSBoundParameters.ContainsKey("SuiteNavBrandingLogoNavigationUrl") ` -and !$PSBoundParameters.ContainsKey("SuiteNavBrandingLogoTitle") ` -and !$PSBoundParameters.ContainsKey("SuiteNavBrandingLogoUrl") ` - -and !$PSBoundParameters.ContainsKey("SuiteNavBrandingText")) + -and !$PSBoundParameters.ContainsKey("SuiteNavBrandingText") ` + -and !$PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { - throw ("You need to specify a value for either SuiteNavBrandingLogoNavigationUrl" + ` - ", SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl and SuiteNavBrandingText " + ` - "with SharePoint 2016") + throw ("You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, " + ` + "SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl, SuiteNavBrandingTextm, " + ` + "and SuiteBarBrandingElementHtml with SharePoint 2016") } } } @@ -184,11 +186,12 @@ function Set-TargetResource Write-Verbose -Message "Processing changes" - if($installedVersion.FileMajorPart -eq 15) + if($installedVersion.FileMajorPart -ge 15) { $wa.SuiteBarBrandingElementHtml = $params.SuiteBarBrandingElementHtml } - elseif($installedVersion.FileMajorPart -ge 16) + + if($installedVersion.FileMajorPart -ge 16) { $wa.SuiteNavBrandingLogoNavigationUrl = $params.SuiteNavBrandingLogoNavigationUrl $wa.SuiteNavBrandingLogoTitle = $params.SuiteNavBrandingLogoTitle @@ -255,7 +258,7 @@ function Test-TargetResource { return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("SuiteNavBrandingLogoNavigationUrl", "SuiteNavBrandingLogoTitle", "SuiteNavBrandingLogoUrl", "SuiteNavBrandingText") + -ValuesToCheck @("SuiteBarBrandingElementHtml", "SuiteNavBrandingLogoNavigationUrl", "SuiteNavBrandingLogoTitle", "SuiteNavBrandingLogoUrl", "SuiteNavBrandingText") } } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.schema.mof index 762e63bb2..724114cff 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.schema.mof @@ -6,6 +6,6 @@ class MSFT_SPWebAppSuiteBar : OMI_BaseResource [Write, Description("SP2016+: Alternative text for the Suite Bar Logo")] String SuiteNavBrandingLogoTitle; [Write, Description("SP2016+: URL of the logo for the Suite Bar")] String SuiteNavBrandingLogoUrl; [Write, Description("SP2016+: Text to display at the left hand side of the suite bar")] String SuiteNavBrandingText; - [Write, Description("SP2013: HTML to inject in the left hand-side of the Suite Bar")] String SuiteBarBrandingElementHtml; + [Write, Description("SP2013+: HTML to inject in the left hand-side of the Suite Bar")] String SuiteBarBrandingElementHtml; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/readme.md index 8d926aa3b..24bf443b8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/readme.md @@ -8,7 +8,6 @@ applications. It supports both the SharePoint 2013 and SharePoint Requirements: For SharePoint 2013, only the SuiteBarBrandingElementHtml -should be specified, whereas for SharePoint 2016, only one -or all of SuiteNavBrandingLogoNavigationUrl, -SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl or -SuiteNavBrandingText should be. +should be specified, whereas for SharePoint 2016, all properties +are supported. Note that SuiteBarBrandingElementHtml has no +effect unless using a SharePoint 2013 master page. diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 index 084ca8992..a80a392da 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 @@ -23,6 +23,29 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { # Mocks for all contexts # Test contexts + + Context -Name "Web application does not exist" -Fixture { + $testParams = @{ + WebAppUrl = "http://sites.sharepoint.com" + SuiteBarBrandingElementHtml = "
Test
" + } + + Mock -CommandName Get-SPWebApplication -MockWith { + return $null + } + + It "Get target resource returns null value" { + $returnValue = Get-TargetResource @testParams + $returnValue | Should Not Be $null + $returnValue.WebAppUrl | Should Be $null + $returnValue.SuiteNavBrandingLogoNavigationUrl | Should Be $null + $returnValue.SuiteNavBrandingLogoTitle | Should Be $null + $returnValue.SuiteNavBrandingLogoUrl | Should Be $null + $returnValue.SuiteNavBrandingText | Should Be $null + $returnValue.SuiteBarBrandingElementHtml | Should Be $null + } + } + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) { Context -Name "Only all SP2016 parameters passed for a SP2013 environment" -Fixture { @@ -141,6 +164,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { SuiteNavBrandingLogoTitle = "LogoTitle" SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" SuiteNavBrandingText = "Suite Bar Text" + SuiteBarBrandingElementHtml = "
Test
" } Mock -CommandName Get-SPWebApplication -MockWith { @@ -151,7 +175,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { SuiteNavBrandingLogoTitle = "LogoTitle" SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" SuiteNavBrandingText = "Suite Bar Text" - SuiteBarBrandingElementHtml = $null + SuiteBarBrandingElementHtml = "
Test
" } $webApp = $webApp | Add-Member -MemberType ScriptMethod -Name Update -Value { $Global:SPDscWebApplicationUpdateCalled = $true @@ -166,6 +190,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $results.SuiteNavBrandingLogoTitle | Should be "LogoTitle" $results.SuiteNavBrandingLogoUrl | Should be "http://sites.sharepoint.com/images/logo.gif" $results.SuiteNavBrandingText | Should be "Suite Bar Text" + $result.SuiteBarBrandingElementHtml | Should be "
Test
" } It "Should properly configure the suite bar for the Web Application" { @@ -192,7 +217,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { SuiteNavBrandingLogoTitle = "LogoTitle" SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" SuiteNavBrandingText = "Suite Bar Text" - SuiteBarBrandingElementHtml = $null + SuiteBarBrandingElementHtml = "
Test
" } $webApp = $webApp | Add-Member -MemberType ScriptMethod -Name Update -Value { $Global:SPDscWebApplicationUpdateCalled = $true From 4c77022ff06e089eff95bec26332b076492a4d31 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Wed, 3 Oct 2018 14:15:53 +0200 Subject: [PATCH 044/101] Fixed typos in error messages and variables. Removed obsolete unit test --- .../MSFT_SPWebAppSuiteBar.psm1 | 6 ++--- .../SharePointDsc.SPWebAppSuiteBar.Tests.ps1 | 26 ++----------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 index 2f838bb23..aea1559d6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPWebAppSuiteBar/MSFT_SPWebAppSuiteBar.psm1 @@ -144,8 +144,8 @@ function Set-TargetResource { if($PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { - Write-Verbose "SuiteBarBrandingElementHtml with SharePoint 2016 only works if using a " + ` - "SharePoint 2016 masterpage" + Write-Verbose ("SuiteBarBrandingElementHtml with SharePoint 2016 only works if using a " + ` + "SharePoint 2016 masterpage") } <# Exception: All the optional parameters are null for SP2016. #> @@ -156,7 +156,7 @@ function Set-TargetResource -and !$PSBoundParameters.ContainsKey("SuiteBarBrandingElementHtml")) { throw ("You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, " + ` - "SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl, SuiteNavBrandingTextm, " + ` + "SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl, SuiteNavBrandingText, " + ` "and SuiteBarBrandingElementHtml with SharePoint 2016") } } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 index a80a392da..9855f6201 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPWebAppSuiteBar.Tests.ps1 @@ -190,7 +190,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $results.SuiteNavBrandingLogoTitle | Should be "LogoTitle" $results.SuiteNavBrandingLogoUrl | Should be "http://sites.sharepoint.com/images/logo.gif" $results.SuiteNavBrandingText | Should be "Suite Bar Text" - $result.SuiteBarBrandingElementHtml | Should be "
Test
" + $results.SuiteBarBrandingElementHtml | Should be "
Test
" } It "Should properly configure the suite bar for the Web Application" { @@ -243,28 +243,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - Context -Name "Only some SP2016 parameters passed along the SP2013 one for an SP2016 environment" -Fixture { - $testParams = @{ - WebAppUrl = "http://sites.sharepoint.com" - SuiteBarBrandingElementHtml = "
Test
" - SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" - SuiteNavBrandingText = "Suite Bar Text" - } - - Mock -CommandName Get-SPWebApplication -MockWith {return @(@{ - DisplayName = "Test Web App" - Url = "http://sites.sharepoint.com" - SuiteNavBrandingLogoNavigationUrl = "http://sites.sharepoint.com" - SuiteNavBrandingLogoTitle = "LogoTitle" - SuiteNavBrandingLogoUrl = "http://sites.sharepoint.com/images/logo.gif" - SuiteNavBrandingText = "Suite Bar Text" - })} - - It "return error that sp2013 parameter was passed for a sp2016 environment" { - { Set-TargetResource @testParams } | Should Throw "Cannot specify SuiteBarBrandingElementHtml with SharePoint 2016. Instead, use the SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl and SuiteNavBrandingText parameters" - } - } - Context -Name "None of the optional parameters passed" -Fixture { $testParams = @{ WebAppUrl = "http://sites.sharepoint.com" @@ -280,7 +258,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { })} It "return error that sp2016 parameters are required" { - { Set-TargetResource @testParams } | Should Throw "You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl and SuiteNavBrandingText with SharePoint 2016" + { Set-TargetResource @testParams } | Should Throw "You need to specify a value for either SuiteNavBrandingLogoNavigationUrl, SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl, SuiteNavBrandingText, and SuiteBarBrandingElementHtml with SharePoint 2016" } } From 9131bee1a068c744d36df2ec21a073512ed97fd7 Mon Sep 17 00:00:00 2001 From: "jens.hatlevold@bouvet.no" Date: Fri, 5 Oct 2018 14:54:03 +0200 Subject: [PATCH 045/101] Forgot to save the changes. --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f346e22a6..70ade8ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,15 +25,12 @@ * Fixed issues that prevented the resource to work as expected in many situations. * SPWebAppPropertyBag * New resource to manage web application property bag -<<<<<<< HEAD * SPWebAppClientCallableSettings * New resource to manage web application client callable settings including proxy libraries. -======= * SPWebAppSuiteBar * Enable usage of SuiteBarBrandingElementHtml for SharePoint 2016 (only supported if using a SharePoint 2013 masterpage) ->>>>>>> Enabled usage of SuiteBarBrandingElementHtml in SharePoiont 2016 ## 2.5 From d12f8670aefd23b652c7fd3be7bfbdb6b98aab39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Fri, 5 Oct 2018 15:19:52 +0200 Subject: [PATCH 046/101] SPManagedMetaDataServiceApp: Add ContentType properties --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 103 +- ...SFT_SPManagedMetaDataServiceApp.schema.mof | 2 + ...tDsc.SPManagedMetadataServiceApp.Tests.ps1 | 2330 +++++++++-------- 3 files changed, 1282 insertions(+), 1153 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index b27a7f92e..83c15da37 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -45,6 +45,14 @@ function Get-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -94,6 +102,13 @@ function Get-TargetResource } } + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $proxyName + if($null -ne $proxy) + { + $contentTypePushDownEnabled = $proxy.Properties["IsContentTypePushdownEnabled"] + $contentTypeSyndicationEnabled = $proxy.Properties["IsNPContentTypeSyndicationEnabled"] + } + # Get the ContentTypeHubUrl value $hubUrl = "" try @@ -196,17 +211,19 @@ function Get-TargetResource } return @{ - Name = $serviceApp.DisplayName - ProxyName = $proxyName - Ensure = "Present" - ApplicationPool = $serviceApp.ApplicationPool.Name - DatabaseName = $serviceApp.Database.Name - DatabaseServer = $serviceApp.Database.NormalizedDataSource - TermStoreAdministrators = $currentAdmins - ContentTypeHubUrl = $hubUrl - DefaultLanguage = $termStoreDefaultLanguage - Languages = $termStoreLanguages - InstallAccount = $params.InstallAccount + Name = $serviceApp.DisplayName + ProxyName = $proxyName + Ensure = "Present" + ApplicationPool = $serviceApp.ApplicationPool.Name + DatabaseName = $serviceApp.Database.Name + DatabaseServer = $serviceApp.Database.NormalizedDataSource + TermStoreAdministrators = $currentAdmins + ContentTypeHubUrl = $hubUrl + DefaultLanguage = $termStoreDefaultLanguage + Languages = $termStoreLanguages + ContentTypePushdownEnabled = $contentTypePushDownEnabled + ContentTypeSyndicationEnabled = $contentTypeSyndicationEnabled + InstallAccount = $params.InstallAccount } } } @@ -259,6 +276,14 @@ function Set-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -552,6 +577,44 @@ function Set-TargetResource } } } + + if (($PSBoundParameters.ContainsKey("ContentTypePushdownEnabled") -eq $true) ` + -and ($ContentTypePushdownEnabled -ne $result.ContentTypePushdownEnabled) + ) + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $result, $pName) ` + -ScriptBlock { + $params = $args[0] + $pName = $args[2] + + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName + if($null -ne $proxy) + { + $proxy.Properties["IsContentTypePushdownEnabled"] = $params.ContentTypePushdownEnabled + $proxy.Update() + } + } + } + + if (($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) ` + -and ($ContentTypeSyndicationEnabled -ne $result.ContentTypeSyndicationEnabled) + ) + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $result, $pName) ` + -ScriptBlock { + $params = $args[0] + $pName = $args[2] + + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName + if($null -ne $proxy) + { + $proxy.Properties["IsNPContentTypeSyndicationEnabled"] = $params.ContentTypeSyndicationEnabled + $proxy.Update() + } + } + } } if ($Ensure -eq "Absent") @@ -628,6 +691,14 @@ function Test-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -665,6 +736,16 @@ function Test-TargetResource $valuesToCheck += "Languages" } + if ($PSBoundParameters.ContainsKey("ContentTypePushdownEnabled") -eq $true) + { + $valuesToCheck += "ContentTypePushdownEnabled" + } + + if ($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) + { + $valuesToCheck += "ContentTypeSyndicationEnabled" + } + $CurrentValues = Get-TargetResource @PSBoundParameters return Test-SPDscParameterState -CurrentValues $CurrentValues ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof index e8aad7910..c6e4be106 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof @@ -11,5 +11,7 @@ class MSFT_SPManagedMetaDataServiceApp : OMI_BaseResource [Write, Description("The URL of the content type hub for this app (only set when the app is provisioned)")] string ContentTypeHubUrl; [Write, Description("The LCID of the default language (only set when the app is provisioned)")] UInt32 DefaultLanguage; [Write, Description("The LCIDs of the working languages (only set when the app is provisioned)")] UInt32 Languages[]; + [Write, Description("Specifies that existing instances of changed content types in subsites and libraries will be updated.")] boolean ContentTypePushdownEnabled; + [Write, Description("Specifies that this connection will provide access to the content types that are associated with the managed metadata service application.")] boolean ContentTypeSyndicationEnabled; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index 5a86294a0..35ae61c92 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -42,6 +42,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } + Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { + return @{ + Name = "Managed Metadata Service App Proxy" + Properties = @{ + IsNPContentTypeSyndicationEnabled = $true + IsContentTypePushdownEnabled = $true + } + } | Add-Member -MemberType ScriptMethod ` + -Name update ` + -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -PassThru -Force + } + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { return @( @{ @@ -147,82 +160,1092 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { "@ } - # Test contexts - Context -Name "When no service applications exist in the current farm" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - TermStoreAdministrators = @() - ContentTypeHubUrl = "" - ProxyName = "Proxy Name" - DefaultLanguage = 1033 - Languages = @() - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { return $null } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should create a new service application in the set method" { - Set-TargetResource @testParams - Assert-MockCalled New-SPMetadataServiceApplication - } - } - - Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - DisplayName = $testParams.Name - } - $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return @{ - FullName = "Microsoft.Office.UnKnownWebServiceApplication" - } - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - } + # # Test contexts + # Context -Name "When no service applications exist in the current farm" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # TermStoreAdministrators = @() + # ContentTypeHubUrl = "" + # ProxyName = "Proxy Name" + # DefaultLanguage = 1033 + # Languages = @() + # ContentTypePushdownEnabled = $true + # ContentTypeSyndicationEnabled = $true + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should create a new service application in the set method" { + # Set-TargetResource @testParams + # Assert-MockCalled New-SPMetadataServiceApplication + # } + # } + + # Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # DisplayName = $testParams.Name + # } + # $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return @{ + # FullName = "Microsoft.Office.UnKnownWebServiceApplication" + # } + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + # } + + # Context -Name "When a service application exists and is configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # It "Should return present from the get method" { + # $results = Get-TargetResource @testParams + # $results.Ensure | Should Be "Present" + # $results.ContentTypeHubUrl | Should Not BeNullOrEmpty + # } + + # It "Should return true when the Test method is called" { + # Test-TargetResource @testParams | Should Be $true + # } + # } + + + # Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationPool -MockWith { + # return @{ + # Name = $testParams.ApplicationPool + # } + # } + + # It "Should return Wrong App Pool Name from the Get method" { + # (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the update service app cmdlet from the set method" { + # Set-TargetResource @testParams + + # Assert-MockCalled Get-SPServiceApplicationPool + # Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { + # $ApplicationPool.Name -eq $testParams.ApplicationPool + # } + # } + # } + + # Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # ContentTypeHubUrl = "https://contenttypes.contoso.com" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "https://contenttypes.contoso.com/wrong" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "https://contenttypes.contoso.com/wrong" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationPool -MockWith { + # return @{ + # Name = $testParams.ApplicationPool + # } + # } + + # It "Should return wrong content type url from the Get method" { + # (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the update service app cmdlet from the set method" { + # Set-TargetResource @testParams + + # Assert-MockCalled Set-SPMetadataServiceApplication + # } + # } + + # Context -Name "When the service application exists but it shouldn't" -Fixture { + # $testParams = @{ + # Name = "Test App" + # ApplicationPool = "-" + # Ensure = "Absent" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "Managed Metadata Service App Proxy" + # } | Add-Member -MemberType ScriptMethod ` + # -Name Update ` + # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name Delete ` + # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + # -PassThru -Force + # ) + # } + + # It "Should return present from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Present" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the remove service application cmdlet in the set method" { + # $Global:SPDscServiceProxyDeleteCalled = $false + + # Set-TargetResource @testParams + # Assert-MockCalled Remove-SPServiceApplication + # $Global:SPDscServiceProxyDeleteCalled | Should be $true + # } + # } + + # Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + # $testParams = @{ + # Name = "Test App" + # ApplicationPool = "-" + # Ensure = "Absent" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # return $null + # } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return true when the Test method is called" { + # Test-TargetResource @testParams | Should Be $true + # } + # } + + # Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return true from the test method" { + # Test-TargetResource @testParams | Should be $true + # } + # } + + # Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1", + # "CONTOSO\User2" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return true from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the add method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscAddUserCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # $termStores = @{ + # "Managed Metadata Service App Proxy" = @{ + # Name = "Managed Metadata Service App Proxy" + # Languages = @(1033) + # DefaultLanguage = 1033 + # WorkingLanguage = 1033 + # TermStoreAdministrators = @( + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "Contoso\User1" + # IsWindowsAuthenticationMode = $true + # } + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "Contoso\User2" + # IsWindowsAuthenticationMode = $true + # } + # ) + # } | Add-Member -MemberType ScriptMethod ` + # -Name AddTermStoreAdministrator ` + # -Value { $Global:SPDscAddUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteTermStoreAdministrator ` + # -Value { $Global:SPDscDeleteUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name AddLanguage ` + # -Value { $Global:SPDscAddLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteLanguage ` + # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force + # } + + # Mock -CommandName Get-SPTaxonomySession -MockWith { + # return @{ + # TermStores = $termStores + # } + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscDeleteUserCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and the proxy name has to be changed" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ProxyName = "Managed Metadata Service App ProxyName" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @() + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return (@{ + # FullName = $getTypeFullName + # }) + # } -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "$($testParams.Name) Proxy Test" + # } | Add-Member -MemberType ScriptMethod ` + # -Name Update ` + # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name Delete ` + # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + # -PassThru -Force + # ) + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscServiceProxyUpdateCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscServiceProxyUpdateCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @() + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # $termStores = @{ + # "Managed Metadata Service App Proxy" = @{ + # Name = "Managed Metadata Service App Proxy" + # Languages = @(1033) + # DefaultLanguage = 1033 + # WorkingLanguage = 1033 + # TermStoreAdministrators = @( + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "i:0#.w|Contoso\User2" + # IsWindowsAuthenticationMode = $false + # } + # ) + # } | Add-Member -MemberType ScriptMethod ` + # -Name AddTermStoreAdministrator ` + # -Value { $Global:SPDscAddUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteTermStoreAdministrator ` + # -Value { $Global:SPDscDeleteUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name AddLanguage ` + # -Value { $Global:SPDscAddLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteLanguage ` + # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force + # } + + # Mock -CommandName Get-SPTaxonomySession -MockWith { + # return @{ + # TermStores = $termStores + # } + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscDeleteUserCalled | Should Be $true + # } + # } + + # # New Test + # Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return (@{ + # FullName = $getTypeFullName + # }) + # } -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return ($true) + # } -PassThru -Force + + # return $spServiceApp + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "$($testParams.Name) Proxy Test" + # } + # ) + # } + + # It "Should return the proxy name" { + # (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" + # } + # } - Context -Name "When a service application exists and is configured correctly" -Fixture { + Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $false + ContentTypeSyndicationEnabled = $false } if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) @@ -234,9 +1257,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -271,9 +1294,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -326,1090 +1349,113 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - It "Should return present from the get method" { - $results = Get-TargetResource @testParams - $results.Ensure | Should Be "Present" - $results.ContentTypeHubUrl | Should Not BeNullOrEmpty - } - - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $true - } - } - - - Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp + $termStoreAdmins = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User2" + IsWindowsAuthenticationMode = $true } + ) + $termStoreAdmins = $termStoreAdmins | Add-Member -MemberType ScriptMethod ` + -Name DoesUserHavePermissions ` + -Value { + param ($userName) + return $true + } -PassThru -Force + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1031) + DefaultLanguage = 1031 + WorkingLanguage = 1033 + TermStoreAdministrators = $termStoreAdmins + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force } - Mock -CommandName Get-SPServiceApplicationPool -MockWith { + Mock -CommandName Get-SPTaxonomySession -MockWith { return @{ - Name = $testParams.ApplicationPool + TermStores = $termStores } } - It "Should return Wrong App Pool Name from the Get method" { - (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + $metadataServiceApplicationProxy = @{ + Name = "Managed Metadata Service App Proxy" + Properties = @{ + IsContentTypePushdownEnabled = $true + IsNPContentTypeSyndicationEnabled = $true + } + } | Add-Member -MemberType ScriptMethod ` + -Name update ` + -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -PassThru -Force + + Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { + return $metadataServiceApplicationProxy } It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams + It "Should match the mocked values" { + $result = Get-TargetResource @testParams + $result.DefaultLanguage | Should Be 1031 + $result.Languages | Should Be @(1031) + } - Assert-MockCalled Get-SPServiceApplicationPool - Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { - $ApplicationPool.Name -eq $testParams.ApplicationPool - } + It "Should change the value for 'Default Language'" { + $result = Get-TargetResource @testParams + Set-TargetResource @testParams + $termStores["$($result.ProxyName)"].DefaultLanguage | Should Be $testParams.DefaultLanguage } - } - Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - ContentTypeHubUrl = "https://contenttypes.contoso.com" - Ensure = "Present" + It "Should change the value for 'Languages'" { + $Global:SPDscAddLanguageCalled = $false + $Global:SPDscDeleteLanguageCalled = $false + Set-TargetResource @testParams + $Global:SPDscAddLanguageCalled | Should Be $true + $Global:SPDscDeleteLanguageCalled | Should Be $true } - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "https://contenttypes.contoso.com/wrong" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } + It "Should change the value for 'ContentTypePushdownEnabled'" { + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false + Set-TargetResource @testParams + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true + # $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $false } - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "https://contenttypes.contoso.com/wrong" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp - } - } - - Mock -CommandName Get-SPServiceApplicationPool -MockWith { - return @{ - Name = $testParams.ApplicationPool - } - } - - It "Should return wrong content type url from the Get method" { - (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams - - Assert-MockCalled Set-SPMetadataServiceApplication - } - } - - Context -Name "When the service application exists but it shouldn't" -Fixture { - $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "Managed Metadata Service App Proxy" - } | Add-Member -MemberType ScriptMethod ` - -Name Update ` - -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name Delete ` - -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - -PassThru -Force - ) - } - - It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should call the remove service application cmdlet in the set method" { - $Global:SPDscServiceProxyDeleteCalled = $false - - Set-TargetResource @testParams - Assert-MockCalled Remove-SPServiceApplication - $Global:SPDscServiceProxyDeleteCalled | Should be $true - } - } - - Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { - $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return $null - } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $true - } - } - - Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return true from the test method" { - Test-TargetResource @testParams | Should be $true - } - } - - Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1", - "CONTOSO\User2" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return true from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the add method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscAddUserCalled | Should Be $true - } - } - - Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1033) - DefaultLanguage = 1033 - WorkingLanguage = 1033 - TermStoreAdministrators = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User1" - IsWindowsAuthenticationMode = $true - } - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User2" - IsWindowsAuthenticationMode = $true - } - ) - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscDeleteUserCalled | Should Be $true - } - } - - Context -Name "A service app exists and the proxy name has to be changed" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ProxyName = "Managed Metadata Service App ProxyName" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @() - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return (@{ - FullName = $getTypeFullName - }) - } -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "$($testParams.Name) Proxy Test" - } | Add-Member -MemberType ScriptMethod ` - -Name Update ` - -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name Delete ` - -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - -PassThru -Force - ) - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscServiceProxyUpdateCalled = $false - Set-TargetResource @testParams - - $Global:SPDscServiceProxyUpdateCalled | Should Be $true - } - } - - Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @() - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1033) - DefaultLanguage = 1033 - WorkingLanguage = 1033 - TermStoreAdministrators = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "i:0#.w|Contoso\User2" - IsWindowsAuthenticationMode = $false - } - ) - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscDeleteUserCalled | Should Be $true - } - } - - # New Test - Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return (@{ - FullName = $getTypeFullName - }) - } -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return ($true) - } -PassThru -Force - - return $spServiceApp - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "$($testParams.Name) Proxy Test" - } - ) - } - - It "Should return the proxy name" { - (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" - } - } - - Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service Application" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - DefaultLanguage = 1033 - Languages = @(1033) - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - $termStoreAdmins = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User1" - IsWindowsAuthenticationMode = $true - } - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User2" - IsWindowsAuthenticationMode = $true - } - ) - $termStoreAdmins = $termStoreAdmins | Add-Member -MemberType ScriptMethod ` - -Name DoesUserHavePermissions ` - -Value { - param ($userName) - return $true - } -PassThru -Force - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1031) - DefaultLanguage = 1031 - WorkingLanguage = 1033 - TermStoreAdministrators = $termStoreAdmins - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should match the mocked values" { - $result = Get-TargetResource @testParams - $result.DefaultLanguage | Should Be 1031 - $result.Languages | Should Be @(1031) - } - - It "Should change the value for 'Default Language'" { - $result = Get-TargetResource @testParams - Set-TargetResource @testParams - $termStores["$($result.ProxyName)"].DefaultLanguage | Should Be $testParams.DefaultLanguage - } - - It "Should change the value for 'Languages'" { - $Global:SPDscAddLanguageCalled = $false - $Global:SPDscDeleteLanguageCalled = $false + It "Should change the value for 'ContentTypeSyndicationEnabled'" { + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams - $Global:SPDscAddLanguageCalled | Should Be $true - $Global:SPDscDeleteLanguageCalled | Should Be $true + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true + # $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $false } } From 49f5e577677bab03fbb170718f8aaf552ffde7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sat, 6 Oct 2018 00:21:54 +0200 Subject: [PATCH 047/101] Added example and changelog --- CHANGELOG.md | 3 ++ .../6-SetContentTypeSettings.ps1 | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f1939d00..2e298c991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ * Fixed issue where enabling providers did not work * SPLogLevel * Added High as TraceLevel, which was not included yet +* SPManagedMetadataServiceApp + * Added additional content type settings (ContentTypePushdownEnabled & + ContentTypeSyndicationEnabled). * SPSearchServiceApp * Updated Set method to check if service application pool exists. Resource will throw an error if it does not exist diff --git a/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 new file mode 100644 index 000000000..a46d6396a --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to deploy the Managed Metadata service app to the local SharePoint farm + and also include a specific list of users to be the term store administrators. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPManagedMetaDataServiceApp ManagedMetadataServiceApp + { + Name = "Managed Metadata Service Application" + PSDscRunAsCredential = $SetupAccount + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "SP_ManagedMetadata" + ContentTypeHubUrl = "http://contoso.sharepoint.com/sites/ct" + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $true + } + } +} From 621d959190b17a7dd1d648ddb7a63f4ab1b856ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sat, 6 Oct 2018 00:27:21 +0200 Subject: [PATCH 048/101] update to readme --- .../DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md index 1283f8583..2dc8bc8b6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md @@ -16,3 +16,6 @@ The content type hub url will be set or reset. The language settings (default and working) are only changed if they are part of the bound parameters. Otherwise they will not be altered. + +ContentTypePushdownEnabled and ContentTypeSyndicationEnabled will only be altered +if they are part of the bound parameters. From 491cd4c457acef1e7eadde72a9a0d834059569b3 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 14:20:04 +0200 Subject: [PATCH 049/101] Fixed permission issues for default group creation. --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 897bb0c1f..bcad079ed 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -262,6 +262,7 @@ function Set-TargetResource -ScriptBlock { $params = $args[0] $CurrentValues = $args[1] + $doCreateDefaultGroups = $false $params.Remove("InstallAccount") | Out-Null @@ -273,12 +274,10 @@ function Set-TargetResource if ($null -eq $site) { $site = New-SPSite @params - if ($CreateDefaultGroups -eq $true) { - $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, - $params.SecondaryOwnerAlias, - $null) + $doCreateDefaultGroups = $true; + } else { @@ -334,10 +333,7 @@ function Set-TargetResource { if ($CreateDefaultGroups -eq $true) { - $site = Get-SPSite -Identity $params.Url -ErrorAction SilentlyContinue - $site.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, - $params.SecondaryOwnerAlias, - $null) + $doCreateDefaultGroups = $true; } else { @@ -346,6 +342,19 @@ function Set-TargetResource } } } + + if ($doCreateDefaultGroups -eq $true) + { + Write-Verbose -Message ("Creating default groups") + + $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local + $centralAdminSite = $centralAdminWebApp.Sites[0] + + $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) + $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, + $params.SecondaryOwnerAlias, + $null) + } } } From 035eaa75ef22ebc6afb10555edcbf6ccc561a993 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 16:57:05 +0200 Subject: [PATCH 050/101] Modified unit tests to work with creating default groups --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 2 +- .../SharePointDsc.SPSite.Tests.ps1 | 103 ++++++++++++++---- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index bcad079ed..ec5170405 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -348,7 +348,7 @@ function Set-TargetResource Write-Verbose -Message ("Creating default groups") $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local - $centralAdminSite = $centralAdminWebApp.Sites[0] + $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index 4753c984b..258f2f0a8 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -18,7 +18,77 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + # Initialize tests + try + { + [Microsoft.SharePoint.Administration.SPAdministrationWebApplication] + } + catch + { + Add-Type -TypeDefinition @" +namespace Microsoft.SharePoint.Administration { + public class SPAdministrationWebApplication { + public SPAdministrationWebApplication() + { + } + public static System.Object Local { get; set;} + } +} +"@ + } + # Mocks for all contexts + $siteImplementation = + { + $rootWeb = @{ + AssociatedVisitorGroup = $null + AssociatedMemberGroup = $null + AssociatedOwnerGroup = $null + CreateDefaultAssociatedGroupsCalled = $false + } + $rootWeb | Add-Member -MemberType ScriptMethod ` + -Name CreateDefaultAssociatedGroups ` + -Value { + $this.CreateDefaultAssociatedGroupsCalled = $true + } + + $site = @{ + HostHeaderIsSiteName = $false + WebApplication = @{ + Url = "https://site.contoso.com" + UseClaimsAuthentication = $true + } + Url = "https://site.contoso.com" + Owner = @{ UserLogin = "DEMO\owner" } + Quota = @{ QuotaId = 65000 } + RootWeb = $rootWeb + } + return $site + } + + [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local = @{ Url = "https://CentralAdmin.contoso.com" } + + Mock -CommandName Get-SPSite -MockWith { + return @{ + Id = 1 + SystemAccount = @{ + UserToken = "SystemAccountUserToken" + } + } + } -ParameterFilter { + $Identity -eq "https://CentralAdmin.contoso.com" + } + + Mock -CommandName New-Object -MockWith { + $site = $siteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site; + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" + $ArgumentList[0] -eq 1 + $ArgumentList[1] -eq "SystemAccountUserToken" + } + Mock -CommandName New-SPSite -MockWith { $rootWeb = @{} $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` @@ -201,28 +271,14 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{ - AssociatedVisitorGroup = $null - AssociatedMemberGroup = $null - AssociatedOwnerGroup = $null - } - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value { - $Global:SPDscGroupsUpdated = $true - } -PassThru - $returnval = @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $true - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - Quota = @{ QuotaId = 65000 } - RootWeb = $rootWeb - } - return $returnval + $site = $siteImplementation.InvokeReturnAsIs() + $site.RootWeb.AssociatedMemberGroup = $null + $site.RootWeb.AssociatedMemberGroup = $null + $site.RootWeb.AssociatedOwnerGroup = $null + + $site.WebApplication.Url = $testParams.Url + $site.Url = $testParams.Url + return $site } Mock -CommandName New-SPClaimsPrincipal -MockWith { @@ -239,10 +295,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Test-TargetResource @testParams | Should Be $false } - $Global:SPDscGroupsUpdated = $false It "Should update the groups in the set method" { Set-TargetResource @testParams - $Global:SPDscGroupsUpdated | Should Be $true + $Script:SPDscSystemAccountSite.RootWeb.CreateDefaultAssociatedGroupsCalled | Should Be $true } } From 40527ff5ce716c4657c60d6023b692409f59a761 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 17:14:28 +0200 Subject: [PATCH 051/101] Changed site mock parameterfilter --- Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index 258f2f0a8..8f1b2ad43 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -72,7 +72,7 @@ namespace Microsoft.SharePoint.Administration { return @{ Id = 1 SystemAccount = @{ - UserToken = "SystemAccountUserToken" + UserToken = "CentralAdminSystemAccountUserToken" } } } -ParameterFilter { @@ -84,9 +84,8 @@ namespace Microsoft.SharePoint.Administration { $Script:SPDscSystemAccountSite = $site return $site; } -ParameterFilter { - $TypeName -eq "Microsoft.SharePoint.SPSite" - $ArgumentList[0] -eq 1 - $ArgumentList[1] -eq "SystemAccountUserToken" + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" } Mock -CommandName New-SPSite -MockWith { From 4474b0bb64d5fc7a7c417537844ca67ef999ce8a Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 18:17:18 +0200 Subject: [PATCH 052/101] Fixed typo in values to check --- Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index ec5170405..651d3a00b 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -448,7 +448,7 @@ function Test-TargetResource "QuotaTemplate", "OwnerAlias", "SecondaryOwnerAlias", - "TenantAdministration") + "AdministrationSiteType") } Export-ModuleMember -Function *-TargetResource From 9d6c0efb1d26741d41e59d9efea83920774df9fc Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 18:20:39 +0200 Subject: [PATCH 053/101] Used System Account to retrieve site collection. Fixed #875 --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 651d3a00b..54e8bf184 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -76,12 +76,21 @@ function Get-TargetResource -Arguments $PSBoundParameters ` -ScriptBlock { $params = $args[0] + $site = $null - $site = Get-SPSite -Identity $params.Url ` - -ErrorAction SilentlyContinue + try + { + $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local + $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url + + $site = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($params.Url, $centralAdminSite.SystemAccount.UserToken) + } + catch [System.Exception] {} if ($null -eq $site) { + Write-Verbose "Site Collection not found" + return @{ Url = $params.Url OwnerAlias = $null From 082828c9b7dd9ce28aef48a38d2d299ebc04f2a2 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 18:23:35 +0200 Subject: [PATCH 054/101] Creating default groups using the resolved principal login name --- .../DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 54e8bf184..a42d6bfa8 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -357,11 +357,19 @@ function Set-TargetResource Write-Verbose -Message ("Creating default groups") $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local - $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url - $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) - $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($params.OwnerAlias, - $params.SecondaryOwnerAlias, + if($null -eq $systemAccountSite.SecondaryOwnerAlias) + { + $secondaryOwnerLogin = $null; + } + else + { + $secondaryOwnerLogin = $systemAccountSite.SecondaryOwnerAlias.UserLogin; + } + + $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($centralAdminWebApp.Url, $centralAdminSite.SystemAccount.UserToken) + $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($systemAccountSite.Owner.UserLogin, + $secondaryOwnerLogin, $null) } } From 4c6c0ba00fecaae7ba7734fd990f30528cb9faaa Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sat, 6 Oct 2018 18:25:57 +0200 Subject: [PATCH 055/101] Reverted to retrieve central admin site when creating groups --- .../SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index a42d6bfa8..29ef290dd 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -357,6 +357,7 @@ function Set-TargetResource Write-Verbose -Message ("Creating default groups") $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local + $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url if($null -eq $systemAccountSite.SecondaryOwnerAlias) { @@ -367,7 +368,7 @@ function Set-TargetResource $secondaryOwnerLogin = $systemAccountSite.SecondaryOwnerAlias.UserLogin; } - $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($centralAdminWebApp.Url, $centralAdminSite.SystemAccount.UserToken) + $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($centralAdminSite.Id, $centralAdminSite.SystemAccount.UserToken) $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($systemAccountSite.Owner.UserLogin, $secondaryOwnerLogin, $null) From 432bbfdf030227f0cf9b197ed83f9a820f6f8926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sun, 7 Oct 2018 20:00:03 +0200 Subject: [PATCH 056/101] Fixed Tests --- ...tDsc.SPManagedMetadataServiceApp.Tests.ps1 | 2180 +++++++++-------- 1 file changed, 1102 insertions(+), 1078 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index 35ae61c92..0a2a2e9a5 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -160,1080 +160,1080 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { "@ } - # # Test contexts - # Context -Name "When no service applications exist in the current farm" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # TermStoreAdministrators = @() - # ContentTypeHubUrl = "" - # ProxyName = "Proxy Name" - # DefaultLanguage = 1033 - # Languages = @() - # ContentTypePushdownEnabled = $true - # ContentTypeSyndicationEnabled = $true - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { return $null } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should create a new service application in the set method" { - # Set-TargetResource @testParams - # Assert-MockCalled New-SPMetadataServiceApplication - # } - # } - - # Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # DisplayName = $testParams.Name - # } - # $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return @{ - # FullName = "Microsoft.Office.UnKnownWebServiceApplication" - # } - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - # } - - # Context -Name "When a service application exists and is configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # It "Should return present from the get method" { - # $results = Get-TargetResource @testParams - # $results.Ensure | Should Be "Present" - # $results.ContentTypeHubUrl | Should Not BeNullOrEmpty - # } - - # It "Should return true when the Test method is called" { - # Test-TargetResource @testParams | Should Be $true - # } - # } - - - # Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationPool -MockWith { - # return @{ - # Name = $testParams.ApplicationPool - # } - # } - - # It "Should return Wrong App Pool Name from the Get method" { - # (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the update service app cmdlet from the set method" { - # Set-TargetResource @testParams - - # Assert-MockCalled Get-SPServiceApplicationPool - # Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { - # $ApplicationPool.Name -eq $testParams.ApplicationPool - # } - # } - # } - - # Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # ContentTypeHubUrl = "https://contenttypes.contoso.com" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "https://contenttypes.contoso.com/wrong" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "https://contenttypes.contoso.com/wrong" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationPool -MockWith { - # return @{ - # Name = $testParams.ApplicationPool - # } - # } - - # It "Should return wrong content type url from the Get method" { - # (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the update service app cmdlet from the set method" { - # Set-TargetResource @testParams - - # Assert-MockCalled Set-SPMetadataServiceApplication - # } - # } - - # Context -Name "When the service application exists but it shouldn't" -Fixture { - # $testParams = @{ - # Name = "Test App" - # ApplicationPool = "-" - # Ensure = "Absent" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "Managed Metadata Service App Proxy" - # } | Add-Member -MemberType ScriptMethod ` - # -Name Update ` - # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name Delete ` - # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - # -PassThru -Force - # ) - # } - - # It "Should return present from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Present" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the remove service application cmdlet in the set method" { - # $Global:SPDscServiceProxyDeleteCalled = $false - - # Set-TargetResource @testParams - # Assert-MockCalled Remove-SPServiceApplication - # $Global:SPDscServiceProxyDeleteCalled | Should be $true - # } - # } - - # Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { - # $testParams = @{ - # Name = "Test App" - # ApplicationPool = "-" - # Ensure = "Absent" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # return $null - # } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return true when the Test method is called" { - # Test-TargetResource @testParams | Should Be $true - # } - # } - - # Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return true from the test method" { - # Test-TargetResource @testParams | Should be $true - # } - # } - - # Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1", - # "CONTOSO\User2" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return true from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the add method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscAddUserCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # $termStores = @{ - # "Managed Metadata Service App Proxy" = @{ - # Name = "Managed Metadata Service App Proxy" - # Languages = @(1033) - # DefaultLanguage = 1033 - # WorkingLanguage = 1033 - # TermStoreAdministrators = @( - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "Contoso\User1" - # IsWindowsAuthenticationMode = $true - # } - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "Contoso\User2" - # IsWindowsAuthenticationMode = $true - # } - # ) - # } | Add-Member -MemberType ScriptMethod ` - # -Name AddTermStoreAdministrator ` - # -Value { $Global:SPDscAddUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteTermStoreAdministrator ` - # -Value { $Global:SPDscDeleteUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name AddLanguage ` - # -Value { $Global:SPDscAddLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteLanguage ` - # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force - # } - - # Mock -CommandName Get-SPTaxonomySession -MockWith { - # return @{ - # TermStores = $termStores - # } - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscDeleteUserCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and the proxy name has to be changed" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ProxyName = "Managed Metadata Service App ProxyName" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @() - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return (@{ - # FullName = $getTypeFullName - # }) - # } -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "$($testParams.Name) Proxy Test" - # } | Add-Member -MemberType ScriptMethod ` - # -Name Update ` - # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name Delete ` - # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - # -PassThru -Force - # ) - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscServiceProxyUpdateCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscServiceProxyUpdateCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @() - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # $termStores = @{ - # "Managed Metadata Service App Proxy" = @{ - # Name = "Managed Metadata Service App Proxy" - # Languages = @(1033) - # DefaultLanguage = 1033 - # WorkingLanguage = 1033 - # TermStoreAdministrators = @( - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "i:0#.w|Contoso\User2" - # IsWindowsAuthenticationMode = $false - # } - # ) - # } | Add-Member -MemberType ScriptMethod ` - # -Name AddTermStoreAdministrator ` - # -Value { $Global:SPDscAddUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteTermStoreAdministrator ` - # -Value { $Global:SPDscDeleteUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name AddLanguage ` - # -Value { $Global:SPDscAddLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteLanguage ` - # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force - # } - - # Mock -CommandName Get-SPTaxonomySession -MockWith { - # return @{ - # TermStores = $termStores - # } - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscDeleteUserCalled | Should Be $true - # } - # } - - # # New Test - # Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return (@{ - # FullName = $getTypeFullName - # }) - # } -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return ($true) - # } -PassThru -Force - - # return $spServiceApp - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "$($testParams.Name) Proxy Test" - # } - # ) - # } - - # It "Should return the proxy name" { - # (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" - # } - # } + # Test contexts + Context -Name "When no service applications exist in the current farm" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + TermStoreAdministrators = @() + ContentTypeHubUrl = "" + ProxyName = "Proxy Name" + DefaultLanguage = 1033 + Languages = @() + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $true + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPMetadataServiceApplication + } + } + + Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.Office.UnKnownWebServiceApplication" + } + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When a service application exists and is configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + It "Should return present from the get method" { + $results = Get-TargetResource @testParams + $results.Ensure | Should Be "Present" + $results.ContentTypeHubUrl | Should Not BeNullOrEmpty + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + + Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + It "Should return Wrong App Pool Name from the Get method" { + (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Get-SPServiceApplicationPool + Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { + $ApplicationPool.Name -eq $testParams.ApplicationPool + } + } + } + + Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + ContentTypeHubUrl = "https://contenttypes.contoso.com" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + It "Should return wrong content type url from the Get method" { + (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Set-SPMetadataServiceApplication + } + } + + Context -Name "When the service application exists but it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "Managed Metadata Service App Proxy" + } | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + -PassThru -Force + ) + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the remove service application cmdlet in the set method" { + $Global:SPDscServiceProxyDeleteCalled = $false + + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + $Global:SPDscServiceProxyDeleteCalled | Should be $true + } + } + + Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $true + } + } + + Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1", + "CONTOSO\User2" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the add method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscAddUserCalled | Should Be $true + } + } + + Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1033) + DefaultLanguage = 1033 + WorkingLanguage = 1033 + TermStoreAdministrators = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true + } + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User2" + IsWindowsAuthenticationMode = $true + } + ) + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + } + + Mock -CommandName Get-SPTaxonomySession -MockWith { + return @{ + TermStores = $termStores + } + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscDeleteUserCalled | Should Be $true + } + } + + Context -Name "A service app exists and the proxy name has to be changed" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ProxyName = "Managed Metadata Service App ProxyName" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "$($testParams.Name) Proxy Test" + } | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + -PassThru -Force + ) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscServiceProxyUpdateCalled = $false + Set-TargetResource @testParams + + $Global:SPDscServiceProxyUpdateCalled | Should Be $true + } + } + + Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1033) + DefaultLanguage = 1033 + WorkingLanguage = 1033 + TermStoreAdministrators = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "i:0#.w|Contoso\User2" + IsWindowsAuthenticationMode = $false + } + ) + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + } + + Mock -CommandName Get-SPTaxonomySession -MockWith { + return @{ + TermStores = $termStores + } + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscDeleteUserCalled | Should Be $true + } + } + + # New Test + Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return ($true) + } -PassThru -Force + + return $spServiceApp + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "$($testParams.Name) Proxy Test" + } + ) + } + + It "Should return the proxy name" { + (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" + } + } Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { $testParams = @{ @@ -1412,8 +1412,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsNPContentTypeSyndicationEnabled = $true } } | Add-Member -MemberType ScriptMethod ` - -Name update ` - -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -Name Update ` + -Value { $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true } ` -PassThru -Force Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { @@ -1445,17 +1445,41 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should change the value for 'ContentTypePushdownEnabled'" { + $testParams = @{ + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $false + } + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true - # $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $false + $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $true } It "Should change the value for 'ContentTypeSyndicationEnabled'" { + $testParams = @{ + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $false + ContentTypeSyndicationEnabled = $true + } + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true - # $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $false + $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $true } } From 84868c639a9792edaeb9176752122cdbd72e6de3 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sun, 7 Oct 2018 20:25:58 +0200 Subject: [PATCH 057/101] Update unit tests to work with new method to retrieve a site --- .../SharePointDsc.SPSite.Tests.ps1 | 293 ++++++++++-------- 1 file changed, 169 insertions(+), 124 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 index 8f1b2ad43..1e9b1e076 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSite.Tests.ps1 @@ -42,8 +42,8 @@ namespace Microsoft.SharePoint.Administration { { $rootWeb = @{ AssociatedVisitorGroup = $null - AssociatedMemberGroup = $null - AssociatedOwnerGroup = $null + AssociatedMemberGroup = $null + AssociatedOwnerGroup = $null CreateDefaultAssociatedGroupsCalled = $false } $rootWeb | Add-Member -MemberType ScriptMethod ` @@ -62,6 +62,7 @@ namespace Microsoft.SharePoint.Administration { Owner = @{ UserLogin = "DEMO\owner" } Quota = @{ QuotaId = 65000 } RootWeb = $rootWeb + AdministrationSiteType = "None" } return $site } @@ -136,6 +137,14 @@ namespace Microsoft.SharePoint.Administration { OwnerAlias = "DEMO\User" } + Mock -CommandName New-Object -MockWith { + return $null; + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq "http://site.sharepoint.com" -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + Mock -CommandName Get-SPSite -MockWith { return $null } It "Should return OwnerAlias=Null from the get method" { @@ -161,28 +170,35 @@ namespace Microsoft.SharePoint.Administration { AdministrationSiteType = "TenantAdministration" } - Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{} - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value {} -PassThru - $returnval = @{ - HostHeaderIsSiteName = $true - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $false - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - SecondaryContact = @{ UserLogin = "DEMO\secondowner" } - Quota = @{ - QuotaId = 1 - } - RootWeb = $rootWeb - AdministrationSiteType = "None" + $contextSiteImplementation = { + $site = $siteImplementation.InvokeReturnAsIs() + $site.WebApplication.Url = $testParams.Url + $site.WebApplication.UseClaimsAuthentication = $false + $site.Url = $testParams.Url + $site.Owner = @{ UserLogin = "DEMO\owner" } + $site.SecondaryContact = @{ UserLogin = "DEMO\secondowner" } + $site.Quota = @{ + QuotaId = 1 } - return $returnval + return $site; } + + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + + Mock -CommandName Get-SPSite -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSite = $site + return $site + } + Mock -CommandName Set-SPSite -MockWith {} -ParameterFilter { $OwnerAlias = "DEMO\User" $SecondaryOwnerAlias = "DEMO\SecondUser" @@ -232,26 +248,34 @@ namespace Microsoft.SharePoint.Administration { OwnerAlias = "DEMO\owner" } + $contextSiteImplementation = { + $site = $siteImplementation.InvokeReturnAsIs() + $site.RootWeb.AssociatedVisitorGroup = "Test Visitors" + $site.RootWeb.AssociatedMemberGroup = "Test Members" + $site.RootWeb.AssociatedOwnerGroup = "Test Owners" + + $site.WebApplication.Url = $testParams.Url + $site.WebApplication.UseClaimsAuthentication = $false + $site.HostHeaderIsSiteName = $true + $site.Url = $testParams.Url + $site.Owner = @{ UserLogin = "DEMO\owner" } + return $site; + } + + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{ - AssociatedVisitorGroup = "Test Visitors" - AssociatedMemberGroup = "Test Members" - AssociatedOwnerGroup = "Test Owners" - } - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value {} -PassThru - $returnval = @{ - HostHeaderIsSiteName = $true - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $false - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - RootWeb = $rootWeb - } - return $returnval + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSite = $site + return $site } It "Should return the site data from the get method" { @@ -271,7 +295,7 @@ namespace Microsoft.SharePoint.Administration { Mock -CommandName Get-SPSite -MockWith { $site = $siteImplementation.InvokeReturnAsIs() - $site.RootWeb.AssociatedMemberGroup = $null + $site.RootWeb.AssociatedVisitorGroup = $null $site.RootWeb.AssociatedMemberGroup = $null $site.RootWeb.AssociatedOwnerGroup = $null @@ -306,27 +330,35 @@ namespace Microsoft.SharePoint.Administration { OwnerAlias = "DEMO\User" } + $contextSiteImplementation = { + $site = $siteImplementation.InvokeReturnAsIs() + $site.RootWeb.AssociatedVisitorGroup = "Test Visitors" + $site.RootWeb.AssociatedMemberGroup = "Test Members" + $site.RootWeb.AssociatedOwnerGroup = "Test Owners" + + $site.WebApplication.Url = $testParams.Url + $site.WebApplication.UseClaimsAuthentication = $true + $site.HostHeaderIsSiteName = $false + $site.Url = $testParams.Url + $site.Owner = @{ UserLogin = "DEMO\owner" } + $site.Quota = @{ QuotaId = 65000 } + return $site; + } + + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{ - AssociatedVisitorGroup = "Test Visitors" - AssociatedMemberGroup = "Test Members" - AssociatedOwnerGroup = "Test Owners" - } - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value {} -PassThru - $returnval = @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $true - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - Quota = @{ QuotaId = 65000 } - RootWeb = $rootWeb - } - return $returnval + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSite = $site + return $site } Mock -CommandName New-SPClaimsPrincipal -MockWith { @@ -343,34 +375,31 @@ namespace Microsoft.SharePoint.Administration { Test-TargetResource @testParams | Should Be $true } - Mock -CommandName Get-SPSite -MockWith { - return @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $true - } - Url = $testParams.Url - Owner = $null - } + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $site.Owner = $null + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" } It "Should return the site data from the get method where a valid site collection admin does not exist" { Get-TargetResource @testParams | Should Not BeNullOrEmpty } - Mock -CommandName Get-SPSite -MockWith { - return @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $true - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - SecondaryContact = @{ UserLogin = "DEMO\secondary" } - Quota = @{ QuotaId = 65000 } - } + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $site.Owner = @{ UserLogin = "DEMO\owner" } + $site.SecondaryContact = @{ UserLogin = "DEMO\secondary" } + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" } It "Should return the site data from the get method where a secondary site contact exists" { @@ -384,27 +413,35 @@ namespace Microsoft.SharePoint.Administration { OwnerAlias = "DEMO\owner" } + $contextSiteImplementation = { + $site = $siteImplementation.InvokeReturnAsIs() + $site.RootWeb.AssociatedVisitorGroup = "Test Visitors" + $site.RootWeb.AssociatedMemberGroup = "Test Members" + $site.RootWeb.AssociatedOwnerGroup = "Test Owners" + + $site.WebApplication.Url = $testParams.Url + $site.WebApplication.UseClaimsAuthentication = $false + $site.HostHeaderIsSiteName = $false + $site.Url = $testParams.Url + $site.Owner = @{ UserLogin = "DEMO\owner" } + $site.Quota = @{ QuotaId = 65000 } + return $site; + } + + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{ - AssociatedVisitorGroup = "Test Visitors" - AssociatedMemberGroup = "Test Members" - AssociatedOwnerGroup = "Test Owners" - } - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value {} -PassThru - $returnval = @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $false - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - Quota = @{ QuotaId = 65000 } - RootWeb = $rootWeb - } - return $returnval + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSite = $site + return $site } It "Should return the site data from the get method" { @@ -441,27 +478,35 @@ namespace Microsoft.SharePoint.Administration { CreateDefaultGroups = $false } + $contextSiteImplementation = { + $site = $siteImplementation.InvokeReturnAsIs() + $site.RootWeb.AssociatedVisitorGroup = $null + $site.RootWeb.AssociatedMemberGroup = $null + $site.RootWeb.AssociatedOwnerGroup = $null + + $site.WebApplication.Url = $testParams.Url + $site.WebApplication.UseClaimsAuthentication = $false + $site.HostHeaderIsSiteName = $false + $site.Url = $testParams.Url + $site.Owner = @{ UserLogin = "DEMO\owner" } + $site.Quota = @{ QuotaId = 65000 } + return $site; + } + + Mock -CommandName New-Object -MockWith { + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSystemAccountSite = $site + return $site + } -ParameterFilter { + $TypeName -eq "Microsoft.SharePoint.SPSite" -and + $ArgumentList[0] -eq $testParams.Url -and + $ArgumentList[1] -eq "CentralAdminSystemAccountUserToken" + } + Mock -CommandName Get-SPSite -MockWith { - $rootWeb = @{ - AssociatedVisitorGroup = $null - AssociatedMemberGroup = $null - AssociatedOwnerGroup = $null - } - $rootWeb = $rootWeb | Add-Member -MemberType ScriptMethod ` - -Name CreateDefaultAssociatedGroups ` - -Value {} -PassThru - $returnval = @{ - HostHeaderIsSiteName = $false - WebApplication = @{ - Url = $testParams.Url - UseClaimsAuthentication = $false - } - Url = $testParams.Url - Owner = @{ UserLogin = "DEMO\owner" } - Quota = @{ QuotaId = 65000 } - RootWeb = $rootWeb - } - return $returnval + $site = $contextSiteImplementation.InvokeReturnAsIs() + $Script:SPDscSite = $site + return $site } It "Should return CreateDefaultGroups=False from the get method" { From 3ed6438f88b3f9b118fdbb81feea02b2a475d6f2 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sun, 7 Oct 2018 20:31:17 +0200 Subject: [PATCH 058/101] Updated changelog file --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f59878768..f0e37f2bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ * SPSite * Added the possibility for creating the default site groups * Added the possibility to set AdministrationSiteType + * Fixed test method that in some cases always would return false + * Fixed a typo in the values to check for AdministrationSiteType + * Fixed an access denied issue when creating default site groups + when the run as account does not have proper permissions for the site * SPUserProfileServiceApp * Fixed issue which was introduced in v2.5 where the service application proxy was not created. From 87d95af6dc1a40215741f6f042ab5d8325fc36dc Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Sun, 7 Oct 2018 20:35:50 +0200 Subject: [PATCH 059/101] Removed force switch on Import-Module in UnitTestHelper --- Tests/Unit/UnitTestHelper.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/UnitTestHelper.psm1 b/Tests/Unit/UnitTestHelper.psm1 index 95d2f6d5a..0b380e422 100644 --- a/Tests/Unit/UnitTestHelper.psm1 +++ b/Tests/Unit/UnitTestHelper.psm1 @@ -27,7 +27,7 @@ function New-SPDscUnitTestHelper $moduleRoot = Join-Path -Path $repoRoot -ChildPath "Modules\SharePointDsc" $mainModule = Join-Path -Path $moduleRoot -ChildPath "SharePointDsc.psd1" - Import-Module -Name $mainModule -Global -Force + Import-Module -Name $mainModule -Global if ($PSBoundParameters.ContainsKey("SubModulePath") -eq $true) { @@ -50,7 +50,7 @@ function New-SPDscUnitTestHelper $describeHeader += " [SP Build: $spBuild]" - Import-Module -Name $moduleToLoad -Global -Force + Import-Module -Name $moduleToLoad -Global From 66eafa225cc8988b4375e94c873eaafc333a2f91 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Mon, 8 Oct 2018 08:29:42 +0200 Subject: [PATCH 060/101] Fixed an incorrect site reference --- Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 29ef290dd..1a6b84a8d 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -368,7 +368,7 @@ function Set-TargetResource $secondaryOwnerLogin = $systemAccountSite.SecondaryOwnerAlias.UserLogin; } - $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($centralAdminSite.Id, $centralAdminSite.SystemAccount.UserToken) + $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($systemAccountSite.Owner.UserLogin, $secondaryOwnerLogin, $null) From 287a6b0c59e601ad38e959d0206eca0e9c3dc841 Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Mon, 8 Oct 2018 08:38:31 +0200 Subject: [PATCH 061/101] Fixed site was retrieved too late --- Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 1a6b84a8d..3c762ee0a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -358,6 +358,7 @@ function Set-TargetResource $centralAdminWebApp = [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]::Local $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url + $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) if($null -eq $systemAccountSite.SecondaryOwnerAlias) { @@ -368,7 +369,6 @@ function Set-TargetResource $secondaryOwnerLogin = $systemAccountSite.SecondaryOwnerAlias.UserLogin; } - $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($systemAccountSite.Owner.UserLogin, $secondaryOwnerLogin, $null) From 446b7e94e7176a94a17abf6dad0ca287904c847b Mon Sep 17 00:00:00 2001 From: Jens oto Hatlevold Date: Mon, 8 Oct 2018 09:06:56 +0200 Subject: [PATCH 062/101] Fixed incorrect secondary contact property name --- .../SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 index 3c762ee0a..6fe4f238c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSite/MSFT_SPSite.psm1 @@ -360,13 +360,13 @@ function Set-TargetResource $centralAdminSite = Get-SPSite -Identity $centralAdminWebApp.Url $systemAccountSite = New-Object "Microsoft.SharePoint.SPSite" -ArgumentList @($site.Id, $centralAdminSite.SystemAccount.UserToken) - if($null -eq $systemAccountSite.SecondaryOwnerAlias) + if($null -eq $systemAccountSite.SecondaryContact) { $secondaryOwnerLogin = $null; } else { - $secondaryOwnerLogin = $systemAccountSite.SecondaryOwnerAlias.UserLogin; + $secondaryOwnerLogin = $systemAccountSite.SecondaryContact.UserLogin; } $systemAccountSite.RootWeb.CreateDefaultAssociatedGroups($systemAccountSite.Owner.UserLogin, From 02a3ec050e0f7e6509230288c52481ab70105420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Fri, 5 Oct 2018 15:19:52 +0200 Subject: [PATCH 063/101] SPManagedMetaDataServiceApp: Add ContentType properties --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 103 +- ...SFT_SPManagedMetaDataServiceApp.schema.mof | 2 + ...tDsc.SPManagedMetadataServiceApp.Tests.ps1 | 2330 +++++++++-------- 3 files changed, 1282 insertions(+), 1153 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index b27a7f92e..83c15da37 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -45,6 +45,14 @@ function Get-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -94,6 +102,13 @@ function Get-TargetResource } } + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $proxyName + if($null -ne $proxy) + { + $contentTypePushDownEnabled = $proxy.Properties["IsContentTypePushdownEnabled"] + $contentTypeSyndicationEnabled = $proxy.Properties["IsNPContentTypeSyndicationEnabled"] + } + # Get the ContentTypeHubUrl value $hubUrl = "" try @@ -196,17 +211,19 @@ function Get-TargetResource } return @{ - Name = $serviceApp.DisplayName - ProxyName = $proxyName - Ensure = "Present" - ApplicationPool = $serviceApp.ApplicationPool.Name - DatabaseName = $serviceApp.Database.Name - DatabaseServer = $serviceApp.Database.NormalizedDataSource - TermStoreAdministrators = $currentAdmins - ContentTypeHubUrl = $hubUrl - DefaultLanguage = $termStoreDefaultLanguage - Languages = $termStoreLanguages - InstallAccount = $params.InstallAccount + Name = $serviceApp.DisplayName + ProxyName = $proxyName + Ensure = "Present" + ApplicationPool = $serviceApp.ApplicationPool.Name + DatabaseName = $serviceApp.Database.Name + DatabaseServer = $serviceApp.Database.NormalizedDataSource + TermStoreAdministrators = $currentAdmins + ContentTypeHubUrl = $hubUrl + DefaultLanguage = $termStoreDefaultLanguage + Languages = $termStoreLanguages + ContentTypePushdownEnabled = $contentTypePushDownEnabled + ContentTypeSyndicationEnabled = $contentTypeSyndicationEnabled + InstallAccount = $params.InstallAccount } } } @@ -259,6 +276,14 @@ function Set-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -552,6 +577,44 @@ function Set-TargetResource } } } + + if (($PSBoundParameters.ContainsKey("ContentTypePushdownEnabled") -eq $true) ` + -and ($ContentTypePushdownEnabled -ne $result.ContentTypePushdownEnabled) + ) + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $result, $pName) ` + -ScriptBlock { + $params = $args[0] + $pName = $args[2] + + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName + if($null -ne $proxy) + { + $proxy.Properties["IsContentTypePushdownEnabled"] = $params.ContentTypePushdownEnabled + $proxy.Update() + } + } + } + + if (($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) ` + -and ($ContentTypeSyndicationEnabled -ne $result.ContentTypeSyndicationEnabled) + ) + { + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments @($PSBoundParameters, $result, $pName) ` + -ScriptBlock { + $params = $args[0] + $pName = $args[2] + + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName + if($null -ne $proxy) + { + $proxy.Properties["IsNPContentTypeSyndicationEnabled"] = $params.ContentTypeSyndicationEnabled + $proxy.Update() + } + } + } } if ($Ensure -eq "Absent") @@ -628,6 +691,14 @@ function Test-TargetResource [System.UInt32[]] $Languages, + [Parameter()] + [System.Boolean] + $ContentTypePushdownEnabled, + + [Parameter()] + [System.Boolean] + $ContentTypeSyndicationEnabled, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -665,6 +736,16 @@ function Test-TargetResource $valuesToCheck += "Languages" } + if ($PSBoundParameters.ContainsKey("ContentTypePushdownEnabled") -eq $true) + { + $valuesToCheck += "ContentTypePushdownEnabled" + } + + if ($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) + { + $valuesToCheck += "ContentTypeSyndicationEnabled" + } + $CurrentValues = Get-TargetResource @PSBoundParameters return Test-SPDscParameterState -CurrentValues $CurrentValues ` diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof index e8aad7910..c6e4be106 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.schema.mof @@ -11,5 +11,7 @@ class MSFT_SPManagedMetaDataServiceApp : OMI_BaseResource [Write, Description("The URL of the content type hub for this app (only set when the app is provisioned)")] string ContentTypeHubUrl; [Write, Description("The LCID of the default language (only set when the app is provisioned)")] UInt32 DefaultLanguage; [Write, Description("The LCIDs of the working languages (only set when the app is provisioned)")] UInt32 Languages[]; + [Write, Description("Specifies that existing instances of changed content types in subsites and libraries will be updated.")] boolean ContentTypePushdownEnabled; + [Write, Description("Specifies that this connection will provide access to the content types that are associated with the managed metadata service application.")] boolean ContentTypeSyndicationEnabled; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index 5a86294a0..35ae61c92 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -42,6 +42,19 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ) } + Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { + return @{ + Name = "Managed Metadata Service App Proxy" + Properties = @{ + IsNPContentTypeSyndicationEnabled = $true + IsContentTypePushdownEnabled = $true + } + } | Add-Member -MemberType ScriptMethod ` + -Name update ` + -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -PassThru -Force + } + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { return @( @{ @@ -147,82 +160,1092 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { "@ } - # Test contexts - Context -Name "When no service applications exist in the current farm" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - TermStoreAdministrators = @() - ContentTypeHubUrl = "" - ProxyName = "Proxy Name" - DefaultLanguage = 1033 - Languages = @() - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { return $null } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should create a new service application in the set method" { - Set-TargetResource @testParams - Assert-MockCalled New-SPMetadataServiceApplication - } - } - - Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - DisplayName = $testParams.Name - } - $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return @{ - FullName = "Microsoft.Office.UnKnownWebServiceApplication" - } - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - } + # # Test contexts + # Context -Name "When no service applications exist in the current farm" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # TermStoreAdministrators = @() + # ContentTypeHubUrl = "" + # ProxyName = "Proxy Name" + # DefaultLanguage = 1033 + # Languages = @() + # ContentTypePushdownEnabled = $true + # ContentTypeSyndicationEnabled = $true + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should create a new service application in the set method" { + # Set-TargetResource @testParams + # Assert-MockCalled New-SPMetadataServiceApplication + # } + # } + + # Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # DisplayName = $testParams.Name + # } + # $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return @{ + # FullName = "Microsoft.Office.UnKnownWebServiceApplication" + # } + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + # } + + # Context -Name "When a service application exists and is configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # It "Should return present from the get method" { + # $results = Get-TargetResource @testParams + # $results.Ensure | Should Be "Present" + # $results.ContentTypeHubUrl | Should Not BeNullOrEmpty + # } + + # It "Should return true when the Test method is called" { + # Test-TargetResource @testParams | Should Be $true + # } + # } + + + # Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationPool -MockWith { + # return @{ + # Name = $testParams.ApplicationPool + # } + # } + + # It "Should return Wrong App Pool Name from the Get method" { + # (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the update service app cmdlet from the set method" { + # Set-TargetResource @testParams + + # Assert-MockCalled Get-SPServiceApplicationPool + # Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { + # $ApplicationPool.Name -eq $testParams.ApplicationPool + # } + # } + # } + + # Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # ContentTypeHubUrl = "https://contenttypes.contoso.com" + # Ensure = "Present" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "https://contenttypes.contoso.com/wrong" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "https://contenttypes.contoso.com/wrong" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationPool -MockWith { + # return @{ + # Name = $testParams.ApplicationPool + # } + # } + + # It "Should return wrong content type url from the Get method" { + # (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the update service app cmdlet from the set method" { + # Set-TargetResource @testParams + + # Assert-MockCalled Set-SPMetadataServiceApplication + # } + # } + + # Context -Name "When the service application exists but it shouldn't" -Fixture { + # $testParams = @{ + # Name = "Test App" + # ApplicationPool = "-" + # Ensure = "Absent" + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + # { + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = "Wrong App Pool Name" + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name FullName ` + # -Value $getTypeFullName ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetProperties ` + # -Value { + # param($x) + # return @( + # (New-Object -TypeName "Object" | + # Add-Member -MemberType NoteProperty ` + # -Name Name ` + # -Value "DatabaseMapper" ` + # -PassThru | + # Add-Member -MemberType ScriptMethod ` + # -Name GetValue ` + # -Value { + # param($x) + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@{ + # Name = "GetContentTypeSyndicationHubLocal" + # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru + # ) + # ) + # } -PassThru + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "Managed Metadata Service App Proxy" + # } | Add-Member -MemberType ScriptMethod ` + # -Name Update ` + # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name Delete ` + # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + # -PassThru -Force + # ) + # } + + # It "Should return present from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Present" + # } + + # It "Should return false when the Test method is called" { + # Test-TargetResource @testParams | Should Be $false + # } + + # It "Should call the remove service application cmdlet in the set method" { + # $Global:SPDscServiceProxyDeleteCalled = $false + + # Set-TargetResource @testParams + # Assert-MockCalled Remove-SPServiceApplication + # $Global:SPDscServiceProxyDeleteCalled | Should be $true + # } + # } + + # Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + # $testParams = @{ + # Name = "Test App" + # ApplicationPool = "-" + # Ensure = "Absent" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # return $null + # } + + # It "Should return absent from the Get method" { + # (Get-TargetResource @testParams).Ensure | Should Be "Absent" + # } + + # It "Should return true when the Test method is called" { + # Test-TargetResource @testParams | Should Be $true + # } + # } + + # Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return true from the test method" { + # Test-TargetResource @testParams | Should be $true + # } + # } + + # Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1", + # "CONTOSO\User2" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return true from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the add method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscAddUserCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @( + # "CONTOSO\User1" + # ) + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # NormalizedDataSource = $testParams.DatabaseServer + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # $termStores = @{ + # "Managed Metadata Service App Proxy" = @{ + # Name = "Managed Metadata Service App Proxy" + # Languages = @(1033) + # DefaultLanguage = 1033 + # WorkingLanguage = 1033 + # TermStoreAdministrators = @( + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "Contoso\User1" + # IsWindowsAuthenticationMode = $true + # } + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "Contoso\User2" + # IsWindowsAuthenticationMode = $true + # } + # ) + # } | Add-Member -MemberType ScriptMethod ` + # -Name AddTermStoreAdministrator ` + # -Value { $Global:SPDscAddUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteTermStoreAdministrator ` + # -Value { $Global:SPDscDeleteUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name AddLanguage ` + # -Value { $Global:SPDscAddLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteLanguage ` + # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force + # } + + # Mock -CommandName Get-SPTaxonomySession -MockWith { + # return @{ + # TermStores = $termStores + # } + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscDeleteUserCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and the proxy name has to be changed" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ProxyName = "Managed Metadata Service App ProxyName" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @() + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return (@{ + # FullName = $getTypeFullName + # }) + # } -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + + # return $spServiceApp + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "$($testParams.Name) Proxy Test" + # } | Add-Member -MemberType ScriptMethod ` + # -Name Update ` + # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name Delete ` + # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + # -PassThru -Force + # ) + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscServiceProxyUpdateCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscServiceProxyUpdateCalled | Should Be $true + # } + # } + + # Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # TermStoreAdministrators = @() + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + # return (@{ + # FullName = $getTypeFullName + # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + # return (@( + # Name = "GetContentTypeSyndicationHubLocal" + # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + # return @{ + # AbsoluteUri = "" + # } + # } -PassThru -Force + # } -PassThru -Force + # } -PassThru -Force + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return $true + # } -PassThru -Force + # return $spServiceApp + # } + + # $termStores = @{ + # "Managed Metadata Service App Proxy" = @{ + # Name = "Managed Metadata Service App Proxy" + # Languages = @(1033) + # DefaultLanguage = 1033 + # WorkingLanguage = 1033 + # TermStoreAdministrators = @( + # New-Object -TypeName PSObject -Property @{ + # PrincipalName = "i:0#.w|Contoso\User2" + # IsWindowsAuthenticationMode = $false + # } + # ) + # } | Add-Member -MemberType ScriptMethod ` + # -Name AddTermStoreAdministrator ` + # -Value { $Global:SPDscAddUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteTermStoreAdministrator ` + # -Value { $Global:SPDscDeleteUserCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name AddLanguage ` + # -Value { $Global:SPDscAddLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name DeleteLanguage ` + # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + # -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name CommitAll ` + # -Value { } ` + # -PassThru -Force + # } + + # Mock -CommandName Get-SPTaxonomySession -MockWith { + # return @{ + # TermStores = $termStores + # } + # } + + # It "Should return the current users from the get method" { + # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + # } + + # It "Should return false from the test method" { + # Test-TargetResource @testParams | Should be $false + # } + + # It "Should call the delete method from the set method" { + # $Global:SPDscAddUserCalled = $false + # $Global:SPDscDeleteUserCalled = $false + # Set-TargetResource @testParams + + # $Global:SPDscDeleteUserCalled | Should Be $true + # } + # } + + # # New Test + # Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { + # $testParams = @{ + # Name = "Managed Metadata Service App" + # ApplicationPool = "SharePoint Service Applications" + # DatabaseServer = "databaseserver\instance" + # DatabaseName = "SP_MMS" + # Ensure = "Present" + # } + + # Mock -CommandName Get-SPServiceApplication -MockWith { + # $spServiceApp = [PSCustomObject]@{ + # TypeName = "Managed Metadata Service" + # DisplayName = $testParams.Name + # ApplicationPool = @{ + # Name = $testParams.ApplicationPool + # } + # Database = @{ + # Name = $testParams.DatabaseName + # Server = @{ Name = $testParams.DatabaseServer } + # } + # } + # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + # -Name GetType ` + # -Value { + # return (@{ + # FullName = $getTypeFullName + # }) + # } -PassThru -Force ` + # | Add-Member -MemberType ScriptMethod ` + # -Name IsConnected ` + # -Value { + # param($x) + # return ($true) + # } -PassThru -Force + + # return $spServiceApp + # } + + # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + # return @( + # @{ + # Name = "$($testParams.Name) Proxy Test" + # } + # ) + # } + + # It "Should return the proxy name" { + # (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" + # } + # } - Context -Name "When a service application exists and is configured correctly" -Fixture { + Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $false + ContentTypeSyndicationEnabled = $false } if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) @@ -234,9 +1257,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -271,9 +1294,9 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { ApplicationPool = @{ Name = $testParams.ApplicationPool } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } } } $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { @@ -326,1090 +1349,113 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } - It "Should return present from the get method" { - $results = Get-TargetResource @testParams - $results.Ensure | Should Be "Present" - $results.ContentTypeHubUrl | Should Not BeNullOrEmpty - } - - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $true - } - } - - - Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp + $termStoreAdmins = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User2" + IsWindowsAuthenticationMode = $true } + ) + $termStoreAdmins = $termStoreAdmins | Add-Member -MemberType ScriptMethod ` + -Name DoesUserHavePermissions ` + -Value { + param ($userName) + return $true + } -PassThru -Force + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1031) + DefaultLanguage = 1031 + WorkingLanguage = 1033 + TermStoreAdministrators = $termStoreAdmins + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force } - Mock -CommandName Get-SPServiceApplicationPool -MockWith { + Mock -CommandName Get-SPTaxonomySession -MockWith { return @{ - Name = $testParams.ApplicationPool + TermStores = $termStores } } - It "Should return Wrong App Pool Name from the Get method" { - (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + $metadataServiceApplicationProxy = @{ + Name = "Managed Metadata Service App Proxy" + Properties = @{ + IsContentTypePushdownEnabled = $true + IsNPContentTypeSyndicationEnabled = $true + } + } | Add-Member -MemberType ScriptMethod ` + -Name update ` + -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -PassThru -Force + + Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { + return $metadataServiceApplicationProxy } It "Should return false when the Test method is called" { Test-TargetResource @testParams | Should Be $false } - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams + It "Should match the mocked values" { + $result = Get-TargetResource @testParams + $result.DefaultLanguage | Should Be 1031 + $result.Languages | Should Be @(1031) + } - Assert-MockCalled Get-SPServiceApplicationPool - Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { - $ApplicationPool.Name -eq $testParams.ApplicationPool - } + It "Should change the value for 'Default Language'" { + $result = Get-TargetResource @testParams + Set-TargetResource @testParams + $termStores["$($result.ProxyName)"].DefaultLanguage | Should Be $testParams.DefaultLanguage } - } - Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - ContentTypeHubUrl = "https://contenttypes.contoso.com" - Ensure = "Present" + It "Should change the value for 'Languages'" { + $Global:SPDscAddLanguageCalled = $false + $Global:SPDscDeleteLanguageCalled = $false + Set-TargetResource @testParams + $Global:SPDscAddLanguageCalled | Should Be $true + $Global:SPDscDeleteLanguageCalled | Should Be $true } - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "https://contenttypes.contoso.com/wrong" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } + It "Should change the value for 'ContentTypePushdownEnabled'" { + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false + Set-TargetResource @testParams + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true + # $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $false } - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "https://contenttypes.contoso.com/wrong" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp - } - } - - Mock -CommandName Get-SPServiceApplicationPool -MockWith { - return @{ - Name = $testParams.ApplicationPool - } - } - - It "Should return wrong content type url from the Get method" { - (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should call the update service app cmdlet from the set method" { - Set-TargetResource @testParams - - Assert-MockCalled Set-SPMetadataServiceApplication - } - } - - Context -Name "When the service application exists but it shouldn't" -Fixture { - $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = "Wrong App Pool Name" - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "Managed Metadata Service App Proxy" - } | Add-Member -MemberType ScriptMethod ` - -Name Update ` - -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name Delete ` - -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - -PassThru -Force - ) - } - - It "Should return present from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Present" - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should call the remove service application cmdlet in the set method" { - $Global:SPDscServiceProxyDeleteCalled = $false - - Set-TargetResource @testParams - Assert-MockCalled Remove-SPServiceApplication - $Global:SPDscServiceProxyDeleteCalled | Should be $true - } - } - - Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { - $testParams = @{ - Name = "Test App" - ApplicationPool = "-" - Ensure = "Absent" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - return $null - } - - It "Should return absent from the Get method" { - (Get-TargetResource @testParams).Ensure | Should Be "Absent" - } - - It "Should return true when the Test method is called" { - Test-TargetResource @testParams | Should Be $true - } - } - - Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return true from the test method" { - Test-TargetResource @testParams | Should be $true - } - } - - Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1", - "CONTOSO\User2" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return true from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the add method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscAddUserCalled | Should Be $true - } - } - - Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @( - "CONTOSO\User1" - ) - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - NormalizedDataSource = $testParams.DatabaseServer - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1033) - DefaultLanguage = 1033 - WorkingLanguage = 1033 - TermStoreAdministrators = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User1" - IsWindowsAuthenticationMode = $true - } - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User2" - IsWindowsAuthenticationMode = $true - } - ) - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscDeleteUserCalled | Should Be $true - } - } - - Context -Name "A service app exists and the proxy name has to be changed" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ProxyName = "Managed Metadata Service App ProxyName" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @() - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return (@{ - FullName = $getTypeFullName - }) - } -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - - return $spServiceApp - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "$($testParams.Name) Proxy Test" - } | Add-Member -MemberType ScriptMethod ` - -Name Update ` - -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name Delete ` - -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - -PassThru -Force - ) - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscServiceProxyUpdateCalled = $false - Set-TargetResource @testParams - - $Global:SPDscServiceProxyUpdateCalled | Should Be $true - } - } - - Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - TermStoreAdministrators = @() - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@( - Name = "GetContentTypeSyndicationHubLocal" - )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1033) - DefaultLanguage = 1033 - WorkingLanguage = 1033 - TermStoreAdministrators = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "i:0#.w|Contoso\User2" - IsWindowsAuthenticationMode = $false - } - ) - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return the current users from the get method" { - (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - } - - It "Should return false from the test method" { - Test-TargetResource @testParams | Should be $false - } - - It "Should call the delete method from the set method" { - $Global:SPDscAddUserCalled = $false - $Global:SPDscDeleteUserCalled = $false - Set-TargetResource @testParams - - $Global:SPDscDeleteUserCalled | Should Be $true - } - } - - # New Test - Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service App" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - } - - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name GetType ` - -Value { - return (@{ - FullName = $getTypeFullName - }) - } -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return ($true) - } -PassThru -Force - - return $spServiceApp - } - - Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - return @( - @{ - Name = "$($testParams.Name) Proxy Test" - } - ) - } - - It "Should return the proxy name" { - (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" - } - } - - Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { - $testParams = @{ - Name = "Managed Metadata Service Application" - ApplicationPool = "SharePoint Service Applications" - DatabaseServer = "databaseserver\instance" - DatabaseName = "SP_MMS" - Ensure = "Present" - DefaultLanguage = 1033 - Languages = @(1033) - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - { - Mock -CommandName Get-SPServiceApplication -MockWith { - $spServiceApp = [PSCustomObject]@{ - TypeName = "Managed Metadata Service" - DisplayName = $testParams.Name - ApplicationPool = @{ - Name = $testParams.ApplicationPool - } - Database = @{ - Name = $testParams.DatabaseName - Server = @{ Name = $testParams.DatabaseServer } - } - } - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name FullName ` - -Value $getTypeFullName ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetProperties ` - -Value { - param($x) - return @( - (New-Object -TypeName "Object" | - Add-Member -MemberType NoteProperty ` - -Name Name ` - -Value "DatabaseMapper" ` - -PassThru | - Add-Member -MemberType ScriptMethod ` - -Name GetValue ` - -Value { - param($x) - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - return (@{ - FullName = $getTypeFullName - }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - return (@{ - Name = "GetContentTypeSyndicationHubLocal" - }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - return @{ - AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - } - } -PassThru -Force - } -PassThru -Force - } -PassThru -Force - } -PassThru - ) - ) - } -PassThru - } -PassThru -Force - $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - -Name IsConnected ` - -Value { - param($x) - return $true - } -PassThru -Force - return $spServiceApp - } - } - - $termStoreAdmins = @( - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User1" - IsWindowsAuthenticationMode = $true - } - New-Object -TypeName PSObject -Property @{ - PrincipalName = "Contoso\User2" - IsWindowsAuthenticationMode = $true - } - ) - $termStoreAdmins = $termStoreAdmins | Add-Member -MemberType ScriptMethod ` - -Name DoesUserHavePermissions ` - -Value { - param ($userName) - return $true - } -PassThru -Force - - $termStores = @{ - "Managed Metadata Service App Proxy" = @{ - Name = "Managed Metadata Service App Proxy" - Languages = @(1031) - DefaultLanguage = 1031 - WorkingLanguage = 1033 - TermStoreAdministrators = $termStoreAdmins - } | Add-Member -MemberType ScriptMethod ` - -Name AddTermStoreAdministrator ` - -Value { $Global:SPDscAddUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteTermStoreAdministrator ` - -Value { $Global:SPDscDeleteUserCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name AddLanguage ` - -Value { $Global:SPDscAddLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name DeleteLanguage ` - -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - -PassThru -Force ` - | Add-Member -MemberType ScriptMethod ` - -Name CommitAll ` - -Value { } ` - -PassThru -Force - } - - Mock -CommandName Get-SPTaxonomySession -MockWith { - return @{ - TermStores = $termStores - } - } - - It "Should return false when the Test method is called" { - Test-TargetResource @testParams | Should Be $false - } - - It "Should match the mocked values" { - $result = Get-TargetResource @testParams - $result.DefaultLanguage | Should Be 1031 - $result.Languages | Should Be @(1031) - } - - It "Should change the value for 'Default Language'" { - $result = Get-TargetResource @testParams - Set-TargetResource @testParams - $termStores["$($result.ProxyName)"].DefaultLanguage | Should Be $testParams.DefaultLanguage - } - - It "Should change the value for 'Languages'" { - $Global:SPDscAddLanguageCalled = $false - $Global:SPDscDeleteLanguageCalled = $false + It "Should change the value for 'ContentTypeSyndicationEnabled'" { + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams - $Global:SPDscAddLanguageCalled | Should Be $true - $Global:SPDscDeleteLanguageCalled | Should Be $true + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true + # $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $false } } From b3a75167592f4aaa5c3af7485f770be186a60820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sat, 6 Oct 2018 00:21:54 +0200 Subject: [PATCH 064/101] Added example and changelog --- CHANGELOG.md | 6 ++++ .../6-SetContentTypeSettings.ps1 | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index f59878768..aa5729c2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,8 +43,14 @@ * Added ability to check and update CentralAdministrationPort * SPLogLevel * Added High as TraceLevel, which was not included yet +<<<<<<< HEAD * SPRemoteFarmTrust * Updated readme.md file to add a link that was lost during earlier updates +======= +* SPManagedMetadataServiceApp + * Added additional content type settings (ContentTypePushdownEnabled & + ContentTypeSyndicationEnabled). +>>>>>>> Added example and changelog * SPSearchServiceApp * Updated Set method to check if service application pool exists. Resource will throw an error if it does not exist diff --git a/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 new file mode 100644 index 000000000..a46d6396a --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPManagedMetaDataServiceApp/6-SetContentTypeSettings.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to deploy the Managed Metadata service app to the local SharePoint farm + and also include a specific list of users to be the term store administrators. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPManagedMetaDataServiceApp ManagedMetadataServiceApp + { + Name = "Managed Metadata Service Application" + PSDscRunAsCredential = $SetupAccount + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "SP_ManagedMetadata" + ContentTypeHubUrl = "http://contoso.sharepoint.com/sites/ct" + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $true + } + } +} From 80df3f6e06379ec8c05a0f17f2a01de3ddaf3a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sat, 6 Oct 2018 00:27:21 +0200 Subject: [PATCH 065/101] update to readme --- .../DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md index 1283f8583..2dc8bc8b6 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/readme.md @@ -16,3 +16,6 @@ The content type hub url will be set or reset. The language settings (default and working) are only changed if they are part of the bound parameters. Otherwise they will not be altered. + +ContentTypePushdownEnabled and ContentTypeSyndicationEnabled will only be altered +if they are part of the bound parameters. From 0cb480cde3f6dfe4911bb3875b4dc917fbc14344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Sun, 7 Oct 2018 20:00:03 +0200 Subject: [PATCH 066/101] Fixed Tests --- ...tDsc.SPManagedMetadataServiceApp.Tests.ps1 | 2180 +++++++++-------- 1 file changed, 1102 insertions(+), 1078 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index 35ae61c92..0a2a2e9a5 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -160,1080 +160,1080 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { "@ } - # # Test contexts - # Context -Name "When no service applications exist in the current farm" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # TermStoreAdministrators = @() - # ContentTypeHubUrl = "" - # ProxyName = "Proxy Name" - # DefaultLanguage = 1033 - # Languages = @() - # ContentTypePushdownEnabled = $true - # ContentTypeSyndicationEnabled = $true - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { return $null } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should create a new service application in the set method" { - # Set-TargetResource @testParams - # Assert-MockCalled New-SPMetadataServiceApplication - # } - # } - - # Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # DisplayName = $testParams.Name - # } - # $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return @{ - # FullName = "Microsoft.Office.UnKnownWebServiceApplication" - # } - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - # } - - # Context -Name "When a service application exists and is configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # It "Should return present from the get method" { - # $results = Get-TargetResource @testParams - # $results.Ensure | Should Be "Present" - # $results.ContentTypeHubUrl | Should Not BeNullOrEmpty - # } - - # It "Should return true when the Test method is called" { - # Test-TargetResource @testParams | Should Be $true - # } - # } - - - # Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationPool -MockWith { - # return @{ - # Name = $testParams.ApplicationPool - # } - # } - - # It "Should return Wrong App Pool Name from the Get method" { - # (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the update service app cmdlet from the set method" { - # Set-TargetResource @testParams - - # Assert-MockCalled Get-SPServiceApplicationPool - # Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { - # $ApplicationPool.Name -eq $testParams.ApplicationPool - # } - # } - # } - - # Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # ContentTypeHubUrl = "https://contenttypes.contoso.com" - # Ensure = "Present" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "https://contenttypes.contoso.com/wrong" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "https://contenttypes.contoso.com/wrong" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationPool -MockWith { - # return @{ - # Name = $testParams.ApplicationPool - # } - # } - - # It "Should return wrong content type url from the Get method" { - # (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the update service app cmdlet from the set method" { - # Set-TargetResource @testParams - - # Assert-MockCalled Set-SPMetadataServiceApplication - # } - # } - - # Context -Name "When the service application exists but it shouldn't" -Fixture { - # $testParams = @{ - # Name = "Test App" - # ApplicationPool = "-" - # Ensure = "Absent" - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) - # { - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = "Wrong App Pool Name" - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name FullName ` - # -Value $getTypeFullName ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetProperties ` - # -Value { - # param($x) - # return @( - # (New-Object -TypeName "Object" | - # Add-Member -MemberType NoteProperty ` - # -Name Name ` - # -Value "DatabaseMapper" ` - # -PassThru | - # Add-Member -MemberType ScriptMethod ` - # -Name GetValue ` - # -Value { - # param($x) - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@{ - # Name = "GetContentTypeSyndicationHubLocal" - # }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru - # ) - # ) - # } -PassThru - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "Managed Metadata Service App Proxy" - # } | Add-Member -MemberType ScriptMethod ` - # -Name Update ` - # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name Delete ` - # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - # -PassThru -Force - # ) - # } - - # It "Should return present from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Present" - # } - - # It "Should return false when the Test method is called" { - # Test-TargetResource @testParams | Should Be $false - # } - - # It "Should call the remove service application cmdlet in the set method" { - # $Global:SPDscServiceProxyDeleteCalled = $false - - # Set-TargetResource @testParams - # Assert-MockCalled Remove-SPServiceApplication - # $Global:SPDscServiceProxyDeleteCalled | Should be $true - # } - # } - - # Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { - # $testParams = @{ - # Name = "Test App" - # ApplicationPool = "-" - # Ensure = "Absent" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # return $null - # } - - # It "Should return absent from the Get method" { - # (Get-TargetResource @testParams).Ensure | Should Be "Absent" - # } - - # It "Should return true when the Test method is called" { - # Test-TargetResource @testParams | Should Be $true - # } - # } - - # Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return true from the test method" { - # Test-TargetResource @testParams | Should be $true - # } - # } - - # Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1", - # "CONTOSO\User2" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return true from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the add method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscAddUserCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @( - # "CONTOSO\User1" - # ) - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # NormalizedDataSource = $testParams.DatabaseServer - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # $termStores = @{ - # "Managed Metadata Service App Proxy" = @{ - # Name = "Managed Metadata Service App Proxy" - # Languages = @(1033) - # DefaultLanguage = 1033 - # WorkingLanguage = 1033 - # TermStoreAdministrators = @( - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "Contoso\User1" - # IsWindowsAuthenticationMode = $true - # } - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "Contoso\User2" - # IsWindowsAuthenticationMode = $true - # } - # ) - # } | Add-Member -MemberType ScriptMethod ` - # -Name AddTermStoreAdministrator ` - # -Value { $Global:SPDscAddUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteTermStoreAdministrator ` - # -Value { $Global:SPDscDeleteUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name AddLanguage ` - # -Value { $Global:SPDscAddLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteLanguage ` - # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force - # } - - # Mock -CommandName Get-SPTaxonomySession -MockWith { - # return @{ - # TermStores = $termStores - # } - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscDeleteUserCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and the proxy name has to be changed" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ProxyName = "Managed Metadata Service App ProxyName" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @() - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return (@{ - # FullName = $getTypeFullName - # }) - # } -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - - # return $spServiceApp - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "$($testParams.Name) Proxy Test" - # } | Add-Member -MemberType ScriptMethod ` - # -Name Update ` - # -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name Delete ` - # -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` - # -PassThru -Force - # ) - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscServiceProxyUpdateCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscServiceProxyUpdateCalled | Should Be $true - # } - # } - - # Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # TermStoreAdministrators = @() - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { - # return (@{ - # FullName = $getTypeFullName - # }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { - # return (@( - # Name = "GetContentTypeSyndicationHubLocal" - # )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { - # return @{ - # AbsoluteUri = "" - # } - # } -PassThru -Force - # } -PassThru -Force - # } -PassThru -Force - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return $true - # } -PassThru -Force - # return $spServiceApp - # } - - # $termStores = @{ - # "Managed Metadata Service App Proxy" = @{ - # Name = "Managed Metadata Service App Proxy" - # Languages = @(1033) - # DefaultLanguage = 1033 - # WorkingLanguage = 1033 - # TermStoreAdministrators = @( - # New-Object -TypeName PSObject -Property @{ - # PrincipalName = "i:0#.w|Contoso\User2" - # IsWindowsAuthenticationMode = $false - # } - # ) - # } | Add-Member -MemberType ScriptMethod ` - # -Name AddTermStoreAdministrator ` - # -Value { $Global:SPDscAddUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteTermStoreAdministrator ` - # -Value { $Global:SPDscDeleteUserCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name AddLanguage ` - # -Value { $Global:SPDscAddLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name DeleteLanguage ` - # -Value { $Global:SPDscDeleteLanguageCalled = $true } ` - # -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name CommitAll ` - # -Value { } ` - # -PassThru -Force - # } - - # Mock -CommandName Get-SPTaxonomySession -MockWith { - # return @{ - # TermStores = $termStores - # } - # } - - # It "Should return the current users from the get method" { - # (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty - # } - - # It "Should return false from the test method" { - # Test-TargetResource @testParams | Should be $false - # } - - # It "Should call the delete method from the set method" { - # $Global:SPDscAddUserCalled = $false - # $Global:SPDscDeleteUserCalled = $false - # Set-TargetResource @testParams - - # $Global:SPDscDeleteUserCalled | Should Be $true - # } - # } - - # # New Test - # Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { - # $testParams = @{ - # Name = "Managed Metadata Service App" - # ApplicationPool = "SharePoint Service Applications" - # DatabaseServer = "databaseserver\instance" - # DatabaseName = "SP_MMS" - # Ensure = "Present" - # } - - # Mock -CommandName Get-SPServiceApplication -MockWith { - # $spServiceApp = [PSCustomObject]@{ - # TypeName = "Managed Metadata Service" - # DisplayName = $testParams.Name - # ApplicationPool = @{ - # Name = $testParams.ApplicationPool - # } - # Database = @{ - # Name = $testParams.DatabaseName - # Server = @{ Name = $testParams.DatabaseServer } - # } - # } - # $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` - # -Name GetType ` - # -Value { - # return (@{ - # FullName = $getTypeFullName - # }) - # } -PassThru -Force ` - # | Add-Member -MemberType ScriptMethod ` - # -Name IsConnected ` - # -Value { - # param($x) - # return ($true) - # } -PassThru -Force - - # return $spServiceApp - # } - - # Mock -CommandName Get-SPServiceApplicationProxy -MockWith { - # return @( - # @{ - # Name = "$($testParams.Name) Proxy Test" - # } - # ) - # } - - # It "Should return the proxy name" { - # (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" - # } - # } + # Test contexts + Context -Name "When no service applications exist in the current farm" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + TermStoreAdministrators = @() + ContentTypeHubUrl = "" + ProxyName = "Proxy Name" + DefaultLanguage = 1033 + Languages = @() + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $true + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { return $null } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should create a new service application in the set method" { + Set-TargetResource @testParams + Assert-MockCalled New-SPMetadataServiceApplication + } + } + + Context -Name "When service applications exist in the current farm but the specific MMS app does not" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + DisplayName = $testParams.Name + } + $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return @{ + FullName = "Microsoft.Office.UnKnownWebServiceApplication" + } + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + } + + Context -Name "When a service application exists and is configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "http://contoso.sharepoint.com/sites/ct" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + It "Should return present from the get method" { + $results = Get-TargetResource @testParams + $results.Ensure | Should Be "Present" + $results.ContentTypeHubUrl | Should Not BeNullOrEmpty + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + + Context -Name "When a service application exists and the app pool is not configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + It "Should return Wrong App Pool Name from the Get method" { + (Get-TargetResource @testParams).ApplicationPool | Should Be "Wrong App Pool Name" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Get-SPServiceApplicationPool + Assert-MockCalled Set-SPMetadataServiceApplication -ParameterFilter { + $ApplicationPool.Name -eq $testParams.ApplicationPool + } + } + } + + Context -Name "When a service application exists and the content type hub is not configured correctly" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + ContentTypeHubUrl = "https://contenttypes.contoso.com" + Ensure = "Present" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "https://contenttypes.contoso.com/wrong" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationPool -MockWith { + return @{ + Name = $testParams.ApplicationPool + } + } + + It "Should return wrong content type url from the Get method" { + (Get-TargetResource @testParams).ContentTypeHubUrl | Should Be "https://contenttypes.contoso.com/wrong" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the update service app cmdlet from the set method" { + Set-TargetResource @testParams + + Assert-MockCalled Set-SPMetadataServiceApplication + } + } + + Context -Name "When the service application exists but it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 15) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16) + { + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = "Wrong App Pool Name" + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name FullName ` + -Value $getTypeFullName ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetProperties ` + -Value { + param($x) + return @( + (New-Object -TypeName "Object" | + Add-Member -MemberType NoteProperty ` + -Name Name ` + -Value "DatabaseMapper" ` + -PassThru | + Add-Member -MemberType ScriptMethod ` + -Name GetValue ` + -Value { + param($x) + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@{ + Name = "GetContentTypeSyndicationHubLocal" + }) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + } -PassThru + ) + ) + } -PassThru + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "Managed Metadata Service App Proxy" + } | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + -PassThru -Force + ) + } + + It "Should return present from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Present" + } + + It "Should return false when the Test method is called" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call the remove service application cmdlet in the set method" { + $Global:SPDscServiceProxyDeleteCalled = $false + + Set-TargetResource @testParams + Assert-MockCalled Remove-SPServiceApplication + $Global:SPDscServiceProxyDeleteCalled | Should be $true + } + } + + Context -Name "When the service application doesn't exist and it shouldn't" -Fixture { + $testParams = @{ + Name = "Test App" + ApplicationPool = "-" + Ensure = "Absent" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + return $null + } + + It "Should return absent from the Get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return true when the Test method is called" { + Test-TargetResource @testParams | Should Be $true + } + } + + Context -Name "A service app exists and has a correct list of term store administrators" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $true + } + } + + Context -Name "A service app exists and is missing a user from the term store administrators list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1", + "CONTOSO\User2" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the add method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscAddUserCalled | Should Be $true + } + } + + Context -Name "A service app exists and has an extra user on the term store administrators list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @( + "CONTOSO\User1" + ) + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + NormalizedDataSource = $testParams.DatabaseServer + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1033) + DefaultLanguage = 1033 + WorkingLanguage = 1033 + TermStoreAdministrators = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User1" + IsWindowsAuthenticationMode = $true + } + New-Object -TypeName PSObject -Property @{ + PrincipalName = "Contoso\User2" + IsWindowsAuthenticationMode = $true + } + ) + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + } + + Mock -CommandName Get-SPTaxonomySession -MockWith { + return @{ + TermStores = $termStores + } + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscDeleteUserCalled | Should Be $true + } + } + + Context -Name "A service app exists and the proxy name has to be changed" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ProxyName = "Managed Metadata Service App ProxyName" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + + return $spServiceApp + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "$($testParams.Name) Proxy Test" + } | Add-Member -MemberType ScriptMethod ` + -Name Update ` + -Value { $Global:SPDscServiceProxyUpdateCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name Delete ` + -Value {$Global:SPDscServiceProxyDeleteCalled = $true } ` + -PassThru -Force + ) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscServiceProxyUpdateCalled = $false + Set-TargetResource @testParams + + $Global:SPDscServiceProxyUpdateCalled | Should Be $true + } + } + + Context -Name "A service app exists and has a non-windows term store administrator in the list" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + TermStoreAdministrators = @() + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value { + return (@{ + FullName = $getTypeFullName + }) | Add-Member -MemberType ScriptMethod -Name GetMethods -Value { + return (@( + Name = "GetContentTypeSyndicationHubLocal" + )) | Add-Member -MemberType ScriptMethod -Name Invoke -Value { + return @{ + AbsoluteUri = "" + } + } -PassThru -Force + } -PassThru -Force + } -PassThru -Force + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return $true + } -PassThru -Force + return $spServiceApp + } + + $termStores = @{ + "Managed Metadata Service App Proxy" = @{ + Name = "Managed Metadata Service App Proxy" + Languages = @(1033) + DefaultLanguage = 1033 + WorkingLanguage = 1033 + TermStoreAdministrators = @( + New-Object -TypeName PSObject -Property @{ + PrincipalName = "i:0#.w|Contoso\User2" + IsWindowsAuthenticationMode = $false + } + ) + } | Add-Member -MemberType ScriptMethod ` + -Name AddTermStoreAdministrator ` + -Value { $Global:SPDscAddUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteTermStoreAdministrator ` + -Value { $Global:SPDscDeleteUserCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name AddLanguage ` + -Value { $Global:SPDscAddLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name DeleteLanguage ` + -Value { $Global:SPDscDeleteLanguageCalled = $true } ` + -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name CommitAll ` + -Value { } ` + -PassThru -Force + } + + Mock -CommandName Get-SPTaxonomySession -MockWith { + return @{ + TermStores = $termStores + } + } + + It "Should return the current users from the get method" { + (Get-TargetResource @testParams).TermStoreAdministrators | Should Not BeNullOrEmpty + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should be $false + } + + It "Should call the delete method from the set method" { + $Global:SPDscAddUserCalled = $false + $Global:SPDscDeleteUserCalled = $false + Set-TargetResource @testParams + + $Global:SPDscDeleteUserCalled | Should Be $true + } + } + + # New Test + Context -Name "When a service proxy exists, it should return the proxy name" -Fixture { + $testParams = @{ + Name = "Managed Metadata Service App" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + } + + Mock -CommandName Get-SPServiceApplication -MockWith { + $spServiceApp = [PSCustomObject]@{ + TypeName = "Managed Metadata Service" + DisplayName = $testParams.Name + ApplicationPool = @{ + Name = $testParams.ApplicationPool + } + Database = @{ + Name = $testParams.DatabaseName + Server = @{ Name = $testParams.DatabaseServer } + } + } + $spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod ` + -Name GetType ` + -Value { + return (@{ + FullName = $getTypeFullName + }) + } -PassThru -Force ` + | Add-Member -MemberType ScriptMethod ` + -Name IsConnected ` + -Value { + param($x) + return ($true) + } -PassThru -Force + + return $spServiceApp + } + + Mock -CommandName Get-SPServiceApplicationProxy -MockWith { + return @( + @{ + Name = "$($testParams.Name) Proxy Test" + } + ) + } + + It "Should return the proxy name" { + (Get-TargetResource @testParams).ProxyName | Should Be "$($testParams.Name) Proxy Test" + } + } Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { $testParams = @{ @@ -1412,8 +1412,8 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { IsNPContentTypeSyndicationEnabled = $true } } | Add-Member -MemberType ScriptMethod ` - -Name update ` - -Value {$Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true} ` + -Name Update ` + -Value { $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $true } ` -PassThru -Force Mock -CommandName Get-SPMetadataServiceApplicationProxy -MockWith { @@ -1445,17 +1445,41 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } It "Should change the value for 'ContentTypePushdownEnabled'" { + $testParams = @{ + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $false + } + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true - # $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $false + $metadataServiceApplicationProxy.Properties["IsContentTypePushdownEnabled"] | Should be $true } It "Should change the value for 'ContentTypeSyndicationEnabled'" { + $testParams = @{ + Name = "Managed Metadata Service Application" + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "databaseserver\instance" + DatabaseName = "SP_MMS" + Ensure = "Present" + DefaultLanguage = 1033 + Languages = @(1033) + ContentTypePushdownEnabled = $false + ContentTypeSyndicationEnabled = $true + } + $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled = $false Set-TargetResource @testParams $Global:SPDscMetaDataServiceApplicationProxyUpdateCalled | Should Be $true - # $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $false + $metadataServiceApplicationProxy.Properties["IsNPContentTypeSyndicationEnabled"] | Should be $true } } From bb292d842ac5d0634f790d180d52a410fafd730a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Mon, 8 Oct 2018 12:15:47 +0200 Subject: [PATCH 067/101] reviewable changesgit --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index 83c15da37..1bda84878 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -103,11 +103,15 @@ function Get-TargetResource } $proxy = Get-SPMetadataServiceApplicationProxy -Identity $proxyName - if($null -ne $proxy) + if ($null -ne $proxy) { $contentTypePushDownEnabled = $proxy.Properties["IsContentTypePushdownEnabled"] $contentTypeSyndicationEnabled = $proxy.Properties["IsNPContentTypeSyndicationEnabled"] } + else + { + Write-Verbose "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + } # Get the ContentTypeHubUrl value $hubUrl = "" @@ -294,7 +298,7 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters $pName = "$Name Proxy" - if($null -ne $result.ProxyName) + if ($null -ne $result.ProxyName) { $pName = $result.ProxyName } @@ -585,16 +589,20 @@ function Set-TargetResource Invoke-SPDSCCommand -Credential $InstallAccount ` -Arguments @($PSBoundParameters, $result, $pName) ` -ScriptBlock { - $params = $args[0] - $pName = $args[2] + $params = $args[0] + $pName = $args[2] - $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName - if($null -ne $proxy) - { - $proxy.Properties["IsContentTypePushdownEnabled"] = $params.ContentTypePushdownEnabled - $proxy.Update() - } + $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName + if ($null -ne $proxy) + { + $proxy.Properties["IsContentTypePushdownEnabled"] = $params.ContentTypePushdownEnabled + $proxy.Update() } + else + { + throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + } + } } if (($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) ` @@ -602,17 +610,21 @@ function Set-TargetResource ) { Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $result, $pName) ` - -ScriptBlock { + -Arguments @($PSBoundParameters, $result, $pName) ` + -ScriptBlock { $params = $args[0] $pName = $args[2] $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName - if($null -ne $proxy) + if ($null -ne $proxy) { $proxy.Properties["IsNPContentTypeSyndicationEnabled"] = $params.ContentTypeSyndicationEnabled $proxy.Update() } + else + { + throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." + } } } } From 8dae55d534886d9c4b54db9c5e30f8711efb2201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Mon, 8 Oct 2018 12:25:03 +0200 Subject: [PATCH 068/101] reviewable fix --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 33 +++---------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index f0b6c1474..d6378c014 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -594,11 +594,10 @@ function Set-TargetResource ) { Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $result, $pName) ` + -Arguments @($PSBoundParameters, $pName) ` -ScriptBlock { -<<<<<<< HEAD $params = $args[0] - $pName = $args[2] + $pName = $args[1] $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName if ($null -ne $proxy) @@ -611,18 +610,6 @@ function Set-TargetResource throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." } } -======= - $params = $args[0] - $pName = $args[2] - - $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName - if($null -ne $proxy) - { - $proxy.Properties["IsContentTypePushdownEnabled"] = $params.ContentTypePushdownEnabled - $proxy.Update() - } - } ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 } if (($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) ` @@ -630,33 +617,21 @@ function Set-TargetResource ) { Invoke-SPDSCCommand -Credential $InstallAccount ` -<<<<<<< HEAD - -Arguments @($PSBoundParameters, $result, $pName) ` + -Arguments @($PSBoundParameters, $pName) ` -ScriptBlock { -======= - -Arguments @($PSBoundParameters, $result, $pName) ` - -ScriptBlock { ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 $params = $args[0] - $pName = $args[2] + $pName = $args[1] $proxy = Get-SPMetadataServiceApplicationProxy -Identity $pName -<<<<<<< HEAD if ($null -ne $proxy) -======= - if($null -ne $proxy) ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 { $proxy.Properties["IsNPContentTypeSyndicationEnabled"] = $params.ContentTypeSyndicationEnabled $proxy.Update() } -<<<<<<< HEAD else { throw [Exception] "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." } -======= ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 } } } From 48482619a59ecb3049371bb3818f6e076ecb8997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Mon, 8 Oct 2018 12:25:39 +0200 Subject: [PATCH 069/101] fix changelog --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ff62aa7a..790ec4ec9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,14 +46,8 @@ * Added ability to check and update CentralAdministrationPort * SPLogLevel * Added High as TraceLevel, which was not included yet -<<<<<<< HEAD * SPRemoteFarmTrust * Updated readme.md file to add a link that was lost during earlier updates -======= -* SPManagedMetadataServiceApp - * Added additional content type settings (ContentTypePushdownEnabled & - ContentTypeSyndicationEnabled). ->>>>>>> Added example and changelog * SPSearchServiceApp * Updated Set method to check if service application pool exists. Resource will throw an error if it does not exist From 44f6638e4cbdb7482f5d0ed944271c92df6e8afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20Kr=C3=BCger?= Date: Mon, 8 Oct 2018 12:28:13 +0200 Subject: [PATCH 070/101] fix --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index d6378c014..616c87069 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -103,22 +103,15 @@ function Get-TargetResource } $proxy = Get-SPMetadataServiceApplicationProxy -Identity $proxyName -<<<<<<< HEAD if ($null -ne $proxy) -======= - if($null -ne $proxy) ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 { $contentTypePushDownEnabled = $proxy.Properties["IsContentTypePushdownEnabled"] $contentTypeSyndicationEnabled = $proxy.Properties["IsNPContentTypeSyndicationEnabled"] } -<<<<<<< HEAD else { Write-Verbose "No SPMetadataServiceApplicationProxy with the name '$($proxyName)' was found. Please verify your Managed Metadata Service Application." } -======= ->>>>>>> 432bbfdf030227f0cf9b197ed83f9a820f6f8926 # Get the ContentTypeHubUrl value $hubUrl = "" From 261369415278c5c116406d16f65cfefb326899a2 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 10 Oct 2018 10:51:35 -0400 Subject: [PATCH 071/101] Added the SearchApplication param to fix some conflict when multiple SA exists --- .../MSFT_SPSearchManagedProperty.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index a077d60b3..d92ee0945 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -303,6 +303,7 @@ function Set-TargetResource -SearchApplication $params.ServiceAppName Set-SPEnterpriseSearchMetadataManagedProperty -Identity $managedProperty.Name ` + -SearchApplication $params.ServiceAppName ` -Retrievable $params.Retrievable ` -SafeForAnonymous $params.SafeForAnonymous ` -NoWordBreaker $params.NoWordBreaker From ef6dfb68280806cc5495e154e98e2ba1ea218be0 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 11 Oct 2018 11:03:18 -0400 Subject: [PATCH 072/101] Added support for Local Result Sources --- CHANGELOG.md | 2 + .../MSFT_SPSearchResultSource.psm1 | 228 ++++++++++-------- .../MSFT_SPSearchResultSource.schema.mof | 1 + ...arePointDsc.SPSearchResultSource.Tests.ps1 | 64 ++++- 4 files changed, 190 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d400f04c..258090150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ * Fixed issue with numerical Content Sources name * SPSearchManagedProperty * Added a new resource to support Search Managed Properties +* SPSearchResultSource + * Added a new ScopeUrl parameter to allow for local source creation * SPSearchTopology * Updated Readme.md to remove some incorrect information * SPSite diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 index bb146ea31..fd662eb96 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.psm1 @@ -4,39 +4,43 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $SearchServiceAppName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Query, - [Parameter(Mandatory = $true)] - [ValidateSet("Exchange Search Provider", - "Local People Provider", - "Local SharePoint Provider", - "OpenSearch Provider", - "Remote People Provider", - "Remote SharePoint Provider")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Exchange Search Provider", + "Local People Provider", + "Local SharePoint Provider", + "OpenSearch Provider", + "Remote People Provider", + "Remote SharePoint Provider")] + [System.String] $ProviderType, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ConnectionUrl, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [System.String] + $ScopeUrl, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -54,9 +58,10 @@ function Get-TargetResource Query = $null ProviderType = $null ConnectionUrl = $null + ScopeUrl = $null Ensure = "Absent" InstallAccount = $params.InstallAccount - } + } $serviceApp = Get-SPEnterpriseSearchServiceApplication -Identity $params.SearchServiceAppName $searchSiteUrl = $serviceApp.SearchCenterUrl -replace "/pages" $searchSite = Get-SPWeb -Identity $searchSiteUrl -ErrorAction SilentlyContinue @@ -72,21 +77,36 @@ function Get-TargetResource $adminNamespace = "Microsoft.Office.Server.Search.Administration" $queryNamespace = "Microsoft.Office.Server.Search.Administration.Query" $objectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel] - $fedManager = New-Object -TypeName "$queryNamespace.FederationManager" ` - -ArgumentList $serviceApp - $searchOwner = New-Object -TypeName "$adminNamespace.SearchObjectOwner" ` - -ArgumentList @( - $objectLevel::Ssa, - $searchSite - ) - $source = $fedManager.GetSourceByName($params.Name, $searchOwner) + $fedManager = $null + if ($null -eq $params.ScopeUrl) + { + $fedManager = New-Object -TypeName "$queryNamespace.FederationManager" ` + -ArgumentList $serviceApp + $searchOwner = New-Object -TypeName "$adminNamespace.SearchObjectOwner" ` + -ArgumentList @( + $objectLevel::Ssa, + $searchSite + ) + + $source = $fedManager.GetSourceByName($params.Name, $searchOwner) + } + else + { + $fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($serviceApp) + $searchOwner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $params.ScopeUrl + $filter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner) + $filter.IncludeHigherLevel = $false + $source = $fedManager.ListSources($filter,$true) | Where-Object -FilterScript { + $_.Name -eq $params.Name + } + } if ($null -ne $source) { $providers = $fedManager.ListProviders() $provider = $providers.Values | Where-Object -FilterScript { - $_.Id -eq $source.ProviderId + $_.Id -eq $source.ProviderId } return @{ Name = $params.Name @@ -94,11 +114,12 @@ function Get-TargetResource Query = $source.QueryTransform.QueryTemplate ProviderType = $provider.Name ConnectionUrl = $source.ConnectionUrlTemplate + ScopeUrl = $params.ScopeUrl Ensure = "Present" InstallAccount = $params.InstallAccount } } - else + else { return $nullReturn } @@ -111,46 +132,50 @@ function Set-TargetResource [CmdletBinding()] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $SearchServiceAppName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Query, - [Parameter(Mandatory = $true)] - [ValidateSet("Exchange Search Provider", - "Local People Provider", - "Local SharePoint Provider", - "OpenSearch Provider", - "Remote People Provider", - "Remote SharePoint Provider")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Exchange Search Provider", + "Local People Provider", + "Local SharePoint Provider", + "OpenSearch Provider", + "Remote People Provider", + "Remote SharePoint Provider")] + [System.String] $ProviderType, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ConnectionUrl, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [System.String] + $ScopeUrl, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Setting search result source '$Name'" $CurrentValues = Get-TargetResource @PSBoundParameters - + if ($CurrentValues.Ensure -eq "Absent" -and $Ensure -eq "Present") { Write-Verbose -Message "Creating search result source $Name" @@ -159,7 +184,7 @@ function Set-TargetResource -ScriptBlock { $params = $args[0] [void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") - + $serviceApp = Get-SPEnterpriseSearchServiceApplication ` -Identity $params.SearchServiceAppName @@ -174,20 +199,31 @@ function Set-TargetResource return } - $adminNamespace = "Microsoft.Office.Server.Search.Administration" - $queryNamespace = "Microsoft.Office.Server.Search.Administration.Query" - $objectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel] - $fedManager = New-Object -TypeName "$queryNamespace.FederationManager" ` - -ArgumentList $serviceApp - $searchOwner = New-Object -TypeName "$adminNamespace.SearchObjectOwner" ` - -ArgumentList @( - $objectLevel::Ssa, - $searchSite - ) - - $transformType = "Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties" - $queryProperties = New-Object -TypeName $transformType - $resultSource = $fedManager.CreateSource($searchOwner) + $fedManager = $null + if ($null -eq $params.ScopeUrl) + { + $adminNamespace = "Microsoft.Office.Server.Search.Administration" + $queryNamespace = "Microsoft.Office.Server.Search.Administration.Query" + $objectLevel = [Microsoft.Office.Server.Search.Administration.SearchObjectLevel] + $fedManager = New-Object -TypeName "$queryNamespace.FederationManager" ` + -ArgumentList $serviceApp + $searchOwner = New-Object -TypeName "$adminNamespace.SearchObjectOwner" ` + -ArgumentList @( + $objectLevel::Ssa, + $searchSite + ) + + $transformType = "Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties" + $queryProperties = New-Object -TypeName $transformType + $resultSource = $fedManager.CreateSource($searchOwner) + } + else { + $fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($serviceApp) + $searchOwner = Get-SPEnterpriseSearchOwner -Level SPWeb -SPWeb $params.ScopeUrl + $transformType = "Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties" + $queryProperties = New-Object -TypeName $transformType + $resultSource = $fedManager.CreateSource($searchOwner) + } $resultSource.Name = $params.Name $providers = $fedManager.ListProviders() $provider = $providers.Values | Where-Object -FilterScript { @@ -223,7 +259,7 @@ function Set-TargetResource -ArgumentList $serviceApp $searchOwner = New-Object -TypeName "$adminNamespace.SearchObjectOwner" ` -ArgumentList @( - $objectLevel::Ssa, + $objectLevel::Ssa, $searchSite ) @@ -233,7 +269,7 @@ function Set-TargetResource $fedManager.RemoveSource($source) } } - } + } } function Test-TargetResource @@ -242,39 +278,43 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Name, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $SearchServiceAppName, - [Parameter(Mandatory = $true)] - [System.String] + [Parameter(Mandatory = $true)] + [System.String] $Query, - [Parameter(Mandatory = $true)] - [ValidateSet("Exchange Search Provider", - "Local People Provider", - "Local SharePoint Provider", - "OpenSearch Provider", - "Remote People Provider", - "Remote SharePoint Provider")] - [System.String] + [Parameter(Mandatory = $true)] + [ValidateSet("Exchange Search Provider", + "Local People Provider", + "Local SharePoint Provider", + "OpenSearch Provider", + "Remote People Provider", + "Remote SharePoint Provider")] + [System.String] $ProviderType, - [Parameter()] - [System.String] + [Parameter()] + [System.String] $ConnectionUrl, - [Parameter()] - [ValidateSet("Present","Absent")] - [System.String] + [Parameter()] + [System.String] + $ScopeUrl, + + [Parameter()] + [ValidateSet("Present","Absent")] + [System.String] $Ensure = "Present", - [Parameter()] - [System.Management.Automation.PSCredential] + [Parameter()] + [System.Management.Automation.PSCredential] $InstallAccount ) @@ -283,10 +323,10 @@ function Test-TargetResource $PSBoundParameters.Ensure = $Ensure $CurrentValues = Get-TargetResource @PSBoundParameters - + return Test-SPDscParameterState -CurrentValues $CurrentValues ` -DesiredValues $PSBoundParameters ` - -ValuesToCheck @("Ensure") + -ValuesToCheck @("Ensure") } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.schema.mof index 7960da7b1..206b3f8cc 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchResultSource/MSFT_SPSearchResultSource.schema.mof @@ -6,6 +6,7 @@ class MSFT_SPSearchResultSource : OMI_BaseResource [Required, Description("The query to pass to the provider source")] String Query; [Required, Description("The provider type to use for the result source"), ValueMap{"Exchange Search Provider","Local People Provider","Local SharePoint Provider","OpenSearch Provider","Remote People Provider","Remote SharePoint Provider"}, Values{"Exchange Search Provider","Local People Provider","Local SharePoint Provider","OpenSearch Provider","Remote People Provider","Remote SharePoint Provider"}] String ProviderType; [Write, Description("The URI to connect to the remote location")] String ConnectionUrl; + [Write, Description("The URI of the site where to create the result source. Leave empty to have it created globally")] String ScopeUrl; [Write, Description("Present if the result source should exist, absent if it should not"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 index 9bad18a85..247785119 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchResultSource.Tests.ps1 @@ -1,7 +1,7 @@ [CmdletBinding()] param( [Parameter()] - [string] + [string] $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` -Resolve) @@ -20,7 +20,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { try { # Initialize tests Add-Type -TypeDefinition @" -namespace Microsoft.Office.Server.Search.Administration { +namespace Microsoft.Office.Server.Search.Administration { public enum SearchObjectLevel { SPWeb, @@ -32,9 +32,10 @@ namespace Microsoft.Office.Server.Search.Administration { "@ -ErrorAction SilentlyContinue } catch { - -} - # Mocks for all contexts + +} + + # Mocks for all contexts Mock -CommandName Get-SPEnterpriseSearchServiceApplication { return @{ SearchCenterUrl = "http://example.sharepoint.com/pages" @@ -44,7 +45,7 @@ catch { Mock -CommandName Get-SPWeb -MockWith { return @{} } - + $Global:SPDscResultSourceProvicers = @( @{ Id = "c1e2843d-1825-4a37-ad15-dce5d50f46d2" @@ -71,7 +72,7 @@ catch { Name = "Remote SharePoint Provider" } ) - + Mock -CommandName New-Object { switch ($TypeName) { "Microsoft.Office.Server.Search.Administration.SearchObjectOwner" { @@ -81,7 +82,7 @@ catch { return [System.Object]::new() | Add-Member -Name GetSourceByName ` -MemberType ScriptMethod ` -PassThru ` - -Value { + -Value { return $Global:SPDscCurrentResultSourceMocks } ` | Add-Member -Name ListProviders ` @@ -105,17 +106,34 @@ catch { | Add-Member -Name Commit ` -MemberType ScriptMethod ` -PassThru ` - -Value { + -Value { $Global:SPDscResultSourceUpdated = $true } } ` | Add-Member -Name RemoveSource ` + -MemberType ScriptMethod ` + -PassThru ` + -Value { } ` + | Add-Member -Name ListSources ` -MemberType ScriptMethod ` -PassThru ` -Value { } } + "Microsoft.Office.Server.Search.Administration.SearchObjectFilter" { + return [System.Object]::new() | Add-Member -Name IncludeHigherLevel ` + -MemberType ScriptProperty ` + -PassThru ` + { + # get + "getter" + }` + { + # set + param ( $arg ) + } + } } - } + } # Test contexts Context -Name "A search result source doesn't exist and should" -Fixture { @@ -127,7 +145,7 @@ catch { ConnectionUrl = "https://sharepoint.contoso.com" Ensure = "Present" } - + $Global:SPDscCurrentResultSourceMocks = $null It "Should return absent from the get method" { @@ -248,6 +266,30 @@ catch { { Set-TargetResource @testParams } | Should throw } } + + Context -Name "Local Result Source" -Fixture { + $testParams = @{ + Name = "Test source" + SearchServiceAppName = "Search Service Application" + ProviderType = "Remote SharePoint Provider" + Query = "{searchTerms}" + ConnectionUrl = "https://sharepoint.contoso.com" + ScopeUrl = "https://sharepoint.contoso.com" + Ensure = "Present" + } + + It "Should return absent from the get method" { + (Get-TargetResource @testParams).Ensure | Should Be "Absent" + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should create the result source in the set method" { + Set-TargetResource @testParams + } + } } } From 009a278cabf957e7c83472fbac9ad807146f2ac9 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 14 Oct 2018 19:45:43 +0200 Subject: [PATCH 073/101] Added self-service site creation resource --- CHANGELOG.md | 2 + .../MSFT_SPSelfServiceSiteCreation.psm1 | 368 ++++++++ .../MSFT_SPSelfServiceSiteCreation.schema.mof | 16 + .../MSFT_SPSelfServiceSiteCreation/readme.md | 24 + .../1-EnableSelfServiceSiteCreation.ps1 | 29 + ...nableSelfServiceSiteCreationCustomForm.ps1 | 25 + .../3-DisableSelfServiceSiteCreation.ps1 | 23 + ...intDsc.SPSelfServiceSiteCreation.Tests.ps1 | 890 ++++++++++++++++++ 8 files changed, 1377 insertions(+) create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof create mode 100644 Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/readme.md create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/1-EnableSelfServiceSiteCreation.ps1 create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/2-EnableSelfServiceSiteCreationCustomForm.ps1 create mode 100644 Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/3-DisableSelfServiceSiteCreation.ps1 create mode 100644 Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d400f04c..b87120c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ * SPWebAppSuiteBar * Enable usage of SuiteBarBrandingElementHtml for SharePoint 2016 (only supported if using a SharePoint 2013 masterpage) +* SPSelfServiceSiteCreation + * New resource to manage self-service site creation ## 2.5 diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 new file mode 100644 index 000000000..d063d9347 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 @@ -0,0 +1,368 @@ +Set-StrictMode -Version 2 + +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Boolean] + $OnlineEnabled, + + [Parameter()] + [System.String] + $QuotaTemplate, + + [Parameter()] + [System.Boolean] + $ShowStartASiteMenuItem, + + [Parameter()] + [System.Boolean] + $CreateIndividualSite, + + [Parameter()] + [System.String] + $ParentSiteUrl, + + [Parameter()] + [ValidateSet("MustHavePolicy","CanHavePolicy","NotHavePolicy")] + [System.String] + $PolicyOption, + + [Parameter()] + [System.Boolean] + $RequireSecondaryContact, + + [Parameter()] + [System.String] + $CustomFormUrl, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Getting self service site creation settings for Web Application '$Url'" + + $result = Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + + if ($null -eq $webApplication) + { + Write-Verbose "Web application $($params.Url) was not found" + return @{ + Url = $null + Enabled = $null + OnlineEnabled = $null + QuotaTemplate = $null + ShowStartASiteMenuItem = $null + CreateIndividualSite = $null + ParentSiteUrl = $null + CustomFormUrl = $null + PolicyOption = $null + RequireSecondaryContact = $null + } + } + + $policyOption = "NotHavePolicy" + if($webApplication.Properties.Contains("PolicyOption")) + { + $policyOptionProperty = $webApplication.Properties["PolicyOption"] + if($policyOptionProperty -eq "CanHavePolicy" -or $policyOptionProperty -eq "MustHavePolicy") + { + $policyOption = $policyOptionProperty + } + } + + return @{ + Url = $params.Url + Enabled = $webApplication.SelfServiceSiteCreationEnabled + OnlineEnabled = $webApplication.SelfServiceSiteCreationOnlineEnabled + QuotaTemplate = $webApplication.SelfServiceCreationQuotaTemplate + ShowStartASiteMenuItem = $webApplication.ShowStartASiteMenuItem + CreateIndividualSite = $webApplication.SelfServiceCreateIndividualSite + ParentSiteUrl = $webApplication.SelfServiceCreationParentSiteUrl + CustomFormUrl = $webApplication.SelfServiceSiteCustomFormUrl + PolicyOption = $policyOption + RequireSecondaryContact = $webApplication.RequireContactForSelfServiceSiteCreation + } + } + return $result +} + +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Boolean] + $OnlineEnabled, + + [Parameter()] + [System.String] + $QuotaTemplate, + + [Parameter()] + [System.Boolean] + $ShowStartASiteMenuItem, + + [Parameter()] + [System.Boolean] + $CreateIndividualSite, + + [Parameter()] + [System.String] + $ParentSiteUrl, + + [Parameter()] + [ValidateSet("MustHavePolicy","CanHavePolicy","NotHavePolicy")] + [System.String] + $PolicyOption, + + [Parameter()] + [System.Boolean] + $RequireSecondaryContact, + + [Parameter()] + [System.String] + $CustomFormUrl, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Setting self service site creation settings for Web Application '$Url'" + + Invoke-SPDSCCommand -Credential $InstallAccount ` + -Arguments $PSBoundParameters ` + -ScriptBlock { + $params = $args[0] + + $webApplication = Get-SPWebApplication -Identity $params.Url -ErrorAction SilentlyContinue + + if ($null -eq $webApplication) + { + throw "The specified web application could not be found." + } + + $webApplicationNeedsUpdate = $false + + if ($params.Enabled -eq $false) + { + if($params.ContainsKey("ShowStartASiteMenuItem")) + { + if($ShowStartASiteMenuItem -eq $true) + { + throw ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + } + } + else + { + $params.Add("ShowStartASiteMenuItem", $false) + } + } + + if ($params.Enabled -ne $webApplication.SelfServiceSiteCreationEnabled) + { + $webApplication.SelfServiceSiteCreationEnabled = $params.Enabled + $webApplicationNeedsUpdate = $true + } + + if ($params.ContainsKey("OnlineEnabled") -eq $true) + { + if ($params.OnlineEnabled -ne $webApplication.SelfServiceSiteCreationOnlineEnabled) + { + $webApplication.SelfServiceSiteCreationOnlineEnabled = $params.OnlineEnabled + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("QuotaTemplate") -eq $true) + { + if ($params.QuotaTemplate -ne $webApplication.SelfServiceCreationQuotaTemplate) + { + $webApplication.SelfServiceCreationQuotaTemplate = $params.QuotaTemplate + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("ShowStartASiteMenuItem") -eq $true) + { + if ($params.ShowStartASiteMenuItem -ne $webApplication.ShowStartASiteMenuItem) + { + $webApplication.ShowStartASiteMenuItem = $params.ShowStartASiteMenuItem + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("CreateIndividualSite") -eq $true) + { + if ($params.CreateIndividualSite -ne $webApplication.SelfServiceCreateIndividualSite) + { + $webApplication.SelfServiceCreateIndividualSite = $params.CreateIndividualSite + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("ParentSiteUrl") -eq $true) + { + if ($params.ParentSiteUrl -ne $webApplication.SelfServiceCreationParentSiteUrl) + { + $webApplication.SelfServiceCreationParentSiteUrl = $params.ParentSiteUrl + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("CustomFormUrl") -eq $true) + { + if ($params.CustomFormUrl -ne $webApplication.SelfServiceSiteCustomFormUrl) + { + $webApplication.SelfServiceSiteCustomFormUrl = $params.CustomFormUrl + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("PolicyOption") -eq $true) + { + if ($params.PolicyOption -ne $webApplication.Properties["PolicyOption"]) + { + $webApplication.Properties["PolicyOption"] = $params.PolicyOption + $webApplicationNeedsUpdate = $true + } + } + + if ($params.ContainsKey("RequireSecondaryContact") -eq $true) + { + if ($params.RequireSecondaryContact -ne $webApplication.RequireContactForSelfServiceSiteCreation) + { + $webApplication.RequireContactForSelfServiceSiteCreation = $params.RequireSecondaryContact + $webApplicationNeedsUpdate = $true + } + } + + if ($webApplicationNeedsUpdate -eq $true) + { + Write-Verbose -Message "Updating web application" + $webApplication.Update() + } + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Url, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.Boolean] + $OnlineEnabled, + + [Parameter()] + [System.String] + $QuotaTemplate, + + [Parameter()] + [System.Boolean] + $ShowStartASiteMenuItem, + + [Parameter()] + [System.Boolean] + $CreateIndividualSite, + + [Parameter()] + [System.String] + $ParentSiteUrl, + + [Parameter()] + [ValidateSet("MustHavePolicy","CanHavePolicy","NotHavePolicy")] + [System.String] + $PolicyOption, + + [Parameter()] + [System.Boolean] + $RequireSecondaryContact, + + [Parameter()] + [System.String] + $CustomFormUrl, + + [Parameter()] + [System.Management.Automation.PSCredential] + $InstallAccount + ) + + Write-Verbose -Message "Testing self service site creation settings for Web Application '$Url'" + + if ($Enabled -eq $false) + { + if($PSBoundParameters.ContainsKey("ShowStartASiteMenuItem")) + { + if($ShowStartASiteMenuItem -eq $true) + { + throw ("It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled.") + } + } + else + { + $PSBoundParameters.Add("ShowStartASiteMenuItem", $false) + } + } + + $currentValues = Get-TargetResource @PSBoundParameters + + if ($Enabled) + { + return Test-SPDscParameterState -CurrentValues $currentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", ` + "Enabled", ` + "OnlineEnabled", ` + "ShowStartASiteMenuItem", ` + "CreateIndividualSite", ` + "ParentSiteUrl", ` + "CustomFormUrl", ` + "PolicyOption", ` + "RequireSecondaryContact") + } + else + { + return Test-SPDscParameterState -CurrentValues $currentValues ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck @("Url", ` + "Enabled", ` + "ShowStartASiteMenuItem") + } +} diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof new file mode 100644 index 000000000..29f12aee6 --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof @@ -0,0 +1,16 @@ +[ClassVersion("1.0.0.0"), FriendlyName("SPSelfServiceSiteCreation")] +class MSFT_SPSelfServiceSiteCreation : OMI_BaseResource +{ + [Key, Description("The url of the web application")] string Url; + [Required, Description("Specifies if users are allowed to create site collections or not")] boolean Enabled; + [Write, Description("Specifies if site collections are created in SharePoint Online in a hybrid configuration. Hybrid configuration needs to be caried out seperately using the Hybrid Picker")] boolean OnlineEnabled; + [Write, Description("The quota template to apply to new site collections. Specify null to not apply any qouta template")] string QuotaTemplate; + [Write, Description("Should the Start a Site link be displayed. Must be false or not specified if Enabled is false")] boolean ShowStartASiteMenuItem; + [Write, Description("Should Self Service Site Creation create an individual Site, false for a Site Collection")] boolean CreateIndividualSite; + [Write, Description("Specifies the URL of the parent site where new sites are to be created. This is only used when CreateIndividualSite is true. Use [%userid%] to represent the ID of the user who is creating the site, for example: /projects/[%userid%]")] string ParentSiteUrl; + [Write, Description("Specifies what site classification should be displayed"), ValueMap{"MustHavePolicy","CanHavePolicy","NotHavePolicy"}, Values{"MustHavePolicy","CanHavePolicy","NotHavePolicy"}] string PolicyOption; + [Write, Description("Specifies if users needs to provide one or more additional site administrators")] boolean RequireSecondaryContact; + [Write, Description("Specifies a custom form URL to use for Self Service Site Creation. This is only used when CreateIndividualSite is true. Must be an absolute URL or empty to use built in form (_layouts/_layouts/15/scsignup.aspx)")] string CustomFormUrl; + [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; +}; + diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/readme.md b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/readme.md new file mode 100644 index 000000000..6f33416da --- /dev/null +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/readme.md @@ -0,0 +1,24 @@ +# Description + +**Type:** Distributed + +This resource is used to configure self-service site creation on a web +application. + +NOTE: +The web application needs a root level ("/") site collection for the +self-service site creation to function properly. It is not required to have this +site collection present in the web application to succesfully configure this +resource. + +NOTE2: +If Enabled is set to false, ShowStartASiteMenuItem is automatically set to false +by the resource if ShowStartASiteMenuItem is not specified. Setting +ShowStartASiteMenuItem to true at the same time as Enabled is set to false +will generate an error. + +## Hybrid self-service site creation + +It is possible to configure self-service site creation to create sites in +SharePoint Online. This requires that [hybrid self-service site creation](https://docs.microsoft.com/en-us/sharepoint/hybrid/hybrid-self-service-site-creation) +is configured using the Hybrid Picker. diff --git a/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/1-EnableSelfServiceSiteCreation.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/1-EnableSelfServiceSiteCreation.ps1 new file mode 100644 index 000000000..528f22e2d --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/1-EnableSelfServiceSiteCreation.ps1 @@ -0,0 +1,29 @@ +<# +.EXAMPLE + This example shows how to configure self-service site creation for a web application +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSelfServiceSiteCreation SSC + { + Url = "http://example.contoso.local" + Enabled = $true + OnlineEnabled = $false + QuotaTemplate = "SSCQoutaTemplate" + ShowStartASiteMenuItem = $true + CreateIndividualSite = $true + PolicyOption = "CanHavePolicy" + RequireSecondaryContact = $false + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/2-EnableSelfServiceSiteCreationCustomForm.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/2-EnableSelfServiceSiteCreationCustomForm.ps1 new file mode 100644 index 000000000..1ff456e07 --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/2-EnableSelfServiceSiteCreationCustomForm.ps1 @@ -0,0 +1,25 @@ +<# +.EXAMPLE + This example shows how to configure self-service site creation with a custom form for a web application +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSelfServiceSiteCreation SSC + { + Url = "http://example.contoso.local" + Enabled = $true + ShowStartASiteMenuItem = $true + CustomFormUrl = "http://ssc.contoso.com.local/ssc" + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/3-DisableSelfServiceSiteCreation.ps1 b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/3-DisableSelfServiceSiteCreation.ps1 new file mode 100644 index 000000000..3ed39d31e --- /dev/null +++ b/Modules/SharePointDsc/Examples/Resources/SPSPSelfServiceSiteCreation/3-DisableSelfServiceSiteCreation.ps1 @@ -0,0 +1,23 @@ +<# +.EXAMPLE + This example shows how to disable self-service site creation for a web application +#> + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSelfServiceSiteCreation SSC + { + Url = "http://example.contoso.local" + Enabled = $false + PsDscRunAsCredential = $SetupAccount + } + } + } diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 new file mode 100644 index 000000000..325f5f217 --- /dev/null +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 @@ -0,0 +1,890 @@ +[CmdletBinding()] +param( + [Parameter()] + [string] + $SharePointCmdletModule = (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\Stubs\SharePoint\15.0.4805.1000\Microsoft.SharePoint.PowerShell.psm1" ` + -Resolve) +) +Set-StrictMode -Version 2 + +Import-Module -Name (Join-Path -Path $PSScriptRoot ` + -ChildPath "..\UnitTestHelper.psm1" ` + -Resolve) + +$Global:SPDscHelper = New-SPDscUnitTestHelper -SharePointStubModule $SharePointCmdletModule ` + -DscResource "SPSelfServiceSiteCreation" + +Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:SPDscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:SPDscHelper.InitializeScript -NoNewScope + + # Mocks for all contexts + + $webAppImplementation = { + $webApp = @{ + Url = $null + SelfServiceSiteCreationEnabled = $null + SelfServiceSiteCreationOnlineEnabled = $null + SelfServiceCreationQuotaTemplate = $null + ShowStartASiteMenuItem = $null + SelfServiceCreateIndividualSite = $null + SelfServiceCreationParentSiteUrl = $null + SelfServiceSiteCustomFormUrl = $null + RequireContactForSelfServiceSiteCreation = $null + Properties = @{} + UpdateCalled = $false + } + + $webApp | Add-Member -MemberType ScriptMethod -Name Update -Value { + $this.UpdateCalled = $true + } + return $webApp + } + + # Test contexts + + Context -Name "Self service site creation settings matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + Enabled = $true + OnlineEnabled = $false + QuotaTemplate = "SSCQoutaTemplate" + ShowStartASiteMenuItem = $true + CreateIndividualSite = $false + ParentSiteUrl = "/sites/SSC" + CustomFormUrl = "" + PolicyOption = "CanHavePolicy" + RequireSecondaryContact = $true + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $webApp = $webAppImplementation.InvokeReturnAsIs() + $webApp.Url = "http://sites.sharepoint.com" + $webApp.SelfServiceSiteCreationEnabled = $true + $webApp.SelfServiceSiteCreationOnlineEnabled = $false + $webApp.SelfServiceCreationQuotaTemplate = "SSCQoutaTemplate" + $webApp.ShowStartASiteMenuItem = $true + $webApp.SelfServiceCreateIndividualSite = $false + $webApp.SelfServiceCreationParentSiteUrl = "/sites/SSC" + $webApp.SelfServiceSiteCustomFormUrl = "" + $webApp.RequireContactForSelfServiceSiteCreation = $true + $webApp.Properties = @{ + PolicyOption = "CanHavePolicy" + } + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return the current data from the get method" { + $result = Get-TargetResource @testParams + $result.Url | Should Be "http://sites.sharepoint.com" + $result.Enabled | Should Be $true + $result.OnlineEnabled | Should Be $false + $result.QuotaTemplate | Should Be "SSCQoutaTemplate" + $result.ShowStartASiteMenuItem | Should Be $true + $result.CreateIndividualSite | Should Be $false + $result.ParentSiteUrl | Should Be "/sites/SSC" + $result.CustomFormUrl | Should Be "" + $result.PolicyOption | Should Be "CanHavePolicy" + $result.RequireSecondaryContact | Should Be $true + } + + It "Should return true from the test method" { + Test-TargetResource @testParams | Should Be $true + } + + It "Should not call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $false + } + } + + Context -Name "Self service site creation settings does not matches the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + Enabled = $true + OnlineEnabled = $false + QuotaTemplate = "SSCQoutaTemplate" + ShowStartASiteMenuItem = $true + CreateIndividualSite = $false + ParentSiteUrl = "/sites/SSC" + CustomFormUrl = "http://CustomForm.SharePoint.com" + PolicyOption = "CanHavePolicy" + RequireSecondaryContact = $true + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $webApp = $webAppImplementation.InvokeReturnAsIs() + $webApp.Url = "http://sites.sharepoint.com" + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.SelfServiceSiteCreationEnabled | Should Be $true + $Script:SPDscWebApplication.SelfServiceSiteCreationOnlineEnabled | Should Be $false + $Script:SPDscWebApplication.SelfServiceCreationQuotaTemplate | Should Be "SSCQoutaTemplate" + $Script:SPDscWebApplication.ShowStartASiteMenuItem | Should Be $true + $Script:SPDscWebApplication.SelfServiceCreateIndividualSite | Should Be $false + $Script:SPDscWebApplication.SelfServiceCreationParentSiteUrl | Should Be "/sites/SSC" + $Script:SPDscWebApplication.SelfServiceSiteCustomFormUrl | Should Be "http://CustomForm.SharePoint.com" + $Script:SPDscWebApplication.Properties["PolicyOption"] | Should Be "CanHavePolicy" + $Script:SPDscWebApplication.RequireContactForSelfServiceSiteCreation | Should Be $true + } + } + + Context -Name "Disabling self service site creation does not match the current state" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + Enabled = $false + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $webApp = $webAppImplementation.InvokeReturnAsIs() + $webApp.Url = "http://sites.sharepoint.com" + $webApp.SelfServiceSiteCreationEnabled = $true + $webApp.SelfServiceSiteCreationOnlineEnabled = $false + $webApp.SelfServiceCreationQuotaTemplate = "SSCQoutaTemplate" + $webApp.ShowStartASiteMenuItem = $true + $webApp.SelfServiceCreateIndividualSite = $false + $webApp.SelfServiceCreationParentSiteUrl = "/sites/SSC" + $webApp.SelfServiceSiteCustomFormUrl = "" + $webApp.RequireContactForSelfServiceSiteCreation = $true + $webApp.Properties = @{ + PolicyOption = "CanHavePolicy" + } + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should call web application update from the set method and disable SSC and start a site link" { + Set-TargetResource @testParams + $Script:SPDscWebApplication.UpdateCalled | Should Be $true + $Script:SPDscWebApplication.SelfServiceSiteCreationEnabled | Should Be $false + $Script:SPDscWebApplication.ShowStartASiteMenuItem | Should Be $false + } + } + + Context -Name "Disabling self service site creation and enabling show start a site menu item" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + Enabled = $false + ShowStartASiteMenuItem = $true + } + + Mock -CommandName Get-SPWebApplication -MockWith { + $webApp = $webAppImplementation.InvokeReturnAsIs() + $webApp.Url = "http://sites.sharepoint.com" + $webApp.SelfServiceSiteCreationEnabled = $true + $webApp.SelfServiceSiteCreationOnlineEnabled = $false + $webApp.SelfServiceCreationQuotaTemplate = "SSCQoutaTemplate" + $webApp.ShowStartASiteMenuItem = $true + $webApp.SelfServiceCreateIndividualSite = $false + $webApp.SelfServiceCreationParentSiteUrl = "/sites/SSC" + $webApp.SelfServiceSiteCustomFormUrl = "" + $webApp.RequireContactForSelfServiceSiteCreation = $true + $webApp.Properties = @{ + PolicyOption = "CanHavePolicy" + } + + $Script:SPDscWebApplication = $webApp + return($webApp) + } + + It "Should throw from the test method" { + { Test-TargetResource @testParams } | Should Throw "It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled." + } + + It "Should throw from the update method" { + { Set-TargetResource @testParams } | Should Throw "It is not allowed to set the ShowStartASiteMenuItem to true when self service site creation is disabled." + } + } + + Context -Name "Web application does not exist" -Fixture { + $testParams = @{ + Url = "http://sites.sharepoint.com" + Enabled = $true + } + + Mock -CommandName Get-SPWebApplication -MockWith { + return($null) + } + + It "Should return a valid object with null on all properties" { + $result = Get-TargetResource @testParams + $result | Should Not BeNullOrEmpty + $result.Url | Should Be $null + $result.Enabled | Should Be $null + $result.OnlineEnabled | Should Be $null + $result.QuotaTemplate | Should Be $null + $result.ShowStartASiteMenuItem | Should Be $null + $result.CreateIndividualSite | Should Be $null + $result.ParentSiteUrl | Should Be $null + $result.CustomFormUrl | Should Be $null + $result.PolicyOption | Should Be $null + $result.RequireSecondaryContact | Should Be $null + } + + It "Should return false from the test method" { + Test-TargetResource @testParams | Should Be $false + } + + It "Should throw an exception from the set method" { + { Set-TargetResource @testParams } | Should Throw + } + } + +# Context -Name "Client callable settings does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# MaxResourcesPerRequest = 8 +# MaxObjectPaths = 128 +# ExecutionTimeout = 45 +# RequestXmlMaxDepth = 16 +# EnableXsdValidation = $false +# EnableStackTrace = $true +# RequestUsageExecutionTimeThreshold = 400 +# EnableRequestUsage = $false +# LogActionsIfHasRequestException = $false +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; +# $webApp.ClientCallableSettings.MaxObjectPaths = 256; +# $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); +# $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; +# $webApp.ClientCallableSettings.EnableXsdValidation = $true; +# $webApp.ClientCallableSettings.EnableStackTrace = $false; +# $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; +# $webApp.ClientCallableSettings.EnableRequestUsage = $true; +# $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return the current data from the get method" { +# $result = Get-TargetResource @testParams +# $result.Url | Should Be "http://sites.sharepoint.com" +# $result.MaxResourcesPerRequest | Should Be 16 +# $result.MaxObjectPaths | Should Be 256 +# $result.ExecutionTimeout | Should Be 90 +# $result.RequestXmlMaxDepth | Should Be 32 +# $result.EnableXsdValidation | Should Be $true +# $result.EnableStackTrace | Should Be $false +# $result.RequestUsageExecutionTimeThreshold | Should Be 800 +# $result.EnableRequestUsage | Should Be $true +# $result.LogActionsIfHasRequestException | Should Be $true +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 +# $Script:SPDscWebApplication.ClientCallableSettings.MaxResourcesPerRequest | Should Be 8 +# $Script:SPDscWebApplication.ClientCallableSettings.MaxObjectPaths | Should Be 128 +# $Script:SPDscWebApplication.ClientCallableSettings.ExecutionTimeout.TotalMinutes | Should Be 45 +# $Script:SPDscWebApplication.ClientCallableSettings.RequestXmlMaxDepth | Should Be 16 +# $Script:SPDscWebApplication.ClientCallableSettings.EnableXsdValidation | Should Be $false +# $Script:SPDscWebApplication.ClientCallableSettings.EnableStackTrace | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.RequestUsageExecutionTimeThreshold | Should Be 400 +# $Script:SPDscWebApplication.ClientCallableSettings.EnableRequestUsage | Should Be $false +# $Script:SPDscWebApplication.ClientCallableSettings.LogActionsIfHasRequestException | Should Be $false +# } +# } +# +# Context -Name "A proxy library does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $false +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "A proxy library to include does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $false +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "Proxy libraries does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "NewAssembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $false +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "NewAssembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "Multiple proxy libraries matches the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly1" +# SupportAppAuthentication = $true +# }), +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly2" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary1 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary1.AssemblyName = "Assembly1" +# $testProxyLibrary1.SupportAppAuthentication = $true +# $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary2.AssemblyName = "Assembly2" +# $testProxyLibrary2.SupportAppAuthentication = $true +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary1) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $true +# } +# +# It "Should not call web application update from the set method" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $false +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly2" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "Assembly1" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "Proxy libraries to include does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "NewAssembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $true +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "NewAssembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "Proxy library to include matches the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $true +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return true from the test method" { +# Test-TargetResource @testParams | Should Be $true +# } +# +# It "Should not call web application update from the set method, proxy libraries should not change" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $false +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "A proxy library to exclude does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToExclude = @("Assembly") +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $false +# +# $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary2.AssemblyName = "AnotherAssembly" +# $testProxyLibrary2.SupportAppAuthentication = $false +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method, and set expected values" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $false +# } +# } +# +# Context -Name "Proxy library to exclude matches the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToExclude = @("Assembly") +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "AnotherAssembly" +# $testProxyLibrary.SupportAppAuthentication = $true +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return true from the test method" { +# Test-TargetResource @testParams | Should Be $true +# } +# +# It "Should not call web application update from the set method, proxy libraries should not change" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $false +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true +# } +# } +# +# Context -Name "Proxy libraries does not match the current state of empty proxy libraries" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# return $webApp +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# } +# +# Context -Name "Empty proxy libraries matches the current state of empty proxy libraries" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @() +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# return $webApp +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $true +# } +# } +# +# Context -Name "Empty proxy libraries does not match the current state" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @() +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary +# $testProxyLibrary.AssemblyName = "Assembly" +# $testProxyLibrary.SupportAppAuthentication = $true +# +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) +# +# $Script:SPDscWebApplication = $webApp +# return($webApp) +# } +# +# It "Should return true from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should call web application update from the set method and update proxy libraries" { +# Set-TargetResource @testParams +# $Script:SPDscWebApplication.UpdateCalled | Should Be $true +# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 +# } +# } +# +# Context -Name "Proxy libraries to include does not match the current state of empty proxy libraries" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# return $webApp +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# } +# +# Context -Name "Proxy libraries to exclude matches the current state of empty proxy libraries" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibrariesToExclude = @("Assembly") +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# $webApp = $webAppImplementation.Invoke() +# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); +# return $webApp +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $true +# } +# } +# +# Context -Name "ProxyLibraries and ProxyLibrariesToInclude properties are provided" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# return $webAppImplementation.Invoke() +# } +# +# It "Should throw an exception from the get method" { +# { Get-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the test method" { +# { Test-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the set method" { +# { Set-TargetResource @testParams } | Should Throw +# } +# } +# +# Context -Name "ProxyLibraries and ProxyLibrariesToExclude properties are provided" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# ProxyLibrariesToExclude = @("Assembly") +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# return $webAppImplementation.Invoke() +# } +# +# It "Should throw an exception from the get method" { +# { Get-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the test method" { +# { Test-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the set method" { +# { Set-TargetResource @testParams } | Should Throw +# } +# } +# +# Context -Name "All of the proxy libraries properties are provided" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# ProxyLibraries = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# ProxyLibrariesToInclude = @( +# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` +# -ClientOnly ` +# -Property @{ +# AssemblyName = "Assembly" +# SupportAppAuthentication = $true +# }) +# ) +# ProxyLibrariesToExclude = @("Assembly") +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# return $webAppImplementation.Invoke() +# } +# +# It "Should throw an exception from the get method" { +# { Get-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the test method" { +# { Test-TargetResource @testParams } | Should Throw +# } +# +# It "Should throw an exception from the set method" { +# { Set-TargetResource @testParams } | Should Throw +# } +# } +# +# Context -Name "The web appliation does not exist" -Fixture { +# $testParams = @{ +# Url = "http://sites.sharepoint.com" +# } +# +# Mock -CommandName Get-SPWebapplication -MockWith { +# return $null +# } +# +# It "Should return a valid object with null on all properties" { +# $result = Get-TargetResource @testParams +# $result | Should Not BeNullOrEmpty +# $result.Url | Should Be $null +# $result.ProxyLibraries | Should Be $null +# $result.ProxyLibrariesToInclude | Should Be $null +# $result.ProxyLibrariesToExclude | Should Be $null +# $result.MaxResourcesPerRequest | Should Be $null +# $result.MaxObjectPaths | Should Be $null +# $result.ExecutionTimeout | Should Be $null +# $result.RequestXmlMaxDepth | Should Be $null +# $result.EnableXsdValidation | Should Be $null +# $result.EnableStackTrace | Should Be $null +# $result.RequestUsageExecutionTimeThreshold | Should Be $null +# $result.EnableRequestUsage | Should Be $null +# $result.LogActionsIfHasRequestException | Should Be $null +# } +# +# It "Should return false from the test method" { +# Test-TargetResource @testParams | Should Be $false +# } +# +# It "Should throw an exception from the set method" { +# { Set-TargetResource @testParams } | Should Throw +# } +# } + } +} + +Invoke-Command -ScriptBlock $Global:SPDscHelper.CleanupScript -NoNewScope From 43a3da58a98bc6c29ed93799e3b9f402cb031735 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 14 Oct 2018 19:46:20 +0200 Subject: [PATCH 074/101] Remove empty line --- .../MSFT_SPSelfServiceSiteCreation.schema.mof | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof index 29f12aee6..8daadd839 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.schema.mof @@ -13,4 +13,3 @@ class MSFT_SPSelfServiceSiteCreation : OMI_BaseResource [Write, Description("Specifies a custom form URL to use for Self Service Site Creation. This is only used when CreateIndividualSite is true. Must be an absolute URL or empty to use built in form (_layouts/_layouts/15/scsignup.aspx)")] string CustomFormUrl; [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; }; - From 1373a912a23ec665b68c20b45243c191f08100e2 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 14 Oct 2018 20:10:28 +0200 Subject: [PATCH 075/101] Removed unused code --- ...intDsc.SPSelfServiceSiteCreation.Tests.ps1 | 636 ------------------ 1 file changed, 636 deletions(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 index 325f5f217..2c4dc12d8 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSelfServiceSiteCreation.Tests.ps1 @@ -248,642 +248,6 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } } -# Context -Name "Client callable settings does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# MaxResourcesPerRequest = 8 -# MaxObjectPaths = 128 -# ExecutionTimeout = 45 -# RequestXmlMaxDepth = 16 -# EnableXsdValidation = $false -# EnableStackTrace = $true -# RequestUsageExecutionTimeThreshold = 400 -# EnableRequestUsage = $false -# LogActionsIfHasRequestException = $false -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.MaxResourcesPerRequest = 16; -# $webApp.ClientCallableSettings.MaxObjectPaths = 256; -# $webApp.ClientCallableSettings.ExecutionTimeout = [System.TimeSpan]::FromMinutes(90); -# $webApp.ClientCallableSettings.RequestXmlMaxDepth = 32; -# $webApp.ClientCallableSettings.EnableXsdValidation = $true; -# $webApp.ClientCallableSettings.EnableStackTrace = $false; -# $webApp.ClientCallableSettings.RequestUsageExecutionTimeThreshold = 800; -# $webApp.ClientCallableSettings.EnableRequestUsage = $true; -# $webApp.ClientCallableSettings.LogActionsIfHasRequestException = $true; -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return the current data from the get method" { -# $result = Get-TargetResource @testParams -# $result.Url | Should Be "http://sites.sharepoint.com" -# $result.MaxResourcesPerRequest | Should Be 16 -# $result.MaxObjectPaths | Should Be 256 -# $result.ExecutionTimeout | Should Be 90 -# $result.RequestXmlMaxDepth | Should Be 32 -# $result.EnableXsdValidation | Should Be $true -# $result.EnableStackTrace | Should Be $false -# $result.RequestUsageExecutionTimeThreshold | Should Be 800 -# $result.EnableRequestUsage | Should Be $true -# $result.LogActionsIfHasRequestException | Should Be $true -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 -# $Script:SPDscWebApplication.ClientCallableSettings.MaxResourcesPerRequest | Should Be 8 -# $Script:SPDscWebApplication.ClientCallableSettings.MaxObjectPaths | Should Be 128 -# $Script:SPDscWebApplication.ClientCallableSettings.ExecutionTimeout.TotalMinutes | Should Be 45 -# $Script:SPDscWebApplication.ClientCallableSettings.RequestXmlMaxDepth | Should Be 16 -# $Script:SPDscWebApplication.ClientCallableSettings.EnableXsdValidation | Should Be $false -# $Script:SPDscWebApplication.ClientCallableSettings.EnableStackTrace | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.RequestUsageExecutionTimeThreshold | Should Be 400 -# $Script:SPDscWebApplication.ClientCallableSettings.EnableRequestUsage | Should Be $false -# $Script:SPDscWebApplication.ClientCallableSettings.LogActionsIfHasRequestException | Should Be $false -# } -# } -# -# Context -Name "A proxy library does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $false -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "A proxy library to include does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $false -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "Proxy libraries does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "NewAssembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $false -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "NewAssembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "Multiple proxy libraries matches the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly1" -# SupportAppAuthentication = $true -# }), -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly2" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary1 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary1.AssemblyName = "Assembly1" -# $testProxyLibrary1.SupportAppAuthentication = $true -# $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary2.AssemblyName = "Assembly2" -# $testProxyLibrary2.SupportAppAuthentication = $true -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary1) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $true -# } -# -# It "Should not call web application update from the set method" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $false -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly2" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "Assembly1" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "Proxy libraries to include does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "NewAssembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $true -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 2 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].AssemblyName | Should Be "NewAssembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[1].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "Proxy library to include matches the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $true -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return true from the test method" { -# Test-TargetResource @testParams | Should Be $true -# } -# -# It "Should not call web application update from the set method, proxy libraries should not change" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $false -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "Assembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "A proxy library to exclude does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToExclude = @("Assembly") -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $false -# -# $testProxyLibrary2 = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary2.AssemblyName = "AnotherAssembly" -# $testProxyLibrary2.SupportAppAuthentication = $false -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary2) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method, and set expected values" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $false -# } -# } -# -# Context -Name "Proxy library to exclude matches the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToExclude = @("Assembly") -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "AnotherAssembly" -# $testProxyLibrary.SupportAppAuthentication = $true -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return true from the test method" { -# Test-TargetResource @testParams | Should Be $true -# } -# -# It "Should not call web application update from the set method, proxy libraries should not change" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $false -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 1 -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].AssemblyName | Should Be "AnotherAssembly" -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries[0].SupportAppAuthentication | Should Be $true -# } -# } -# -# Context -Name "Proxy libraries does not match the current state of empty proxy libraries" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# return $webApp -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# } -# -# Context -Name "Empty proxy libraries matches the current state of empty proxy libraries" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @() -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# return $webApp -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $true -# } -# } -# -# Context -Name "Empty proxy libraries does not match the current state" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @() -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $testProxyLibrary = New-Object Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary -# $testProxyLibrary.AssemblyName = "Assembly" -# $testProxyLibrary.SupportAppAuthentication = $true -# -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# $webApp.ClientCallableSettings.ProxyLibraries.Add($testProxyLibrary) -# -# $Script:SPDscWebApplication = $webApp -# return($webApp) -# } -# -# It "Should return true from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should call web application update from the set method and update proxy libraries" { -# Set-TargetResource @testParams -# $Script:SPDscWebApplication.UpdateCalled | Should Be $true -# $Script:SPDscWebApplication.ClientCallableSettings.ProxyLibraries.Count | Should Be 0 -# } -# } -# -# Context -Name "Proxy libraries to include does not match the current state of empty proxy libraries" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# return $webApp -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# } -# -# Context -Name "Proxy libraries to exclude matches the current state of empty proxy libraries" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibrariesToExclude = @("Assembly") -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# $webApp = $webAppImplementation.Invoke() -# $webApp.ClientCallableSettings.ProxyLibraries.Clear(); -# return $webApp -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $true -# } -# } -# -# Context -Name "ProxyLibraries and ProxyLibrariesToInclude properties are provided" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# return $webAppImplementation.Invoke() -# } -# -# It "Should throw an exception from the get method" { -# { Get-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the test method" { -# { Test-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the set method" { -# { Set-TargetResource @testParams } | Should Throw -# } -# } -# -# Context -Name "ProxyLibraries and ProxyLibrariesToExclude properties are provided" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# ProxyLibrariesToExclude = @("Assembly") -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# return $webAppImplementation.Invoke() -# } -# -# It "Should throw an exception from the get method" { -# { Get-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the test method" { -# { Test-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the set method" { -# { Set-TargetResource @testParams } | Should Throw -# } -# } -# -# Context -Name "All of the proxy libraries properties are provided" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# ProxyLibraries = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# ProxyLibrariesToInclude = @( -# (New-CimInstance -ClassName "MSFT_SPProxyLibraryEntry" ` -# -ClientOnly ` -# -Property @{ -# AssemblyName = "Assembly" -# SupportAppAuthentication = $true -# }) -# ) -# ProxyLibrariesToExclude = @("Assembly") -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# return $webAppImplementation.Invoke() -# } -# -# It "Should throw an exception from the get method" { -# { Get-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the test method" { -# { Test-TargetResource @testParams } | Should Throw -# } -# -# It "Should throw an exception from the set method" { -# { Set-TargetResource @testParams } | Should Throw -# } -# } -# -# Context -Name "The web appliation does not exist" -Fixture { -# $testParams = @{ -# Url = "http://sites.sharepoint.com" -# } -# -# Mock -CommandName Get-SPWebapplication -MockWith { -# return $null -# } -# -# It "Should return a valid object with null on all properties" { -# $result = Get-TargetResource @testParams -# $result | Should Not BeNullOrEmpty -# $result.Url | Should Be $null -# $result.ProxyLibraries | Should Be $null -# $result.ProxyLibrariesToInclude | Should Be $null -# $result.ProxyLibrariesToExclude | Should Be $null -# $result.MaxResourcesPerRequest | Should Be $null -# $result.MaxObjectPaths | Should Be $null -# $result.ExecutionTimeout | Should Be $null -# $result.RequestXmlMaxDepth | Should Be $null -# $result.EnableXsdValidation | Should Be $null -# $result.EnableStackTrace | Should Be $null -# $result.RequestUsageExecutionTimeThreshold | Should Be $null -# $result.EnableRequestUsage | Should Be $null -# $result.LogActionsIfHasRequestException | Should Be $null -# } -# -# It "Should return false from the test method" { -# Test-TargetResource @testParams | Should Be $false -# } -# -# It "Should throw an exception from the set method" { -# { Set-TargetResource @testParams } | Should Throw -# } -# } } } From 8021811d73bc24440a9e8226476e98daf299af15 Mon Sep 17 00:00:00 2001 From: Jens Otto Hatlevold Date: Sun, 14 Oct 2018 20:16:05 +0200 Subject: [PATCH 076/101] Removed strict mode in the SSC resource code --- .../MSFT_SPSelfServiceSiteCreation.psm1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 index d063d9347..281db0e62 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSelfServiceSiteCreation/MSFT_SPSelfServiceSiteCreation.psm1 @@ -1,5 +1,3 @@ -Set-StrictMode -Version 2 - function Get-TargetResource { [CmdletBinding()] From 4c8a06f0db0e35e8034f1b2e4fc6ace9d4652922 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 16 Oct 2018 15:28:49 +0200 Subject: [PATCH 077/101] Update package.json with new versions of NPM packages --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b03b6a726..5afe3c1b0 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,11 @@ "main": "gulpfile.js", "dependencies": { "gulp": "^3.9.1", - "through2": "^2.0.1", - "markdownlint": "^0.2.0" + "through2": "^2.0.3", + "markdownlint": "^0.11.0" }, "devDependencies": { - "gulp-concat": "^2.6.0" + "gulp-concat": "^2.6.1" }, "scripts": { "test": "powershell -File .vscode\\RunPesterTests.ps1" From c28a8af636eaa4307821e726a1c5d92b4bf96d14 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 16 Oct 2018 15:40:13 +0200 Subject: [PATCH 078/101] Removing tests to see if AppVeyor issue is resolved --- appveyor.yml | 2 -- gulpfile.js | 24 ------------------------ package.json | 27 --------------------------- 3 files changed, 53 deletions(-) delete mode 100644 gulpfile.js delete mode 100644 package.json diff --git a/appveyor.yml b/appveyor.yml index 79208bc25..76779f610 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,8 +3,6 @@ version: 2.6.0.{build} install: - git clone https://github.com/PowerShell/DscResource.Tests - - npm --silent install - - ps: | $moduleName = 'SharePointDsc' $mainModuleFolder = "Modules\$moduleName" diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 29bf14cc1..000000000 --- a/gulpfile.js +++ /dev/null @@ -1,24 +0,0 @@ -var gulp = require("gulp"); -var concat = require("gulp-concat"); -var through2 = require("through2"); -var markdownlint = require("markdownlint"); - -gulp.task("test-mdsyntax", function task() { - return gulp.src("Modules/SharePointDsc/DSCResources/**/*.md", { "read": false }) - .pipe(through2.obj(function obj(file, enc, next) { - markdownlint( - { - "files": [ file.path ], - "config": require("./.markdownlint.json") - }, - function callback(err, result) { - var resultString = (result || "").toString(); - if (resultString) { - file.contents = new Buffer(resultString); - } - next(err, file); - }); - })) - .pipe(concat("markdownissues.txt", { newLine: "\r\n" })) - .pipe(gulp.dest(".")); -}); diff --git a/package.json b/package.json deleted file mode 100644 index 5afe3c1b0..000000000 --- a/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "sharepointdsc", - "version": "1.4.0", - "description": "The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm ", - "main": "gulpfile.js", - "dependencies": { - "gulp": "^3.9.1", - "through2": "^2.0.3", - "markdownlint": "^0.11.0" - }, - "devDependencies": { - "gulp-concat": "^2.6.1" - }, - "scripts": { - "test": "powershell -File .vscode\\RunPesterTests.ps1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/PowerShell/SharePointDsc.git" - }, - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/PowerShell/SharePointDsc/issues" - }, - "homepage": "https://github.com/PowerShell/SharePointDsc#readme" -} From af37bd0b5d0ca10b8d6876184bab12941eb33f8e Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Tue, 16 Oct 2018 17:00:16 -0400 Subject: [PATCH 079/101] Fix --- .../MSFT_SPSearchManagedProperty.psm1 | 52 ++++++++++++------- .../MSFT_SPSearchManagedProperty.schema.mof | 2 +- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 index d92ee0945..1499f2aba 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.psm1 @@ -46,8 +46,8 @@ function Get-TargetResource $SafeForAnonymous, [Parameter()] - [System.String] - $Alias, + [System.String[]] + $Aliases, [Parameter()] [System.Boolean] @@ -102,17 +102,12 @@ function Get-TargetResource else { $aliases = $managedProperty.GetAliases() - $alias = "" - if ($aliases) - { - $alias = $aliases[0] - } $mappedCrawlProperties = $managedProperty.GetMappedCrawledProperties($false) - $includeAllCrawlProperties = $false + $includeAllCrawlProperties = $true if ($mappedCrawlProperties) { - $includeAllCrawlProperties = $true + $includeAllCrawlProperties = $false } $results = @{ Name = $params.Name @@ -125,7 +120,7 @@ function Get-TargetResource Refinable = $managedProperty.Refinable Sortable = $managedProperty.Sortable SafeForAnonymous = $managedProperty.SafeForAnonymous - Alias = $alias + Aliases = $aliases TokenNormalization = $managedProperty.TokenNormalization NoWordBreaker = $managedProperty.NoWordBreaker IncludeAllCrawledProperties = $includeAllCrawlProperties @@ -194,8 +189,8 @@ function Set-TargetResource $SafeForAnonymous, [Parameter()] - [System.String] - $Alias, + [System.String[]] + $Aliases, [Parameter()] [System.Boolean] @@ -317,13 +312,32 @@ function Set-TargetResource $managedProperty.RespectPriority = !($params.IncludeAllCrawledProperties) $managedProperty.OverrideValueOfHasMultipleValues = !($params.IncludeAllCrawledProperties) - $managedProperty.Update() + # If alias doesn't already exist, add it - $alias = $managedProperty.GetAliases() | Where-Object{$_ -eq $params.Alias} - if ($alias) + $currentAliases = $managedProperty.GetAliases() + + foreach($alias in $params.Aliases) { - $managedProperty.AddAlias($params.Alias) + $currentAlias = $managedProperty.GetAliases() | Where-Object {$_ -eq $alias} + if(!$currentAlias) + { + $managedProperty.AddAlias($alias) + } } + $managedProperty.Update() + + # Remove the aliases that are different, meaning they currently exist, but were not specified in the config, + # which means we need to remove them. + $currentAliases = $managedProperty.GetAliases() + + foreach($alias in $currentAliases) + { + if(!$params.Aliases.Contains($alias)) + { + $managedProperty.DeleteAlias($alias) + } + } + $managedProperty.Update() # Generate the Crawled Properties mapping $listOfMappedCrawlProperty = [Microsoft.Office.Server.Search.Administration.MappingCollection]::new() @@ -390,8 +404,8 @@ function Test-TargetResource $SafeForAnonymous, [Parameter()] - [System.String] - $Alias, + [System.String[]] + $Aliases, [Parameter()] [System.Boolean] @@ -436,7 +450,7 @@ function Test-TargetResource "Searchable", "NoWordBreaker", "IncludeAllCrawledProperties", - "Alias", + "Aliases", "Sortable", "SafeForAnonymous") } diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof index 70ca94008..f89ef97ef 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchManagedProperty/MSFT_SPSearchManagedProperty.schema.mof @@ -11,7 +11,7 @@ class MSFT_SPSearchManagedProperty : OMI_BaseResource [Write, Description("Should the property be Refinable")] Boolean Refinable; [Write, Description("Should the property be Sortable")] Boolean Sortable; [Write, Description("Should the property be marked as safe for anonymous access")] Boolean SafeForAnonymous; - [Write, Description("Alias of the managed property")] String Alias; + [Write, Description("Aliases of the managed property")] String Aliases[]; [Write, Description("Should the property be case sensitive")] Boolean TokenNormalization; [Write, Description("Should the property only match exact content")] Boolean NoWordBreaker; [Write, Description("Should the property be mapped to all crawled properties")] Boolean IncludeAllCrawledProperties; From 63c154029b25d3dff3acae14188f13af0e18ce63 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 17 Oct 2018 12:53:31 +0200 Subject: [PATCH 080/101] Revert "Removing tests to see if AppVeyor issue is resolved" This reverts commit c28a8af636eaa4307821e726a1c5d92b4bf96d14. --- appveyor.yml | 2 ++ gulpfile.js | 24 ++++++++++++++++++++++++ package.json | 27 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/appveyor.yml b/appveyor.yml index 76779f610..79208bc25 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,8 @@ version: 2.6.0.{build} install: - git clone https://github.com/PowerShell/DscResource.Tests + - npm --silent install + - ps: | $moduleName = 'SharePointDsc' $mainModuleFolder = "Modules\$moduleName" diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..29bf14cc1 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,24 @@ +var gulp = require("gulp"); +var concat = require("gulp-concat"); +var through2 = require("through2"); +var markdownlint = require("markdownlint"); + +gulp.task("test-mdsyntax", function task() { + return gulp.src("Modules/SharePointDsc/DSCResources/**/*.md", { "read": false }) + .pipe(through2.obj(function obj(file, enc, next) { + markdownlint( + { + "files": [ file.path ], + "config": require("./.markdownlint.json") + }, + function callback(err, result) { + var resultString = (result || "").toString(); + if (resultString) { + file.contents = new Buffer(resultString); + } + next(err, file); + }); + })) + .pipe(concat("markdownissues.txt", { newLine: "\r\n" })) + .pipe(gulp.dest(".")); +}); diff --git a/package.json b/package.json new file mode 100644 index 000000000..5afe3c1b0 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "sharepointdsc", + "version": "1.4.0", + "description": "The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm ", + "main": "gulpfile.js", + "dependencies": { + "gulp": "^3.9.1", + "through2": "^2.0.3", + "markdownlint": "^0.11.0" + }, + "devDependencies": { + "gulp-concat": "^2.6.1" + }, + "scripts": { + "test": "powershell -File .vscode\\RunPesterTests.ps1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/PowerShell/SharePointDsc.git" + }, + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/PowerShell/SharePointDsc/issues" + }, + "homepage": "https://github.com/PowerShell/SharePointDsc#readme" +} From c387d5fc29614c1b70d6bed75e1e52ad68393cf7 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 17 Oct 2018 14:23:37 +0200 Subject: [PATCH 081/101] Enable AppVeyor RDP --- appveyor.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 79208bc25..90c6c7592 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,11 @@ version: 2.6.0.{build} +environment: + APPVEYOR_RDP_PASSWORD: "P@ssw0rd" + +init: + - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) + install: - git clone https://github.com/PowerShell/DscResource.Tests From 757d24142beb7252a2a4c7eff1f13334752fc17c Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 17 Oct 2018 16:09:29 +0200 Subject: [PATCH 082/101] Revert "Enable AppVeyor RDP" This reverts commit c387d5fc29614c1b70d6bed75e1e52ad68393cf7. --- appveyor.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 90c6c7592..79208bc25 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,5 @@ version: 2.6.0.{build} -environment: - APPVEYOR_RDP_PASSWORD: "P@ssw0rd" - -init: - - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - install: - git clone https://github.com/PowerShell/DscResource.Tests From 472ea6ad4f43fb8e5ba13711d622b1268d90026e Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 17 Oct 2018 12:04:40 -0400 Subject: [PATCH 083/101] Fix for CA service instance naming --- .../DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 index 9ccd614e3..5339284cc 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1 @@ -164,7 +164,7 @@ function Get-TargetResource $centralAdminProvisioned = $false $ca = Get-SPServiceInstance -Server $env:ComputerName ` | Where-Object -Filterscript { - $_.TypeName -eq "Central Administration" -and $_.Status -eq "Online" + $_.Name -eq "WSS_Administration" -and $_.Status -eq "Online" } if ($null -ne $ca) { @@ -358,7 +358,7 @@ function Set-TargetResource { $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } if ($null -eq $serviceInstance) { @@ -366,7 +366,7 @@ function Set-TargetResource $fqdn = "$($env:COMPUTERNAME).$domain" $serviceInstance = Get-SPServiceInstance -Server $fqdn ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } } if ($null -eq $serviceInstance) @@ -380,7 +380,7 @@ function Set-TargetResource # Unprovision central administration $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } if ($null -eq $serviceInstance) { @@ -388,7 +388,7 @@ function Set-TargetResource $fqdn = "$($env:COMPUTERNAME).$domain" $serviceInstance = Get-SPServiceInstance -Server $fqdn ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } } if ($null -eq $serviceInstance) @@ -600,7 +600,7 @@ function Set-TargetResource { $serviceInstance = Get-SPServiceInstance -Server $env:COMPUTERNAME ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } if ($null -eq $serviceInstance) { @@ -608,7 +608,7 @@ function Set-TargetResource $fqdn = "$($env:COMPUTERNAME).$domain" $serviceInstance = Get-SPServiceInstance -Server $fqdn ` | Where-Object -FilterScript { - $_.TypeName -eq "Central Administration" + $_.Name -eq "WSS_Administration" } } if ($null -eq $serviceInstance) From 75371e99f34622a54dd94e0f5a50e0be2090715c Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 17 Oct 2018 12:07:18 -0400 Subject: [PATCH 084/101] Changelog Changes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258090150..36c250a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * Changes to SharePointDsc * Updated test helpers to force a reload of the resource every time you run a test +* SPFarm + * Fixed issue where Central Admin service was not starting for non-english farms * SPSearchContentSource * Fixed issue with numerical Content Sources name * SPSearchManagedProperty From 83bdaf9912e692b7b3b27877bf16efa99f67ff8b Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 15:59:49 -0400 Subject: [PATCH 085/101] Fixed Tests --- Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 index fa7d39fa5..9b8edc6f2 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1 @@ -188,6 +188,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { if ($global:SPDscCentralAdminCheckDone -eq $true) { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" }) } @@ -263,6 +264,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { if ($global:SPDscCentralAdminCheckDone -eq $true) { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" }) } @@ -408,6 +410,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { $global:SPDscSIRunCount++ return @(@{ TypeName = "Central Administration" + Name = "WSS_Administration" Status = "Online" }) } @@ -495,6 +498,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Mock -CommandName Get-SPServiceInstance -MockWith { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" Status = "Online" }) @@ -574,6 +578,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { { $global:SPDscSIRunCount++ return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" Status = "Online" }) @@ -658,6 +663,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { if ($global:SPDscCentralAdminCheckDone -eq $true) { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" Status = "Online" }) @@ -1002,6 +1008,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { if ($global:SPDscCentralAdminCheckDone -eq $true) { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" Status = "Online" }) @@ -1089,6 +1096,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { if ($global:SPDscCentralAdminCheckDone -eq $true) { return @(@{ + Name = "WSS_Administration" TypeName = "Central Administration" Status = "Online" }) From fc7fb9c771b793ee14aaf42224ae157ee3671104 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 17:41:36 -0400 Subject: [PATCH 086/101] Fixed Aliases Test --- .../SharePointDsc.SPSearchManagedProperty.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 index 762c98e2b..3e891c353 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 @@ -88,7 +88,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { PropertyType = "Text" ServiceAppName = "Search Service Application" HasMultipleValues = $false - Alias = "TestAlias" + Aliases = @("TestAlias") CrawledProperties = @("CP1", "CP2") Ensure = "Present" } From 3a5e9b42266b9f09e988b1cbc5182c1f554923f1 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 18:40:06 -0400 Subject: [PATCH 087/101] Properly retrieve the firstpartitiondirectory --- .../MSFT_SPSearchTopology.psm1 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 index 426eca67e..42805bcd4 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchTopology/MSFT_SPSearchTopology.psm1 @@ -144,16 +144,23 @@ function Get-TargetResource $firstPartition = $null $enterpriseSearchServiceInstance = Get-SPEnterpriseSearchServiceInstance - if($null -ne $enterpriseSearchServiceInstance) + if ($null -ne $enterpriseSearchServiceInstance) { $ssiComponents = $enterpriseSearchServiceInstance.Components - if($null -ne $ssiComponents) + if ($null -ne $ssiComponents) { - if($ssiComponents.Length -gt 1) + if ($ssiComponents.Length -gt 1) { $ssiComponents = $ssiComponents[0] } - $firstPartition = $ssiComponents.IndexLocation + + if ($ssiComponents.IndexLocation.GetType().Name -eq "String") + { + $firstPartition = $ssiComponents.IndexLocation + } + elseif ($ssiComponents.IndexLocation.GetType().Name -eq "Object[]") { + $firstPartition = $ssiComponents.IndexLocation[0] + } } } From 8650ea2d9675c50a5d1302b5c8e1c0b7334df134 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 18:40:54 -0400 Subject: [PATCH 088/101] ChangeLog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258090150..14a4cd331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Added a new ScopeUrl parameter to allow for local source creation * SPSearchTopology * Updated Readme.md to remove some incorrect information + * Fixed logic to handle the FirstPartitionDirectory in Get-TargetResource * SPSite * Added the possibility for creating the default site groups * Added the possibility to set AdministrationSiteType From a57a9bfea9bbb061769ccdd1795715c55870227a Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 19:03:26 -0400 Subject: [PATCH 089/101] Added Delete Alias ScriptMethod to tests --- .../SharePointDsc.SPSearchManagedProperty.Tests.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 index 3e891c353..14c18e13e 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchManagedProperty.Tests.ps1 @@ -131,6 +131,11 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { } -PassThru -Force | Add-Member -MemberType ScriptMethod ` -Name SetMappings ` + -Value { + $null + } -PassThru -Force | + Add-Member -MemberType ScriptMethod ` + -Name DeleteAlias ` -Value { $null } -PassThru -Force From 9dcf0852ca84e6407316403dbff83ff619aabf46 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 19:43:20 -0400 Subject: [PATCH 090/101] Code Coverage changes for the tests --- .../Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 index 9a212b9cf..bdc2de702 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 @@ -120,7 +120,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { AnalyticsProcessing = @($env:COMPUTERNAME) QueryProcessing = @($env:COMPUTERNAME) IndexPartition = @($env:COMPUTERNAME) - FirstPartitionDirectory = "I:\SearchIndexes\0" + FirstPartitionDirectory = @("I:\SearchIndexes\0", "N:\SearchIndexes\1") } Mock -CommandName Get-SPEnterpriseSearchComponent -MockWith { From 9ebebdd082af96f38ecc4d2701297fd0e7322ec0 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 18 Oct 2018 21:19:22 -0400 Subject: [PATCH 091/101] Fixing Tests --- .../Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 index bdc2de702..9a212b9cf 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 @@ -120,7 +120,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { AnalyticsProcessing = @($env:COMPUTERNAME) QueryProcessing = @($env:COMPUTERNAME) IndexPartition = @($env:COMPUTERNAME) - FirstPartitionDirectory = @("I:\SearchIndexes\0", "N:\SearchIndexes\1") + FirstPartitionDirectory = "I:\SearchIndexes\0" } Mock -CommandName Get-SPEnterpriseSearchComponent -MockWith { From 439443b15e7c3f93f5930aef921ce86882b24aaa Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Fri, 19 Oct 2018 08:33:51 -0400 Subject: [PATCH 092/101] Improved Test Coverage --- .../SharePointDsc.SPSearchTopology.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 index 9a212b9cf..862c3fb14 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPSearchTopology.Tests.ps1 @@ -63,6 +63,14 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Server = @{ Address = $env:COMPUTERNAME } + Components = @( + @{ + IndexLocation = @("C:\Program Files\Fake", "C:\Program Files\Fake2") + }, + @{ + IndexLocation = @("C:\Program Files\Fake3") + } + ) Status = "Online" } } From d1910fe37710af098a42de28f23ff9f223513ba7 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Mon, 22 Oct 2018 11:38:23 +0200 Subject: [PATCH 093/101] Added parameter UseWReplyParameter --- .../MSFT_SPTrustedIdentityTokenIssuer.psm1 | 16 ++++++++++++++++ .../MSFT_SPTrustedIdentityTokenIssuer.schema.mof | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 index d076e02a6..533eabd48 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 @@ -49,6 +49,10 @@ [String] $ProviderSignOutUri, + [Parameter()] + [System.Boolean] + $UseWReplyParameter = $false, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -74,6 +78,7 @@ $currentState = "Present" $claimProviderName = $sptrust.ClaimProviderName $providerSignOutUri = $sptrust.ProviderSignOutUri.OriginalString + $useWReplyParameter = $sptrust.UseWReplyParameter $spTrust.ClaimTypeInformation| Foreach-Object -Process { $claimsMappings = $claimsMappings + @{ Name = $_.DisplayName @@ -92,6 +97,7 @@ $currentState = "Absent" $claimProviderName = "" $providerSignOutUri = "" + $useWReplyParameter = [String]::Empty } return @{ @@ -106,6 +112,7 @@ Ensure = $currentState ClaimProviderName = $claimProviderName ProviderSignOutUri = $providerSignOutUri + UseWReplyParameter = $useWReplyParameter } } return $result @@ -161,6 +168,10 @@ function Set-TargetResource [String] $ProviderSignOutUri, + [Parameter()] + [System.Boolean] + $UseWReplyParameter = $false, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount @@ -272,6 +283,7 @@ function Set-TargetResource $runParams.Add("SignInUrl", $params.SignInUrl) $runParams.Add("IdentifierClaim", $params.IdentifierClaim) $runParams.Add("ClaimsMappings", $claimsMappingsArray) + $runParams.Add("UseWReply", $params.UseWReplyParameter) $trust = New-SPTrustedIdentityTokenIssuer @runParams if ($null -eq $trust) @@ -397,6 +409,10 @@ function Test-TargetResource [String] $ProviderSignOutUri, + [Parameter()] + [System.Boolean] + $UseWReplyParameter = $false, + [Parameter()] [System.Management.Automation.PSCredential] $InstallAccount diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof index f0056d898..02d68693c 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.schema.mof @@ -8,7 +8,7 @@ class MSFT_SPClaimTypeMapping }; -[ClassVersion("1.1.0.0"), FriendlyName("SPTrustedIdentityTokenIssuer")] +[ClassVersion("1.2.0.0"), FriendlyName("SPTrustedIdentityTokenIssuer")] class MSFT_SPTrustedIdentityTokenIssuer : OMI_BaseResource { [Key, Description("Name of the SPTrustedIdentityTokenIssuer")] String Name; @@ -21,6 +21,7 @@ class MSFT_SPTrustedIdentityTokenIssuer : OMI_BaseResource [Write, Description("Specify the file path to the signing certificate if it is not stored in the local certificate store already")] String SigningCertificateFilePath; [Write, Description("Name of a claims provider to set with this SPTrustedIdentityTokenIssuer")] String ClaimProviderName; [Write, Description("Sign-out URL")] String ProviderSignOutUri; + [Write, Description("WReply parameter allows SharePoint to specify the return URL to the 3rd party STS upon successful authentication")] Boolean UseWReplyParameter; [Write, Description("Present if the SPTrustedIdentityTokenIssuer should be created, or Absent if it should be removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; + [Write, EmbeddedInstance("MSFT_Credential"), Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5")] String InstallAccount; }; From 8a3547bdeb7a450d0e0b9e47c1920b3ba83073a7 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 22 Oct 2018 07:17:10 -0400 Subject: [PATCH 094/101] Added ChangeLog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04f98b9d3..9b3b12685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fixed issue with numerical Content Sources name * SPSearchManagedProperty * Added a new resource to support Search Managed Properties + * Fix for multiple aliases * SPSearchResultSource * Added a new ScopeUrl parameter to allow for local source creation * SPSearchTopology From 1a7b1f17bc93f0438b0ca5ad2ae692825839b4c5 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Mon, 22 Oct 2018 16:23:15 +0200 Subject: [PATCH 095/101] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4bd6bcd9..80ff59969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ (only supported if using a SharePoint 2013 masterpage) * SPSelfServiceSiteCreation * New resource to manage self-service site creation +* SPTrustedIdentityTokenIssuer + * Added parameter UseWReplyParameter ## 2.5 From ac7bc6166ce7015046dedb2e8895e4e5a7b412f7 Mon Sep 17 00:00:00 2001 From: Yvan Duhamel Date: Tue, 23 Oct 2018 08:26:30 +0200 Subject: [PATCH 096/101] Fixed default value of $useWReplyParameter --- .../MSFT_SPTrustedIdentityTokenIssuer.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 index 533eabd48..f8a37d69a 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPTrustedIdentityTokenIssuer/MSFT_SPTrustedIdentityTokenIssuer.psm1 @@ -97,7 +97,7 @@ $currentState = "Absent" $claimProviderName = "" $providerSignOutUri = "" - $useWReplyParameter = [String]::Empty + $useWReplyParameter = $false } return @{ From 90c41f1880672dc21e6c8734c9fe16d307d6455d Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 23 Oct 2018 16:21:43 +0200 Subject: [PATCH 097/101] Fixes for #935, #936, #937, #939 --- CHANGELOG.md | 8 + .../MSFT_SPManagedMetaDataServiceApp.psm1 | 148 ++++++++---------- .../MSFT_SPSearchContentSource.psm1 | 6 + .../MSFT_SPUserProfileSyncConnection.psm1 | 16 +- ...tDsc.SPManagedMetadataServiceApp.Tests.ps1 | 8 +- 5 files changed, 95 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4bd6bcd9..4868fe0ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,13 @@ * SPManagedMetadataServiceApp * Added additional content type settings (ContentTypePushdownEnabled & ContentTypeSyndicationEnabled). + * Fixed issue where Get method would throw an error when the proxy did not exist. + * Fixed an issue where the resource checks if the proxy exists and if not, it is + created. * SPSearchContentSource * Fixed issue with numerical Content Sources name + * Fixed issue where the code throws an error when the content source cannot be + successfully created * SPSearchManagedProperty * Added a new resource to support Search Managed Properties * SPSearchResultSource @@ -27,6 +32,8 @@ was not created. * Updated resource to grant the InstallAccount permissions to a newly created service application to prevent issues in the Get method. +* SPUserProfileSyncConnection + * Fixed issue where empty IncludedOUs and ExcludedOUs would throw an error * SPWebAppSuiteBar * Fixed incorrect test method that resulted in this resource to never apply changes. * SPServiceAppSecurity @@ -43,6 +50,7 @@ * SPSelfServiceSiteCreation * New resource to manage self-service site creation + ## 2.5 * SPAppCatalog diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index 616c87069..43ab25f78 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -61,22 +61,24 @@ function Get-TargetResource Write-Verbose -Message "Getting managed metadata service application $Name" $result = Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + -Arguments $PSBoundParameters ` + -ScriptBlock { $params = $args[0] $serviceApps = Get-SPServiceApplication -Name $params.Name ` - -ErrorAction SilentlyContinue + -ErrorAction SilentlyContinue $nullReturn = @{ Name = $params.Name Ensure = "Absent" ApplicationPool = $params.ApplicationPool TermStoreAdministrators = @() } + if ($null -eq $serviceApps) { return $nullReturn } + $serviceApp = $serviceApps | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplication" } @@ -181,32 +183,39 @@ function Get-TargetResource if ($null -ne $session) { - $termStore = $session.TermStores[$proxyName] - - if ($null -ne $termstore) + if ($null -ne $proxyName) { - $termStore.TermStoreAdministrators | ForEach-Object -Process { - $name = [string]::Empty - if ($_.IsWindowsAuthenticationMode -eq $true) - { - $name = $_.PrincipalName - } - else - { - $name = (New-SPClaimsPrincipal -Identity $_.PrincipalName -IdentityType EncodedClaim).Value - if ($name -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") + $termStore = $session.TermStores[$proxyName] + + if ($null -ne $termstore) + { + $termStore.TermStoreAdministrators | ForEach-Object -Process { + $name = [string]::Empty + if ($_.IsWindowsAuthenticationMode -eq $true) + { + $name = $_.PrincipalName + } + else { - $name = Resolve-SPDscSecurityIdentifier -SID $name + $name = (New-SPClaimsPrincipal -Identity $_.PrincipalName -IdentityType EncodedClaim).Value + if ($name -match "^s-1-[0-59]-\d+-\d+-\d+-\d+-\d+") + { + $name = Resolve-SPDscSecurityIdentifier -SID $name + } } + $currentAdmins += $name } - $currentAdmins += $name + $termStoreDefaultLanguage = $termStore.DefaultLanguage + $termStoreLanguages = $termStore.Languages + } + else + { + Write-Verbose "No termstore matching to the proxy name '$proxyName' was found" } - $termStoreDefaultLanguage = $termStore.DefaultLanguage - $termStoreLanguages = $termStore.Languages } else { - Write-Verbose "No termstore matching to the proxy name '$proxyName' was found" + Write-Verbose "No valid proxy for $($params.Name) was found" } } else @@ -298,10 +307,6 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters $pName = "$Name Proxy" - if ($null -ne $result.ProxyName) - { - $pName = $result.ProxyName - } if ($PSBoundParameters.ContainsKey("ProxyName")) { $pName = $ProxyName @@ -311,10 +316,10 @@ function Set-TargetResource { Write-Verbose -Message "Creating Managed Metadata Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments ($PSBoundParameters, $pName) ` - -ScriptBlock { + -Arguments ($PSBoundParameters, $pName) ` + -ScriptBlock { $params = $args[0] - $pName = $args[1 ] + $pName = $args[1] $newParams = @{ Name = $params.Name @@ -332,9 +337,9 @@ function Set-TargetResource if ($null -ne $app) { New-SPMetadataServiceApplicationProxy -Name $pName ` - -ServiceApplication $app ` - -DefaultProxyGroup ` - -ContentTypePushdownEnabled + -ServiceApplication $app ` + -DefaultProxyGroup ` + -ContentTypePushdownEnabled } } $result = Get-TargetResource @PSBoundParameters @@ -342,13 +347,13 @@ function Set-TargetResource if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { - if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false ` - -and $ApplicationPool -ne $result.ApplicationPool) + if ([string]::IsNullOrEmpty($ApplicationPool) -eq $false -and ` + $ApplicationPool -ne $result.ApplicationPool) { - Write-Verbose -Message "Updating Managed Metadata Service Application $Name" + Write-Verbose -Message "Updating application pool of Managed Metadata Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments $PSBoundParameters ` - -ScriptBlock { + -Arguments $PSBoundParameters ` + -ScriptBlock { $params = $args[0] $serviceApp = Get-SPServiceApplication -Name $params.Name ` @@ -360,33 +365,42 @@ function Set-TargetResource } } - if (($PSBoundParameters.ContainsKey("ProxyName") -eq $true) ` - -and ($pName -ne $result.ProxyName) - ) + if ($pName -ne $result.ProxyName) { - Write-Verbose -Message "Updating Managed Metadata Service Application Proxy Name from '$($result.ProxyName)' to '$pName'" + Write-Verbose -Message "Updating Managed Metadata Service Application Proxy" Invoke-SPDSCCommand -Credential $InstallAccount ` - -Arguments @($PSBoundParameters, $pName) ` - -ScriptBlock { + -Arguments @($PSBoundParameters, $pName) ` + -ScriptBlock { $params = $args[0] $pName = $args[1] $serviceApps = Get-SPServiceApplication -Name $params.Name ` - -ErrorAction SilentlyContinue + -ErrorAction SilentlyContinue $serviceApp = $serviceApps | Where-Object -FilterScript { $_.GetType().FullName -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplication" } + $serviceAppProxies = Get-SPServiceApplicationProxy -ErrorAction SilentlyContinue if ($null -ne $serviceAppProxies) { $serviceAppProxy = $serviceAppProxies | Where-Object -FilterScript { $serviceApp.IsConnected($_) } + if ($null -ne $serviceAppProxy) { + Write-Verbose -Message "Updating Proxy Name from '$($result.ProxyName)' to '$pName'" $serviceAppProxy.Name = $pName $serviceAppProxy.Update() } + else + { + Write-Verbose -Message "Creating Service Application Proxy '$pName'" + New-SPMetadataServiceApplicationProxy -Name $pName ` + -ServiceApplication $serviceApp ` + -DefaultProxyGroup ` + -ContentTypePushdownEnabled + } } } } @@ -718,51 +732,27 @@ function Test-TargetResource Write-Verbose -Message "Testing managed metadata service application $Name" - $valuesToCheck = @("ApplicationPool", - "Ensure") - $PSBoundParameters.Ensure = $Ensure if ($PSBoundParameters.ContainsKey("ContentTypeHubUrl") -eq $true) { $PSBoundParameters.ContentTypeHubUrl = $ContentTypeHubUrl.TrimEnd('/') - $valuesToCheck += "ContentTypeHubUrl" - } - - if ($PSBoundParameters.ContainsKey("ProxyName") -eq $true) - { - $valuesToCheck += "ProxyName" - } - - if ($PSBoundParameters.ContainsKey("TermStoreAdministrators") -eq $true) - { - $valuesToCheck += "TermStoreAdministrators" - } - - if ($PSBoundParameters.ContainsKey("DefaultLanguage") -eq $true) - { - $valuesToCheck += "DefaultLanguage" - } - - if ($PSBoundParameters.ContainsKey("Languages") -eq $true) - { - $valuesToCheck += "Languages" - } - - if ($PSBoundParameters.ContainsKey("ContentTypePushdownEnabled") -eq $true) - { - $valuesToCheck += "ContentTypePushdownEnabled" - } - - if ($PSBoundParameters.ContainsKey("ContentTypeSyndicationEnabled") -eq $true) - { - $valuesToCheck += "ContentTypeSyndicationEnabled" } $CurrentValues = Get-TargetResource @PSBoundParameters + $valuesToCheck = @("ApplicationPool", + "ContentTypeHubUrl" + "ContentTypePushdownEnabled" + "ContentTypeSyndicationEnabled" + "DefaultLanguage" + "Ensure", + "Languages" + "TermStoreAdministrators" + "ProxyName") + return Test-SPDscParameterState -CurrentValues $CurrentValues ` - -DesiredValues $PSBoundParameters ` - -ValuesToCheck $valuesToCheck + -DesiredValues $PSBoundParameters ` + -ValuesToCheck $valuesToCheck } Export-ModuleMember -Function *-TargetResource diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 index 3c79aa170..79786ce43 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPSearchContentSource/MSFT_SPSearchContentSource.psm1 @@ -363,6 +363,12 @@ function Set-TargetResource -Type $newType ` -Name $params.Name ` -StartAddresses $startAddresses + + if ($null -eq $source) + { + throw ("An error occurred during creation of the Content Source, " + ` + "please check if all parameters are correct.") + } } $allSetArguments = @{ diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 index fc56cbf55..a6b2d7c01 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPUserProfileSyncConnection/MSFT_SPUserProfileSyncConnection.psm1 @@ -137,7 +137,7 @@ function Get-TargetResource if ($null -eq $namingContexts.ContainersIncluded) { - $inclOUs = $null + $inclOUs = @() } else { @@ -146,7 +146,7 @@ function Get-TargetResource if ($null -eq $namingContexts.ContainersExcluded) { - $exclOUs = $null + $exclOUs = @() } else { @@ -158,8 +158,8 @@ function Get-TargetResource UserProfileService = $params.UserProfileService Forest = $namingContexts.DistinguishedName ConnectionCredentials = $accountCredentials - IncludedOUs = @($namingContexts.ContainersIncluded) - ExcludedOUs = @($namingContexts.ContainersExcluded) + IncludedOUs = ,$inclOUs + ExcludedOUs = ,$exclOUs Server = $null Port = $params.Port UseSSL = $useSSL @@ -175,7 +175,7 @@ function Get-TargetResource if ($null -eq $namingContext.ContainersIncluded) { - $inclOUs = $null + $inclOUs = @() } else { @@ -184,7 +184,7 @@ function Get-TargetResource if ($null -eq $namingContext.ContainersExcluded) { - $exclOUs = $null + $exclOUs = @() } else { @@ -196,8 +196,8 @@ function Get-TargetResource Forest = $connection.Server Name = $params.Name ConnectionCredentials = $accountCredentials - IncludedOUs = $inclOUs - ExcludedOUs = $exclOUs + IncludedOUs = ,$inclOUs + ExcludedOUs = ,$exclOUs Server = $domainController UseSSL = $connection.UseSSL UseDisabledFilter = $connection.UseDisabledFilter diff --git a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 index 0a2a2e9a5..195c4485d 100644 --- a/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 +++ b/Tests/Unit/SharePointDsc/SharePointDsc.SPManagedMetadataServiceApp.Tests.ps1 @@ -1237,7 +1237,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Context -Name "When the termstore for the service application proxy exists in the current farm and is not configured correctly" -Fixture { $testParams = @{ - Name = "Managed Metadata Service Application" + Name = "Managed Metadata Service App" ApplicationPool = "SharePoint Service Applications" DatabaseServer = "databaseserver\instance" DatabaseName = "SP_MMS" @@ -1446,7 +1446,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should change the value for 'ContentTypePushdownEnabled'" { $testParams = @{ - Name = "Managed Metadata Service Application" + Name = "Managed Metadata Service App" ApplicationPool = "SharePoint Service Applications" DatabaseServer = "databaseserver\instance" DatabaseName = "SP_MMS" @@ -1465,7 +1465,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { It "Should change the value for 'ContentTypeSyndicationEnabled'" { $testParams = @{ - Name = "Managed Metadata Service Application" + Name = "Managed Metadata Service App" ApplicationPool = "SharePoint Service Applications" DatabaseServer = "databaseserver\instance" DatabaseName = "SP_MMS" @@ -1485,7 +1485,7 @@ Describe -Name $Global:SPDscHelper.DescribeHeader -Fixture { Context -Name "When there is no Managed Metadata Service and everything should be created and configured correctly" -Fixture { $testParams = @{ - Name = "Managed Metadata Service Application" + Name = "Managed Metadata Service App" ProxyName = "Managed Metadata Service Application Proxy" ApplicationPool = "SharePoint Service Applications" DatabaseServer = "databaseserver\instance" From e9a5aeea02aae64c90eaf475db476cf22a4a2205 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 23 Oct 2018 16:24:45 +0200 Subject: [PATCH 098/101] Updated changelog alphabetically --- CHANGELOG.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e512ea6d3..e03c4dfd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,11 @@ * SPSearchTopology * Updated Readme.md to remove some incorrect information * Fixed logic to handle the FirstPartitionDirectory in Get-TargetResource +* SPSelfServiceSiteCreation + * New resource to manage self-service site creation +* SPServiceAppSecurity + * Added local farm token. + * Fixed issues that prevented the resource to work as expected in many situations. * SPSite * Added the possibility for creating the default site groups * Added the possibility to set AdministrationSiteType @@ -31,6 +36,8 @@ * Fixed a typo in the values to check for AdministrationSiteType * Fixed an access denied issue when creating default site groups when the run as account does not have proper permissions for the site +* SPTrustedIdentityTokenIssuer + * Added parameter UseWReplyParameter * SPUserProfileServiceApp * Fixed issue which was introduced in v2.5 where the service application proxy was not created. @@ -38,24 +45,15 @@ application to prevent issues in the Get method. * SPUserProfileSyncConnection * Fixed issue where empty IncludedOUs and ExcludedOUs would throw an error -* SPWebAppSuiteBar - * Fixed incorrect test method that resulted in this resource to never apply changes. -* SPServiceAppSecurity - * Added local farm token. - * Fixed issues that prevented the resource to work as expected in many situations. -* SPWebAppPropertyBag - * New resource to manage web application property bag * SPWebAppClientCallableSettings * New resource to manage web application client callable settings including proxy libraries. +* SPWebAppPropertyBag + * New resource to manage web application property bag * SPWebAppSuiteBar + * Fixed incorrect test method that resulted in this resource to never apply changes. * Enable usage of SuiteBarBrandingElementHtml for SharePoint 2016 (only supported if using a SharePoint 2013 masterpage) -* SPSelfServiceSiteCreation - * New resource to manage self-service site creation -* SPTrustedIdentityTokenIssuer - * Added parameter UseWReplyParameter - ## 2.5 From 395a943b61449c7e7c91f190b171b27d27e6c2f3 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Tue, 23 Oct 2018 16:31:24 +0200 Subject: [PATCH 099/101] Corrected deleted code --- .../MSFT_SPManagedMetaDataServiceApp.psm1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 index 43ab25f78..5d6a0db23 100644 --- a/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 +++ b/Modules/SharePointDsc/DSCResources/MSFT_SPManagedMetadataServiceApp/MSFT_SPManagedMetaDataServiceApp.psm1 @@ -307,6 +307,11 @@ function Set-TargetResource $result = Get-TargetResource @PSBoundParameters $pName = "$Name Proxy" + if ($null -ne $result.ProxyName) + { + $pName = $result.ProxyName + } + if ($PSBoundParameters.ContainsKey("ProxyName")) { $pName = $ProxyName From bbf0051c1bfd693855a69e8a63299a9a88e05fa7 Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 24 Oct 2018 09:41:13 +0200 Subject: [PATCH 100/101] Updated manifest and changelog for v2.6 release --- CHANGELOG.md | 4 +- Modules/SharePointDsc/SharePointDsc.psd1 | 78 ++++++++++++++---------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e03c4dfd1..5f32f1a66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,7 @@ # Change log for SharePointDsc -## Unreleased +## 2.6 -* Changes to SharePointDsc - * Updated test helpers to force a reload of the resource every time you run a test * SPFarm * Fixed issue where Central Admin service was not starting for non-english farms * SPManagedMetadataServiceApp diff --git a/Modules/SharePointDsc/SharePointDsc.psd1 b/Modules/SharePointDsc/SharePointDsc.psd1 index c3eb9f8bb..667f4baa8 100644 --- a/Modules/SharePointDsc/SharePointDsc.psd1 +++ b/Modules/SharePointDsc/SharePointDsc.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '2.5.0.0' +ModuleVersion = '2.6.0.0' # ID used to uniquely identify this module GUID = '6c1176a0-4fac-4134-8ca2-3fa8a21a7b90' @@ -128,40 +128,56 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = " - * SPAppCatalog - * Updated resource to retrieve the Farm account instead of requiring it - to be specifically used - * SPDatabaseAAG - * Updated readme.md to specify that this resource also updates the database - connection string - * SPDiagnosticsProvider - * Fixed issue where enabling providers did not work * SPFarm - * Added ability to check and update CentralAdministrationPort - * SPLogLevel - * Added High as TraceLevel, which was not included yet - * SPRemoteFarmTrust - * Updated readme.md file to add a link that was lost during earlier updates - * SPSearchServiceApp - * Updated Set method to check if service application pool exists. Resource - will throw an error if it does not exist + * Fixed issue where Central Admin service was not starting for non-english farms + * SPManagedMetadataServiceApp + * Added additional content type settings (ContentTypePushdownEnabled & + ContentTypeSyndicationEnabled). + * Fixed issue where Get method would throw an error when the proxy did not exist. + * Fixed an issue where the resource checks if the proxy exists and if not, it is + created. + * SPSearchContentSource + * Fixed issue with numerical Content Sources name + * Fixed issue where the code throws an error when the content source cannot be + successfully created + * SPSearchManagedProperty + * Added a new resource to support Search Managed Properties + * Fix for multiple aliases + * SPSearchResultSource + * Added a new ScopeUrl parameter to allow for local source creation * SPSearchTopology - * Fixed issue where Get method threw an error when the specified service - application didn't exist yet - * Fixed issue where the resource would fail is the FQDN was specified - * SPShellAdmins - * Added ExcludeDatabases parameter for AllDatabases + * Updated Readme.md to remove some incorrect information + * Fixed logic to handle the FirstPartitionDirectory in Get-TargetResource + * SPSelfServiceSiteCreation + * New resource to manage self-service site creation + * SPServiceAppSecurity + * Added local farm token. + * Fixed issues that prevented the resource to work as expected in many situations. * SPSite - * Added ability to check and update QuotaTemplate, OwnerAlias and SecondaryOwnerAlias - * SPSiteUrl - * New resource to manage site collection urls for host named site collections - * SPTrustedIdentityTokenIssuerProviderRealm - * Fixed issue where Get method threw an error when the realm didn't exist yet + * Added the possibility for creating the default site groups + * Added the possibility to set AdministrationSiteType + * Fixed test method that in some cases always would return false + * Fixed a typo in the values to check for AdministrationSiteType + * Fixed an access denied issue when creating default site groups + when the run as account does not have proper permissions for the site + * SPTrustedIdentityTokenIssuer + * Added parameter UseWReplyParameter * SPUserProfileServiceApp - * Fix for issue where an update conflict error was thrown when new service - application was created - * Added SiteNamingConflictResolution parameter to the resource - " + * Fixed issue which was introduced in v2.5 where the service application proxy + was not created. + * Updated resource to grant the InstallAccount permissions to a newly created service + application to prevent issues in the Get method. + * SPUserProfileSyncConnection + * Fixed issue where empty IncludedOUs and ExcludedOUs would throw an error + * SPWebAppClientCallableSettings + * New resource to manage web application client callable settings including + proxy libraries. + * SPWebAppPropertyBag + * New resource to manage web application property bag + * SPWebAppSuiteBar + * Fixed incorrect test method that resulted in this resource to never apply changes. + * Enable usage of SuiteBarBrandingElementHtml for SharePoint 2016 + (only supported if using a SharePoint 2013 masterpage) " } # End of PSData hashtable } # End of PrivateData hashtable From db86c283ffaefa6d067b7f566f71f0a163e0baff Mon Sep 17 00:00:00 2001 From: Yorick Kuijs Date: Wed, 24 Oct 2018 10:41:20 +0200 Subject: [PATCH 101/101] Added help files --- ...about_SPManagedMetaDataServiceApp.help.txt | 41 +++++ .../about_SPSearchManagedProperty.help.txt | 112 ++++++++++++ .../en-US/about_SPSearchResultSource.help.txt | 4 + .../en-US/about_SPSearchTopology.help.txt | 5 +- .../about_SPSelfServiceSiteCreation.help.txt | 74 ++++++++ .../en-US/about_SPServiceAppSecurity.help.txt | 36 ++++ .../SharePointDsc/en-US/about_SPSite.help.txt | 46 +++++ ...bout_SPTrustedIdentityTokenIssuer.help.txt | 4 + ...ut_SPWebAppClientCallableSettings.help.txt | 168 ++++++++++++++++++ .../en-US/about_SPWebAppPropertyBag.help.txt | 93 ++++++++++ .../en-US/about_SPWebAppSuiteBar.help.txt | 9 +- 11 files changed, 583 insertions(+), 9 deletions(-) create mode 100644 Modules/SharePointDsc/en-US/about_SPSearchManagedProperty.help.txt create mode 100644 Modules/SharePointDsc/en-US/about_SPSelfServiceSiteCreation.help.txt create mode 100644 Modules/SharePointDsc/en-US/about_SPWebAppClientCallableSettings.help.txt create mode 100644 Modules/SharePointDsc/en-US/about_SPWebAppPropertyBag.help.txt diff --git a/Modules/SharePointDsc/en-US/about_SPManagedMetaDataServiceApp.help.txt b/Modules/SharePointDsc/en-US/about_SPManagedMetaDataServiceApp.help.txt index 62362444e..65cb8b84d 100644 --- a/Modules/SharePointDsc/en-US/about_SPManagedMetaDataServiceApp.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPManagedMetaDataServiceApp.help.txt @@ -20,6 +20,9 @@ The language settings (default and working) are only changed if they are part of the bound parameters. Otherwise they will not be altered. + ContentTypePushdownEnabled and ContentTypeSyndicationEnabled will only be altered + if they are part of the bound parameters. + .PARAMETER Name Key - string The name of the managed metadata service application @@ -61,6 +64,14 @@ Write - UInt32 The LCIDs of the working languages (only set when the app is provisioned) +.PARAMETER ContentTypePushdownEnabled + Write - boolean + Specifies that existing instances of changed content types in subsites and libraries will be updated. + +.PARAMETER ContentTypeSyndicationEnabled + Write - boolean + Specifies that this connection will provide access to the content types that are associated with the managed metadata service application. + .PARAMETER InstallAccount Write - String POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 @@ -213,3 +224,33 @@ Configuration Example } +.EXAMPLE + This example shows how to deploy the Managed Metadata service app to the local SharePoint farm + and also include a specific list of users to be the term store administrators. + + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPManagedMetaDataServiceApp ManagedMetadataServiceApp + { + Name = "Managed Metadata Service Application" + PSDscRunAsCredential = $SetupAccount + ApplicationPool = "SharePoint Service Applications" + DatabaseServer = "SQL.contoso.local" + DatabaseName = "SP_ManagedMetadata" + ContentTypeHubUrl = "http://contoso.sharepoint.com/sites/ct" + ContentTypePushdownEnabled = $true + ContentTypeSyndicationEnabled = $true + } + } +} + + diff --git a/Modules/SharePointDsc/en-US/about_SPSearchManagedProperty.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchManagedProperty.help.txt new file mode 100644 index 000000000..a144dcf8b --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSearchManagedProperty.help.txt @@ -0,0 +1,112 @@ +.NAME + SPSearchManagedProperty + +# Description + + **Type:** Distributed + + This resource will deploy and configure a managed property in a specified search + service application. + + The default value for the Ensure parameter is Present. When not specifying this + parameter, the managed property is created. + +.PARAMETER Name + Key - String + The name of the managed property + +.PARAMETER ServiceAppName + Key - String + The name of the search service app that this managed property exists within + +.PARAMETER PropertyType + Required - String + Allowed values: Binary, DateTime, Decimal, Double, Integer, Text, YesNo + The type of managed property - choose between Binary, DateTime, Decimal, Double, Integer, Text, and YesNo + +.PARAMETER Searchable + Write - Boolean + Should the property be Searchable + +.PARAMETER Queryable + Write - Boolean + Should the property be Queryable + +.PARAMETER Retrievable + Write - Boolean + Should the property be Retrievable + +.PARAMETER HasMultipleValues + Write - Boolean + Should the property allow for multiple values to be selected + +.PARAMETER Refinable + Write - Boolean + Should the property be Refinable + +.PARAMETER Sortable + Write - Boolean + Should the property be Sortable + +.PARAMETER SafeForAnonymous + Write - Boolean + Should the property be marked as safe for anonymous access + +.PARAMETER Aliases + Write - String + Aliases of the managed property + +.PARAMETER TokenNormalization + Write - Boolean + Should the property be case sensitive + +.PARAMETER NoWordBreaker + Write - Boolean + Should the property only match exact content + +.PARAMETER IncludeAllCrawledProperties + Write - Boolean + Should the property be mapped to all crawled properties + +.PARAMETER CrawledProperties + Write - String + List of crawled properties that the property is mapped with + +.PARAMETER Ensure + Write - string + Allowed values: Present, Absent + Present if the source should exist, absent if it should not + +.PARAMETER InstallAccount + Write - String + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + +.EXAMPLE + This example shows how create a new Managed Property, using the required parameters + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSearchManagedProperty MyProperty + { + Name = "MyProperty" + ServiceAppName = "Search Service Application" + PropertyType = "Text" + Searchable = $true + IncludeAllCrawledProperties = $false + CrawledProperties = @("OWS_Notes, Personal:AboutMe") + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPSearchResultSource.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchResultSource.help.txt index 831637c09..2fa561889 100644 --- a/Modules/SharePointDsc/en-US/about_SPSearchResultSource.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPSearchResultSource.help.txt @@ -40,6 +40,10 @@ Write - String The URI to connect to the remote location +.PARAMETER ScopeUrl + Write - String + The URI of the site where to create the result source. Leave empty to have it created globally + .PARAMETER Ensure Write - string Allowed values: Present, Absent diff --git a/Modules/SharePointDsc/en-US/about_SPSearchTopology.help.txt b/Modules/SharePointDsc/en-US/about_SPSearchTopology.help.txt index 0fc94c07a..47784d4f2 100644 --- a/Modules/SharePointDsc/en-US/about_SPSearchTopology.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPSearchTopology.help.txt @@ -10,10 +10,7 @@ that the current server should be running. Any combination of roles can be specified and the topology will be upaded to reflect the current servers new roles. If this is the first server to apply topology to a farm, then at least - one search index must be provided. To this end, the FirstPartitionIndex, - FirstPartitionDirectory and FirstPartitionServers allow configuring where the - first index partition will belong. This will behave the same as the - SPSearchIndexPartition resource. + one search index must be provided. You only need to run the topology resource on a single server in the farm. It will enable the components on each server in the farm, as specified in diff --git a/Modules/SharePointDsc/en-US/about_SPSelfServiceSiteCreation.help.txt b/Modules/SharePointDsc/en-US/about_SPSelfServiceSiteCreation.help.txt new file mode 100644 index 000000000..4044d0d72 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPSelfServiceSiteCreation.help.txt @@ -0,0 +1,74 @@ +.NAME + SPSelfServiceSiteCreation + +# Description + + **Type:** Distributed + + This resource is used to configure self-service site creation on a web + application. + + NOTE: + The web application needs a root level ("/") site collection for the + self-service site creation to function properly. It is not required to have this + site collection present in the web application to succesfully configure this + resource. + + NOTE2: + If Enabled is set to false, ShowStartASiteMenuItem is automatically set to false + by the resource if ShowStartASiteMenuItem is not specified. Setting + ShowStartASiteMenuItem to true at the same time as Enabled is set to false + will generate an error. + + ## Hybrid self-service site creation + + It is possible to configure self-service site creation to create sites in + SharePoint Online. This requires that [hybrid self-service site creation](https://docs.microsoft.com/en-us/sharepoint/hybrid/hybrid-self-service-site-creation) + is configured using the Hybrid Picker. + +.PARAMETER Url + Key - string + The url of the web application + +.PARAMETER Enabled + Required - boolean + Specifies if users are allowed to create site collections or not + +.PARAMETER OnlineEnabled + Write - boolean + Specifies if site collections are created in SharePoint Online in a hybrid configuration. Hybrid configuration needs to be caried out seperately using the Hybrid Picker + +.PARAMETER QuotaTemplate + Write - string + The quota template to apply to new site collections. Specify null to not apply any qouta template + +.PARAMETER ShowStartASiteMenuItem + Write - boolean + Should the Start a Site link be displayed. Must be false or not specified if Enabled is false + +.PARAMETER CreateIndividualSite + Write - boolean + Should Self Service Site Creation create an individual Site, false for a Site Collection + +.PARAMETER represent + Write - to + Specifies the URL of the parent site where new sites are to be created. This is only used when CreateIndividualSite is true. Use [%userid%] to represent the ID of the user who is creating the site, for example: /projects/[%userid%] + +.PARAMETER PolicyOption + Write - string + Allowed values: MustHavePolicy, CanHavePolicy, NotHavePolicy + Specifies what site classification should be displayed + +.PARAMETER RequireSecondaryContact + Write - boolean + Specifies if users needs to provide one or more additional site administrators + +.PARAMETER CustomFormUrl + Write - string + Specifies a custom form URL to use for Self Service Site Creation. This is only used when CreateIndividualSite is true. Must be an absolute URL or empty to use built in form (_layouts/_layouts/15/scsignup.aspx) + +.PARAMETER InstallAccount + Write - String + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + diff --git a/Modules/SharePointDsc/en-US/about_SPServiceAppSecurity.help.txt b/Modules/SharePointDsc/en-US/about_SPServiceAppSecurity.help.txt index 0e92c08a2..df557c5cc 100644 --- a/Modules/SharePointDsc/en-US/about_SPServiceAppSecurity.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPServiceAppSecurity.help.txt @@ -18,6 +18,10 @@ control a specific set of users to add or remove, without changing any other members that are in the group already that may not be specified here, allowing + NOTE: + In order to specify Local Farm you can use the token "\{LocalFarm\}" + as the username. The token is case sensitive. + .PARAMETER ServiceAppName Key - String The name of the service application you wish to apply security settings to @@ -81,3 +85,35 @@ } +.EXAMPLE + This example shows how to use the local farm token to grant + full control permission to the local farm to the + user profile service app's sharing permission. + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + $members = @() + $members += MSFT_SPServiceAppSecurityEntry { + Username = "{LocalFarm}" + AccessLevel = "Full Control" + } + SPServiceAppSecurity UserProfileServiceSecurity + { + ServiceAppName = "User Profile Service Application" + SecurityType = "SharingPermissions" + Members = $members + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPSite.help.txt b/Modules/SharePointDsc/en-US/about_SPSite.help.txt index 3af78c55b..25972ab8c 100644 --- a/Modules/SharePointDsc/en-US/about_SPSite.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPSite.help.txt @@ -21,6 +21,15 @@ If you want to change the IIS website binding settings, please use the xWebsite resource in the xWebAdministration module. + NOTE2: + The CreateDefaultGroups parameter is only used for creating default site + groups. It will not remove or change the default groups if they already exist. + + NOTE3: + AdministrationSiteType is used in combination with the resource + SPWebAppClientCallableSettings. The required proxy library must be configured + before the administration site type has any effect. + .PARAMETER Url Key - string The URL of the site collection @@ -73,6 +82,15 @@ Write - string The template to apply to the site collection +.PARAMETER CreateDefaultGroups + Write - boolean + Create the default site groups in the site collection + +.PARAMETER AdministrationSiteType + Write - string + Allowed values: TenantAdministration, None + The administration site type + .PARAMETER InstallAccount Write - String POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 @@ -133,3 +151,31 @@ } +.EXAMPLE + This example creates a site collection with the provided details + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPSite TeamSite + { + Url = "http://sharepoint.contoso.com" + OwnerAlias = "CONTOSO\ExampleUser" + HostHeaderWebApplication = "http://spsites.contoso.com" + Name = "Team Sites" + Template = "STS#0" + AdministrationSiteType = "TenantAdministration" + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPTrustedIdentityTokenIssuer.help.txt b/Modules/SharePointDsc/en-US/about_SPTrustedIdentityTokenIssuer.help.txt index 4987bc90d..fc2ad394c 100644 --- a/Modules/SharePointDsc/en-US/about_SPTrustedIdentityTokenIssuer.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPTrustedIdentityTokenIssuer.help.txt @@ -74,6 +74,10 @@ Write - String Sign-out URL +.PARAMETER UseWReplyParameter + Write - Boolean + WReply parameter allows SharePoint to specify the return URL to the 3rd party STS upon successful authentication + .PARAMETER Ensure Write - String Allowed values: Present, Absent diff --git a/Modules/SharePointDsc/en-US/about_SPWebAppClientCallableSettings.help.txt b/Modules/SharePointDsc/en-US/about_SPWebAppClientCallableSettings.help.txt new file mode 100644 index 000000000..14b999c8a --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPWebAppClientCallableSettings.help.txt @@ -0,0 +1,168 @@ +.NAME + SPWebAppClientCallableSettings + +# Description + + **Type:** Distributed + + This resource sets the client callable settings for the web application. + It can set the proxy libraries and specific properties for the client + callable settings. + The resource can for example be used to increase the timeout for client + code, and to enable the tenant administration functionality. + + Tenant administration functionality enables client code to work with + the namespace Microsoft.Online.SharePoint.Client.Tenant from the + assembly with the same name. This enables client code to create site + collection, list all site collections, and more. + + In order to use the tenant administration client code a site collection + within the web application needs to be designated as a tenant + administration site collection. This can be done using the SPSite + resource setting the AdministrationSiteType to TenantAdministration. + Use this site collection when creating a client side connection. + + More information about the tenant can be found in a [blog + post] + (https://blogs.msdn.microsoft.com/vesku/2015/12/04/sharepoint-tenant-csom-object-support-in-sharepoint-2013-and-2016/) + by Vesa Juvonen. In another [blog post] + (https://blogs.msdn.microsoft.com/vesku/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom/) + he goes into more details of + the setup and architecture, and includes sample code for how to use. + + NOTE: + Proxy library used for enabling tenant administration: + + **SharePoint 2013** (Requires mininum April 2014 Cumulative Update): + Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub + , Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + + **SharePoint 2016**: + Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub + , Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c + + In both version set the SupportAppAuthentication property to true. + + NOTE2: + An IIS reset needs to be performed on all servers in the farm after + modifying the registered proxy libraries. + +.PARAMETER Url + Key - string + The URL of the web application to set blocked file types for + +.PARAMETER ProxyLibraries + write - string + A list of proxy libraries to set. Those not in this list will be removed + +.PARAMETER ProxyLibrariesToInclude + write - string + A list of proxy libraries to add. Proxy libraries not in this list will be kept + +.PARAMETER ProxyLibrariesToExclude + write - string + A list of proxy libraries to remove. Proxy libraries not in this list will be kept + +.PARAMETER MaxResourcesPerRequest + write - UInt32 + Sets the maximum number of internal SPRequest objects that can be included in one request + +.PARAMETER MaxObjectPaths + write - UInt32 + Sets the maximum number of object paths that can be used within one request + +.PARAMETER ExecutionTimeout + write - UInt32 + Sets the execution timeout for the client request in minutes + +.PARAMETER RequestXmlMaxDepth + write - UInt32 + Sets the maximum depth of the request XML that is sent by the client measured in 'tag' count + +.PARAMETER EnableXsdValidation + write - Boolean + Sets a Boolean value that specifies whether to enable XSD validation against an XML request or not + +.PARAMETER EnableStackTrace + write - Boolean + Sets a Boolean value that specifies whether the server can send stack trace data to the client + +.PARAMETER RequestUsageExecutionTimeThreshold + write - UInt32 + Sets the threshold in milliseconds for logging csom request usage data + +.PARAMETER EnableRequestUsage + write - Boolean + Sets a Boolean value that specifies whether to log usage data or not + +.PARAMETER LogActionsIfHasRequestException + write - Boolean + Sets a Boolean value that specifies whether to log usage data when request has an exception or not + +.PARAMETER InstallAccount + Write - string + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + +.EXAMPLE + This example shows how to set the client callable settings for a web application + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + SPWebAppClientCallableSettings DefaultClientCallableSettings + { + Url = "http://example.contoso.local" + MaxResourcesPerRequest = 16 + MaxObjectPaths = 256 + ExecutionTimeout = 90 + RequestXmlMaxDepth = 32 + EnableXsdValidation = $true + EnableStackTrace = $false + RequestUsageExecutionTimeThreshold = 800 + EnableRequestUsage = $true + LogActionsIfHasRequestException = $true + PsDscRunAsCredential = $SetupAccount + } + } + } + + +.EXAMPLE + This example shows how to enable tenant administration for a web application in a SharePoint 2013 farm + + + Configuration Example + { + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + Import-DscResource -ModuleName SharePointDsc + + node localhost { + $proxyLibraries = @() + $proxyLibraries += MSFT_SPProxyLibraryEntry { + AssemblyName = "Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" + SupportAppAuthentication = $true + } + + SPWebAppClientCallableSettings TenantAdministration + { + Url = "http://example.contoso.local" + ProxyLibraries = $proxyLibraries + PsDscRunAsCredential = $SetupAccount + } + } + } + + diff --git a/Modules/SharePointDsc/en-US/about_SPWebAppPropertyBag.help.txt b/Modules/SharePointDsc/en-US/about_SPWebAppPropertyBag.help.txt new file mode 100644 index 000000000..0a91519b8 --- /dev/null +++ b/Modules/SharePointDsc/en-US/about_SPWebAppPropertyBag.help.txt @@ -0,0 +1,93 @@ +.NAME + SPWebAppPropertyBag + +# Description + + **Type:** Distributed + + This resource is used to work with SharePoint Property Bags + at the web application level. + The account that runs this resource must be a farm administrator. + + The default value for the Ensure parameter is Present. When not specifying this + parameter, the property bag is configured. + +.PARAMETER WebAppUrl + Key - string + The URL of the web application + +.PARAMETER Key + Key - string + The key of the SPWebApplication property + +.PARAMETER Value + Write - String + Value of the SPWebApplication property + +.PARAMETER Ensure + Write - string + Allowed values: Present, Absent + Set to present to ensure the SPWebApplication property exists, or absent to ensure it is removed + +.PARAMETER InstallAccount + Write - String + POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5 + + +.EXAMPLE + This example shows how add property bag value in a web application. + + +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + + Import-DscResource -ModuleName SharePointDsc + + node localhost + { + SPWebAppPropertyBag APPLICATION_APPCodeProperty + { + PsDscRunAsCredential = $SetupAccount + WebAppUrl = "https://web.contoso.com" + Key = "KeyToAdd" + Value = "ValueToAddOrModify" + Ensure = "Present" + } + } +} + + +.EXAMPLE + This example shows how remove a property bag value in a web application. + + +Configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [PSCredential] + $SetupAccount + ) + + Import-DscResource -ModuleName SharePointDsc + + node localhost + { + SPWebAppPropertyBag APPLICATION_APPCodeProperty + { + PsDscRunAsCredential = $SetupAccount + WebAppUrl = "https://web.contoso.com" + Key = "KeyToRemove" + Ensure = "Absent" + } + } +} + + diff --git a/Modules/SharePointDsc/en-US/about_SPWebAppSuiteBar.help.txt b/Modules/SharePointDsc/en-US/about_SPWebAppSuiteBar.help.txt index 6654bb948..5f7e74cb9 100644 --- a/Modules/SharePointDsc/en-US/about_SPWebAppSuiteBar.help.txt +++ b/Modules/SharePointDsc/en-US/about_SPWebAppSuiteBar.help.txt @@ -11,10 +11,9 @@ Requirements: For SharePoint 2013, only the SuiteBarBrandingElementHtml - should be specified, whereas for SharePoint 2016, only one - or all of SuiteNavBrandingLogoNavigationUrl, - SuiteNavBrandingLogoTitle, SuiteNavBrandingLogoUrl or - SuiteNavBrandingText should be. + should be specified, whereas for SharePoint 2016, all properties + are supported. Note that SuiteBarBrandingElementHtml has no + effect unless using a SharePoint 2013 master page. .PARAMETER WebAppUrl Key - string @@ -38,7 +37,7 @@ .PARAMETER SuiteBarBrandingElementHtml Write - String - SP2013: HTML to inject in the left hand-side of the Suite Bar + SP2013+: HTML to inject in the left hand-side of the Suite Bar .PARAMETER InstallAccount Write - String