Skip to content

tests, warehouse: disable egg uploads #14118

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

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
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
33 changes: 0 additions & 33 deletions tests/unit/cli/test_projects.py

This file was deleted.

89 changes: 0 additions & 89 deletions tests/unit/email/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5825,92 +5825,3 @@ def test_trusted_publisher_emails(
},
)
]


class TestPEP715Emails:
@pytest.mark.parametrize(
"fn, template_name",
[
(email.send_egg_uploads_deprecated_email, "egg-uploads-deprecated"),
(
email.send_egg_uploads_deprecated_initial_email,
"egg-uploads-deprecated-initial-notice",
),
],
)
def test_pep_715_emails(
self, pyramid_request, pyramid_config, monkeypatch, fn, template_name
):
stub_user = pretend.stub(
id="id",
username="username",
name="",
email="[email protected]",
primary_email=pretend.stub(email="[email protected]", verified=True),
)
subject_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/subject.txt"
)
subject_renderer.string_response = "Email Subject"
body_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/body.txt"
)
body_renderer.string_response = "Email Body"
html_renderer = pyramid_config.testing_add_renderer(
f"email/{ template_name }/body.html"
)
html_renderer.string_response = "Email HTML Body"

send_email = pretend.stub(
delay=pretend.call_recorder(lambda *args, **kwargs: None)
)
pyramid_request.task = pretend.call_recorder(lambda *args, **kwargs: send_email)
monkeypatch.setattr(email, "send_email", send_email)

pyramid_request.db = pretend.stub(
query=lambda a: pretend.stub(
filter=lambda *a: pretend.stub(
one=lambda: pretend.stub(user_id=stub_user.id)
)
),
)
pyramid_request.user = stub_user
pyramid_request.registry.settings = {"mail.sender": "[email protected]"}

project_name = "test_project"
result = fn(
pyramid_request,
stub_user,
project_name=project_name,
)

assert result == {
"project_name": project_name,
}
subject_renderer.assert_()
body_renderer.assert_(project_name=project_name)
html_renderer.assert_(project_name=project_name)
assert pyramid_request.task.calls == [pretend.call(send_email)]
assert send_email.delay.calls == [
pretend.call(
f"{stub_user.username} <{stub_user.email}>",
{
"subject": "Email Subject",
"body_text": "Email Body",
"body_html": (
"<html>\n<head></head>\n"
"<body><p>Email HTML Body</p></body>\n</html>\n"
),
},
{
"tag": "account:email:sent",
"user_id": stub_user.id,
"additional": {
"from_": "[email protected]",
"to": stub_user.email,
"subject": "Email Subject",
"redact_ip": False,
},
},
)
]
155 changes: 4 additions & 151 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
from wtforms.form import Form
from wtforms.validators import ValidationError

from tests.common.db.organizations import (
OrganizationFactory,
OrganizationProjectFactory,
OrganizationRoleFactory,
TeamFactory,
TeamProjectRoleFactory,
TeamRoleFactory,
)
from warehouse.admin.flags import AdminFlag, AdminFlagValue
from warehouse.classifiers.models import Classifier
from warehouse.errors import BasicAuthTwoFactorEnabled
Expand Down Expand Up @@ -85,13 +77,6 @@ def _get_whl_testdata(name="fake_package", version="1.0"):
return temp_f.getvalue()


def _get_egg_testdata():
temp_f = io.BytesIO()
with zipfile.ZipFile(file=temp_f, mode="w") as zfp:
zfp.writestr("fake_package/PKG-INFO", "Fake metadata")
return temp_f.getvalue()


def _storage_hash(data):
return hashlib.blake2b(data, digest_size=256 // 8).hexdigest()

Expand All @@ -107,12 +92,6 @@ def _storage_hash(data):
_TAR_BZ2_PKG_STORAGE_HASH = _storage_hash(_TAR_BZ2_PKG_TESTDATA)


_EGG_PKG_TESTDATA = _get_egg_testdata()
_EGG_PKG_MD5 = hashlib.md5(_EGG_PKG_TESTDATA).hexdigest()
_EGG_PKG_SHA256 = hashlib.sha256(_EGG_PKG_TESTDATA).hexdigest()
_EGG_PKG_STORAGE_HASH = _storage_hash(_EGG_PKG_TESTDATA)


class TestExcWithMessage:
def test_exc_with_message(self):
exc = legacy._exc_with_message(HTTPBadRequest, "My Test Message.")
Expand Down Expand Up @@ -510,7 +489,6 @@ def test_defaults_to_true(self):
("filename", "filetype"),
[
("test.zip", "sdist"),
("test.egg", "bdist_egg"),
("test.whl", "bdist_wheel"),
],
)
Expand Down Expand Up @@ -610,23 +588,6 @@ def test_zipfile_exceeds_compression_threshold(self, tmpdir):

assert not legacy._is_valid_dist_file(f, "")

def test_egg_no_pkg_info(self, tmpdir):
f = str(tmpdir.join("test.egg"))

with zipfile.ZipFile(f, "w") as zfp:
zfp.writestr("something.txt", b"Just a placeholder file")

assert not legacy._is_valid_dist_file(f, "bdist_egg")

def test_egg_has_pkg_info(self, tmpdir):
f = str(tmpdir.join("test.egg"))

with zipfile.ZipFile(f, "w") as zfp:
zfp.writestr("something.txt", b"Just a placeholder file")
zfp.writestr("PKG-INFO", b"this is the package info")

assert legacy._is_valid_dist_file(f, "bdist_egg")

def test_wheel_no_wheel_file(self, tmpdir):
f = str(tmpdir.join("test.whl"))

Expand Down Expand Up @@ -1594,9 +1555,9 @@ def test_upload_fails_with_legacy_ext(self, pyramid_config, db_request):

assert resp.status_code == 400
assert resp.status == (
"400 Invalid file extension: Use .egg, .tar.gz, .whl or .zip "
"400 Invalid file extension: Use .tar.gz, .whl or .zip "
"extension. See https://www.python.org/dev/peps/pep-0527 "
"for more information."
"and https://peps.python.org/pep-0715/ for more information"
)

def test_upload_fails_for_second_sdist(self, pyramid_config, db_request):
Expand Down Expand Up @@ -2314,15 +2275,12 @@ def test_upload_fails_with_diff_filename_same_blake2(
# completely different
("nope-{version}.tar.gz", "something_else"),
("nope-{version}-py3-none-any.whl", "something_else"),
("nope-{version}-py3-none-any.egg", "something_else"),
# starts with same prefix
("nope-{version}.tar.gz", "no"),
("nope-{version}-py3-none-any.whl", "no"),
("nope-{version}-py3-none-any.egg", "no"),
# starts with same prefix with hyphen
("no-way-{version}.tar.gz", "no"),
("no_way-{version}-py3-none-any.whl", "no"),
("no_way-{version}-py3-none-any.egg", "no"),
# multiple delimiters
("foo__bar-{version}-py3-none-any.whl", "foo-.bar"),
],
Expand Down Expand Up @@ -2407,9 +2365,9 @@ def test_upload_fails_with_invalid_extension(self, pyramid_config, db_request):

assert resp.status_code == 400
assert resp.status == (
"400 Invalid file extension: Use .egg, .tar.gz, .whl or .zip "
"400 Invalid file extension: Use .tar.gz, .whl or .zip "
"extension. See https://www.python.org/dev/peps/pep-0527 "
"for more information."
"and https://peps.python.org/pep-0715/ for more information"
)

@pytest.mark.parametrize("character", ["/", "\\"])
Expand Down Expand Up @@ -3921,111 +3879,6 @@ def test_fails_without_user(self, pyramid_config, pyramid_request):
"See /the/help/url/ for more information."
)

def test_egg_upload_sends_pep_715_notice(
self, pyramid_config, db_request, metrics, monkeypatch
):
user = UserFactory.create()
EmailFactory.create(user=user)
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project)

pyramid_config.testing_securitypolicy(identity=user)
db_request.user = user
db_request.user_agent = "warehouse-tests/6.6.6"
db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": project.name,
"version": "1.0.0",
"summary": "This is my summary!",
"filetype": "bdist_egg",
"pyversion": "2.7",
"md5_digest": _EGG_PKG_MD5,
"content": pretend.stub(
filename="{}-{}.egg".format(project.name, "1.0.0"),
file=io.BytesIO(_EGG_PKG_TESTDATA),
type="application/zip",
),
}
)

send_email = pretend.call_recorder(lambda *a, **kw: None)
monkeypatch.setattr(legacy, "send_egg_uploads_deprecated_email", send_email)

storage_service = pretend.stub(store=lambda path, filepath, meta: None)
db_request.find_service = lambda svc, name=None, context=None: {
IFileStorage: storage_service,
IMetricsService: metrics,
}.get(svc)

resp = legacy.file_upload(db_request)

assert resp.status_code == 200
assert send_email.calls == [
pretend.call(db_request, user, project_name=project.name)
]

def test_egg_upload_sends_pep_715_notice_org_roles(
self, pyramid_config, db_request, metrics, monkeypatch
):
user = UserFactory.create()
EmailFactory.create(user=user)
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project)

org = OrganizationFactory()
OrganizationProjectFactory(organization=org, project=project)
org_owner = UserFactory.create()
OrganizationRoleFactory.create(user=org_owner, organization=org)

org_member = UserFactory.create()
OrganizationRoleFactory.create(
user=org_member, organization=org, role_name="Member"
)
team = TeamFactory.create(organization=org)
TeamRoleFactory.create(team=team, user=org_member)
# Duplicate the role directly on the project to ensure only one email
RoleFactory.create(user=org_member, project=project, role_name="Maintainer")
TeamProjectRoleFactory.create(project=project, team=team)

pyramid_config.testing_securitypolicy(identity=user)
db_request.user = user
db_request.user_agent = "warehouse-tests/6.6.6"
db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": project.name,
"version": "1.0.0",
"summary": "This is my summary!",
"filetype": "bdist_egg",
"pyversion": "2.7",
"md5_digest": _EGG_PKG_MD5,
"content": pretend.stub(
filename="{}-{}.egg".format(project.name, "1.0.0"),
file=io.BytesIO(_EGG_PKG_TESTDATA),
type="application/zip",
),
}
)

send_email = pretend.call_recorder(lambda *a, **kw: None)
monkeypatch.setattr(legacy, "send_egg_uploads_deprecated_email", send_email)

storage_service = pretend.stub(store=lambda path, filepath, meta: None)
db_request.find_service = lambda svc, name=None, context=None: {
IFileStorage: storage_service,
IMetricsService: metrics,
}.get(svc)

resp = legacy.file_upload(db_request)

assert resp.status_code == 200
assert set(send_email.calls) == {
pretend.call(db_request, user, project_name=project.name),
pretend.call(db_request, org_owner, project_name=project.name),
pretend.call(db_request, org_member, project_name=project.name),
}


def test_submit(pyramid_request):
resp = legacy.submit(pyramid_request)
Expand Down
Loading