diff --git a/tests/unit/forklift/test_legacy.py b/tests/unit/forklift/test_legacy.py index abe3dfa0d370..99067b8962ec 100644 --- a/tests/unit/forklift/test_legacy.py +++ b/tests/unit/forklift/test_legacy.py @@ -1513,7 +1513,10 @@ def test_upload_fails_with_legacy_type(self, pyramid_config, db_request): resp = excinfo.value assert resp.status_code == 400 - assert resp.status == "400 Unknown type of file." + assert ( + resp.status + == "400 Invalid value for filetype. Error: Use a known file type." + ) def test_upload_fails_with_legacy_ext(self, pyramid_config, db_request): pyramid_config.testing_securitypolicy(userid=1) @@ -2519,106 +2522,6 @@ def storage_service_store(path, file_path, *, meta): ) ] - def test_upload_succeeds_with_legacy_ext( - self, tmpdir, monkeypatch, pyramid_config, db_request, metrics - ): - monkeypatch.setattr(tempfile, "tempdir", str(tmpdir)) - - pyramid_config.testing_securitypolicy(userid=1) - - user = UserFactory.create() - EmailFactory.create(user=user) - project = ProjectFactory.create(allow_legacy_files=True) - release = ReleaseFactory.create(project=project, version="1.0") - RoleFactory.create(user=user, project=project) - - filename = "{}-{}.tar.bz2".format(project.name, release.version) - - db_request.user = user - db_request.remote_addr = "10.10.10.30" - db_request.user_agent = "warehouse-tests/6.6.6" - db_request.POST = MultiDict( - { - "metadata_version": "1.2", - "name": project.name, - "version": release.version, - "filetype": "sdist", - "pyversion": "source", - "md5_digest": _TAR_BZ2_PKG_MD5, - "content": pretend.stub( - filename=filename, - file=io.BytesIO(_TAR_BZ2_PKG_TESTDATA), - type="application/tar", - ), - } - ) - - def storage_service_store(path, file_path, *, meta): - with open(file_path, "rb") as fp: - assert fp.read() == _TAR_BZ2_PKG_TESTDATA - - storage_service = pretend.stub(store=storage_service_store) - db_request.find_service = lambda svc, name=None, context=None: { - IFileStorage: storage_service, - IMetricsService: metrics, - }.get(svc) - - monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True) - - resp = legacy.file_upload(db_request) - - assert resp.status_code == 200 - - def test_upload_succeeds_with_legacy_type( - self, tmpdir, monkeypatch, pyramid_config, db_request, metrics - ): - monkeypatch.setattr(tempfile, "tempdir", str(tmpdir)) - - pyramid_config.testing_securitypolicy(userid=1) - - user = UserFactory.create() - EmailFactory.create(user=user) - project = ProjectFactory.create(allow_legacy_files=True) - release = ReleaseFactory.create(project=project, version="1.0") - RoleFactory.create(user=user, project=project) - - filename = "{}-{}.tar.gz".format(project.name, release.version) - - db_request.user = user - db_request.remote_addr = "10.10.10.30" - db_request.user_agent = "warehouse-tests/6.6.6" - db_request.POST = MultiDict( - { - "metadata_version": "1.2", - "name": project.name, - "version": release.version, - "filetype": "bdist_dumb", - "pyversion": "3.5", - "md5_digest": _TAR_GZ_PKG_MD5, - "content": pretend.stub( - filename=filename, - file=io.BytesIO(_TAR_GZ_PKG_TESTDATA), - type="application/tar", - ), - } - ) - - def storage_service_store(path, file_path, *, meta): - with open(file_path, "rb") as fp: - assert fp.read() == _TAR_GZ_PKG_TESTDATA - - storage_service = pretend.stub(store=storage_service_store) - db_request.find_service = lambda svc, name=None, context=None: { - IFileStorage: storage_service, - IMetricsService: metrics, - }.get(svc) - - monkeypatch.setattr(legacy, "_is_valid_dist_file", lambda *a, **kw: True) - - resp = legacy.file_upload(db_request) - - assert resp.status_code == 200 - @pytest.mark.parametrize("plat", ["linux_x86_64", "linux_x86_64.win32"]) def test_upload_fails_with_unsupported_wheel_plat( self, monkeypatch, pyramid_config, db_request, plat diff --git a/warehouse/forklift/legacy.py b/warehouse/forklift/legacy.py index 2159762e8307..22d65b3a74b4 100644 --- a/warehouse/forklift/legacy.py +++ b/warehouse/forklift/legacy.py @@ -142,11 +142,7 @@ def _valid_platform_tag(platform_tag): _error_message_order = ["metadata_version", "name", "version"] -_dist_file_regexes = { - # True/False is for legacy or not. - True: re.compile(r".+?\.(exe|tar\.gz|bz2|rpm|deb|zip|tgz|egg|dmg|msi|whl)$", re.I), - False: re.compile(r".+?\.(tar\.gz|zip|whl|egg)$", re.I), -} +_dist_file_re = re.compile(r".+?\.(tar\.gz|zip|whl|egg)$", re.I) _wheel_file_re = re.compile( @@ -500,17 +496,7 @@ class MetadataForm(forms.Form): validators=[ wtforms.validators.DataRequired(), wtforms.validators.AnyOf( - [ - "bdist_dmg", - "bdist_dumb", - "bdist_egg", - "bdist_msi", - "bdist_rpm", - "bdist_wheel", - "bdist_wininst", - "sdist", - ], - message="Use a known file type.", + ["bdist_egg", "bdist_wheel", "sdist"], message="Use a known file type.", ), ] ) @@ -1171,7 +1157,7 @@ def file_upload(request): ) # Make sure the filename ends with an allowed extension. - if _dist_file_regexes[project.allow_legacy_files].search(filename) is None: + if _dist_file_re.search(filename) is None: raise _exc_with_message( HTTPBadRequest, "Invalid file extension: Use .egg, .tar.gz, .whl or .zip " @@ -1193,16 +1179,6 @@ def file_upload(request): ): raise _exc_with_message(HTTPBadRequest, "Invalid distribution file.") - # Ensure that the package filetype is allowed. - # TODO: Once PEP 527 is completely implemented we should be able to delete - # this and just move it into the form itself. - if not project.allow_legacy_files and form.filetype.data not in { - "sdist", - "bdist_wheel", - "bdist_egg", - }: - raise _exc_with_message(HTTPBadRequest, "Unknown type of file.") - # The project may or may not have a file size specified on the project, if # it does then it may or may not be smaller or larger than our global file # size limits. diff --git a/warehouse/migrations/versions/b265ed9eeb8a_fully_deprecate_legacy_distribution_.py b/warehouse/migrations/versions/b265ed9eeb8a_fully_deprecate_legacy_distribution_.py new file mode 100644 index 000000000000..b6e9773f225e --- /dev/null +++ b/warehouse/migrations/versions/b265ed9eeb8a_fully_deprecate_legacy_distribution_.py @@ -0,0 +1,31 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Fully deprecate legacy distribution types + +Revision ID: b265ed9eeb8a +Revises: c4cb2d15dada +Create Date: 2020-03-12 17:51:08.447903 +""" + +from alembic import op + +revision = "b265ed9eeb8a" +down_revision = "c4cb2d15dada" + + +def upgrade(): + op.drop_column("projects", "allow_legacy_files") + + +def downgrade(): + raise RuntimeError("Order No. 227 - Ни шагу назад!") diff --git a/warehouse/packaging/models.py b/warehouse/packaging/models.py index 1bd05ac0cea9..4b11d7c7a1e3 100644 --- a/warehouse/packaging/models.py +++ b/warehouse/packaging/models.py @@ -115,7 +115,6 @@ class Project(SitemapMixin, db.Model): has_docs = Column(Boolean) upload_limit = Column(Integer, nullable=True) last_serial = Column(Integer, nullable=False, server_default=sql.text("0")) - allow_legacy_files = Column(Boolean, nullable=False, server_default=sql.false()) zscore = Column(Float, nullable=True) total_size = Column(BigInteger, server_default=sql.text("0"))