@ -21,6 +21,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
__metaclass__ = type
#!/usr/bin/env python
#!/usr/bin/env python
import sys
import getpass
import getpass
import os
import os
import shutil
import shutil
@ -32,6 +33,7 @@ from nose.plugins.skip import SkipTest
from ansible . compat . tests import unittest
from ansible . compat . tests import unittest
from ansible . compat . tests . mock import patch
from ansible . compat . tests . mock import patch
from ansible . utils . unicode import to_bytes , to_unicode
from ansible import errors
from ansible import errors
from ansible . parsing . vault import VaultLib
from ansible . parsing . vault import VaultLib
@ -107,12 +109,16 @@ class TestVaultEditor(unittest.TestCase):
self . assertTrue ( os . path . exists ( tmp_file . name ) )
self . assertTrue ( os . path . exists ( tmp_file . name ) )
def test_decrypt_1_0 ( self ) :
def test_decrypt_1_0 ( self ) :
if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2 :
"""
Skip testing decrypting 1.0 files if we don ' t have access to AES, KDF or
Counter , or we are running on python3 since VaultAES hasn ' t been backported.
"""
if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2 or sys . version > ' 3 ' :
raise SkipTest
raise SkipTest
v10_file = tempfile . NamedTemporaryFile ( delete = False )
v10_file = tempfile . NamedTemporaryFile ( delete = False )
with v10_file as f :
with v10_file as f :
f . write ( v10_data)
f . write ( to_bytes( v10_data) )
ve = VaultEditor ( None , " ansible " , v10_file . name )
ve = VaultEditor ( None , " ansible " , v10_file . name )
@ -125,8 +131,8 @@ class TestVaultEditor(unittest.TestCase):
# verify decrypted content
# verify decrypted content
f = open ( v10_file . name , " rb " )
f = open ( v10_file . name , " rb " )
fdata = f. read ( )
fdata = to_unicode( f. read ( ) )
f . clo s e( )
f . clo es ( )
os . unlink ( v10_file . name )
os . unlink ( v10_file . name )
@ -140,7 +146,7 @@ class TestVaultEditor(unittest.TestCase):
v11_file = tempfile . NamedTemporaryFile ( delete = False )
v11_file = tempfile . NamedTemporaryFile ( delete = False )
with v11_file as f :
with v11_file as f :
f . write ( v11_data)
f . write ( to_bytes( v11_data) )
ve = VaultEditor ( None , " ansible " , v11_file . name )
ve = VaultEditor ( None , " ansible " , v11_file . name )
@ -153,7 +159,7 @@ class TestVaultEditor(unittest.TestCase):
# verify decrypted content
# verify decrypted content
f = open ( v11_file . name , " rb " )
f = open ( v11_file . name , " rb " )
fdata = f. read ( )
fdata = to_unicode( f. read ( ) )
f . close ( )
f . close ( )
os . unlink ( v11_file . name )
os . unlink ( v11_file . name )
@ -163,12 +169,16 @@ class TestVaultEditor(unittest.TestCase):
def test_rekey_migration ( self ) :
def test_rekey_migration ( self ) :
if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2 :
"""
Skip testing rekeying files if we don ' t have access to AES, KDF or
Counter , or we are running on python3 since VaultAES hasn ' t been backported.
"""
if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2 or sys . version > ' 3 ' :
raise SkipTest
raise SkipTest
v10_file = tempfile . NamedTemporaryFile ( delete = False )
v10_file = tempfile . NamedTemporaryFile ( delete = False )
with v10_file as f :
with v10_file as f :
f . write ( v10_data)
f . write ( to_bytes( v10_data) )
ve = VaultEditor ( None , " ansible " , v10_file . name )
ve = VaultEditor ( None , " ansible " , v10_file . name )