Skip to content

Commit 2082a12

Browse files
authored
Remove per-project 2FA requirements (#15131)
* Remove per-project 2FA requirements * Add back manage_2fa_required redirect * Add migration * Update translations * Add back missing test case
1 parent bcb3fec commit 2082a12

34 files changed

+238
-1330
lines changed

requirements/dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ asyncudp>=0.7
22
hupper>=1.9
33
pip-tools>=1.0
44
pyramid_debugtoolbar>=2.5
5+
pip-api

requirements/main.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ packaging_legacy
3838
paginate>=0.5.2
3939
paginate_sqlalchemy
4040
passlib>=1.6.4
41-
pip-api
4241
premailer
4342
psycopg[c]
4443
pycurl

requirements/main.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,6 @@ pastedeploy==3.1.0 \
11581158
--hash=sha256:76388ad53a661448d436df28c798063108f70e994ddc749540d733cdbd1b38cf \
11591159
--hash=sha256:9ddbaf152f8095438a9fe81f82c78a6714b92ae8e066bed418b6a7ff6a095a95
11601160
# via plaster-pastedeploy
1161-
pip-api==0.0.30 \
1162-
--hash=sha256:2a0314bd31522eb9ffe8a99668b0d07fee34ebc537931e7b6483001dbedcbdc9 \
1163-
--hash=sha256:a05df2c7aa9b7157374bcf4273544201a0c7bae60a9c65bcf84f3959ef3896f3
1164-
# via -r requirements/main.in
11651161
plaster==1.1.2 \
11661162
--hash=sha256:42992ab1f4865f1278e2ad740e8ad145683bb4022e03534265528f0c23c0df2d \
11671163
--hash=sha256:f8befc54bf8c1147c10ab40297ec84c2676fa2d4ea5d6f524d9436a80074ef98
@@ -1789,10 +1785,6 @@ zxcvbn==4.4.28 \
17891785
# via -r requirements/main.in
17901786

17911787
# The following packages are considered to be unsafe in a requirements file:
1792-
pip==23.3.2 \
1793-
--hash=sha256:5052d7889c1f9d05224cd41741acb7c5d6fa735ab34e339624a614eaaa7e7d76 \
1794-
--hash=sha256:7fd9972f96db22c8077a1ee2691b172c8089b17a5652a44494a9ecb0d78f9149
1795-
# via pip-api
17961788
setuptools==69.0.3 \
17971789
--hash=sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05 \
17981790
--hash=sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78

tests/unit/accounts/test_security_policy.py

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -586,136 +586,6 @@ def test_acl(self, monkeypatch, policy_class, principals, expected):
586586
policy = policy_class()
587587
assert bool(policy.permits(request, context, "myperm")) == expected
588588

589-
@pytest.mark.parametrize(
590-
"mfa_required,has_mfa,expected",
591-
[
592-
(True, True, True),
593-
(False, True, True),
594-
(True, False, False),
595-
(False, False, True),
596-
],
597-
)
598-
def test_2fa_owner_requires(
599-
self, monkeypatch, policy_class, mfa_required, has_mfa, expected
600-
):
601-
monkeypatch.setattr(security_policy, "User", pretend.stub)
602-
monkeypatch.setattr(security_policy, "TwoFactorRequireable", pretend.stub)
603-
604-
request = pretend.stub(
605-
flags=pretend.stub(enabled=lambda flag: False),
606-
identity=pretend.stub(
607-
__principals__=lambda: ["user:5"],
608-
has_primary_verified_email=True,
609-
has_two_factor=has_mfa,
610-
date_joined=datetime(2022, 8, 1),
611-
),
612-
matched_route=pretend.stub(name="random.route"),
613-
registry=pretend.stub(
614-
settings={
615-
"warehouse.two_factor_requirement.enabled": True,
616-
"warehouse.two_factor_mandate.enabled": False,
617-
"warehouse.two_factor_mandate.available": False,
618-
}
619-
),
620-
)
621-
context = pretend.stub(
622-
__acl__=[(Allow, "user:5", "myperm")], owners_require_2fa=mfa_required
623-
)
624-
625-
policy = policy_class()
626-
assert bool(policy.permits(request, context, "myperm")) == expected
627-
628-
@pytest.mark.parametrize(
629-
"mfa_required,has_mfa,expected",
630-
[
631-
(True, True, True),
632-
(False, True, True),
633-
(True, False, False),
634-
(False, False, True),
635-
],
636-
)
637-
def test_2fa_pypi_mandates_2fa(
638-
self, monkeypatch, policy_class, mfa_required, has_mfa, expected
639-
):
640-
monkeypatch.setattr(security_policy, "User", pretend.stub)
641-
monkeypatch.setattr(security_policy, "TwoFactorRequireable", pretend.stub)
642-
643-
request = pretend.stub(
644-
flags=pretend.stub(enabled=lambda flag: False),
645-
identity=pretend.stub(
646-
__principals__=lambda: ["user:5"],
647-
has_primary_verified_email=True,
648-
has_two_factor=has_mfa,
649-
date_joined=datetime(2022, 8, 1),
650-
),
651-
matched_route=pretend.stub(name="random.route"),
652-
registry=pretend.stub(
653-
settings={
654-
"warehouse.two_factor_requirement.enabled": False,
655-
"warehouse.two_factor_mandate.enabled": True,
656-
"warehouse.two_factor_mandate.available": False,
657-
}
658-
),
659-
)
660-
context = pretend.stub(
661-
__acl__=[(Allow, "user:5", "myperm")], pypi_mandates_2fa=mfa_required
662-
)
663-
664-
policy = policy_class()
665-
assert bool(policy.permits(request, context, "myperm")) == expected
666-
667-
@pytest.mark.parametrize(
668-
"mfa_required,has_mfa,expected",
669-
[
670-
(True, True, True),
671-
(False, True, True),
672-
(True, False, False),
673-
(False, False, True),
674-
],
675-
)
676-
def test_2fa_pypi_mandates_2fa_with_warning(
677-
self, monkeypatch, policy_class, mfa_required, has_mfa, expected
678-
):
679-
monkeypatch.setattr(security_policy, "User", pretend.stub)
680-
monkeypatch.setattr(security_policy, "TwoFactorRequireable", pretend.stub)
681-
682-
request = pretend.stub(
683-
flags=pretend.stub(enabled=lambda flag: False),
684-
identity=pretend.stub(
685-
__principals__=lambda: ["user:5"],
686-
has_primary_verified_email=True,
687-
has_two_factor=has_mfa,
688-
date_joined=datetime(2022, 8, 1),
689-
),
690-
matched_route=pretend.stub(name="random.route"),
691-
registry=pretend.stub(
692-
settings={
693-
"warehouse.two_factor_requirement.enabled": False,
694-
"warehouse.two_factor_mandate.enabled": False,
695-
"warehouse.two_factor_mandate.available": True,
696-
}
697-
),
698-
session=pretend.stub(flash=pretend.call_recorder(lambda msg, queue: None)),
699-
)
700-
context = pretend.stub(
701-
__acl__=[(Allow, "user:5", "myperm")], pypi_mandates_2fa=mfa_required
702-
)
703-
704-
policy = policy_class()
705-
assert bool(policy.permits(request, context, "myperm"))
706-
707-
if not expected:
708-
assert request.session.flash.calls == [
709-
pretend.call(
710-
"This project is included in PyPI's two-factor mandate "
711-
"for critical projects. In the future, you will be unable to "
712-
"perform this action without enabling 2FA for your account",
713-
queue="warning",
714-
)
715-
]
716-
else:
717-
assert request.session.flash.calls == []
718-
719589
def test_permits_with_unverified_email(self, monkeypatch, policy_class):
720590
monkeypatch.setattr(security_policy, "User", pretend.stub)
721591

tests/unit/cli/test_two_factor.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/unit/manage/test_forms.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,16 +807,6 @@ def test_validate_name_with_organization(self):
807807
]
808808

809809

810-
class TestToggle2FARequirementForm:
811-
def test_creation(self):
812-
# TODO
813-
pass
814-
815-
def test_validate(self):
816-
# TODO
817-
pass
818-
819-
820810
class TestSaveOrganizationNameForm:
821811
def test_save(self, pyramid_request):
822812
pyramid_request.POST = MultiDict({"name": "my_org_name"})

0 commit comments

Comments
 (0)