def test_dufl_add_does_not_add_file_whose_content_matches_security_rule(cli_run, temp_folder): dufl_root = os.path.join(temp_folder, '.dufl') # Initialize repo, and create a settings.yaml with custom suspicous_content expressions cli_run('-r', dufl_root, 'init') create_files_in_folder(dufl_root, { 'settings.yaml': yaml.dump({ 'suspicious_content': { 'PRIVATE KEY': 'refused on suspicious content' }, 'suspicious_name': {} }) }) # Create the suspicious file and try to add it file_names = create_files_in_folder(temp_folder, { 'path/to/file.txt': "hello\n here is a PRIVATE KEY ;)\n!" }) r = cli_run('-r', dufl_root, 'add', file_names['path/to/file.txt']) assert r.exit_code != 0 assert 'refused on suspicious content' in r.output assert not os.path.isfile(os.path.join( dufl_root, 'root', re.sub('^/', '', file_names['path/to/file.txt'] )))
def test_dufl_push_pushes_to_git(cli_run, temp_folder, remote_git_path): dufl_root = os.path.join(temp_folder, '.dufl') cli_run('-r', dufl_root, 'init', remote_git_path) # Create and commit file file_names = create_files_in_folder(temp_folder, { 'the/path/file.txt': 'hello' }) cli_run('-r', dufl_root, 'add', file_names['the/path/file.txt']) # Push cli_run('-r', dufl_root, 'push') # Now pull that remote repo somewhere else, and check the file is there. repo_clone = os.path.join(temp_folder, 'clone') os.makedirs(repo_clone) git = utils.Git('/usr/bin/git', repo_clone) git.run('init') git.run('remote', 'add', 'origin', remote_git_path) git.run('pull', 'origin', 'master') assert os.path.isfile(os.path.join( repo_clone, 'root', re.sub('^/+', '', file_names['the/path/file.txt']) ))
def test_dufl_add_adds_and_commits_file_to_git(cli_run, temp_folder): dufl_root = os.path.join(temp_folder, '.dufl') cli_run('-r', dufl_root, 'init') file_names = create_files_in_folder(temp_folder, { 'the/path/file.txt': 'hello' }) cli_run('-r', dufl_root, 'add', file_names['the/path/file.txt']) git = utils.Git('/usr/bin/git', dufl_root) files = git.get_output('ls-files') assert 'the/path/file.txt' in files
def test_dufl_add_copies_file_in_home_to_dufl_home_subfolder(cli_run, temp_folder, user_home): dufl_root = os.path.join(temp_folder, '.dufl') cli_run('-r', dufl_root, 'init') file_names = create_files_in_folder(user_home, { 'the/path/file.txt': 'hello' }) cli_run('-r', dufl_root, 'add', file_names['the/path/file.txt']) assert os.path.isfile(os.path.join( dufl_root, 'home', 'the/path/file.txt' ))
def test_dufl_add_uses_provided_commit_message(cli_run, temp_folder): dufl_root = os.path.join(temp_folder, '.dufl') cli_run('-r', dufl_root, 'init') file_names = create_files_in_folder(temp_folder, { 'the/path/file.txt': 'hello' }) cli_run('-r', dufl_root, 'add', file_names['the/path/file.txt'], '-m', 'Good job!') git = utils.Git('/usr/bin/git', dufl_root) logs = git.get_output('log') assert 'Good job!' in logs
def test_dufl_add_copies_file_not_in_home_to_dufl_root_subfolder(cli_run, temp_folder): dufl_root = os.path.join(temp_folder, '.dufl') cli_run('-r', dufl_root, 'init') file_names = create_files_in_folder(temp_folder, { 'the/path/file.txt': 'hello' }) cli_run('-r', dufl_root, 'add', file_names['the/path/file.txt']) assert os.path.isfile(os.path.join( dufl_root, 'root', re.sub('^/', '', file_names['the/path/file.txt']) ))