#Requires -Version 5.1 BeforeAll { . (Join-Path $PSScriptRoot '..\collector\Test-SmInput.ps1') } Describe 'Test-SmUsername' { It 'accepts a simple username' { (Test-SmUsername 'jamie').Ok | Should -BeTrue } It 'rejects empty' { (Test-SmUsername '').Ok | Should -BeFalse } It 'rejects reserved name' { (Test-SmUsername 'Administrator').Ok | Should -BeFalse } It 'rejects illegal chars' { (Test-SmUsername 'a\b').Ok | Should -BeFalse } It 'rejects > 20 chars' { (Test-SmUsername ('x'*21)).Ok| Should -BeFalse } } Describe 'Test-SmPassword' { It 'accepts matching 8+ char password' { (Test-SmPassword 'Sup3rPass!' 'Sup3rPass!').Ok | Should -BeTrue } It 'rejects mismatch' { (Test-SmPassword 'a' 'b').Ok | Should -BeFalse } It 'rejects < 8 chars' { (Test-SmPassword 'short' 'short').Ok | Should -BeFalse } } Describe 'Test-SmPin' { It 'accepts 6-digit matching pin' { (Test-SmPin '246810' '246810').Ok | Should -BeTrue } It 'rejects < 6 digits' { (Test-SmPin '123' '123').Ok | Should -BeFalse } It 'rejects non-numeric' { (Test-SmPin 'abcdef' 'abcdef').Ok | Should -BeFalse } It 'rejects mismatch' { (Test-SmPin '246810' '999999').Ok | Should -BeFalse } } Describe 'Test-SmComputerName' { It 'accepts a valid name' { (Test-SmComputerName 'SILVER-01').Ok | Should -BeTrue } It 'rejects empty' { (Test-SmComputerName '').Ok | Should -BeFalse } It 'rejects > 15 chars' { (Test-SmComputerName ('A'*16)).Ok | Should -BeFalse } It 'rejects illegal chars' { (Test-SmComputerName 'bad name').Ok | Should -BeFalse } } Describe 'New-SmAnswerFile' { BeforeAll { . (Join-Path $PSScriptRoot '..\collector\New-SmAnswerFile.ps1') $cfg = @{ DisplayName = 'Jamie'; Username = 'jamie'; Password = 'Sup3rPass!' ComputerName = 'SILVER-01' InputLocale = '0809:00000809'; SystemLocale = 'en-GB'; UiLanguage = 'en-US'; UserLocale = 'en-GB' Flavour = 'developer'; BitLockerEnable = $true; BitLockerPin = '246810' } $script:xml = New-SmAnswerFile @cfg } It 'is valid XML' { { [xml]$script:xml } | Should -Not -Throw } It 'creates the real account in Administrators' { $script:xml | Should -Match 'jamie' $script:xml | Should -Match 'Administrators' } It 'does NOT contain sm-bootstrap' { $script:xml | Should -Not -Match 'sm-bootstrap' } It 'sets AutoLogon once as the user' { $script:xml | Should -Match '1' $script:xml | Should -Match 'jamie' } It 'sets the computer name' { $script:xml | Should -Match 'SILVER-01' } It 'keeps WillWipeDisk for disk 0' { $script:xml | Should -Match 'true' } It 'embeds a base64 preconfig write in specialize' { $script:xml | Should -Match 'preconfig\.json' $script:xml | Should -Match 'FromBase64String' } It 'embedded preconfig round-trips with the flavour and pin' { $m = [regex]::Match($script:xml, "FromBase64String\('([^']+)'\)") $m.Success | Should -BeTrue $json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($m.Groups[1].Value)) | ConvertFrom-Json $json.flavour | Should -Be 'developer' $json.bitlocker.pin | Should -Be '246810' } It 'launches the toolbox in FirstLogonCommands' { $script:xml | Should -Match 'SilverOS\.Welcome\.App\.exe' } }