Skip to content

Commit 10b7d26

Browse files
Merge pull request #995 from dataplat/instancecheckscontinued
so that we can see failed connections and they are in the results #882
2 parents 7111e69 + 85229dc commit 10b7d26

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

source/checks/Instancev5.Tests.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,29 @@ BeforeDiscovery {
3434
Set-PSFConfig -Module dbachecks -Name global.notcontactable -Value $NotContactable
3535
# Get-DbcConfig is expensive so we call it once
3636
$__dbcconfig = Get-DbcConfig
37+
$notcontactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value
38+
$Checks = Get-DbcCheck
39+
$TestsNoGoBrrr = foreach ($Not in $notcontactable) {
40+
foreach ($tag in $tags) {
41+
[PSCustomObject]@{
42+
Name = $Not
43+
Tag = $tag
44+
}
45+
}
46+
}
47+
}
48+
49+
BeforeAll {
50+
3751
}
52+
Describe "<_.Tag> failed on <_.Name>" -Tag FailedConnections -ForEach $TestsNoGoBrrr {
53+
Context "Checking <_.Tag> on <_.Name>" {
54+
It "The instance <_.Name> is not connectable" -Skip:$skip {
55+
$false | Should -BeTrue -Because "This instance is not connectable"
56+
}
57+
}
58+
}
59+
3860

3961
# Ordered alphabetically by unique tag please
4062
Describe "Ad Hoc Distributed Queries" -Tag AdHocDistributedQueriesEnabled, security, CIS, Medium, Instance -ForEach $InstancesToTest {

source/functions/Invoke-DbcCheck.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function Invoke-DbcCheck {
286286
}
287287
}
288288
process {
289+
289290
if ($legacy) {
290291
try {
291292
Write-PSFMessage 'Running in legacy mode, we need Version 4'
@@ -365,7 +366,7 @@ function Invoke-DbcCheck {
365366
# cast from empty hashtable to get default
366367
$configuration = New-PesterConfiguration
367368
$configuration.Output.Verbosity = $NewShow
368-
$configuration.Filter.Tag = $check
369+
$configuration.Filter.Tag = $check + 'FailedConnections'
369370
$configuration.Filter.ExcludeTag = $ExcludeCheck
370371
if ($PassThru) {
371372
$configuration.Run.PassThru = $true

source/internal/functions/Invoke-DbcCheckv5.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Invoke-DbcCheckv5 {
4646
$name = "Config" + (($name.Split(".") | ForEach-Object { $_.SubString(0, 1).ToUpper() + $_.SubString(1) }) -join '')
4747
$ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
4848
$ParamAttrib.ParameterSetName = '__AllParameterSets'
49-
$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
49+
$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
5050
$AttribColl.Add($ParamAttrib)
5151

5252
$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter($name, [object], $AttribColl)
@@ -159,8 +159,8 @@ function Invoke-DbcCheckv5 {
159159
Write-PSFMessage -Message "SqlInstance is $SqlInstance" -Level Verbose
160160
# Because we have all these bound params :-(
161161
$null = $PSBoundParameters.Remove('configuration')
162-
163162
Invoke-Pester -Configuration $configuration
163+
164164
Pop-Location
165165
}
166166
}

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,16 @@ function NewGet-AllInstanceInfo {
419419
{ 'PublicRolePermissions' -or 'PublicPermission' } {
420420
#This needs to be done in query just in case the account had already been renamed
421421
$query = "
422-
SELECT Count(*) AS [RowCount]
423-
FROM master.sys.server_permissions
424-
WHERE (grantee_principal_id = SUSER_SID(N'public') and state_desc LIKE 'GRANT%')
425-
AND NOT (state_desc = 'GRANT' and [permission_name] = 'VIEW ANY DATABASE' and class_desc = 'SERVER')
426-
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 2)
427-
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 3)
428-
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 4)
429-
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 5);
422+
SELECT Count(*) AS [RowCount]
423+
FROM master.sys.server_permissions
424+
WHERE (grantee_principal_id = SUSER_SID(N'public') and state_desc LIKE 'GRANT%')
425+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'VIEW ANY DATABASE' and class_desc = 'SERVER')
426+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 2)
427+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 3)
428+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 4)
429+
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 5);
430430
"
431-
$PublicRolePermsCount = $srv.Query($query).RowCount
431+
$PublicRolePermsCount = $Instance.Query($query).RowCount
432432
}
433433

434434
'SuspectPageLimit' {

0 commit comments

Comments
 (0)