@ -25,7 +25,7 @@ class TestConnectionWinRM(object):
OPTIONS_DATA = (
# default options
(
{ ' _extras ' : { } } ,
{ } ,
{ } ,
{
' _kerb_managed ' : False ,
@ -44,7 +44,7 @@ class TestConnectionWinRM(object):
) ,
# http through port
(
{ ' _extras' : { } , ' ansible_port' : 5985 } ,
{ ' ansible_port' : 5985 } ,
{ } ,
{
' _winrm_kwargs ' : { ' username ' : None , ' password ' : None } ,
@ -56,7 +56,7 @@ class TestConnectionWinRM(object):
) ,
# kerberos user with kerb present
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' } ,
{ ' ansible_user' : ' user@domain.com ' } ,
{ } ,
{
' _kerb_managed ' : False ,
@ -71,7 +71,7 @@ class TestConnectionWinRM(object):
) ,
# kerberos user without kerb present
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' } ,
{ ' ansible_user' : ' user@domain.com ' } ,
{ } ,
{
' _kerb_managed ' : False ,
@ -86,7 +86,7 @@ class TestConnectionWinRM(object):
) ,
# kerberos user with managed ticket (implicit)
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' } ,
{ ' ansible_user' : ' user@domain.com ' } ,
{ ' remote_password ' : ' pass ' } ,
{
' _kerb_managed ' : True ,
@ -101,7 +101,7 @@ class TestConnectionWinRM(object):
) ,
# kerb with managed ticket (explicit)
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' ,
{ ' ansible_user' : ' user@domain.com ' ,
' ansible_winrm_kinit_mode ' : ' managed ' } ,
{ ' password ' : ' pass ' } ,
{
@ -111,7 +111,7 @@ class TestConnectionWinRM(object):
) ,
# kerb with unmanaged ticket (explicit))
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' ,
{ ' ansible_user' : ' user@domain.com ' ,
' ansible_winrm_kinit_mode ' : ' manual ' } ,
{ ' password ' : ' pass ' } ,
{
@ -121,7 +121,7 @@ class TestConnectionWinRM(object):
) ,
# transport override (single)
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' ,
{ ' ansible_user' : ' user@domain.com ' ,
' ansible_winrm_transport ' : ' ntlm ' } ,
{ } ,
{
@ -134,7 +134,7 @@ class TestConnectionWinRM(object):
) ,
# transport override (list)
(
{ ' _extras' : { } , ' ansible_user' : ' user@domain.com ' ,
{ ' ansible_user' : ' user@domain.com ' ,
' ansible_winrm_transport ' : [ ' ntlm ' , ' certificate ' ] } ,
{ } ,
{
@ -147,8 +147,10 @@ class TestConnectionWinRM(object):
) ,
# winrm extras
(
{ ' _extras ' : { ' ansible_winrm_server_cert_validation ' : ' ignore ' ,
' ansible_winrm_service ' : ' WSMAN ' } } ,
{
' ansible_winrm_server_cert_validation ' : ' ignore ' ,
' ansible_winrm_service ' : ' WSMAN ' ,
} ,
{ } ,
{
' _winrm_kwargs ' : { ' username ' : None , ' password ' : None ,
@ -159,7 +161,7 @@ class TestConnectionWinRM(object):
) ,
# direct override
(
{ ' _extras' : { } , ' ansible_winrm_connection_timeout' : 5 } ,
{ ' ansible_winrm_connection_timeout' : 5 } ,
{ ' connection_timeout ' : 10 } ,
{
' _winrm_connection_timeout ' : 10 ,
@ -168,7 +170,7 @@ class TestConnectionWinRM(object):
) ,
# password as ansible_password
(
{ ' _extras' : { } , ' ansible_password' : ' pass ' } ,
{ ' ansible_password' : ' pass ' } ,
{ } ,
{
' _winrm_pass ' : ' pass ' ,
@ -178,7 +180,7 @@ class TestConnectionWinRM(object):
) ,
# password as ansible_winrm_pass
(
{ ' _extras' : { } , ' ansible_winrm_pass' : ' pass ' } ,
{ ' ansible_winrm_pass' : ' pass ' } ,
{ } ,
{
' _winrm_pass ' : ' pass ' ,
@ -189,7 +191,7 @@ class TestConnectionWinRM(object):
# password as ansible_winrm_password
(
{ ' _extras' : { } , ' ansible_winrm_password' : ' pass ' } ,
{ ' ansible_winrm_password' : ' pass ' } ,
{ } ,
{
' _winrm_pass ' : ' pass ' ,
@ -213,23 +215,31 @@ class TestConnectionWinRM(object):
for attr , expected in expected . items ( ) :
actual = getattr ( conn , attr )
assert actual == expected , \
" winrm attr ' %s ' , actual ' %s ' != expected ' %s ' " \
% ( attr , actual , expected )
if attr == ' _winrm_kwargs ' :
for k , v in expected . items ( ) :
actual_v = actual [ k ]
assert actual_v == v , \
f " winrm Protocol kwarg ' { k } ' , actual ' { actual_v } ' != expected ' { v } ' "
else :
assert actual == expected , \
" winrm attr ' %s ' , actual ' %s ' != expected ' %s ' " \
% ( attr , actual , expected )
class TestWinRMKerbAuth ( object ) :
@pytest.mark.parametrize ( ' options, expected ' , [
[ { " _extras " : { } } ,
[ { } ,
( [ " kinit " , " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kinit_cmd ' : ' kinit2 ' } ,
[ { ' ansible_winrm_kinit_cmd ' : ' kinit2 ' } ,
( [ " kinit2 " , " user@domain " ] , ) ] ,
[ { " _extras " : { ' ansible_winrm_kerberos_delegation ' : True } } ,
[ { ' ansible_winrm_kerberos_delegation ' : True } ,
( [ " kinit " , " -f " , " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kinit_args ' : ' -f -p ' } ,
[ { ' ansible_winrm_kinit_args ' : ' -f -p ' } ,
( [ " kinit " , " -f " , " -p " , " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kerberos_delegation ' : True , ' ansible_winrm_kinit_args ' : ' -p ' } ,
[ { ' ansible_winrm_kerberos_delegation ' : True , ' ansible_winrm_kinit_args ' : ' -p ' } ,
( [ " kinit " , " -p " , " user@domain " ] , ) ]
] )
def test_kinit_success_subprocess ( self , monkeypatch , options , expected ) :
@ -258,15 +268,15 @@ class TestWinRMKerbAuth(object):
assert actual_env [ ' PATH ' ] == os . environ [ ' PATH ' ]
@pytest.mark.parametrize ( ' options, expected ' , [
[ { " _extras " : { } } ,
[ { } ,
( " kinit " , [ " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kinit_cmd ' : ' kinit2 ' } ,
[ { ' ansible_winrm_kinit_cmd ' : ' kinit2 ' } ,
( " kinit2 " , [ " user@domain " ] , ) ] ,
[ { " _extras " : { ' ansible_winrm_kerberos_delegation ' : True } } ,
[ { ' ansible_winrm_kerberos_delegation ' : True } ,
( " kinit " , [ " -f " , " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kinit_args ' : ' -f -p ' } ,
[ { ' ansible_winrm_kinit_args ' : ' -f -p ' } ,
( " kinit " , [ " -f " , " -p " , " user@domain " ] , ) ] ,
[ { " _extras " : { } , ' ansible_winrm_kerberos_delegation ' : True , ' ansible_winrm_kinit_args ' : ' -p ' } ,
[ { ' ansible_winrm_kerberos_delegation ' : True , ' ansible_winrm_kinit_args ' : ' -p ' } ,
( " kinit " , [ " -p " , " user@domain " ] , ) ]
] )
def test_kinit_success_pexpect ( self , monkeypatch , options , expected ) :
@ -308,7 +318,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
options = { " _extras " : { } , " ansible_winrm_kinit_cmd " : " /fake/kinit " }
options = { " ansible_winrm_kinit_cmd " : " /fake/kinit " }
conn . set_options ( var_options = options )
conn . _build_winrm_kwargs ( )
@ -331,7 +341,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
options = { " _extras " : { } , " ansible_winrm_kinit_cmd " : " /fake/kinit " }
options = { " ansible_winrm_kinit_cmd " : " /fake/kinit " }
conn . set_options ( var_options = options )
conn . _build_winrm_kwargs ( )
@ -356,7 +366,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " _extras " : { } } )
conn . set_options ( var_options = { } )
conn . _build_winrm_kwargs ( )
with pytest . raises ( AnsibleConnectionFailure ) as err :
@ -381,7 +391,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " _extras " : { } } )
conn . set_options ( var_options = { } )
conn . _build_winrm_kwargs ( )
with pytest . raises ( AnsibleConnectionFailure ) as err :
@ -404,7 +414,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " _extras " : { } } )
conn . set_options ( var_options = { } )
conn . _build_winrm_kwargs ( )
with pytest . raises ( AnsibleConnectionFailure ) as err :
@ -429,7 +439,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " _extras " : { } } )
conn . set_options ( var_options = { } )
conn . _build_winrm_kwargs ( )
with pytest . raises ( AnsibleConnectionFailure ) as err :
@ -483,7 +493,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , " _extras " : { } } )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , } )
mock_proto = MagicMock ( )
mock_proto . open_shell . side_effect = ValueError ( " Custom exc Code 401 " )
@ -499,7 +509,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , " _extras " : { } } )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , } )
mock_proto = MagicMock ( )
mock_proto . open_shell . side_effect = ValueError ( " Custom exc " )
@ -515,7 +525,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , " _extras " : { } } )
conn . set_options ( var_options = { " ansible_winrm_transport " : " basic " , } )
mock_proto = MagicMock ( )
mock_proto . open_shell . side_effect = ValueError ( " Custom exc Operation timed out " )
@ -531,7 +541,7 @@ class TestWinRMKerbAuth(object):
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' winrm ' , pc , new_stdin )
conn . set_options ( var_options = { " _extras " : { } } )
conn . set_options ( var_options = { } )
conn . _build_winrm_kwargs ( )
conn . _winrm_transport = [ ]