-
Notifications
You must be signed in to change notification settings - Fork 608
/
Copy pathMOBConnection.Tests.ps1
122 lines (100 loc) · 3.6 KB
/
MOBConnection.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<#
Copyright (c) 2025 JetStream Software Inc.
SPDX-License-Identifier: BSD-2-Clause
#>
param(
[Parameter(Mandatory = $true)]
[string]
$VcAddress,
[Parameter(Mandatory = $true)]
[string]
$User,
[Parameter(Mandatory = $true)]
[string]
$Password
)
# Import Vmware.vSphere.SsoAdmin Module
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
Import-Module $modulePath
# Global test variables
#$testUser = $null
#$testRole = $null
#$viServer = $null
#$ssoServer = $null
#$TESTUSERNAME='testuser_'
#$TESTUSERDOMAIN="${TESTUSERNAME}@vsphere.local"
#$TESTROLENAME='testrole_'
Describe "MOB Connect Tests" {
BeforeAll {
$testUser = $null
$testRole = $null
$viServer = $null
$ssoServer = $null
$trid = $null
$TESTUSERNAME='testuser_'
$TESTUSERDOMAIN="${TESTUSERNAME}@vsphere.local"
$TESTROLENAME='testrole_'
$ssoServer = Connect-SsoAdminServer `
-Server $VcAddress `
-User $User `
-Password $Password `
-SkipCertificateCheck
$viServer = Connect-VIServer `
-Server $VcAddress `
-User $User `
-Password $Password `
try {
$testUser = Get-SsoPersonUser -name $TESTUSERNAME -Domain 'vsphere.local'
} catch {}
if (!$testUser) {
$testUser = New-SsoPersonUser -UserName $TESTUSERNAME -Password 'TestP@$$w0rdXXX'
}
try {
$testRole = Get-VIRole -Name $TESTROLENAME -ErrorAction SilentlyContinue
} catch { }
if (!$testRole) {
$testPriv = Get-VIPrivilege -Id "System.View"
$testRole = New-VIRole -Privilege $testPriv -Name $TESTROLENAME
$testRole = Get-VIRole -Name $TESTROLENAME
}
$trid = $testRole.ExtensionData.RoleId
}
AfterAll {
Remove-SsoPersonUser -User $testUser
Remove-VIRole -Role $testRole -Confirm:$False
Disconnect-VIServer -Server $viServer -Confirm:$False
Disconnect-SsoAdminServer -Server $ssoServer
}
Context "Check Command Operation" {
It 'Verifies MOB connection' {
# Try bad credentials
{
$vCenterMOB1 = Connect-VcenterServerMOB -Server $VcAddress -User $User -Password "${Password}++" -SkipCertificateCheck
} | Should -Throw
# Act
$vCenterMOB1 = Connect-VcenterServerMOB -Server $VcAddress -User $User -Password $Password -SkipCertificateCheck
# Assert
$vCenterMOB1 | Should -Not -Be $null
$vCenterMOB1.IsConnected() | Should -Be $True
# Act
$vCenterMOB1 | Disconnect-VcenterServerMOB
# Assert
$vCenterMOB1.IsConnected() | Should -Be $False
}
It 'Verifies Global policy assignment' {
$vCenterMOB2 = Connect-VcenterServerMOB -Server $VcAddress -User $User -Password $Password -SkipCertificateCheck
$vCenterMob2 | Should -Not -Be $null
$vCenterMob2.IsConnected() | Should -Be $True
# Set global permission.
$vCenterMob2 | Set-VcenterServerGlobalPermission -TargetUser $TESTUSERDOMAIN -RoleId $trid -Propagate
$perms = $vCenterMOB2 | Get-VcenterServerGlobalPermissions -TargetUser $TESTUSERDOMAIN
$perms | Should -Contain "System.View"
# Drop all global permissions.
$vCenterMob2 | Reset-VcenterServerGlobalPermissions -TargetUser $TESTUSERDOMAIN
$perms = $vCenterMOB2 | Get-VcenterServerGlobalPermissions -TargetUser $TESTUSERDOMAIN
$perms | Should -BeNullOrEmpty
Disconnect-VcenterServerMOB $vCenterMOB2
$vCenterMob2.IsConnected() | Should -Be $False
}
}
}