Skip to content

Commit 0455999

Browse files
test(spp_api_v2): cover form-encoded without Content-Type header
Add tests for form-encoded body sent without Content-Type header: - With Basic Auth fallback (succeeds via auth header) - Without any fallback (returns 400)
1 parent a777ccc commit 0455999

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

spp_api_v2/tests/test_oauth.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,51 @@ def test_basic_auth_no_colon_in_decoded(self):
379379
# Should still succeed via form body credentials
380380
self.assertEqual(response.status_code, 200)
381381

382+
def test_form_encoded_without_content_type_falls_back(self):
383+
"""Form-encoded body without Content-Type header falls back to Basic Auth"""
384+
credentials = base64.b64encode(f"{self.client.client_id}:{self.client.client_secret}".encode()).decode("utf-8")
385+
386+
# Send form-encoded body but WITHOUT the Content-Type header.
387+
# The endpoint won't parse it as form data, JSON parsing will also
388+
# fail, so it must fall back to the Basic Auth header.
389+
body = urlencode(
390+
{
391+
"grant_type": "client_credentials",
392+
"client_id": self.client.client_id,
393+
"client_secret": self.client.client_secret,
394+
}
395+
)
396+
397+
response = self.url_open(
398+
self.url,
399+
data=body,
400+
headers={"Authorization": f"Basic {credentials}"},
401+
)
402+
403+
self.assertEqual(response.status_code, 200)
404+
405+
data = json.loads(response.content)
406+
self.assertIn("access_token", data)
407+
408+
def test_form_encoded_without_content_type_no_fallback_returns_400(self):
409+
"""Form-encoded body without Content-Type and no Basic Auth returns 400"""
410+
body = urlencode(
411+
{
412+
"grant_type": "client_credentials",
413+
"client_id": self.client.client_id,
414+
"client_secret": self.client.client_secret,
415+
}
416+
)
417+
418+
response = self.url_open(
419+
self.url,
420+
data=body,
421+
)
422+
423+
# Form body is not parsed (no Content-Type), JSON parsing fails,
424+
# no Basic Auth header to fall back on → 400
425+
self.assertEqual(response.status_code, 400)
426+
382427
def test_no_credentials_returns_400(self):
383428
"""No credentials at all returns 400"""
384429
response = self.url_open(

0 commit comments

Comments
 (0)