Skip to content

[OIDC] Pending provider views, routes, forms #12646

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

Merged
merged 51 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6e885a6
accounts/models: initial permissions helper
woodruffw Nov 29, 2022
9d8964f
warehouse: initial view/route skeleton for pending publishers
woodruffw Nov 29, 2022
b6e61d7
templates/manage: devolve common OIDC components
woodruffw Nov 29, 2022
e097343
HTML, form work
woodruffw Nov 29, 2022
d762f9c
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Dec 6, 2022
683f278
warehouse: `make translations`
woodruffw Dec 6, 2022
5250920
warehouse: stamp the new pending publisher form out
woodruffw Dec 6, 2022
b7b1846
warehouse: more pending OIDC provider scaffolding, deletions, ratelim…
woodruffw Dec 6, 2022
a65a796
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Dec 7, 2022
964acd5
migrations: rebase
woodruffw Dec 7, 2022
c64ba29
oidc/forms: handle connection errors against GitHub's API
woodruffw Dec 7, 2022
bf4fd00
warehouse: pending provider events
woodruffw Dec 7, 2022
226460d
warehouse: `make translations`
woodruffw Dec 7, 2022
cbc0fc2
tests: make the tests pass
woodruffw Dec 7, 2022
0acd8e9
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Dec 7, 2022
35c9630
tests: add another OIDC form test
woodruffw Dec 7, 2022
37871ab
warehouse: reintroduce UniqueConstraint
woodruffw Dec 8, 2022
f4b6991
templates: initial help text for OIDC, restrict add form
woodruffw Dec 8, 2022
a49b062
accounts/views: more constraints on pending registration
woodruffw Dec 8, 2022
ab09480
accounts/views: warn the user if the OIDC provider has already been r…
woodruffw Dec 8, 2022
bd0ba4c
warehouse/local: `make translations`
woodruffw Dec 8, 2022
235957b
tests: some more account model tests for pending providers
woodruffw Dec 8, 2022
8e118ea
tests: more pending provider qualification tests
woodruffw Dec 9, 2022
f4600a1
tests: more form tests
woodruffw Dec 9, 2022
db1e216
tests: round out form coverage
woodruffw Dec 9, 2022
60bf2b9
tests, warehouse: more coverage
woodruffw Dec 9, 2022
856e7d5
tests, warehouse: more coverage
woodruffw Dec 9, 2022
a1eaa40
warehouse/local: `make translations`
woodruffw Dec 9, 2022
f533018
tests, warehouse: round out coverage
woodruffw Dec 9, 2022
c8fb5d8
tests, warehouse: lintage
woodruffw Dec 9, 2022
caf8717
warehouse/locale: `make translations`
woodruffw Dec 9, 2022
4770ab4
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Dec 12, 2022
f1d40eb
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Dec 14, 2022
de2809f
Apply suggestions from code review
woodruffw Jan 13, 2023
91cce8f
warehouse: `make translations`
woodruffw Jan 17, 2023
6b5c1f0
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Jan 17, 2023
be942bc
accounts/views: reformat
woodruffw Jan 17, 2023
9e5679d
tests, warehouse: fixups, fix tests
woodruffw Jan 17, 2023
2b49e31
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Jan 17, 2023
c11015a
tests, warehouse: remove some OIDC restrictions
woodruffw Jan 17, 2023
c1b06e9
Merge remote-tracking branch 'upstream/main' into tob-pending-oidc-pr…
woodruffw Jan 17, 2023
044738e
pages/help: remove talk of OIDC "flavors"
woodruffw Jan 17, 2023
bd973ba
warehouse, tests: better error flashes
woodruffw Jan 17, 2023
b52f3e7
warehouse: dedupe project name regexps
woodruffw Jan 17, 2023
1371f10
warehouse: `make translations`
woodruffw Jan 17, 2023
9fa59c2
Update warehouse/accounts/views.py
woodruffw Jan 19, 2023
f95fb5c
Merge branch 'main' into tob-pending-oidc-provider-views
woodruffw Jan 19, 2023
2a65b0e
warehouse, tests: tweak OIDC limit message
woodruffw Jan 19, 2023
91e9e69
Merge branch 'main' into tob-pending-oidc-provider-views
woodruffw Jan 25, 2023
20cbe76
warehouse, tests: drop OIDC helper
woodruffw Jan 25, 2023
5e2ef09
Merge branch 'main' into tob-pending-oidc-provider-views
woodruffw Jan 26, 2023
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
911 changes: 910 additions & 1 deletion tests/unit/accounts/test_views.py

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9959,10 +9959,9 @@ def test_add_github_oidc_provider_oidc_not_enabled(self):

def test_add_github_oidc_provider_admin_disabled(self, monkeypatch):
project = pretend.stub()
metrics = pretend.stub(increment=pretend.call_recorder(lambda *a, **kw: None))
request = pretend.stub(
registry=pretend.stub(settings={"warehouse.oidc.enabled": True}),
find_service=lambda *a, **kw: metrics,
find_service=lambda *a, **kw: None,
flags=pretend.stub(enabled=pretend.call_recorder(lambda f: True)),
session=pretend.stub(flash=pretend.call_recorder(lambda *a, **kw: None)),
_=lambda s: s,
Expand All @@ -9975,11 +9974,6 @@ def test_add_github_oidc_provider_admin_disabled(self, monkeypatch):
)

assert view.add_github_oidc_provider() == default_response
assert view.metrics.increment.calls == [
pretend.call(
"warehouse.oidc.add_provider.attempt", tags=["provider:GitHub"]
),
]
assert request.session.flash.calls == [
pretend.call(
(
Expand Down Expand Up @@ -10336,10 +10330,9 @@ def test_delete_oidc_provider_oidc_not_enabled(self):

def test_delete_oidc_provider_admin_disabled(self, monkeypatch):
project = pretend.stub()
metrics = pretend.stub(increment=pretend.call_recorder(lambda *a, **kw: None))
request = pretend.stub(
registry=pretend.stub(settings={"warehouse.oidc.enabled": True}),
find_service=lambda *a, **kw: metrics,
find_service=lambda *a, **kw: None,
flags=pretend.stub(enabled=pretend.call_recorder(lambda f: True)),
session=pretend.stub(flash=pretend.call_recorder(lambda *a, **kw: None)),
)
Expand All @@ -10351,11 +10344,6 @@ def test_delete_oidc_provider_admin_disabled(self, monkeypatch):
)

assert view.delete_oidc_provider() == default_response
assert view.metrics.increment.calls == [
pretend.call(
"warehouse.oidc.delete_provider.attempt",
),
]
assert request.session.flash.calls == [
pretend.call(
(
Expand Down
64 changes: 63 additions & 1 deletion tests/unit/oidc/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,51 @@
import pytest
import wtforms

from requests import HTTPError, Timeout
from requests import ConnectionError, HTTPError, Timeout
from webob.multidict import MultiDict

from warehouse.oidc import forms


class TestPendingGitHubProviderForm:
def test_creation(self):
project_factory = pretend.stub()
form = forms.PendingGitHubProviderForm(
api_token="fake-token", project_factory=project_factory
)

assert form._project_factory == project_factory

def test_validate_project_name_already_in_use(self):
project_factory = ["some-project"]
form = forms.PendingGitHubProviderForm(
api_token="fake-token", project_factory=project_factory
)

field = pretend.stub(data="some-project")
with pytest.raises(wtforms.validators.ValidationError):
form.validate_project_name(field)

def test_validate(self, monkeypatch):
data = MultiDict(
{
"owner": "some-owner",
"repository": "some-repo",
"workflow_filename": "some-workflow.yml",
"project_name": "some-project",
}
)
form = forms.PendingGitHubProviderForm(
MultiDict(data), api_token=pretend.stub(), project_factory=[]
)

# We're testing only the basic validation here.
owner_info = {"login": "fake-username", "id": "1234"}
monkeypatch.setattr(form, "_lookup_owner", lambda o: owner_info)

assert form.validate()


class TestGitHubProviderForm:
@pytest.mark.parametrize(
"token, headers",
Expand Down Expand Up @@ -138,6 +177,7 @@ def test_lookup_owner_http_timeout(self, monkeypatch):
get=pretend.raiser(Timeout),
Timeout=Timeout,
HTTPError=HTTPError,
ConnectionError=ConnectionError,
)
monkeypatch.setattr(forms, "requests", requests)

Expand All @@ -152,6 +192,28 @@ def test_lookup_owner_http_timeout(self, monkeypatch):
pretend.call("Timeout from GitHub user lookup API (possibly offline)")
]

def test_lookup_owner_connection_error(self, monkeypatch):
requests = pretend.stub(
get=pretend.raiser(ConnectionError),
Timeout=Timeout,
HTTPError=HTTPError,
ConnectionError=ConnectionError,
)
monkeypatch.setattr(forms, "requests", requests)

sentry_sdk = pretend.stub(capture_message=pretend.call_recorder(lambda s: None))
monkeypatch.setattr(forms, "sentry_sdk", sentry_sdk)

form = forms.GitHubProviderForm(api_token="fake-token")
with pytest.raises(wtforms.validators.ValidationError):
form._lookup_owner("some-owner")

assert sentry_sdk.capture_message.calls == [
pretend.call(
"Connection error from GitHub user lookup API (possibly offline)"
)
]

def test_lookup_owner_succeeds(self, monkeypatch):
fake_owner_info = pretend.stub()
response = pretend.stub(
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def add_policy(name, filename):
domain=warehouse,
),
pretend.call("manage.account", "/manage/account/", domain=warehouse),
pretend.call(
"manage.account.publishing", "/manage/account/publishing/", domain=warehouse
),
pretend.call(
"manage.account.two-factor",
"/manage/account/two-factor/",
Expand Down
Loading