Skip to content

Commit

Permalink
Add negative tests for VaultLib
Browse files Browse the repository at this point in the history
  • Loading branch information
jctanner committed Feb 26, 2014
1 parent 96f1c3c commit f5359c3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/units/TestVault.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from binascii import hexlify
from nose.plugins.skip import SkipTest

from ansible import errors
from ansible.utils.vault import VaultLib
# AES IMPORTS
try:
Expand Down Expand Up @@ -73,3 +74,37 @@ def test_encyrpt_decrypt(self):
assert enc_data != "foobar", "encryption failed"
assert dec_data == "foobar", "decryption failed"

@unittest.skipIf(not HAS_AES, "aes not installed")
def test_encrypt_encrypted(self):
v = VaultLib('ansible')
v.cipher_name = 'AES'
data = "$ANSIBLE_VAULT;9.9;TEST\n%s" % hexlify("ansible")
error_hit = False
try:
enc_data = v.encrypt(data)
except errors.AnsibleError, e:
error_hit = True
assert error_hit, "No error was thrown when trying to encrypt data with a header"

def test_decrypt_decrypted(self):
v = VaultLib('ansible')
data = "ansible"
error_hit = False
try:
dec_data = v.decrypt(data)
except errors.AnsibleError, e:
error_hit = True
assert error_hit, "No error was thrown when trying to decrypt data without a header"

@unittest.skipIf(not HAS_AES, "aes not installed")
def test_cipher_not_set(self):
v = VaultLib('ansible')
data = "ansible"
error_hit = False
try:
enc_data = v.encrypt(data)
except errors.AnsibleError, e:
error_hit = True
assert error_hit, "No error was thrown when trying to encrypt data without the cipher set"


0 comments on commit f5359c3

Please sign in to comment.