Skip to content

Commit

Permalink
Add a test case for a successful auth for client credentials flow
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash committed Jun 13, 2024
1 parent f509877 commit 5bde898
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/sources/helpers/rest_client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
APIKeyAuth,
HttpBasicAuth,
OAuthJWTAuth,
OAuth2ImplicitFlow,
)
from dlt.sources.helpers.rest_client.exceptions import IgnoreResponseException

Expand Down Expand Up @@ -163,6 +164,44 @@ def test_api_key_auth_success(self, rest_client: RESTClient):
assert response.status_code == 200
assert response.json()["data"][0] == {"id": 0, "title": "Post 0"}

def test_oauth2_client_credentials_flow_auth_success(self, rest_client: RESTClient):
class OAuth2ClientCredentialsExample(OAuth2ImplicitFlow):
def build_access_token_request(self):
return {
"url": "https://api.example.com/oauth/token",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
},
"data": {
**self.access_token_request_data,
"client_id": self.client_id,
"client_secret": self.client_secret,
}
}

auth = OAuth2ClientCredentialsExample(
access_token_request_data={
"grant_type": "client_credentials",
},
client_id="test-client-id",
client_secret="test-client-secret",
)

response = rest_client.get(
"/protected/posts/bearer-token",
auth=auth,
)

assert response.status_code == 200
assert "test-token" in response.request.headers["Authorization"]

pages_iter = rest_client.paginate(
"/protected/posts/bearer-token",
auth=auth,
)

assert_pagination(list(pages_iter))

def test_oauth_jwt_auth_success(self, rest_client: RESTClient):
auth = OAuthJWTAuth(
client_id="test-client-id",
Expand Down

0 comments on commit 5bde898

Please sign in to comment.