DeVaNsHk72 commented on code in PR #44391: URL: https://github.com/apache/superset/pull/44391#discussion_r4053816409
########## tests/unit_tests/utils/create_zip_tests.py: ########## @@ -0,0 +1,85 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + +from datetime import datetime, timedelta +from io import BytesIO +from zipfile import ZIP_DEFLATED, ZipFile + +from superset.utils.core import create_zip, write_zip_entry + +DOS_EPOCH = (1980, 1, 1, 0, 0, 0) + + +def test_create_zip_stamps_entries_with_the_current_time() -> None: + """ + Entries must carry a real modification date. + + Without an explicit ZipInfo, zipfile falls back to the 1980-01-01 DOS epoch, + which extractors show as a bogus or empty modification date on every + extracted file (#44388). + """ + # DOS timestamps have a two-second resolution, so an entry can be stamped + # slightly before the moment the archive was built. + before = datetime.now() - timedelta(seconds=2) + archive = create_zip({"query_1.csv": b"value\n1\n", "query_2.csv": b"value\n2\n"}) + after = datetime.now() + + with ZipFile(archive) as bundle: + infos = bundle.infolist() + + assert [info.filename for info in infos] == ["query_1.csv", "query_2.csv"] + for info in infos: + assert info.date_time != DOS_EPOCH + assert before <= datetime(*info.date_time) <= after + + +def test_write_zip_entry_preserves_contents_and_permissions() -> None: + buf = BytesIO() + with ZipFile(buf, "w") as bundle: + write_zip_entry(bundle, "root/metadata.yaml", b"version: 1.0.0") + + with ZipFile(buf) as bundle: + info = bundle.getinfo("root/metadata.yaml") + assert bundle.read("root/metadata.yaml") == b"version: 1.0.0" + + assert info.date_time != DOS_EPOCH + assert info.external_attr >> 16 == 0o600 Review Comment: You're right, and thanks for actually mutating it — that's the kind of check I should have run myself. Confirmed: `_open_to_write` fills in `0o600 << 16` for any entry whose `external_attr` is unset (3.11 zipfile.py:1667-1668), and it behaves the same on 3.11, 3.12 and 3.14 here. So the helper line was a no-op and the assertion was testing CPython, not us. Dropped both in a21497b. Entries still come out `?rw-------`, just by the stdlib's own default now instead of a line pretending to do the work. The remaining two assertions in that test are ones I checked do fail when mutated. Re CI: every run on this PR is sitting at `action_required` — first-time contributor, so it needs a maintainer to approve the workflows. Nothing I can do from my side, but happy to push again if that shakes anything loose. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
