Skip to content

Commit

Permalink
Merge pull request #856 from rubrikinc/devel
Browse files Browse the repository at this point in the history
Merge Devel into Master for 9.0.1 release
  • Loading branch information
mwpreston authored Jul 8, 2024
2 parents a55819f + 8c68c71 commit c4745b6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 38 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.

## Unreleased

## [9.0.1]

### Added
* Added `Test-PowerShellSeven` private function to test if PS 7 is being used to facilate fix for DELETE calls without explicit ContentType parameter.

### Modified
* Modified `Invoke-RubrikWebRequest` to check for PS 7 and DELETE calls - if so, add ContentType parameter to bound parameters. This resolves [Issue 853](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues#:~:text=Issues%20list-,Disconnect%2DRubrik%20not%20working%20after%20PowerShell%207.3.9,-kind%2Dbug)
* Modified `Invoke-RubrikWebRequest` to fix logic that tests for blank and/or default timeout value that is less than 100. Previously, if a timeout of less than 100 was specified it would be used by Invoke-WebRequest. We need at least a value of 100 so now the logic will ensure that is applied

## [9.0.0]

### Added
Expand Down
18 changes: 14 additions & 4 deletions Rubrik/Private/Invoke-RubrikWebRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@ function Invoke-RubrikWebRequest {
if (Test-UnicodeInString -String $Body) {
$PSBoundParameters.Add('ContentType', 'text/plain; charset=utf-8')
Write-Verbose -Message ('Submitting "{0}" request as "text/plain; charset=utf-8"' -f $Method)
}

}
if (Test-PowerShellSeven) {
if ($Method -eq "DELETE") {
if ($PSBoundParameters.ContainsKey('ContentType')) {
$PSBoundParameters.Remove('ContentType')
}
$PSBoundParameters.Add('ContentType', 'application/json')
Write-Verbose -Message ('Submitting "{0}" request as "application/json"' -f $Method)
}
}


if (Test-PowerShellSix) {
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -or $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -and $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
Write-Verbose -Message "Invoking request with a custom timeout of $($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) seconds"
$result = Invoke-WebRequest -UseBasicParsing -SkipCertificateCheck -TimeoutSec $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut @PSBoundParameters
} else {
Write-Verbose -Message "No custom timeout specified or custom timeout is less than 100 seconds, invoking request with default value of 100 seconds"
$result = Invoke-WebRequest -UseBasicParsing -SkipCertificateCheck @PSBoundParameters
}
} else {
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -or $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -and $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
Write-Verbose -Message "Invoking request with a custom timeout of $($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) seconds"
$result = Invoke-WebRequest -UseBasicParsing -TimeoutSec $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut @PSBoundParameters
} else {
Expand Down
11 changes: 11 additions & 0 deletions Rubrik/Private/Test-PowerShellSeven.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function Test-PowerShellSeven {
<#
.SYNOPSIS
Test if the PowerShell version is 7 or higher, this is to provide backwards compatibility for older version of PowerShell
.DESCRIPTION
This function is used to fix the latest Mircrosoft Update which requieres a content-type in the header for Invoke-WebRequest
#>
$PSVersionTable.PSVersion.Major -ge 7
}
2 changes: 1 addition & 1 deletion Rubrik/Rubrik.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Rubrik.psm1'

# Version number of this module.
ModuleVersion = '9.0.0'
ModuleVersion = '9.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
47 changes: 25 additions & 22 deletions Tests/Connect-Rubrik.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ Describe -Name 'Public/Connect-Rubrik' -Tag 'Public', 'Connect-Rubrik' -Fixture
#endregion

Context -Name 'Validate Connecting to Cluster' {
Mock -CommandName Get-RubrikAPIVersion -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Get-RubrikSoftwareVersion -Verifiable -ModuleName 'Rubrik' -MockWith {
'5.1.2-8188'
}
Mock -CommandName New-UserAgentString -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
[pscustomobject]@{
id = 11111
userId = 22222
token = 33333
}
}
Mock -CommandName Invoke-RestMethod -Verifiable -ModuleName 'Rubrik' -MockWith {
[pscustomobject]@{
sessionId = "22222"
serviceAccountId = "11111"
token = "33333"
expirationTime = "3022-12-10T06:19:52.250Z"
organizationId = "44444"

Mock -CommandName Get-RubrikAPIVersion -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Get-RubrikSoftwareVersion -Verifiable -ModuleName 'Rubrik' -MockWith {
'5.1.2-8188'
}
}
Mock -CommandName New-UserAgentString -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
[pscustomobject]@{
id = 11111
userId = 22222
token = 33333
}

Mock -CommandName Invoke-RestMethod -Verifiable -ModuleName 'Rubrik' -MockWith {
[pscustomobject]@{
sessionId = "22222"
serviceAccountId = "11111"
token = "33333"
expirationTime = "3022-12-10T06:19:52.250Z"
organizationId = "44444"
}
}
}
It -Name 'Username / Password combination' -Test {
(Connect-Rubrik -Server testcluster -Username jaapbrasser -Password $(ConvertTo-SecureString -String password -AsPlainText -Force)) | Out-String |
Should -BeLikeExactly '*Basic*'
Expand All @@ -59,19 +60,21 @@ Describe -Name 'Public/Connect-Rubrik' -Tag 'Public', 'Connect-Rubrik' -Fixture
It -Name 'API Token' -Test {
(Connect-Rubrik -Server testcluster -Token 33333) | Out-String |
Should -BeLikeExactly '*Token*'

}

It -Name 'Service Account' -Test {
(Connect-Rubrik -Server testcluster -Id Username -Secret 33333) | Out-String |
Should -BeLikeExactly '*ServiceAccount*'

}

It -Name 'RubrikConnections array should contain 4 entries' -Test {
@($RubrikConnections).Count |
Should -Be 4

}

Assert-VerifiableMock
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 3

}
}
23 changes: 14 additions & 9 deletions Tests/Get-RubrikDNSSetting.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ Describe -Name 'Public/Get-RubrikDNSSetting' -Tag 'Public', 'Get-RubrikDNSSettin
#endregion

Context -Name 'Returned Results' {
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
@{
'DNSServers' = @("192.168.150.1", "10.10.1.5")
'DNSSearchDomain' = @("lab.local", "domain.local")
BeforeAll {
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith { }
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
@{
'DNSServers' = @("192.168.150.1", "10.10.1.5")
'DNSSearchDomain' = @("lab.local", "domain.local")
}
}
}
It -Name 'No parameters returns all results' -Test {
@( Get-RubrikDNSSetting).Count |

It -Name 'No parameters returns all results' -Test {
@( Get-RubrikDNSSetting).Count |
Should -BeExactly 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
}

Assert-VerifiableMock
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
#Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
#Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
}
}
6 changes: 4 additions & 2 deletions azure-pipelines/scripts/Invoke-RunTests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Install-Module -Name Pester -MaximumVersion 4.99.99 -Force
Install-Module -Name Pester -MaximumVersion 4.2.0 -Force -SkipPublisherCheck
Remove-Module Pester -ErrorAction SilentlyContinue
Import-Module -Name Pester -MaximumVersion 4.99.99
Import-Module -Name Pester -MaximumVersion 4.2.0
Install-Module -Name RubrikSecurityCloud -Force -SkipPublisherCheck
Import-Module RubrikSecurityCloud

$PesterSplat = @{
PassThru = $true
Expand Down

0 comments on commit c4745b6

Please sign in to comment.