Skip to content

Commit 4881d27

Browse files
authored
New-SqlDscLogin: command to create SQL Server logins (#2132)
1 parent 9df1132 commit 4881d27

22 files changed

+1359
-90
lines changed

.build/Test-ShouldRunDscResourceIntegrationTests.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function Test-ShouldRunDscResourceIntegrationTests
413413
}
414414

415415
# Check if any public commands used by DSC resources are changed
416-
$changedPublicCommands = $changedFiles | Where-Object -FilterScript { $_ -match '^source/Public/(.+)\.ps1$' } |
416+
$changedPublicCommands = $changedFiles | Where-Object -FilterScript { $_ -match '^source/Public/(.+)\.ps1$' } |
417417
ForEach-Object -Process { [System.IO.Path]::GetFileNameWithoutExtension((Split-Path -Path $_ -Leaf)) }
418418

419419
$affectedCommands = $changedPublicCommands | Where-Object -FilterScript { $_ -in $PublicCommandsUsedByDscResources }
@@ -428,7 +428,7 @@ function Test-ShouldRunDscResourceIntegrationTests
428428
}
429429

430430
# Check if any private functions used by the affected public commands or class-based DSC resources are changed
431-
$changedPrivateFunctions = $changedFiles | Where-Object -FilterScript { $_ -match '^source/Private/(.+)\.ps1$' } |
431+
$changedPrivateFunctions = $changedFiles | Where-Object -FilterScript { $_ -match '^source/Private/(.+)\.ps1$' } |
432432
ForEach-Object -Process { [System.IO.Path]::GetFileNameWithoutExtension((Split-Path -Path $_ -Leaf)) }
433433

434434
$affectedPrivateFunctions = @()
@@ -490,10 +490,6 @@ if ($MyInvocation.InvocationName -ne '.')
490490
Write-Host "RESULT: DSC resource integration tests will be SKIPPED"
491491
}
492492

493-
# Output the result for the calling script to capture
494-
Write-Output -InputObject ""
495-
Write-Output -InputObject "ShouldRunDscResourceIntegrationTests: $shouldRun"
496-
497493
# Return the boolean value for pipeline script to use
498494
return $shouldRun
499495
}

.github/instructions/dsc-community-style-guidelines-markdown.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ applyTo: "**/*.md"
55

66
# Markdown Style Guidelines
77

8-
- Wrap lines at 80 characters
8+
- Wrap lines at word boundaries when over 80 characters
99
- Use 2 spaces for indentation
1010
- Use '1.' for all items in ordered lists (1/1/1 numbering style)
1111
- Surround fenced code blocks with blank lines

.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ function Get-Something
134134
- Parameter type on line above parameter name
135135
- Parameters separated by blank line
136136
- Parameters should use full type name.
137+
- Pipeline parameters (`ValueFromPipeline = $true`) must be declared in ALL parameter sets
137138

138139
## Best Practices
139140

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
22
.vs
33
output/
4+
coverage.xml

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@
7979
"PBIRS",
8080
"SSRS",
8181
"DSCSQLTEST",
82-
"unshallow"
82+
"unshallow",
83+
"pullrequest",
84+
"targetbranch",
85+
"hqrm",
86+
"sqlps",
87+
"securestring",
88+
"encryptorname",
89+
"wsfc"
8390
],
8491
"cSpell.ignorePaths": [
8592
".git"

.vscode/tasks.json

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,64 @@
8484
"label": "test",
8585
"type": "shell",
8686
"command": "&${cwd}/build.ps1",
87-
"args": ["-AutoRestore", "-UseModuleFast", "-Tasks", "test"],
87+
"args": [
88+
"-AutoRestore",
89+
"-UseModuleFast",
90+
"-Tasks",
91+
"test",
92+
"-PesterPath",
93+
"./tests/Unit/Classes,./tests/Unit/Private,./tests/Unit/Public,./tests/QA",
94+
"-CodeCoverageThreshold",
95+
"0"
96+
],
97+
"presentation": {
98+
"echo": true,
99+
"reveal": "always",
100+
"focus": true,
101+
"panel": "dedicated",
102+
"showReuseMessage": true,
103+
"clear": false
104+
},
105+
"problemMatcher": [
106+
{
107+
"owner": "powershell",
108+
"fileLocation": [
109+
"absolute"
110+
],
111+
"severity": "error",
112+
"pattern": [
113+
{
114+
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
115+
"message": 1
116+
},
117+
{
118+
"regexp": "(.*)",
119+
"code": 1
120+
},
121+
{
122+
"regexp": ""
123+
},
124+
{
125+
"regexp": "^.*,\\s*(.*):\\s*line\\s*(\\d+).*",
126+
"file": 1,
127+
"line": 2
128+
}
129+
]
130+
}
131+
]
132+
},
133+
{
134+
"label": "hqrmtest",
135+
"type": "shell",
136+
"command": "&${cwd}/build.ps1",
137+
"args": [
138+
"-AutoRestore",
139+
"-UseModuleFast",
140+
"-Tasks",
141+
"hqrmtest",
142+
"-CodeCoverageThreshold",
143+
"0"
144+
],
88145
"presentation": {
89146
"echo": true,
90147
"reveal": "always",

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Make sure tests forcibly imports the module being tested to avoid AI failing
1111
when testing changes.
12+
- Fixed Azure DevOps pipeline conditions that were preventing DSC resource
13+
integration tests from running when they should by removing incorrect quotes
14+
around boolean values.
1215

1316
### Added
1417

@@ -37,12 +40,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3740
- Includes a `-Refresh` parameter to refresh the server's login collection
3841
before attempting removal.
3942
- Provides detailed error messages with localization support.
43+
- `New-SqlDscLogin`
44+
- Added new public command to create a new login on a SQL Server Database
45+
Engine instance.
46+
- Supports creating SQL Server logins, Windows user logins, Windows group
47+
logins, certificate-based logins, and asymmetric key-based logins.
48+
- Implements proper parameter sets to prevent combining hashed passwords
49+
with password policy options, following SQL Server restrictions.
4050

4151
### Changed
4252

4353
- Module now outputs a verbose message instead of a warning when the SMO
4454
dependency module is missing during import to work around a DSC v3 issue.
4555
- VS Code tasks configuration was improved to support AI.
56+
- `Prerequisites` tests
57+
- Added creation of `SqlIntegrationTest` local Windows user for integration testing.
58+
- `tests/Integration/Commands/README.md`
59+
- Added documentation for `SqlIntegrationTest` user and
60+
`IntegrationTestSqlLogin` login.
61+
- Added run order information for `New-SqlDscLogin` integration test.
4662
- `azure-pipelines.yml`
4763
- Remove `windows-2019` images fixes [#2106](https://github.com/dsccommunity/SqlServerDsc/issues/2106).
4864
- Move individual tasks to `windows-latest`.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ be compiled to a .mof file. If the tests find any errors the build will fail.
296296

297297
A terminating error is an error that prevents the resource to continue further.
298298
If a DSC resource shall throw an terminating error the commands of the module
299-
**DscResource.Common** shall be used primarily; [`New-InvalidArgumentException`](https://github.com/dsccommunity/DscResource.Common#new-invalidargumentexception),
299+
**DscResource.Common** shall be used primarily; [`New-ArgumentException`](https://github.com/dsccommunity/DscResource.Common#new-invalidargumentexception),
300300
[`New-InvalidDataExcpetion`](https://github.com/dsccommunity/DscResource.Common#new-invaliddataexception),
301301
[`New-InvalidOperationException`](https://github.com/dsccommunity/DscResource.Common#new-invalidoperationexception),
302302
[`New-InvalidResultException`](https://github.com/dsccommunity/DscResource.Common#new-invalidresultexception),

azure-pipelines.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ stages:
9292
targetType: 'inline'
9393
script: |
9494
# Set the target branch for comparison
95-
$targetBranch = "origin/$(System.PullRequest.TargetBranch)"
96-
if (-not $env:SYSTEM_PULLREQUEST_TARGETBRANCH) {
97-
$targetBranch = "origin/main"
95+
if ($env:SYSTEM_PULLREQUEST_TARGETBRANCH) {
96+
$targetBranch = "origin/$env:SYSTEM_PULLREQUEST_TARGETBRANCH"
97+
} else {
98+
$targetBranch = "origin/$(defaultBranch)"
9899
}
99100
100101
Write-Output "Target branch: $targetBranch"
@@ -103,8 +104,15 @@ stages:
103104
# Run the script to determine if DSC resource integration tests should run
104105
$shouldRun = ./.build/Test-ShouldRunDscResourceIntegrationTests.ps1 -BaseBranch $targetBranch -CurrentBranch HEAD
105106
107+
# Debug: print computed value before exporting as output
108+
Write-Host "Computed ShouldRunDscResourceIntegrationTests: $shouldRun"
109+
110+
# Normalize to lowercase string so conditions can use a simple string comparison
111+
$shouldRunNormalized = ([string] $shouldRun).ToLower()
112+
Write-Host "Normalized ShouldRunDscResourceIntegrationTests: $shouldRunNormalized"
113+
106114
# Set Azure DevOps output variable for pipeline conditions
107-
Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRun"
115+
Write-Host "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests;isOutput=true]$shouldRunNormalized"
108116
pwsh: true
109117

110118
- job: Test_HQRM
@@ -282,6 +290,7 @@ stages:
282290
'tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1'
283291
# Group 2
284292
'tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1'
293+
'tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1'
285294
'tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1'
286295
'tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1'
287296
# Group 9
@@ -438,7 +447,7 @@ stages:
438447
condition: |
439448
and(
440449
succeeded(),
441-
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'True')
450+
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true')
442451
)
443452
jobs:
444453
- job: Test_Integration
@@ -536,7 +545,7 @@ stages:
536545
condition: |
537546
and(
538547
succeeded(),
539-
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'True')
548+
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true')
540549
)
541550
jobs:
542551
- job: Test_Integration
@@ -631,7 +640,7 @@ stages:
631640
condition: |
632641
and(
633642
succeeded(),
634-
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'True')
643+
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true')
635644
)
636645
jobs:
637646
- job: Test_Integration
@@ -707,7 +716,7 @@ stages:
707716
condition: |
708717
and(
709718
succeeded(),
710-
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'True')
719+
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true')
711720
)
712721
jobs:
713722
- job: Test_Integration
@@ -774,7 +783,7 @@ stages:
774783
condition: |
775784
and(
776785
succeeded(),
777-
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'True')
786+
eq(dependencies.Quality_Test_and_Unit_Test.outputs['Determine_DSC_Resource_Test_Requirements.determineDscResourceTests.ShouldRunDscResourceIntegrationTests'], 'true')
778787
)
779788
jobs:
780789
- job: Test_Integration

source/Classes/002.DatabasePermission.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class DatabasePermission : IComparable, System.IEquatable[Object]
260260
$object.GetType().FullName
261261
)
262262

263-
New-InvalidArgumentException -ArgumentName 'Object' -Message $errorMessage
263+
New-ArgumentException -ArgumentName 'Object' -Message $errorMessage
264264
}
265265

266266
return $returnValue

0 commit comments

Comments
 (0)