def test_read_file_not_executable(self, mock_popen): self._mock_popen(mock_popen) secret = vault.ScriptVaultSecret() with patch.object(secret, 'loader') as mock_loader: mock_loader.is_executable = MagicMock(return_value=False) self.assertRaisesRegexp( vault.AnsibleVaultError, 'The vault password script .* was not executable', secret.load)
def test_read_file_empty(self, mock_popen): self._mock_popen(mock_popen, stdout=b'') secret = vault.ScriptVaultSecret() with patch.object(secret, 'loader') as mock_loader: mock_loader.is_executable = MagicMock(return_value=True) self.assertRaisesRegexp( vault.AnsibleVaultPasswordError, 'Invalid vault password was provided from script', secret.load)
def test_read_file_os_error(self, mock_popen): self._mock_popen(mock_popen) mock_popen.side_effect = OSError('That is not an executable') secret = vault.ScriptVaultSecret() with patch.object(secret, 'loader') as mock_loader: mock_loader.is_executable = MagicMock(return_value=True) self.assertRaisesRegexp(errors.AnsibleError, 'Problem running vault password script.*', secret.load)
def test_read_file_non_zero_return_code(self, mock_popen): stderr = b'That did not work for a random reason' rc = 37 self._mock_popen(mock_popen, return_code=rc, stderr=stderr) secret = vault.ScriptVaultSecret(filename='/dev/null/some_vault_secret') with patch.object(secret, 'loader') as mock_loader: mock_loader.is_executable = MagicMock(return_value=True) self.assertRaisesRegexp(errors.AnsibleError, 'Vault password script.*returned non-zero \(%s\): %s' % (rc, stderr), secret.load)
def test_read_file(self, mock_popen): self._mock_popen(mock_popen, stdout=b'some_password') secret = vault.ScriptVaultSecret() with patch.object(secret, 'loader') as mock_loader: mock_loader.is_executable = MagicMock(return_value=True) secret.load()
def test(self): secret = vault.ScriptVaultSecret() self.assertIsNone(secret._bytes) self.assertIsNone(secret._text)