|
| 1 | +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')] |
| 2 | +param () |
| 3 | + |
| 4 | +BeforeDiscovery { |
| 5 | + try |
| 6 | + { |
| 7 | + if (-not (Get-Module -Name 'DscResource.Test')) |
| 8 | + { |
| 9 | + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) |
| 10 | + { |
| 11 | + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null |
| 12 | + } |
| 13 | + |
| 14 | + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' |
| 15 | + } |
| 16 | + } |
| 17 | + catch [System.IO.FileNotFoundException] |
| 18 | + { |
| 19 | + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.' |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +BeforeAll { |
| 24 | + $script:moduleName = 'SqlServerDsc' |
| 25 | + |
| 26 | + $env:SqlServerDscCI = $true |
| 27 | + |
| 28 | + Import-Module -Name $script:moduleName -ErrorAction 'Stop' |
| 29 | + |
| 30 | + $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName |
| 31 | + $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName |
| 32 | + $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName |
| 33 | +} |
| 34 | + |
| 35 | +AfterAll { |
| 36 | + $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') |
| 37 | + $PSDefaultParameterValues.Remove('Mock:ModuleName') |
| 38 | + $PSDefaultParameterValues.Remove('Should:ModuleName') |
| 39 | + |
| 40 | + Remove-Item -Path 'env:SqlServerDscCI' |
| 41 | +} |
| 42 | + |
| 43 | +Describe 'ConvertTo-TlsProtocolRegistryKeyName' -Tag 'Private' { |
| 44 | + Context 'When converting known friendly protocol names' { |
| 45 | + It 'Maps Tls12 to TLS 1.2' { |
| 46 | + InModuleScope -ScriptBlock { |
| 47 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Tls12' | Should -Be 'TLS 1.2' |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + It 'Maps Tls11 to TLS 1.1' { |
| 52 | + InModuleScope -ScriptBlock { |
| 53 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Tls11' | Should -Be 'TLS 1.1' |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + It 'Maps Tls to TLS 1.0' { |
| 58 | + InModuleScope -ScriptBlock { |
| 59 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Tls' | Should -Be 'TLS 1.0' |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + It 'Maps Ssl3 to SSL 3.0' { |
| 64 | + InModuleScope -ScriptBlock { |
| 65 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Ssl3' | Should -Be 'SSL 3.0' |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + It 'Maps Ssl2 to SSL 2.0' { |
| 70 | + InModuleScope -ScriptBlock { |
| 71 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Ssl2' | Should -Be 'SSL 2.0' |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + It 'Maps Tls13 to TLS 1.3' { |
| 76 | + InModuleScope -ScriptBlock { |
| 77 | + ConvertTo-TlsProtocolRegistryKeyName -Protocol 'Tls13' | Should -Be 'TLS 1.3' |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + Context 'When given an unknown protocol' { |
| 83 | + It 'Should throw a terminating error' { |
| 84 | + InModuleScope -ScriptBlock { |
| 85 | + { ConvertTo-TlsProtocolRegistryKeyName -Protocol 'NoSuchProto' } | Should -Throw -ErrorId 'InvalidProtocol,ConvertTo-TlsProtocolRegistryKeyName' |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments