Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Pester v5 #48

Merged
merged 14 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Tests/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ else {
$script:pester_longint = "long"
}

if ($port) {
$script:port = "443"
$script:invokeParams = @{
server = $ipaddress;
token = $token;
port = $port;
SkipCertificateCheck = $true;
}

if ($null -eq $port) {
$invokeParams.port = 443
}

. ../credential.ps1
#TODO: Add check if no ipaddress/token info...
Connect-ArubaCP @invokeParams -SkipCertificateCheck

Connect-ArubaCP -Server $ipaddress -port $port -Token $token -SkipCertificateCheck
$script:VersionBefore680 = $DefaultArubaCPConnection.Version -lt [version]"6.8.0"

$script:VersionBefore680 = $DefaultArubaCPConnection.Version -lt [version]"6.8.0"
Disconnect-ArubaCP -noconfirm
74 changes: 40 additions & 34 deletions Tests/integration/ApiClient.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#
. ../common.ps1

BeforeAll {
Connect-ArubaCP @invokeParams
}

Describe "Get API Client" {

BeforeAll {
Expand All @@ -16,40 +20,40 @@ Describe "Get API Client" {
It "Get NetworkDevice Does not throw an error" {
{
Get-ArubaCPApiClient
} | Should Not Throw
} | Should -Not -Throw
}

It "Get ALL Api Client" {
$ac = Get-ArubaCPApiClient
$ac.count | Should not be $NULL
$ac.count | Should -Not -Be $NULL
}

It "Get Api Client (pester_PowerArubaCP1)" {
$ac = Get-ArubaCPApiClient | Where-Object { $_.client_id -eq "pester_PowerArubaCP1" }
$ac.id | Should not be BeNullOrEmpty
$ac.client_id | Should be "pester_PowerArubaCP1"
$ac.client_secret | should not be BeNullOrEmpty
$ac.client_description | Should be "Add by PowerArubaCP"
$ac.grant_types | Should be "client_credentials"
$ac.profile_id | Should be "1"
$ac.id | Should -Not -BeNullOrEmpty
$ac.client_id | Should -Be "pester_PowerArubaCP1"
$ac.client_secret | Should -Not -BeNullOrEmpty
$ac.client_description | Should -Be "Add by PowerArubaCP"
$ac.grant_types | Should -Be "client_credentials"
$ac.profile_id | Should -Be "1"
}

It "Get Api Client (pester_PowerArubaCP2) and confirm (via Confirm-ArubaCPApiClient)" {
$ac = Get-ArubaCPApiClient | Where-Object { $_.client_id -eq "pester_PowerArubaCP2" }
Confirm-ArubaCPApiClient $ac | Should be $true
Confirm-ArubaCPApiClient $ac | Should -Be $true
}

It "Search Api Client by client_id (pester_PowerArubaCP1)" {
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
@($ac).count | Should be 1
$ac.id | Should not be BeNullOrEmpty
$ac.client_id | Should be "pester_PowerArubaCP1"
$ac.client_description | Should be "Add by PowerArubaCP"
@($ac).count | Should -Be 1
$ac.id | Should -Not -BeNullOrEmpty
$ac.client_id | Should -Be "pester_PowerArubaCP1"
$ac.client_description | Should -Be "Add by PowerArubaCP"
}

It "Search Api Client by client_id (contains *pester*)" {
$ac = Get-ArubaCPApiClient -client_id pester -filter_type contains
@($ac).count | Should be 2
@($ac).count | Should -Be 2
}

AfterAll {
Expand All @@ -64,22 +68,22 @@ Describe "Add Api Client" {
It "Add Api Client with grant types client_credentials and description" {
Add-ArubaCPApiClient -client_id pester_PowerArubaCP1 -client_description "Add by PowerArubaCP" -grant_types "client_credentials" -profile_id 1
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac.id | Should not be BeNullOrEmpty
$ac.client_id | Should not be BeNullOrEmpty
$ac.client_secret | should not be BeNullOrEmpty
$ac.client_description | Should be "Add by PowerArubaCP"
$ac.grant_types | Should be "client_credentials"
$ac.profile_id | Should be "1"
$ac.id | Should -Not -BeNullOrEmpty
$ac.client_id | Should -Not -BeNullOrEmpty
$ac.client_secret | Should -Not -BeNullOrEmpty
$ac.client_description | Should -Be "Add by PowerArubaCP"
$ac.grant_types | Should -Be "client_credentials"
$ac.profile_id | Should -Be "1"
}

It "Add Api Client with grant type password (refresh_token) and status disabled" {
Add-ArubaCPApiClient -client_id pester_PowerArubaCP1 -grant_types password -profile_id 1 -enabled:$false
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac.id | Should not be BeNullOrEmpty
$ac.client_id | Should be "pester_PowerArubaCP1"
$ac.grant_types | Should be "password refresh_token"
$ac.profile_id | Should be "1"
$ac.enabled | should be "false"
$ac.id | Should -Not -BeNullOrEmpty
$ac.client_id | Should -Be "pester_PowerArubaCP1"
$ac.grant_types | Should -Be "password refresh_token"
$ac.profile_id | Should -Be "1"
$ac.enabled | Should -Be "false"
}

AfterEach {
Expand All @@ -93,28 +97,30 @@ Describe "Remove Api Client" {
It "Remove Api Client by id" {
Add-ArubaCPApiClient -client_id pester_PowerArubaCP1 -grant_types "client_credentials" -profile_id 1
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac.client_id | Should be "pester_PowerArubaCP1"
@($ac).count | should be 1
$ac.client_id | Should -Be "pester_PowerArubaCP1"
@($ac).count | Should -Be 1
Remove-ArubaCPApiClient -id $ac.client_id -noconfirm
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac | Should BeNullOrEmpty
@($ac).count | should be 0
$ac | Should -BeNullOrEmpty
@($ac).count | Should -Be 0
}

It "Remove Api Client by client_id (and pipeline)" {
Add-ArubaCPApiClient -client_id pester_PowerArubaCP1 -grant_types "client_credentials" -profile_id 1
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac.client_id | Should be "pester_PowerArubaCP1"
@($ac).count | should be 1
$ac.client_id | Should -Be "pester_PowerArubaCP1"
@($ac).count | Should -Be 1
Get-ArubaCPApiClient -client_id pester_PowerArubaCP1 | Remove-ArubaCPApiClient -noconfirm
$ac = Get-ArubaCPApiClient -client_id pester_PowerArubaCP1
$ac | Should BeNullOrEmpty
@($ac).count | should be 0
$ac | Should -BeNullOrEmpty
@($ac).count | Should -Be 0
}

AfterEach {
Get-ArubaCPApiClient -client_id pester_PowerArubaCP1 | Remove-ArubaCPApiClient -noconfirm
}
}

Disconnect-ArubaCP -noconfirm
AfterAll {
Disconnect-ArubaCP -noconfirm
}
23 changes: 14 additions & 9 deletions Tests/integration/ApplicationLicense.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
#
. ../common.ps1

BeforeAll {
Connect-ArubaCP @invokeParams
}

Describe "Get Application License" {

It "Get Application License Does not throw an error" -Skip:$VersionBefore680 {
{
Get-ArubaCPApplicationLicense
} | Should Not Throw
} | Should -Not -Throw
}

It "Get ALL Application License" -Skip:$VersionBefore680 {
$al = Get-ArubaCPApplicationLicense
$al.count | Should not be $NULL
$al.count | Should -Not -Be $NULL
}

It "Get Application License and confirm" -Skip:$VersionBefore680 {
$al = Get-ArubaCPApplicationLicense
Confirm-ArubaCPApplicationLicense $al[0] | Should be $true
Confirm-ArubaCPApplicationLicense $al[0] | Should -Be $true
}

It "Get Application License throw a error when use with CPPM <= 6.8.0" -Skip: ($VersionBefore680 -eq 0) {
{ Get-ArubaCPApplicationLicense } | Should throw "Need ClearPass >= 6.8.0 for use this cmdlet"
{ Get-ArubaCPApplicationLicense } | Should -Throw "Need ClearPass >= 6.8.0 for use this cmdlet"
}

}
Expand All @@ -34,17 +38,18 @@ Describe "Add and Remove Application License" {
It "Add Application License ($pester_license_type)" -Skip:( -not ($pester_license -ne $null -and $VersionBefore680 -eq 0) ) {
Add-ArubaCPApplicationLicense -product_name $pester_license_type -license_key $pester_license
$al = Get-ArubaCPApplicationLicense -product_name $pester_license_type #Only check if search work !
$al.id | Should not be BeNullOrEmpty
$al.product_name | Should be $pester_license_type
$al.id | Should -Not -BeNullOrEmpty
$al.product_name | Should -Be $pester_license_type
}

It "Remove Application License ($pester_license_type)" -Skip:( -not ($pester_license -ne $null -and $VersionBefore680 -eq 0)) {
Get-ArubaCPApplicationLicense -product_name $pester_license_type | Remove-ArubaCPApplicationLicense -noconfirm
$al = Get-ArubaCPApplicationLicense -product_name $pester_license_type
$al | Should be $null
$al | Should -Be $null
}

}


Disconnect-ArubaCP -noconfirm
AfterAll {
Disconnect-ArubaCP -noconfirm
}
61 changes: 31 additions & 30 deletions Tests/integration/Connection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ Describe "Connect to a ClearPass (using Token)" {
Disconnect-ArubaCP -noconfirm
}
It "Connect to ClearPass (using Token) and check global variable" {
Connect-ArubaCP $ipaddress -Token $token -port $port -SkipCertificateCheck
$DefaultArubaCPConnection | Should Not BeNullOrEmpty
$DefaultArubaCPConnection.server | Should be $ipaddress
$DefaultArubaCPConnection.token | Should be $token
$DefaultArubaCPConnection.port | Should be $port
Connect-ArubaCP @invokeParams
$DefaultArubaCPConnection | Should -Not -BeNullOrEmpty
$DefaultArubaCPConnection.server | Should -Be $invokeParams.server
$DefaultArubaCPConnection.token | Should -Be $invokeParams.token
$DefaultArubaCPConnection.port | Should -Be $invokeParams.port
}
It "Disconnect to ClearPass and check global variable" {
Disconnect-ArubaCP -noconfirm
$DefaultArubaCPConnection | Should be $null
$DefaultArubaCPConnection | Should -Be $null
}
#TODO: Connect using wrong login/password

#This test only work with PowerShell 6 / Core (-SkipCertificateCheck don't change global variable but only Invoke-WebRequest/RestMethod)
#This test will be fail, if there is valid certificate...
It "Throw when try to use Connect-ArubaCP with don't use -SkipCertificateCheck" -Skip:("Desktop" -eq $PSEdition) {
{ Connect-ArubaCP $ipaddress -Token $token -port $port } | Should throw "Unable to connect (certificate)"
{ Connect-ArubaCP $invokeParams.server -Token $invokeParams.token -port $invokeParams.port } | Should -Throw "Unable to connect (certificate)"
Disconnect-ArubaCP -noconfirm
}
It "Throw when try to use Invoke-ArubaCPRestMethod and not connected" {
{ Invoke-ArubaCPRestMethod -uri "api/cppm-version" } | Should throw "Not Connected. Connect to the ClearPass with Connect-ArubaCP"
{ Invoke-ArubaCPRestMethod -uri "api/cppm-version" } | Should -Throw "Not Connected. Connect to the ClearPass with Connect-ArubaCP"
}
}

Expand All @@ -39,68 +39,69 @@ Describe "Connect to a ClearPass (using multi connection)" {
#Disconnect "default connection"
Disconnect-ArubaCP -noconfirm
}

It "Connect to a ClearPass (using token and store on cppm variable)" {
$script:cppm = Connect-ArubaCP $ipaddress -Token $token -SkipCertificateCheck -port $port -DefaultConnection:$false
$script:cppm = Connect-ArubaCP @invokeParams -DefaultConnection:$false
$DefaultArubaCPConnection | Should -BeNullOrEmpty
$cppm.server | Should be $ipaddress
$cppm.token | Should be $token
$cppm.port | Should be $port
$cppm.server | Should -Be $invokeParams.server
$cppm.token | Should -Be $invokeParams.token
$cppm.port | Should -Be $invokeParams.port
}

Context "Use Multi connection for call some (Get) cmdlet (Application Licence, Version, NAS, SHL...)" {
It "Use Multi connection for call Get Applicetion License " -Skip:$VersionBefore680 {
{ Get-ArubaCPApplicationLicense -connection $cppm } | Should Not throw
{ Get-ArubaCPApplicationLicense -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get CPPM Version" {
{ Get-ArubaCPCPPMVersion -connection $cppm } | Should Not throw
{ Get-ArubaCPCPPMVersion -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Network Device" {
{ Get-ArubaCPNetworkDevice -connection $cppm } | Should Not throw
{ Get-ArubaCPNetworkDevice -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Server Configuration" {
{ Get-ArubaCPServerConfiguration -connection $cppm } | Should Not throw
{ Get-ArubaCPServerConfiguration -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Server Version" {
{ Get-ArubaCPServerVersion -connection $cppm } | Should Not throw
{ Get-ArubaCPServerVersion -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Static Host List" -Skip:$VersionBefore680 {
{ Get-ArubaCPStaticHostList -connection $cppm } | Should Not throw
{ Get-ArubaCPStaticHostList -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Endpoint" {
{ Get-ArubaCPEndpoint -connection $cppm } | Should Not throw
{ Get-ArubaCPEndpoint -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Api Client" {
{ Get-ArubaCPApiClient -connection $cppm } | Should Not throw
{ Get-ArubaCPApiClient -connection $cppm } | Should -Not -Throw
}
It "Use Multi connection for call Get Service" -Skip:$VersionBefore680 {
{ Get-ArubaCPService -connection $cppm } | Should Not throw
{ Get-ArubaCPService -connection $cppm } | Should -Not -Throw
}
}

It "Disconnect to a ClearPass (Multi connection)" {
Disconnect-ArubaCP -connection $cppm -noconfirm
$DefaultArubaCPConnection | Should be $null
$DefaultArubaCPConnection | Should -Be $null
}

}

Describe "Connect using client_credentials" {
BeforeAll {
#connect...
Connect-ArubaCP $ipaddress -Token $token -SkipCertificateCheck -port $port
Connect-ArubaCP @invokeParams
#Create a API Client with client credentials
Add-ArubaCPApiClient -client_id pester_PowerArubaCP -client_secret pester_MySecret -grant_types "client_credentials" -profile_id 1
}

It "Connect to a ClearPass (using client_credentials and store on cppm variable)" {
$script:cppm = Connect-ArubaCP $ipaddress -client_id pester_PowerArubaCP -client_secret pester_MySecret -SkipCertificateCheck -port $port -DefaultConnection:$false
$cppm.server | Should be $ipaddress
$cppm.token | Should not be BeNullOrEmpty
$cppm.port | Should be $port
$script:cppm = Connect-ArubaCP $invokeParams.server -client_id pester_PowerArubaCP -client_secret pester_MySecret -SkipCertificateCheck -port $invokeParams.port -DefaultConnection:$false
$cppm.server | Should -Be $invokeParams.server
$cppm.token | Should -Not -BeNullOrEmpty
$cppm.port | Should -Be $invokeParams.port
}

It "Use Multi connection for call Get (Api Client)" {
{ Get-ArubaCPApiClient -connection $cppm } | Should Not throw
{ Get-ArubaCPApiClient -connection $cppm } | Should -Not -Throw
}

AfterAll {
Expand All @@ -114,7 +115,7 @@ Describe "Connect using client_credentials" {
Describe "Invoke ArubaCP RestMethod tests" {
BeforeAll {
#connect...
Connect-ArubaCP $ipaddress -Token $token -SkipCertificateCheck -port $port
Connect-ArubaCP @invokeParams
#Add 26 Network Device (NAS)
Add-ArubaCPNetworkDevice -name pester_SW1 -ip_address 192.0.2.1 -radius_secret MySecurePassword -vendor Aruba
Add-ArubaCPNetworkDevice -name pester_SW2 -ip_address 192.0.2.2 -radius_secret MySecurePassword -vendor Aruba
Expand Down Expand Up @@ -154,7 +155,7 @@ Describe "Invoke ArubaCP RestMethod tests" {
It "Use Invoke-ArubaCPRestMethod with limit parameter" {
$response = Invoke-ArubaCPRestMethod -method "GET" -uri "api/network-device" -limit 1000
$nad = $response._embedded.items | where-object { $_.name -match "pester_" }
$nad.count | should be 26
$nad.count | Should -Be 26
}

It "Use Invoke-ArubaCPRestMethod with filter parameter (equal)" {
Expand Down
Loading