/
Get-DbaCredential.Tests.ps1
59 lines (52 loc) 路 3.02 KB
/
Get-DbaCredential.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
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
. "$PSScriptRoot\..\private\functions\Invoke-Command2.ps1"
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Credential', 'ExcludeCredential', 'Identity', 'ExcludeIdentity', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$logins = "dbatoolsci_thor", "dbatoolsci_thorsmomma"
$plaintext = "BigOlPassword!"
$password = ConvertTo-SecureString $plaintext -AsPlainText -Force
# Add user
foreach ($login in $logins) {
$null = Invoke-Command2 -ScriptBlock { net user $args[0] $args[1] /add *>&1 } -ArgumentList $login, $plaintext -ComputerName $script:instance2
}
$results = New-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password
$results = New-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma -Password $password
}
AfterAll {
try {
(Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma -ErrorAction Stop -WarningAction SilentlyContinue).Drop()
} catch { }
foreach ($login in $logins) {
$null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2
$null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2
}
}
Context "Get credentials" {
It "Should get just one credential with the proper properties when using Identity" {
$results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thorsmomma
$results.Name | Should Be "dbatoolsci_thorsmomma"
$results.Identity | Should Be "dbatoolsci_thorsmomma"
}
It "Should get just one credential with the proper properties when using Name" {
$results = Get-DbaCredential -SqlInstance $script:instance2 -Name dbatoolsci_thorsmomma
$results.Name | Should Be "dbatoolsci_thorsmomma"
$results.Identity | Should Be "dbatoolsci_thorsmomma"
}
It "gets more than one credential" {
$results = Get-DbaCredential -SqlInstance $script:instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma
$results.count -gt 1
}
}
}