MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "TestWSMan tests" -Tags 'Feature','RequireAdminOnWindows' {4 5 BeforeAll {6 $originalDefaultParameterValues = $PSDefaultParameterValues.Clone()7 if ( !$IsWindows ) {8 $PSDefaultParameterValues["it:skip"] = $true9 }10 else {11 $testWsman = [Microsoft.WSMan.Management.TestWSManCommand]::new()12 }13 }14 15 AfterAll {16 $global:PSDefaultParameterValues = $originalDefaultParameterValues17 }18 19 It "TestWSmanCommand can be used as API for '<parameter>' with '<value>'" -TestCases @(20 @{ parameter = "computername" ; value = "foo" },21 @{ parameter = "computername" ; value = $null ; expected = "localhost" },22 @{ parameter = "computername" ; value = "." ; expected = "localhost" },23 @{ parameter = "authentication" ; value = "Basic" },24 @{ parameter = "authentication" ; value = "CredSSP" },25 @{ parameter = "authentication" ; value = "Digest" },26 @{ parameter = "authentication" ; value = "Negotiate" },27 @{ parameter = "authentication" ; value = "ClientCertificate" },28 @{ parameter = "authentication" ; value = "Default" },29 @{ parameter = "authentication" ; value = "Kerberos" },30 @{ parameter = "authentication" ; value = "None" },31 @{ parameter = "port" ; value = 5985 },32 @{ parameter = "port" ; value = 8888 },33 @{ parameter = "usessl" ; value = $true },34 @{ parameter = "usessl" ; value = $false },35 @{ parameter = "applicationname" ; value = "foo" }36 ) {37 param($parameter, $value, $expected)38 $testWsman.$parameter = $value39 if ($expected -eq $null) {40 $expected = $value41 }42 $testWsman.$parameter | Should -Be $expected43 }44 45 It "-Authentication for unsupported type should return error" {46 { Test-WSMan -Authentication foo -ErrorAction Stop } | Should -Throw -ErrorId "CannotConvertArgumentNoMessage,Microsoft.WSMan.Management.TestWSManCommand"47 }48 49 It "Test-WSMan works for <testName>" -TestCases @(50 @{ testName = "Null"; computername = $null },51 @{ testName = "localhost"; computername = "localhost" },52 @{ testName = "computername"; computername = $env:COMPUTERNAME }53 ) {54 param($computername)55 $response = Test-WSMan -ComputerName $computername56 $response | Should -Not -BeNullOrEmpty57 $response.PSObject.TypeNames[0] | Should -Be "System.Xml.XmlElement#http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd#IdentifyResponse"58 $response.wsmid | Should -Be "http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"59 $response.ProtocolVersion | Should -Be "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"60 $response.ProductVendor | Should -Be "Microsoft Corporation"61 $response.ProductVersion | Should -Be "OS: 0.0.0 SP: 0.0 Stack: 3.0"62 }63}64 