def test_git_clone_ssh_auth_method_missing_ssh_key(_): fake_user = test_utils.rand_name('fake_user') url = ('ssh://%[email protected]:29418/airship/armada' % fake_user) with pytest.raises(exceptions.GitSSHException): git.git_handler(url, ref='refs/changes/17/388517/5', auth_key='/home/user/.ssh/')
def test_git_clone_fake_proxy(): url = 'https://opendev.org/airship/armada' proxy_url = test_utils.rand_name('not.a.proxy.that.works.and.never.will', prefix='http://') + ":8080" with pytest.raises(exceptions.GitProxyException): git.git_handler(url, ref='master', proxy_server=proxy_url)
def test_encrypt_and_decrypt(): data = test_utils.rand_name("this is an example of un-encrypted " "data.", "pegleg").encode() passphrase = test_utils.rand_name("passphrase1", "pegleg").encode() salt = test_utils.rand_name("salt1", "pegleg").encode() enc1 = crypt.encrypt(data, passphrase, salt) dec1 = crypt.decrypt(enc1, passphrase, salt) assert data == dec1 enc2 = crypt.encrypt(dec1, passphrase, salt) dec2 = crypt.decrypt(enc2, passphrase, salt) assert data == dec2 passphrase2 = test_utils.rand_name("passphrase2", "pegleg").encode() salt2 = test_utils.rand_name("salt2", "pegleg").encode() enc3 = crypt.encrypt(dec2, passphrase2, salt2) dec3 = crypt.decrypt(enc3, passphrase2, salt2) assert data == dec3 assert data != enc3
def test_git_clone_ssh_auth_method_fails_auth(_): fake_user = test_utils.rand_name('fake_user') url = ('ssh://%[email protected]:29418/openstack/airship-armada' % fake_user) with pytest.raises(exceptions.GitAuthException): git._try_git_clone(url, ref='refs/changes/17/388517/5', auth_key='/home/user/.ssh/')
def test_git_checkout_dirty_repo_untracked_file_committed(mock_log): """Validate a dirty untracked file is committed.""" # Clone the openstack-helm repo and automatically checkout patch 73. ref = 'refs/changes/54/457754/73' repo_url = 'https://review.opendev.org/openstack/openstack-helm' git_dir = git.git_handler(repo_url, ref) _validate_git_clone(git_dir, ref) # Simulate a dirty repo by adding in a new untracked file. with open(os.path.join(git_dir, test_utils.rand_name('test_file')), 'w') as f: f.write('whatever') # Sanity check that the repo has an untracked file. repo = Repo(git_dir) assert len(repo.untracked_files) git.git_handler(git_dir, ref) # Validate that the untracked file is committed. assert not len(repo.untracked_files) assert not repo.is_dirty(untracked_files=True)