aminghadersohi commented on code in PR #44391: URL: https://github.com/apache/superset/pull/44391#discussion_r4051442737
########## 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: Deleting `info.external_attr = 0o600 << 16` from the helper leaves this assertion green (mutated: `3 passed`). `writestr` routes through `_open_to_write`, which applies the identical default (CPython 3.11 `zipfile.py:1656-1657`), so this pins stdlib behaviour, not the helper. -- 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]
