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

Dm/draft header #3116

Draft
wants to merge 24 commits into
base: dm/published-date
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a45892a
Fix cherry-pick
warsaw Sep 21, 2024
831095a
Add `published` to the `ReleaseFactory`
alanbato May 2, 2022
5846e30
Add migrations
DarkaMaul Dec 6, 2024
60f4a01
Add a default value for Release.published field.
DarkaMaul Dec 9, 2024
60de6e8
Change to a boolean field
DarkaMaul Dec 10, 2024
d2438e8
Merge branch 'main' into dm/published-date
DarkaMaul Dec 10, 2024
a792738
Filter out unpublished releases
DarkaMaul Dec 10, 2024
76fd2e4
Merge branch 'main' into dm/published-date
DarkaMaul Dec 11, 2024
018d047
Merge branch 'main' into dm/draft-header
DarkaMaul Dec 16, 2024
35395da
Merge branch 'main' into dm/published-date
woodruffw Dec 16, 2024
38221fb
Merge branch 'main' into dm/published-date
DarkaMaul Dec 18, 2024
0957242
Merge branch 'dm/published-date' into dm/draft-header
DarkaMaul Dec 18, 2024
4b8b395
Add `staged` releases publication
DarkaMaul Dec 20, 2024
1d81d5d
Remove empty upload.
DarkaMaul Dec 27, 2024
c781e5b
Add test with OIDC publishing
DarkaMaul Dec 27, 2024
e6efef9
Merge branch 'main' into dm/draft-header
DarkaMaul Dec 27, 2024
90bc0b3
Update translations
DarkaMaul Dec 27, 2024
943f630
Merge branch 'main' into dm/draft-header
DarkaMaul Dec 31, 2024
2b51092
Upgrade tests
DarkaMaul Dec 31, 2024
852db29
Merge remote-tracking branch 'origin/dm/draft-header' into dm/draft-h…
DarkaMaul Dec 31, 2024
73363b1
Merge branch 'main' into dm/draft-header
DarkaMaul Jan 28, 2025
76ad6b7
Update PR
DarkaMaul Jan 28, 2025
b629c84
Merge branch 'dm/published-date' into dm/draft-header
DarkaMaul Jan 28, 2025
6d14433
Rebase PR on top of other changes
DarkaMaul Jan 28, 2025
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
8 changes: 8 additions & 0 deletions tests/functional/_fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ This is from https://pypi.org/project/sampleproject/3.0.0/#files, get it with:
```
$ wget https://files.pythonhosted.org/packages/67/2a/9f056e5fa36e43ef1037ff85581a2963cde420457de0ef29c779d41058ca/sampleproject-3.0.0.tar.gz
```

## `sampleproject-3.0.0-py3-none-any.whl`

This is from https://pypi.org/project/sampleproject/3.0.0/#files, get it with:

```
$ wget https://files.pythonhosted.org/packages/ec/a8/5ec62d18adde798d33a170e7f72930357aa69a60839194c93eb0fb05e59c/sampleproject-3.0.0-py3-none-any.whl
```
Binary file not shown.
127 changes: 125 additions & 2 deletions tests/functional/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ def test_remove_doc_upload(webtest):
("/legacy/", {":action": "file_upload", "protocol_version": "1"}),
],
)
def test_file_upload(webtest, upload_url, additional_data):
@pytest.mark.parametrize(
"staged_release",
[
True,
False,
],
)
def test_file_upload(webtest, upload_url, additional_data, staged_release):
user = UserFactory.create(with_verified_primary_email=True, clear_pwd="password")

# Construct the macaroon
Expand Down Expand Up @@ -118,9 +125,15 @@ def test_file_upload(webtest, upload_url, additional_data):
params.add("classifiers", "Programming Language :: Python :: 3.10")
params.add("classifiers", "Programming Language :: Python :: 3.11")

headers = {
"Authorization": f"Basic {credentials}",
}
if staged_release:
headers["X-PyPI-Is-Staged"] = "1"

webtest.post(
upload_url,
headers={"Authorization": f"Basic {credentials}"},
headers=headers,
params=params,
upload_files=[("content", "sampleproject-3.0.0.tar.gz", content)],
status=HTTPStatus.OK,
Expand All @@ -134,6 +147,116 @@ def test_file_upload(webtest, upload_url, additional_data):
assert len(project.releases) == 1
release = project.releases[0]
assert release.version == "3.0.0"
assert release.published != staged_release


@pytest.mark.parametrize(
"stage_first_file",
[
True,
False,
],
)
@pytest.mark.parametrize(
"stage_second_file",
[
True,
False,
],
)
def test_stage_release(webtest, stage_first_file, stage_second_file):
user = UserFactory.create(with_verified_primary_email=True, clear_pwd="password")

# Construct the macaroon
dm = MacaroonFactory.create(
user_id=user.id,
caveats=[caveats.RequestUser(user_id=str(user.id))],
)

m = pymacaroons.Macaroon(
location="localhost",
identifier=str(dm.id),
key=dm.key,
version=pymacaroons.MACAROON_V2,
)
for caveat in dm.caveats:
m.add_first_party_caveat(caveats.serialize(caveat))
serialized_macaroon = f"pypi-{m.serialize()}"

credentials = base64.b64encode(f"__token__:{serialized_macaroon}".encode()).decode(
"utf-8"
)

with open("./tests/functional/_fixtures/sampleproject-3.0.0.tar.gz", "rb") as f:
first_file = f.read()

with open(
"./tests/functional/_fixtures/sampleproject-3.0.0-py3-none-any.whl", "rb"
) as f:
second_file = f.read()

webtest.post(
"/legacy/?:action=file_upload",
headers={
"Authorization": f"Basic {credentials}",
**({"X-PyPI-Is-Staged": "1"} if stage_first_file else {}),
},
params=MultiDict(
{
"name": "sampleproject",
"sha256_digest": (
"117ed88e5db073bb92969a7545745fd977ee85b7019706dd256a64058f70963d"
),
"filetype": "sdist",
"metadata_version": "2.1",
"version": "3.0.0",
"classifiers": "Programming Language :: Python :: 3.11",
}
),
upload_files=[("content", "sampleproject-3.0.0.tar.gz", first_file)],
status=HTTPStatus.OK,
)

assert user.projects
assert len(user.projects) == 1
project = user.projects[0]
assert project.name == "sampleproject"
assert project.releases
assert len(project.releases) == 1
release = project.releases[0]

assert release.published != stage_first_file

second_request_status = (
HTTPStatus.BAD_REQUEST
if stage_second_file and not stage_first_file
else HTTPStatus.OK
)
webtest.post(
"/legacy/?:action=file_upload",
headers={
"Authorization": f"Basic {credentials}",
**({"X-PyPI-Is-Staged": "1"} if stage_second_file else {}),
},
params=MultiDict(
{
"name": "sampleproject",
"sha256_digest": (
"2e52702990c22cf1ce50206606b769fe0dbd5646a32873916144bd5aec5473b3"
),
"filetype": "bdist_wheel",
"metadata_version": "2.1",
"version": "3.0.0",
"pyversion": "3.11",
"classifiers": "Programming Language :: Python :: 3.11",
}
),
upload_files=[("content", "sampleproject-3.0.0-py3-none-any.whl", second_file)],
status=second_request_status,
)

if second_request_status == HTTPStatus.OK:
assert release.published != stage_second_file


def test_duplicate_file_upload_error(webtest):
Expand Down
Loading