-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sending an empty scope on OAuth2ClientCredentialsAuth
According to the section 3.3 of RFC 6749 OAuth2 Access Token Scope, this is the notation that defines how the scope should be send to the IdentityProvider: `scope = scope-token *( SP scope-token )` Basically it should be omitted if it's empty.
- Loading branch information
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed sending no scope instead an empty scope when using the `OAuth2ClientCredentialsAuth` authentication class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import typing as t | ||
|
||
import pytest | ||
|
||
from pulp_glue.common.authentication import OAuth2ClientCredentialsAuth | ||
|
||
pytestmark = pytest.mark.glue | ||
|
||
|
||
def test_sending_no_scope_when_empty(monkeypatch: pytest.MonkeyPatch) -> None: | ||
|
||
class OAuth2MockResponse: | ||
def raise_for_status(self): | ||
return None | ||
|
||
def json(self): | ||
return {"expires_in": 1, "access_token": "aaa"} | ||
|
||
def _requests_post_mocked(url: str, data: t.Dict[str, t.Any]): | ||
assert "scope" not in data | ||
return OAuth2MockResponse() | ||
|
||
monkeypatch.setattr("requests.post", _requests_post_mocked) | ||
|
||
OAuth2ClientCredentialsAuth(token_url="", client_id="", client_secret="").retrieve_token() | ||
|
||
OAuth2ClientCredentialsAuth(token_url="", client_id="", client_secret="", scopes=[]).retrieve_token() |