-
Notifications
You must be signed in to change notification settings - Fork 0
feat(spp_api_v2): support HTTP Basic Auth on OAuth token endpoint #69
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
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| # Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
| """Tests for OAuth endpoints""" | ||
|
|
||
| import base64 | ||
| import json | ||
| from urllib.parse import urlencode | ||
|
|
||
| from ..middleware.rate_limit import get_rate_limiter | ||
| from .common import ApiV2HttpTestCase | ||
|
|
@@ -45,7 +47,7 @@ def test_token_generation_success(self): | |
| self.assertIn("token_type", data) | ||
| self.assertEqual(data["token_type"], "Bearer") | ||
| self.assertIn("expires_in", data) | ||
| self.assertEqual(data["expires_in"], 3600) # 1 hour | ||
| self.assertEqual(data["expires_in"], 86400) # 24 hours (default) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this test is correctly updated for the new default token lifetime, the test suite is missing coverage for the new authentication methods introduced in this PR (HTTP Basic Auth and |
||
| self.assertIn("scope", data) | ||
| self.assertIn("individual:read", data["scope"]) | ||
| self.assertIn("group:search", data["scope"]) | ||
|
|
@@ -218,6 +220,55 @@ def test_client_last_used_date_updated(self): | |
| self.client.invalidate_recordset() | ||
| self.assertTrue(self.client.last_used_date) | ||
|
|
||
| def test_token_generation_basic_auth(self): | ||
| """HTTP Basic Auth header returns access token""" | ||
| credentials = base64.b64encode(f"{self.client.client_id}:{self.client.client_secret}".encode()).decode("utf-8") | ||
|
|
||
| body = urlencode({"grant_type": "client_credentials"}) | ||
|
|
||
| response = self.url_open( | ||
| self.url, | ||
| data=body, | ||
| headers={ | ||
| "Content-Type": "application/x-www-form-urlencoded", | ||
| "Authorization": f"Basic {credentials}", | ||
| }, | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| data = json.loads(response.content) | ||
| self.assertIn("access_token", data) | ||
| self.assertEqual(data["token_type"], "Bearer") | ||
| self.assertIn("expires_in", data) | ||
| self.assertIn("scope", data) | ||
|
|
||
| def test_token_generation_form_encoded(self): | ||
| """Form-encoded body (application/x-www-form-urlencoded) returns access token""" | ||
| body = urlencode( | ||
| { | ||
| "grant_type": "client_credentials", | ||
| "client_id": self.client.client_id, | ||
| "client_secret": self.client.client_secret, | ||
| } | ||
| ) | ||
|
|
||
| response = self.url_open( | ||
| self.url, | ||
| data=body, | ||
| headers={"Content-Type": "application/x-www-form-urlencoded"}, | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| data = json.loads(response.content) | ||
| self.assertIn("access_token", data) | ||
| self.assertEqual(data["token_type"], "Bearer") | ||
| self.assertIn("expires_in", data) | ||
| self.assertIn("scope", data) | ||
| self.assertIn("individual:read", data["scope"]) | ||
| self.assertIn("group:search", data["scope"]) | ||
|
|
||
| def test_token_no_scopes(self): | ||
| """Client with no scopes still gets token but empty scope string""" | ||
| # Create client without scopes | ||
|
|
||
Check warning
Code scanning / Semgrep OSS
Semgrep Finding: python.lang.security.audit.logging.logger-credential-leak.python-logger-credential-disclosure Warning