def test_encrypt_missing_file_no_secret(self, mock_setup_vault_secrets): mock_setup_vault_secrets.return_value = [] cli = VaultCLI(args=['assible-vault', 'encrypt', '/dev/null/foo']) cli.parse() self.assertRaisesRegexp(errors.AssibleOptionsError, "A vault password is required to use Assible's Vault", cli.run)
def test_verbosity_arguments(cli_args, expected, tmp_path_factory, monkeypatch): # Add a password file so we don't get a prompt in the test test_dir = to_text(tmp_path_factory.mktemp('test-assible-vault')) pass_file = os.path.join(test_dir, 'pass.txt') with open(pass_file, 'w') as pass_fd: pass_fd.write('password') cli_args.extend(['--vault-id', pass_file]) # Mock out the functions so we don't actually execute anything for func_name in [f for f in dir(VaultCLI) if f.startswith("execute_")]: monkeypatch.setattr(VaultCLI, func_name, MagicMock()) cli = VaultCLI(args=cli_args) cli.run() assert context.CLIARGS['verbosity'] == expected
def test_encrypt_string_names(self, mock_vault_editor, mock_setup_vault_secrets): mock_setup_vault_secrets.return_value = [('default', TextVaultSecret('password'))] cli = VaultCLI(args=['assible-vault', 'encrypt_string', '--name', 'foo1', '--name', 'foo2', 'some string to encrypt']) cli.parse() cli.run()
def test_encrypt_string_stdin(self, mock_stdin_read, mock_vault_editor, mock_setup_vault_secrets): mock_setup_vault_secrets.return_value = [('default', TextVaultSecret('password'))] cli = VaultCLI(args=['assible-vault', 'encrypt_string', '--stdin-name', 'the_var_from_stdin', '-']) cli.parse() cli.run()
def test_encrypt(self, mock_vault_editor, mock_setup_vault_secrets): mock_setup_vault_secrets.return_value = [('default', TextVaultSecret('password'))] cli = VaultCLI(args=['assible-vault', 'encrypt', '/dev/null/foo']) cli.parse() cli.run()
def test_parse_view_file(self): cli = VaultCLI(args=['assible-vault', 'view', '/dev/null/foo']) cli.parse()
def test_parse_empty(self): cli = VaultCLI(['vaultcli']) self.assertRaises(SystemExit, cli.parse)