2021-07-23 22:06:42 +02:00
|
|
|
|
<#
|
2018-05-11 15:54:43 -04:00
|
|
|
|
.NOTES
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.150
|
|
|
|
|
|
Created on: 5/8/2018 10:33 AM
|
|
|
|
|
|
Created by: Ben Claussen
|
|
|
|
|
|
Organization: NEOnet
|
|
|
|
|
|
Filename: Setup.Tests.ps1
|
|
|
|
|
|
===========================================================================
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
|
Setup function Pester tests
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
|
|
Import-Module Pester
|
|
|
|
|
|
Remove-Module NetboxPS -Force -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
|
|
|
|
$ModulePath = "$PSScriptRoot\..\dist\NetboxPS.psd1"
|
|
|
|
|
|
|
|
|
|
|
|
if (Test-Path $ModulePath) {
|
|
|
|
|
|
Import-Module $ModulePath -ErrorAction Stop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Describe "Setup tests" -Tag 'Core', 'Setup' -Fixture {
|
|
|
|
|
|
It "Throws an error for an empty hostname" {
|
|
|
|
|
|
{ Get-NetboxHostname } | Should -Throw
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Sets the hostname" {
|
|
|
|
|
|
Set-NetboxHostName -HostName 'netbox.domain.com' | Should -Be 'netbox.domain.com'
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Gets the hostname from the variable" {
|
|
|
|
|
|
Get-NetboxHostName | Should -Be 'netbox.domain.com'
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Throws an error for empty credentials" {
|
2018-05-21 10:56:20 -04:00
|
|
|
|
{ Get-NetboxCredential } | Should -Throw
|
2018-05-11 15:54:43 -04:00
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
Context "Plain text credentials" {
|
|
|
|
|
|
It "Sets the credentials using plain text" {
|
2018-05-21 10:56:20 -04:00
|
|
|
|
Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText) | Should -BeOfType [pscredential]
|
2018-05-11 15:54:43 -04:00
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Checks the set credentials" {
|
2018-05-21 10:56:20 -04:00
|
|
|
|
$Creds = Set-NetboxCredential -Token (ConvertTo-SecureString -String "faketoken" -Force -AsPlainText)
|
|
|
|
|
|
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly "faketoken"
|
2018-05-11 15:54:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
Context "Credentials object" {
|
|
|
|
|
|
$Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Sets the credentials using [pscredential]" {
|
2018-05-21 10:56:20 -04:00
|
|
|
|
Set-NetboxCredential -Credential $Creds | Should -BeOfType [pscredential]
|
2018-05-11 15:54:43 -04:00
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Checks the set credentials" {
|
2018-05-21 10:56:20 -04:00
|
|
|
|
(Get-NetboxCredential).GetNetworkCredential().Password | Should -BeExactly 'faketoken'
|
2018-05-11 15:54:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
<#
|
|
|
|
|
|
Context "Connecting to the API" {
|
|
|
|
|
|
Mock Get-NetboxCircuitsChoices {
|
|
|
|
|
|
return $true
|
|
|
|
|
|
} -ModuleName NetboxPS -Verifiable
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
$Creds = [PSCredential]::new('notapplicable', (ConvertTo-SecureString -String "faketoken" -AsPlainText -Force))
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Connects using supplied hostname and obtained credentials" {
|
|
|
|
|
|
#$null = Set-NetboxCredentials -Credentials $Creds
|
|
|
|
|
|
Connect-NetboxAPI -Hostname "fake.org" | Should -Be $true
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
It "Connects using supplied hostname and credentials" {
|
|
|
|
|
|
Connect-NetboxAPI -Hostname 'fake.org' -Credentials $Creds | Should -Be $true
|
|
|
|
|
|
}
|
2021-07-23 22:06:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 15:54:43 -04:00
|
|
|
|
Assert-MockCalled -CommandName Get-NetboxCircuitsChoices -ModuleName NetboxPS
|
|
|
|
|
|
}
|
|
|
|
|
|
#>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|