Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One server for unit tests #203

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python/test_perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ def run_p4d(p4port, from_zip=None):
archive.extractall(tmpdir)

p4ssldir = os.path.join(tmpdir, 'ssl')
p4trust = os.path.join(tmpdir, 'trust.txt')
shutil.copytree(os.path.join(os.path.dirname(__file__), 'fixture', 'insecure-ssl'), p4ssldir)
# Like a beautifully crafted work of art, p4d fails to start if permissions on the secrets are too open.
# https://www.perforce.com/manuals/v18.1/cmdref/Content/CmdRef/P4SSLDIR.html
os.chmod(p4ssldir, 0o700)
os.chmod(os.path.join(p4ssldir, 'privatekey.txt'), 0o600)
os.chmod(os.path.join(p4ssldir, 'certificate.txt'), 0o600)
os.environ['P4SSLDIR'] = p4ssldir
os.environ['P4TRUST'] = p4trust

yield subprocess.Popen(['p4d', '-r', tmpdir, '-p', p4port])

@pytest.fixture
@pytest.fixture(scope='package')
def server():
"""Start a p4 server in the background and return the address"""
port = find_free_port()
Expand Down Expand Up @@ -414,18 +412,24 @@ def test_stream_switching_migration(server, tmpdir):

def test_fingerprint_good(server, tmpdir):
"""Test supplying the correct fingerprint"""
os.environ['P4TRUST'] = os.path.join(tmpdir, 'trust.txt')

repo = P4Repo(root=tmpdir, fingerprint=__LEGIT_P4_FINGERPRINT__)
synced = repo.sync()
assert len(synced) > 0, "Didn't sync any files"

def test_fingerprint_bad(server, tmpdir):
"""Test supplying an incorrect fingerprint"""
os.environ['P4TRUST'] = os.path.join(tmpdir, 'trust.txt')

repo = P4Repo(root=tmpdir, fingerprint='FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF')
with pytest.raises(Exception, match=r"The authenticity of '.+' can't be established"):
repo.sync()

def test_fingerprint_changed(server, tmpdir):
"""Test updating a fingerprint"""
os.environ['P4TRUST'] = os.path.join(tmpdir, 'trust.txt')

repo = P4Repo(root=tmpdir, fingerprint='FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF')
with pytest.raises(Exception, match=r"The authenticity of '.*' can't be established"):
repo.sync()
Expand Down