Skip to content

Commit

Permalink
client: raise generic exception on user auth abort
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
  • Loading branch information
mattiaverga committed Nov 18, 2022
1 parent 77ffa75 commit 31c8358
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bodhi-client/bodhi/client/oidcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def login_with_browser(self, uri):
),
hide_input=True,
)
except KeyboardInterrupt:
raise click.ClickException("Cancelled.")
except click.exceptions.Abort:
# Raise a generic exception for friendliness to outside scripts
# that don't want to import click
raise SystemExit("Cancelled.")
try:
self.auth_callback(f"?{value}")
except OAuthError as e:
Expand Down
5 changes: 3 additions & 2 deletions bodhi-client/tests/test_oidcclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from authlib.integrations.base_client.errors import OAuthError
from click import ClickException
from click.exceptions import Abort
import pytest
import requests

Expand Down Expand Up @@ -250,15 +251,15 @@ def test_oidcclient_login_no_oob_failure(mocker, client):
def test_oidcclient_login_interrupted(mocker, client):
oauth2client = mocker.Mock()
client.client = oauth2client
mocker.patch("bodhi.client.oidcclient.click.prompt", side_effect=KeyboardInterrupt)
mocker.patch("bodhi.client.oidcclient.click.prompt", side_effect=Abort)
# Enable OOB
client.metadata = {
"token_endpoint": "http://id.example.com/token",
"authorization_endpoint": "http://id.example.com/auth",
"response_modes_supported": ["oob"]
}
oauth2client.create_authorization_url.return_value = ("auth-url", "state")
with pytest.raises(ClickException) as exc:
with pytest.raises(SystemExit) as exc:
client.login()
oauth2client.fetch_token.assert_not_called()
assert str(exc.value) == "Cancelled."
Expand Down
1 change: 1 addition & 0 deletions news/4623.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bodhi-client now raises a generic `SysExit` exception instead of `click.exceptions.Abort` when a user aborts authentication, so external scripts can avoid importing Click in their code

0 comments on commit 31c8358

Please sign in to comment.