Skip to content

Commit c4745b6

Browse files
authored
Merge pull request #856 from rubrikinc/devel
Merge Devel into Master for 9.0.1 release
2 parents a55819f + 8c68c71 commit c4745b6

File tree

7 files changed

+80
-38
lines changed

7 files changed

+80
-38
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
* **Fixed** for any bug fixes.
1515
* **Security** in case of vulnerabilities.
1616

17+
## Unreleased
18+
19+
## [9.0.1]
20+
21+
### Added
22+
* Added `Test-PowerShellSeven` private function to test if PS 7 is being used to facilate fix for DELETE calls without explicit ContentType parameter.
23+
24+
### Modified
25+
* 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)
26+
* 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
27+
1728
## [9.0.0]
1829

1930
### Added

Rubrik/Private/Invoke-RubrikWebRequest.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@ function Invoke-RubrikWebRequest {
2020
if (Test-UnicodeInString -String $Body) {
2121
$PSBoundParameters.Add('ContentType', 'text/plain; charset=utf-8')
2222
Write-Verbose -Message ('Submitting "{0}" request as "text/plain; charset=utf-8"' -f $Method)
23-
}
24-
23+
}
24+
if (Test-PowerShellSeven) {
25+
if ($Method -eq "DELETE") {
26+
if ($PSBoundParameters.ContainsKey('ContentType')) {
27+
$PSBoundParameters.Remove('ContentType')
28+
}
29+
$PSBoundParameters.Add('ContentType', 'application/json')
30+
Write-Verbose -Message ('Submitting "{0}" request as "application/json"' -f $Method)
31+
}
32+
}
33+
34+
2535
if (Test-PowerShellSix) {
26-
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -or $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
36+
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -and $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
2737
Write-Verbose -Message "Invoking request with a custom timeout of $($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) seconds"
2838
$result = Invoke-WebRequest -UseBasicParsing -SkipCertificateCheck -TimeoutSec $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut @PSBoundParameters
2939
} else {
3040
Write-Verbose -Message "No custom timeout specified or custom timeout is less than 100 seconds, invoking request with default value of 100 seconds"
3141
$result = Invoke-WebRequest -UseBasicParsing -SkipCertificateCheck @PSBoundParameters
3242
}
3343
} else {
34-
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -or $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
44+
if (-not [string]::IsNullOrWhiteSpace($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) -and $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut -gt 99) {
3545
Write-Verbose -Message "Invoking request with a custom timeout of $($rubrikOptions.ModuleOption.DefaultWebRequestTimeOut) seconds"
3646
$result = Invoke-WebRequest -UseBasicParsing -TimeoutSec $rubrikOptions.ModuleOption.DefaultWebRequestTimeOut @PSBoundParameters
3747
} else {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
function Test-PowerShellSeven {
3+
<#
4+
.SYNOPSIS
5+
Test if the PowerShell version is 7 or higher, this is to provide backwards compatibility for older version of PowerShell
6+
7+
.DESCRIPTION
8+
This function is used to fix the latest Mircrosoft Update which requieres a content-type in the header for Invoke-WebRequest
9+
#>
10+
$PSVersionTable.PSVersion.Major -ge 7
11+
}

Rubrik/Rubrik.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'Rubrik.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '9.0.0'
15+
ModuleVersion = '9.0.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

Tests/Connect-Rubrik.Tests.ps1

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,29 @@ Describe -Name 'Public/Connect-Rubrik' -Tag 'Public', 'Connect-Rubrik' -Fixture
2121
#endregion
2222

2323
Context -Name 'Validate Connecting to Cluster' {
24-
Mock -CommandName Get-RubrikAPIVersion -Verifiable -ModuleName 'Rubrik' -MockWith { }
25-
Mock -CommandName Get-RubrikSoftwareVersion -Verifiable -ModuleName 'Rubrik' -MockWith {
26-
'5.1.2-8188'
27-
}
28-
Mock -CommandName New-UserAgentString -Verifiable -ModuleName 'Rubrik' -MockWith { }
29-
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
30-
[pscustomobject]@{
31-
id = 11111
32-
userId = 22222
33-
token = 33333
34-
}
35-
}
36-
Mock -CommandName Invoke-RestMethod -Verifiable -ModuleName 'Rubrik' -MockWith {
37-
[pscustomobject]@{
38-
sessionId = "22222"
39-
serviceAccountId = "11111"
40-
token = "33333"
41-
expirationTime = "3022-12-10T06:19:52.250Z"
42-
organizationId = "44444"
24+
25+
Mock -CommandName Get-RubrikAPIVersion -Verifiable -ModuleName 'Rubrik' -MockWith { }
26+
Mock -CommandName Get-RubrikSoftwareVersion -Verifiable -ModuleName 'Rubrik' -MockWith {
27+
'5.1.2-8188'
4328
}
44-
}
29+
Mock -CommandName New-UserAgentString -Verifiable -ModuleName 'Rubrik' -MockWith { }
30+
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
31+
[pscustomobject]@{
32+
id = 11111
33+
userId = 22222
34+
token = 33333
35+
}
4536

37+
Mock -CommandName Invoke-RestMethod -Verifiable -ModuleName 'Rubrik' -MockWith {
38+
[pscustomobject]@{
39+
sessionId = "22222"
40+
serviceAccountId = "11111"
41+
token = "33333"
42+
expirationTime = "3022-12-10T06:19:52.250Z"
43+
organizationId = "44444"
44+
}
45+
}
46+
}
4647
It -Name 'Username / Password combination' -Test {
4748
(Connect-Rubrik -Server testcluster -Username jaapbrasser -Password $(ConvertTo-SecureString -String password -AsPlainText -Force)) | Out-String |
4849
Should -BeLikeExactly '*Basic*'
@@ -59,19 +60,21 @@ Describe -Name 'Public/Connect-Rubrik' -Tag 'Public', 'Connect-Rubrik' -Fixture
5960
It -Name 'API Token' -Test {
6061
(Connect-Rubrik -Server testcluster -Token 33333) | Out-String |
6162
Should -BeLikeExactly '*Token*'
63+
6264
}
6365

6466
It -Name 'Service Account' -Test {
6567
(Connect-Rubrik -Server testcluster -Id Username -Secret 33333) | Out-String |
6668
Should -BeLikeExactly '*ServiceAccount*'
69+
6770
}
6871

6972
It -Name 'RubrikConnections array should contain 4 entries' -Test {
7073
@($RubrikConnections).Count |
7174
Should -Be 4
75+
7276
}
73-
74-
Assert-VerifiableMock
7577
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 3
78+
7679
}
7780
}

Tests/Get-RubrikDNSSetting.Tests.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@ Describe -Name 'Public/Get-RubrikDNSSetting' -Tag 'Public', 'Get-RubrikDNSSettin
2020
#endregion
2121

2222
Context -Name 'Returned Results' {
23-
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith { }
24-
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
25-
@{
26-
'DNSServers' = @("192.168.150.1", "10.10.1.5")
27-
'DNSSearchDomain' = @("lab.local", "domain.local")
23+
BeforeAll {
24+
Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith { }
25+
Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {
26+
@{
27+
'DNSServers' = @("192.168.150.1", "10.10.1.5")
28+
'DNSSearchDomain' = @("lab.local", "domain.local")
29+
}
2830
}
2931
}
30-
It -Name 'No parameters returns all results' -Test {
31-
@( Get-RubrikDNSSetting).Count |
32+
33+
It -Name 'No parameters returns all results' -Test {
34+
@( Get-RubrikDNSSetting).Count |
3235
Should -BeExactly 1
36+
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
37+
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
3338
}
3439

3540
Assert-VerifiableMock
36-
Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
37-
Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
41+
#Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1
42+
#Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2
3843
}
3944
}

azure-pipelines/scripts/Invoke-RunTests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
Install-Module -Name Pester -MaximumVersion 4.99.99 -Force
1+
Install-Module -Name Pester -MaximumVersion 4.2.0 -Force -SkipPublisherCheck
22
Remove-Module Pester -ErrorAction SilentlyContinue
3-
Import-Module -Name Pester -MaximumVersion 4.99.99
3+
Import-Module -Name Pester -MaximumVersion 4.2.0
4+
Install-Module -Name RubrikSecurityCloud -Force -SkipPublisherCheck
5+
Import-Module RubrikSecurityCloud
46

57
$PesterSplat = @{
68
PassThru = $true

0 commit comments

Comments
 (0)