-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAdd-SsoExclusionsFromCSV.Tests.ps1
61 lines (54 loc) · 2.21 KB
/
Add-SsoExclusionsFromCSV.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
# Copyright (c) 2019-2023 TeamViewer Germany GmbH
# See file LICENSE
BeforeAll {
$testApiToken = [securestring]@{}
. "$PSScriptRoot\Add-SsoExclusionsFromCSV.ps1" -ApiToken $testApiToken -Path 'testPath' -HeaderName 'Email' -InformationAction 'SilentlyContinue'
Mock Invoke-TeamViewerPing { $true }
Mock Get-TeamViewerSsoDomain { @(
[PSCustomObject]@{Id = '9602c5f4-2779-4f9a-80e8-4829531789fe'; Name = 'example1.org' },
[PSCustomObject]@{Id = '33ad81bb-e88b-46d0-92e1-b4f1663abf31'; Name = 'example2.org' }
)
}
Mock Add-TeamViewerSsoExclusion {}
Mock Import-Csv { ConvertFrom-Csv -InputObject @'
"EMail","Name"
"[email protected]","User1"
"[email protected]","User2"
"[email protected]","User3"
"[email protected]","User4"
"[email protected]","User5"
"[email protected]","User6"
'@
}
function Resolve-TeamViewerSsoDomainId {
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[object]
$Domain
)
Process {
if ($Domain.PSObject.TypeNames -contains 'TeamViewerPS.SsoDomain') {
return [guid]$Domain.Id
}
elseif ($Domain -is [string]) {
return [guid]$Domain
}
elseif ($Domain -is [guid]) {
return $Domain
}
else {
throw "Invalid SSO domain identifier '$Domain'. Must be either a [TeamViewerPS.SsoDomain], [guid] or [string]."
}
}
}
}
Describe 'Add-SsoExclusionsFromCSV' {
It 'Should blah' {
Add-SsoExclusionsFromCSV -Path 'example.csv' -HeaderName 'Email'
Assert-MockCalled Get-TeamViewerSsoDomain -Times 1 -Scope It
Assert-MockCalled Add-TeamViewerSsoExclusion -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -And $DomainId -eq [guid]'9602c5f4-2779-4f9a-80e8-4829531789fe' -And $Email.Count -eq 2 }
Assert-MockCalled Add-TeamViewerSsoExclusion -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -And $DomainId -eq [guid]'33ad81bb-e88b-46d0-92e1-b4f1663abf31' -And $Email.Count -eq 3 }
}
}