зеркало из https://github.com/microsoft/PFE.git
Merge branch 'master' of https://github.com/RCormier-MSFT/PFE
This commit is contained in:
Коммит
1f00935be3
|
@ -0,0 +1,4 @@
|
|||
[
|
||||
"Common Tests - Validate Markdown Files",
|
||||
"Common Tests - Validate Example Files"
|
||||
]
|
|
@ -0,0 +1,26 @@
|
|||
codecov:
|
||||
notify:
|
||||
require_ci_to_pass: no
|
||||
# dev should be the baseline for reporting
|
||||
branch: dev
|
||||
|
||||
comment:
|
||||
layout: "reach, diff"
|
||||
behavior: default
|
||||
|
||||
coverage:
|
||||
range: 50..80
|
||||
round: down
|
||||
precision: 0
|
||||
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
# Set the overall project code coverage requirement to 80%
|
||||
target: 80
|
||||
patch:
|
||||
default:
|
||||
# Set the pull request requirement to not regress overall coverage by more than 5%
|
||||
# and let codecov.io set the goal for the code changed in the patch.
|
||||
target: auto
|
||||
threshold: 5
|
|
@ -285,4 +285,4 @@ __pycache__/
|
|||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
*.xsd.cs
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD029": {
|
||||
"style": "ordered"
|
||||
},
|
||||
"MD034": false,
|
||||
"no-hard-tabs": true
|
||||
}
|
|
@ -2,36 +2,39 @@ function Get-RegistryCredential
|
|||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]$ApplicationName,
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]$OrgName,
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]$AccountDescription
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]
|
||||
$ApplicationName,
|
||||
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]
|
||||
$OrgName,
|
||||
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]
|
||||
$AccountDescription
|
||||
)
|
||||
|
||||
$CredentialExists = CheckForExistingRegistryCredential
|
||||
$CredentialExists = CheckForExistingRegistryCredential -ApplicationName $ApplicationName -OrgName $OrgName -AccountDescription $AccountDescription
|
||||
|
||||
if($CredentialExists)
|
||||
{
|
||||
Write-Verbose "Credential object matching the parameters specified has been found`r`nRetrieving credential object from the registry"
|
||||
$CredentialUserName = (Get-ItemProperty -Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)" -Name "UserName" -ErrorAction SilentlyContinue).UserName
|
||||
$CredentialPassword = ConvertTo-SecureString (Get-ItemProperty -Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)" -Name "Password" -ErrorAction SilentlyContinue).Password
|
||||
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($CredentialUserName, $CredentialPassword)
|
||||
if($Credential)
|
||||
{
|
||||
Write-Verbose "Credential `'$($AccountDescription)`' has been retrieved"
|
||||
try {
|
||||
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($CredentialUserName, $CredentialPassword)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Verbose "Could not create credential object using information stored in the registry at `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountName)`'"
|
||||
catch {
|
||||
throw "Could not create credential object using information stored in the registry at `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountName)`'"
|
||||
Write-Host "Credential `'$($AccountDescription)`' could not be retrieved" -ForegroundColor Yellow
|
||||
}
|
||||
Return $Credential
|
||||
Write-Verbose "Credential `'$($AccountDescription)`' has been retrieved"
|
||||
|
||||
return $Credential
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Verbose "Could not locate credential object at `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)`'"
|
||||
Write-Host "No credentials could be found at the specified location"
|
||||
throw "Could not locate credential object at `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)`'"
|
||||
}
|
||||
}
|
|
@ -10,25 +10,25 @@ function Get-SPAllUserInfo
|
|||
|
||||
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
|
||||
|
||||
$site = (Get-SPWeb $Url).Site
|
||||
$usersList = $site.RootWeb.Lists["User Information List"];
|
||||
$site = Get-SPSite $Url
|
||||
$usersList = $site.RootWeb.Lists["User Information List"]
|
||||
|
||||
$userInfo = @();
|
||||
$userInfo = @()
|
||||
|
||||
foreach($userItem in $usersList.Items)
|
||||
{
|
||||
$xml = $userItem.Xml
|
||||
|
||||
$createdDate = $null
|
||||
$start = $xml.IndexOf("ows_Created", 0) + 13;
|
||||
$start = $xml.IndexOf("ows_Created", 0) + 13
|
||||
if($start -ge 13)
|
||||
{
|
||||
$end = $xml.IndexOf("'", $start)
|
||||
$createdDate = $xml.Substring($start, $end-$start)
|
||||
}
|
||||
|
||||
$createdBy = $null
|
||||
$start = $xml.IndexOf("ows_Author", 0) + 12;
|
||||
$createdBy = $null
|
||||
$start = $xml.IndexOf("ows_Author", 0) + 12
|
||||
if($start -ge 12)
|
||||
{
|
||||
$end = $xml.IndexOf("'", $start)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Description
|
||||
|
||||
This cmdlet takes in a URL pattern and returns a array of hashtables
|
||||
This cmdlet takes in a URL and returns an array of hashtables
|
||||
that contains information about all users in the given site collection.
|
||||
Information returned includes the Date when the user was added to the
|
||||
Information returned includes the date when the user was added to the
|
||||
site collection and by whom.
|
||||
|
|
|
@ -2,37 +2,46 @@ Function New-RegistryCredential
|
|||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]$ApplicationName,
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]$OrgName,
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]$AccountDescription
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]
|
||||
$ApplicationName,
|
||||
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]
|
||||
$OrgName,
|
||||
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]
|
||||
$AccountDescription,
|
||||
|
||||
[Parameter (Mandatory=$False, Position=3)]
|
||||
[System.Management.Automation.PSCredential]
|
||||
$SecureCredential
|
||||
)
|
||||
|
||||
|
||||
$CredentialExists = CheckForExistingRegistryCredential
|
||||
$CredentialExists = CheckForExistingRegistryCredential -ApplicationName $ApplicationName `
|
||||
-OrgName $OrgName `
|
||||
-AccountDescription $AccountDescription
|
||||
|
||||
if(!($CredentialExists))
|
||||
{
|
||||
Write-Verbose "Credential matching specified parameters does not exist`r`nOK to proceed"
|
||||
$SecureCredential = Get-Credential -Message "Enter the service account credential in `'DOMAIN\Username`' or`' Username@Domain.com`' format"
|
||||
$SecurePasswordString = $SecureCredential.Password | ConvertFrom-SecureString
|
||||
Write-Verbose "Captured credential for user `'$($SecureCredential.UserName)`'"
|
||||
Try
|
||||
if($null -eq $SecureCredential)
|
||||
{
|
||||
Write-Verbose "Attempting to create path to store credential object"
|
||||
New-Item -Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials" -Name "$($AccountDescription)" -Force
|
||||
if(Test-Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)")
|
||||
{
|
||||
Write-Verbose "Successfully created path `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescrioption)`' to store credential object"
|
||||
}
|
||||
$SecureCredential = Get-Credential -Message "Enter the service account credential in `'DOMAIN\Username`' or`' Username@Domain.com`' format"
|
||||
$SecurePasswordString = $SecureCredential.Password | ConvertFrom-SecureString
|
||||
}
|
||||
Catch
|
||||
Write-Verbose "Captured credential for user `'$($SecureCredential.UserName)`'"
|
||||
|
||||
Write-Verbose "Attempting to create path to store credential object"
|
||||
New-Item -Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials" -Name "$($AccountDescription)" -Force
|
||||
if(Test-Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)")
|
||||
{
|
||||
Write-Verbose "Unable to create the requested registry object"
|
||||
[System.Exception]
|
||||
Write-Host "Unable to create path `'`KHCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)`'." -Foreground Red
|
||||
Write-Verbose "Successfully created path `'HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescrioption)`' to store credential object"
|
||||
}
|
||||
else {
|
||||
throw "Unable to create path `'`KHCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)`'."
|
||||
}
|
||||
try
|
||||
{
|
||||
|
@ -46,19 +55,15 @@ Function New-RegistryCredential
|
|||
}
|
||||
catch
|
||||
{
|
||||
Write-Verbose "Exception was encountered while storing username and encrypted password to the registry"
|
||||
[System.Exception]
|
||||
Write-Host "Could not commit values to registry`r`nCredential not saved" -ForegroundColor Red
|
||||
throw "Could not commit values to registry`r`nCredential not saved"
|
||||
}
|
||||
Write-Verbose "Credential `'$($AccountDescription) has been created.`r`nUser `'$($SecureCredential.UserName)`' has been assigned"
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Verbose "Credential matching specified parameters already exists"
|
||||
Write-Host "Credential for account `'$($AccountDescription)`' already exists in org `'$($OrgName)`' for application `'$($ApplicationName)`'`r`nPlease review your parameters" -ForegroundColor Red
|
||||
throw "Credential for account '$AccountDescription' already exists in org '$OrgName' for application '$ApplicationName'"
|
||||
}
|
||||
|
||||
$Creds = Get-RegistryCredential -ApplicationName $ApplicationName -OrgName $OrgName -AccountDescription $AccountDescription
|
||||
Return $Creds
|
||||
|
||||
return $SecureCredential
|
||||
}
|
|
@ -15,31 +15,17 @@ function Remove-SPEnterpriseSearchURLFromIndex
|
|||
|
||||
foreach($logEntry in $logEntries.Rows)
|
||||
{
|
||||
Write-Host "You are about to remove " -NoNewline
|
||||
Write-Host "Removing entry " -NoNewline
|
||||
Write-Host $logEntry.FullUrl -ForegroundColor Green
|
||||
|
||||
do{
|
||||
$deletionAnswer = Read-Host "Do you confirm the deletion (y/n)"
|
||||
}while($deletionAnswer.ToLower() -ne 'n' -and $deletionAnswer.ToLower() -ne 'y')
|
||||
|
||||
switch($deletionAnswer)
|
||||
$catch = $cl.RemoveDocumentFromSearchResults($logEntry.FullUrl)
|
||||
if($catch)
|
||||
{
|
||||
'y'
|
||||
{
|
||||
$catch = $cl.RemoveDocumentFromSearchResults($logEntry.FullUrl)
|
||||
if($catch)
|
||||
{
|
||||
Write-Host "Deleted" -ForegroundColor Yellow
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Could not delete the item" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
'n'
|
||||
{
|
||||
break
|
||||
}
|
||||
Write-Host "Deleted" -ForegroundColor Yellow
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Could not delete the item"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,16 @@
|
|||
"Cmdlets\Get-SPAllUserInfo\Get-SPAllUserInfo.psm1",
|
||||
"Cmdlets\Set-SPContentDatabasePreferredTimerJobServer\Set-SPContentDatabasePreferredTimerJobServer.psm1",
|
||||
"Cmdlets\Get-RegistryCredential\Get-RegistryCredential.psm1",
|
||||
<<<<<<< HEAD
|
||||
"Cmdlets\New-RegistryCredential\New-RegistryCredential.psm1",
|
||||
"Cmdlets\Get-CheckedOutFilesInList\Get-CheckedOutFilesInList.psm1",
|
||||
"Cmdlets\New-BulkFileCheckIn\New-BulkFileCheckIn.psm1"
|
||||
=======
|
||||
"Cmdlets\New-RegistryCredential\New-RegistryCredential.psm1",
|
||||
"Cmdlets\Get-CheckedOutFilesInList\Get-CheckedOutFilesInList.psm1"
|
||||
"Cmdlets\New-BulkFileCheckIn\New-BulkFileCheckIn.psm1"
|
||||
"Utility\PFE-SharePoint.Utility.psm1"
|
||||
>>>>>>> 8e2f8090c5f5f21567b9600d46c2957372c00193
|
||||
)
|
||||
CmdletsToExport = "*"
|
||||
#FunctionsToExport = @("*")
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
function CheckForExistingRegistryCredential
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]$ApplicationName,
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]$OrgName,
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]$AccountDescription
|
||||
)
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter (Mandatory=$True, Position=0)]
|
||||
[String]$ApplicationName,
|
||||
|
||||
Write-Verbose "Checking to see if a credential that matches the specified parameters already exists"
|
||||
$RegistryCredential = Test-Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)"
|
||||
Return $RegistryCredential
|
||||
}
|
||||
[Parameter (Mandatory=$True, Position=1)]
|
||||
[String]$OrgName,
|
||||
|
||||
[Parameter (Mandatory=$True, Position=2)]
|
||||
[String]$AccountDescription
|
||||
)
|
||||
|
||||
Write-Verbose "Checking to see if a credential that matches the specified parameters already exists"
|
||||
$RegistryCredential = Test-Path "HKCU:\Software\$($ApplicationName)\$($OrgName)\Credentials\$($AccountDescription)"
|
||||
return $RegistryCredential
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function *
|
|
@ -1,3 +1,5 @@
|
|||
![Microsoft Loves Open-Source](https://i0.wp.com/nikcharlebois.com/wp-content/uploads/2018/02/MSLoveOS.png)
|
||||
|
||||
# Disclaimer
|
||||
|
||||
This public repository contains various open-source tools and scripts created by Microsoft Premier Field Engineers (PFE). Items in it are supported on a best-effort basis and are not officially supported by Microsoft to be used by the community.
|
||||
|
@ -13,3 +15,9 @@ This repository exposes PowerShell modules that are currently in development. On
|
|||
Currently available modules:
|
||||
|
||||
Install-Module PFE-SharePoint
|
||||
|
||||
# Releases
|
||||
|
||||
The next major release to the PowerShell Gallery will be on February 7th, 2018
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Import-Module .\Tests\TestHarness.psm1 -Force
|
||||
|
||||
Invoke-TestHarness
|
|
@ -0,0 +1,89 @@
|
|||
function Invoke-TestHarness
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[System.String]
|
||||
$TestResultsFile,
|
||||
|
||||
[Parameter()]
|
||||
[System.String]
|
||||
$TestsPath,
|
||||
|
||||
[Parameter()]
|
||||
[Switch]
|
||||
$IgnoreCodeCoverage
|
||||
)
|
||||
|
||||
Write-Verbose -Message 'Commencing all SharePointDsc tests'
|
||||
|
||||
$repoDir = Join-Path -Path $PSScriptRoot -ChildPath '..\' -Resolve
|
||||
|
||||
$testCoverageFiles = @()
|
||||
if ($IgnoreCodeCoverage.IsPresent -eq $false)
|
||||
{
|
||||
Get-ChildItem -Path "$repoDir\PowerShell\Modules\PFE-SharePoint\Cmdlets\**\*.psm1" -Recurse | ForEach-Object {
|
||||
$testCoverageFiles += $_.FullName
|
||||
}
|
||||
}
|
||||
|
||||
$testResultSettings = @{}
|
||||
if ([String]::IsNullOrEmpty($TestResultsFile) -eq $false)
|
||||
{
|
||||
$testResultSettings.Add('OutputFormat', 'NUnitXml' )
|
||||
$testResultSettings.Add('OutputFile', $TestResultsFile)
|
||||
}
|
||||
|
||||
$mainModule = $repoDir + "PowerShell\Modules\PFE-SharePoint\PFE-SharePoint.psd1"
|
||||
Import-Module $mainModule
|
||||
$testsToRun = @()
|
||||
|
||||
# Run Unit Tests
|
||||
$versionsPath = Join-Path -Path $repoDir -ChildPath "\Tests\Unit\Stubs\SharePoint\"
|
||||
$versionsToTest = (Get-ChildItem -Path $versionsPath).Name
|
||||
# Import the first stub found so that there is a base module loaded before the tests start
|
||||
$firstVersion = $versionsToTest | Select-Object -First 1
|
||||
$firstStub = Join-Path -Path $repoDir `
|
||||
-ChildPath "\Tests\Unit\Stubs\SharePoint\$firstVersion\Microsoft.SharePoint.PowerShell.psm1"
|
||||
Import-Module $firstStub -WarningAction SilentlyContinue
|
||||
|
||||
$versionsToTest | ForEach-Object -Process {
|
||||
$stubPath = Join-Path -Path $repoDir `
|
||||
-ChildPath "\Tests\Unit\Stubs\SharePoint\$_\Microsoft.SharePoint.PowerShell.psm1"
|
||||
$testsToRun += @(@{
|
||||
'Path' = (Join-Path -Path $repoDir -ChildPath "\Tests\Unit")
|
||||
'Parameters' = @{
|
||||
'SharePointStubsModule' = $stubPath
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
# Integration Tests (not run in appveyor due to time/reboots needed to install SharePoint)
|
||||
#$integrationTestsPath = Join-Path -Path $repoDir -ChildPath 'Tests\Integration'
|
||||
#$testsToRun += @( (Get-ChildItem -Path $integrationTestsPath -Filter '*.Tests.ps1').FullName )
|
||||
|
||||
# DSC Common Tests
|
||||
if ($PSBoundParameters.ContainsKey('TestsPath') -eq $true)
|
||||
{
|
||||
$getChildItemParameters = @{
|
||||
Path = $TestsPath
|
||||
Recurse = $true
|
||||
Filter = '*.Tests.ps1'
|
||||
}
|
||||
|
||||
# Get all tests '*.Tests.ps1'.
|
||||
$commonTestFiles = Get-ChildItem @getChildItemParameters
|
||||
|
||||
$testsToRun += @( $commonTestFiles.FullName )
|
||||
}
|
||||
|
||||
if ($IgnoreCodeCoverage.IsPresent -eq $false)
|
||||
{
|
||||
$testResultSettings.Add('CodeCoverage', $testCoverageFiles)
|
||||
}
|
||||
|
||||
$results = Invoke-Pester -Script $testsToRun -PassThru @testResultSettings
|
||||
|
||||
return $results
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]
|
||||
$SharePointStubsModule = (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:TestHelper = New-UnitTestHelper -SharePointStubModule $SharePointStubsModule `
|
||||
-Cmdlet "Get-RegistryCredential"
|
||||
|
||||
Describe -Name $Global:TestHelper.DescribeHeader -Fixture {
|
||||
|
||||
InModuleScope -ModuleName $Global:TestHelper.ModuleName -ScriptBlock {
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.InitializeScript -NoNewScope
|
||||
|
||||
$mockPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
|
||||
$mockCredential = New-Object -TypeName System.Management.Automation.PSCredential `
|
||||
-ArgumentList @("DOMAIN\username", $mockPassword)
|
||||
|
||||
Mock -CommandName Get-ItemProperty -MockWith {
|
||||
return @{
|
||||
UserName = "contoso\john.smith"
|
||||
Password = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000f74bf2f14b6cdf4586266f16f1dfac130000000002000000000010660000000100002000000074cd73f55cadf2725bcb64431d9edef3035d12505cdbf5d93501a128e1c06385000000000e8000000002000020000000c91bd5204db65776114afa3441a6d91b8bb10e109357a36a08ceb4c2ae7d795310000000c689444aecd318866642e4d767f3b37f4000000024d0de35fd828a0b9e0a8ce4d4717a6bc58103287ea0b19b668cb04de85ba3a7e412fa038452bea13b994db890a7511befbf4b7b738f91822dab8aa3869a4bed"
|
||||
}
|
||||
}
|
||||
|
||||
Mock -CommandName ConvertTo-SecureString -MockWith {
|
||||
return $mockPassword
|
||||
}
|
||||
|
||||
Context -Name "When the credential object is found" -Fixture {
|
||||
Mock -CommandName CheckForExistingRegistryCredential -MockWith {
|
||||
return $true
|
||||
}
|
||||
$testParams = @{
|
||||
ApplicationName = "MyTestApplication"
|
||||
OrgName = "Contoso"
|
||||
AccountDescription = "JohnSmith"
|
||||
}
|
||||
|
||||
It "Should return contoso\john.smith" {
|
||||
(Get-RegistryCredential @testParams).UserName | Should Be "contoso\john.smith"
|
||||
}
|
||||
}
|
||||
|
||||
Context -Name "When the credential don't exist" -Fixture {
|
||||
Mock -CommandName CheckForExistingRegistryCredential -MockWith {
|
||||
return $false
|
||||
}
|
||||
$testParams = @{
|
||||
ApplicationName = "MyTestApplication"
|
||||
OrgName = "Contoso"
|
||||
AccountDescription = "JohnSmith"
|
||||
}
|
||||
|
||||
It "Should return contoso\john.smith" {
|
||||
{ Get-RegistryCredential @testParams } | Should Throw "Could not locate credential object at 'HKCU:\Software\MyTestApplication\Contoso\Credentials\JohnSmith'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.CleanupScript -NoNewScope
|
|
@ -0,0 +1,52 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]
|
||||
$SharePointStubsModule = (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:TestHelper = New-UnitTestHelper -SharePointStubModule $SharePointStubsModule `
|
||||
-Cmdlet "Get-SPAllUserInfo"
|
||||
|
||||
Describe -Name $Global:TestHelper.DescribeHeader -Fixture {
|
||||
InModuleScope -ModuleName $Global:TestHelper.ModuleName -ScriptBlock {
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.InitializeScript -NoNewScope
|
||||
|
||||
Mock -CommandName Get-SPSite -MockWith {
|
||||
return @{
|
||||
RootWeb = @{
|
||||
Lists = @{
|
||||
"User Information List" = @{
|
||||
Items = @(
|
||||
@{
|
||||
Title = "contoso\john.smith"
|
||||
Xml = "<xml ows_Created='2017-01-01' ows_author='contoso\john.smith'></xml>"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}| Add-Member ScriptMethod Update {
|
||||
} -PassThru
|
||||
}
|
||||
|
||||
Context -Name "When the User Info List is Found" -Fixture {
|
||||
|
||||
$testParams = @{
|
||||
Url = "http://sharepoint.contoso.com"
|
||||
}
|
||||
|
||||
It "Should return contoso\john.smith" {
|
||||
(Get-SPAllUserInfo @testParams).UserName | Should Be "contoso\john.smith"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.CleanupScript -NoNewScope
|
|
@ -0,0 +1,110 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]
|
||||
$SharePointStubsModule = (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:TestHelper = New-UnitTestHelper -SharePointStubModule $SharePointStubsModule `
|
||||
-Cmdlet "New-RegistryCredential"
|
||||
|
||||
Describe -Name $Global:TestHelper.DescribeHeader -Fixture {
|
||||
InModuleScope -ModuleName $Global:TestHelper.ModuleName -ScriptBlock {
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.InitializeScript -NoNewScope
|
||||
|
||||
Mock -CommandName New-Item -MockWith {}
|
||||
|
||||
Mock -CommandName Get-ItemProperty -MockWith {
|
||||
return @{
|
||||
UserName = "contoso\john.smith"
|
||||
Password = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000f74bf2f14b6cdf4586266f16f1dfac130000000002000000000010660000000100002000000074cd73f55cadf2725bcb64431d9edef3035d12505cdbf5d93501a128e1c06385000000000e8000000002000020000000c91bd5204db65776114afa3441a6d91b8bb10e109357a36a08ceb4c2ae7d795310000000c689444aecd318866642e4d767f3b37f4000000024d0de35fd828a0b9e0a8ce4d4717a6bc58103287ea0b19b668cb04de85ba3a7e412fa038452bea13b994db890a7511befbf4b7b738f91822dab8aa3869a4bed"
|
||||
}
|
||||
}
|
||||
|
||||
$mockPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
|
||||
$mockCredential = New-Object -TypeName System.Management.Automation.PSCredential `
|
||||
-ArgumentList @("contoso\john.smith", $mockPassword)
|
||||
|
||||
Mock -CommandName ConvertTo-SecureString -MockWith {
|
||||
return $mockPassword
|
||||
}
|
||||
|
||||
Context -Name "The credential already exists" -Fixture {
|
||||
Mock -CommandName Test-Path -MockWith {
|
||||
return $true
|
||||
}
|
||||
|
||||
Mock -CommandName CheckForExistingRegistryCredential -MockWith {
|
||||
return $true
|
||||
}
|
||||
|
||||
$testParams = @{
|
||||
ApplicationName = "SharePoint"
|
||||
OrgName = "Microsoft"
|
||||
AccountDescription = "System Account"
|
||||
}
|
||||
|
||||
It "Should throw an error about the credentials already existing" {
|
||||
{ New-RegistryCredential @testParams } | Should Throw "Credential for account 'System Account' already exists in org 'Microsoft' for application 'SharePoint'"
|
||||
}
|
||||
}
|
||||
|
||||
Context -Name "The credential were successfully created" -Fixture {
|
||||
|
||||
Mock -CommandName Test-Path -MockWith {
|
||||
return $true
|
||||
}
|
||||
|
||||
Mock -CommandName CheckForExistingRegistryCredential -MockWith {
|
||||
return $false
|
||||
}
|
||||
|
||||
Mock -CommandName Get-Credential -MockWith {
|
||||
return $mockCredential
|
||||
}
|
||||
|
||||
$testParams = @{
|
||||
ApplicationName = "SharePoint"
|
||||
OrgName = "Microsoft"
|
||||
AccountDescription = "System Account"
|
||||
}
|
||||
|
||||
It "Should return contoso\john.smith as a newly created credential set" {
|
||||
(New-RegistryCredential @testParams).UserName | Should Be "contoso\john.smith"
|
||||
}
|
||||
}
|
||||
|
||||
Context -Name "The credentials don't exist, but the registry path does" -Fixture {
|
||||
|
||||
Mock -CommandName Test-Path -MockWith {
|
||||
return $false
|
||||
}
|
||||
|
||||
Mock -CommandName CheckForExistingRegistryCredential -MockWith {
|
||||
return $false
|
||||
}
|
||||
|
||||
Mock -CommandName Get-Credential -MockWith {
|
||||
return $mockCredential
|
||||
}
|
||||
|
||||
$testParams = @{
|
||||
ApplicationName = "SharePoint"
|
||||
OrgName = "Microsoft"
|
||||
AccountDescription = "System Account"
|
||||
}
|
||||
|
||||
It "Should throw an error saying it couldn't create the registry path" {
|
||||
{ New-RegistryCredential @testParams } | Should Throw "Unable to create path 'KHCU:\Software\SharePoint\Microsoft\Credentials\System Account'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.CleanupScript -NoNewScope
|
|
@ -0,0 +1,94 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]
|
||||
$SharePointStubsModule = (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:TestHelper = New-UnitTestHelper -SharePointStubModule $SharePointStubsModule `
|
||||
-Cmdlet "Remove-SPEnterpriseSearchURLFromIndex"
|
||||
|
||||
Describe -Name $Global:TestHelper.DescribeHeader -Fixture {
|
||||
InModuleScope -ModuleName $Global:TestHelper.ModuleName -ScriptBlock {
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.InitializeScript -NoNewScope
|
||||
|
||||
try { [Microsoft.Office.Server.Search.Administration] }
|
||||
catch
|
||||
{
|
||||
try {
|
||||
Add-Type -TypeDefinition @"
|
||||
namespace Microsoft.Office.Server.Search.Administration
|
||||
{
|
||||
public class CrawlLog
|
||||
{
|
||||
public CrawlLog(System.Object a)
|
||||
{
|
||||
|
||||
}
|
||||
public System.Collections.Generic.List<FakeJournal> GetCrawledUrls(System.Object a, System.Object b, System.Object c, System.Object d, System.Object e, System.Object f, System.Object g, System.Object h, System.Object i)
|
||||
{
|
||||
System.Collections.Generic.List<FakeJournal> CrawledUrls = new System.Collections.Generic.List<FakeJournal>();
|
||||
CrawledUrls.Add(new FakeJournal());
|
||||
return CrawledUrls;
|
||||
}
|
||||
|
||||
public System.Boolean RemoveDocumentFromSearchResults(System.Object a)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class FakeJournal
|
||||
{
|
||||
public System.Collections.Generic.List<FakeEntry> Rows = new System.Collections.Generic.List<FakeEntry>();
|
||||
public FakeJournal()
|
||||
{
|
||||
Rows.Add(new FakeEntry());
|
||||
}
|
||||
}
|
||||
|
||||
public class FakeEntry
|
||||
{
|
||||
public string FullUrl;
|
||||
public FakeEntry()
|
||||
{
|
||||
FullUrl = "http://sharepoint.contoso.com";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"@ -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
Write-Verbose "The type Microsoft.Office.Server.Search.Administration.CrawlLog was already added."
|
||||
}
|
||||
}
|
||||
|
||||
Mock -CommandName Get-SPEnterpriseSearchServiceApplication -MockWith {
|
||||
return @(
|
||||
@{
|
||||
Name = "Search Service Application"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Context -Name "When the item is found and properly removed" -Fixture {
|
||||
|
||||
$testParams = @{
|
||||
Url = "http://sharepoint.contoso.com"
|
||||
}
|
||||
|
||||
It "Should not throw errors" {
|
||||
Remove-SPEnterpriseSearchURLFromIndex @testParams
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.CleanupScript -NoNewScope
|
|
@ -0,0 +1,77 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]
|
||||
$SharePointStubsModule = (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:TestHelper = New-UnitTestHelper -SharePointStubModule $SharePointStubsModule `
|
||||
-Cmdlet "Set-SPContentDatabasePreferredTimerJobServer"
|
||||
|
||||
Describe -Name $Global:TestHelper.DescribeHeader -Fixture {
|
||||
InModuleScope -ModuleName $Global:TestHelper.ModuleName -ScriptBlock {
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.InitializeScript -NoNewScope
|
||||
|
||||
|
||||
Context -Name "When the content database is found" -Fixture {
|
||||
Mock -CommandName Get-SPFarm -MockWith {
|
||||
return @{
|
||||
TimerService = @{
|
||||
Instances = @(
|
||||
@{
|
||||
Server = @{
|
||||
Address = "localhost"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mock -CommandName Get-SPContentDatabase -MockWith{
|
||||
return @{
|
||||
PreferredTimerServiceInstance = "localhost";
|
||||
}|
|
||||
Add-Member -MemberType ScriptMethod `
|
||||
-Name Update `
|
||||
-Value {
|
||||
} -PassThru
|
||||
}
|
||||
|
||||
$testParams = @{
|
||||
Database = "WSS_Content"
|
||||
Server = "localhost"
|
||||
}
|
||||
|
||||
It "Should properly assign the prefered server" {
|
||||
Set-SPContentDatabasePreferredTimerJobServer @testParams
|
||||
}
|
||||
}
|
||||
|
||||
Context -Name "When the instance is not found" -Fixture {
|
||||
Mock -CommandName Get-SPFarm -MockWith {
|
||||
return @{
|
||||
TimerService = @{
|
||||
Instances = @()
|
||||
}
|
||||
}
|
||||
}
|
||||
$testParams = @{
|
||||
Database = "WSS_Content"
|
||||
Server = "localhost"
|
||||
}
|
||||
|
||||
It "Should properly assign the prefered server" {
|
||||
{ Set-SPContentDatabasePreferredTimerJobServer @testParams } | Should Throw "A timer job service instance could not be found on server localhost"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-Command -ScriptBlock $Global:TestHelper.CleanupScript -NoNewScope
|
|
@ -0,0 +1,18 @@
|
|||
function Use-CacheCluster() {
|
||||
|
||||
}
|
||||
|
||||
function Get-CacheHost() {
|
||||
|
||||
}
|
||||
|
||||
function Get-AFCacheHostConfiguration() {
|
||||
param(
|
||||
[Parameter(Mandatory=$true, Position=0)]
|
||||
[string]
|
||||
${ComputerName},
|
||||
|
||||
[Parameter(ParameterSetName='Default', Mandatory=$true)]
|
||||
[uint32]
|
||||
${CachePort})
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
function CheckForExistingRegistryCredential {
|
||||
[CmdletBinding(DefaultParameterSetName='Default')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true, Position=0)]
|
||||
[string]
|
||||
${ApplicationName},
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
${OrgName},
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
${AccountDescription})
|
||||
|
||||
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,107 @@
|
|||
function New-UnitTestHelper
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
$SharePointStubModule,
|
||||
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Cmdlet')]
|
||||
[String]
|
||||
$Cmdlet,
|
||||
|
||||
[Parameter()]
|
||||
[Switch]
|
||||
$ExcludeInvokeHelper,
|
||||
|
||||
[Parameter()]
|
||||
[Switch]
|
||||
$IncludeDistributedCacheStubs
|
||||
)
|
||||
|
||||
$repoRoot = Join-Path -Path $PSScriptRoot -ChildPath "..\..\" -Resolve
|
||||
$moduleRoot = Join-Path -Path $repoRoot -ChildPath "PowerShell\Modules\PFE-SharePoint"
|
||||
|
||||
$mainModule = Join-Path -Path $moduleRoot -ChildPath "PFE-SharePoint.psd1"
|
||||
Import-Module -Name $mainModule -Global
|
||||
|
||||
if ($PSBoundParameters.ContainsKey("CmdLet") -eq $true)
|
||||
{
|
||||
$describeHeader = "CMDLet '$Cmdlet'"
|
||||
$moduleName = "$Cmdlet"
|
||||
$modulePath = "Cmdlets\$Cmdlet\$Cmdlet.psm1"
|
||||
$moduleToLoad = Join-Path -Path $moduleRoot -ChildPath $modulePath
|
||||
}
|
||||
|
||||
$spBuild = (Get-Item -Path $SharePointStubModule).Directory.BaseName
|
||||
$firstDot = $spBuild.IndexOf(".")
|
||||
|
||||
$describeHeader += " [SP Build: $spBuild]"
|
||||
|
||||
Import-Module -Name $moduleToLoad -Global
|
||||
|
||||
$PFEStubs = (Join-Path -Path $PSScriptRoot `
|
||||
-ChildPath "..\Unit\Stubs\PFE-SharePoint\PFE-SharePointStubs.psm1" `
|
||||
-Resolve)
|
||||
$initScript = @"
|
||||
Remove-Module -Name "Microsoft.SharePoint.PowerShell" -Force -ErrorAction SilentlyContinue
|
||||
Import-Module -Name "$SharePointStubModule" -WarningAction SilentlyContinue
|
||||
Import-Module -Name "$PFEStubs" -WarningAction SilentlyContinue
|
||||
Import-Module -Name "$moduleToLoad"
|
||||
"@
|
||||
|
||||
return @{
|
||||
DescribeHeader = $describeHeader
|
||||
ModuleName = $moduleName
|
||||
CurrentStubModulePath = $SharePointStubModule
|
||||
CurrentStubBuildNumber = [Version]::Parse($spBuild)
|
||||
InitializeScript = [ScriptBlock]::Create($initScript)
|
||||
RepoRoot = $repoRoot
|
||||
CleanupScript = [ScriptBlock]::Create(@"
|
||||
|
||||
Get-Variable -Scope Global -Name "SPDsc*" | Remove-Variable -Force -Scope "Global"
|
||||
`$global:DSCMachineStatus = 0
|
||||
|
||||
"@)
|
||||
}
|
||||
}
|
||||
|
||||
function Write-SPDSCStubFile() {
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
$SharePointStubPath
|
||||
)
|
||||
|
||||
Add-PSSnapin Microsoft.SharePoint.PowerShell
|
||||
|
||||
$SPStubContent = ((Get-Command | Where-Object -FilterScript {
|
||||
$_.Source -eq "Microsoft.SharePoint.PowerShell"
|
||||
} ) | ForEach-Object -Process {
|
||||
$signature = $null
|
||||
$command = $_
|
||||
$metadata = New-Object -TypeName System.Management.Automation.CommandMetaData `
|
||||
-ArgumentList $command
|
||||
$definition = [System.Management.Automation.ProxyCommand]::Create($metadata)
|
||||
foreach ($line in $definition -split "`n")
|
||||
{
|
||||
if ($line.Trim() -eq 'begin')
|
||||
{
|
||||
break
|
||||
}
|
||||
$signature += $line
|
||||
}
|
||||
"function $($command.Name) { `n $signature `n } `n"
|
||||
}) | Out-String
|
||||
|
||||
foreach ($line in $SPStubContent.Split([Environment]::NewLine))
|
||||
{
|
||||
$line = $line.Replace("[System.Nullable``1[[Microsoft.Office.Server.Search.Cmdlet.ContentSourceCrawlScheduleType, Microsoft.Office.Server.Search.PowerShell, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]", "[object]")
|
||||
$line = $line.Replace("[System.Collections.Generic.List``1[[Microsoft.SharePoint.PowerShell.SPUserLicenseMapping, Microsoft.SharePoint.PowerShell, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]", "[object]")
|
||||
$line = $line -replace "\[System.Nullable\[Microsoft.*]]", "[System.Nullable[object]]"
|
||||
$line = $line -replace "\[Microsoft.*.\]", "[object]"
|
||||
|
||||
$line | Out-File -FilePath $SharePointStubPath -Encoding utf8 -Append
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
#---------------------------------#
|
||||
# environment configuration #
|
||||
#---------------------------------#
|
||||
version: 0.0.{build}.0
|
||||
image: Visual Studio 2017
|
||||
install:
|
||||
- git clone https://github.com/PowerShell/DscResource.Tests
|
||||
- ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose
|
||||
- ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1"
|
||||
- ps: Invoke-AppveyorInstallTask
|
||||
- ps: $moduleName = "PFE-SharePoint"
|
||||
- ps: $mainModuleFolder = "PowerShell\Modules\$moduleName"
|
||||
|
||||
#---------------------------------#
|
||||
# build configuration #
|
||||
#---------------------------------#
|
||||
build: false
|
||||
|
||||
#---------------------------------#
|
||||
# test configuration #
|
||||
#---------------------------------#
|
||||
test_script:
|
||||
- ps: Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag @() -RunTestInOrder
|
||||
|
||||
#---------------------------------#
|
||||
# deployment configuration #
|
||||
#---------------------------------#
|
||||
|
||||
# scripts to run before deployment
|
||||
deploy_script:
|
||||
- ps: |
|
||||
Invoke-AppveyorAfterTestTask
|
Загрузка…
Ссылка в новой задаче