mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Errors don't set the HTTP status code
Some (if not all) just ignore the response if it's not a 200 and just consider the server borked. Closes #192
This commit is contained in:
parent
b438bb0121
commit
b511b1c647
@ -3,7 +3,7 @@
|
|||||||
# This file is part of Supysonic.
|
# This file is part of Supysonic.
|
||||||
# Supysonic is a Python implementation of the Subsonic server API.
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018-2019 Alban 'spl0k' Féron
|
# Copyright (C) 2018-2020 Alban 'spl0k' Féron
|
||||||
#
|
#
|
||||||
# Distributed under terms of the GNU AGPLv3 license.
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ class SubsonicAPIException(HTTPException):
|
|||||||
|
|
||||||
def get_response(self, environ=None):
|
def get_response(self, environ=None):
|
||||||
rv = request.formatter.error(self.api_code, self.message)
|
rv = request.formatter.error(self.api_code, self.message)
|
||||||
rv.status_code = self.code
|
# rv.status_code = self.code
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -122,5 +122,5 @@ class AggregateException(SubsonicAPIException):
|
|||||||
rv = request.formatter(
|
rv = request.formatter(
|
||||||
"error", dict(code=list(codes)[0] if len(codes) == 1 else 0, error=errors)
|
"error", dict(code=list(codes)[0] if len(codes) == 1 else 0, error=errors)
|
||||||
)
|
)
|
||||||
rv.status_code = self.code
|
# rv.status_code = self.code
|
||||||
return rv
|
return rv
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# This file is part of Supysonic.
|
# This file is part of Supysonic.
|
||||||
# Supysonic is a Python implementation of the Subsonic server API.
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2018 Alban 'spl0k' Féron
|
# Copyright (C) 2018-2020 Alban 'spl0k' Féron
|
||||||
#
|
#
|
||||||
# Distributed under terms of the GNU AGPLv3 license.
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ methods = (
|
|||||||
|
|
||||||
|
|
||||||
def unsupported():
|
def unsupported():
|
||||||
return GenericError("Not supported by Supysonic"), 501
|
return GenericError("Not supported by Supysonic")
|
||||||
|
|
||||||
|
|
||||||
for m in methods:
|
for m in methods:
|
||||||
|
@ -51,13 +51,13 @@ class ApiSetupTestCase(TestBase):
|
|||||||
def __test_auth(self, method):
|
def __test_auth(self, method):
|
||||||
# non-existent user
|
# non-existent user
|
||||||
rv = method("null", "null")
|
rv = method("null", "null")
|
||||||
self.assertEqual(rv.status_code, 401)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="40"', rv.data)
|
self.assertIn('code="40"', rv.data)
|
||||||
|
|
||||||
# user request with bad password
|
# user request with bad password
|
||||||
rv = method("alice", "wrong password")
|
rv = method("alice", "wrong password")
|
||||||
self.assertEqual(rv.status_code, 401)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="40"', rv.data)
|
self.assertIn('code="40"', rv.data)
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class ApiSetupTestCase(TestBase):
|
|||||||
def test_auth_basic(self):
|
def test_auth_basic(self):
|
||||||
# No auth info
|
# No auth info
|
||||||
rv = self.client.get("/rest/ping.view?c=tests")
|
rv = self.client.get("/rest/ping.view?c=tests")
|
||||||
self.assertEqual(rv.status_code, 400)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="10"', rv.data)
|
self.assertIn('code="10"', rv.data)
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class ApiSetupTestCase(TestBase):
|
|||||||
|
|
||||||
# Shouldn't accept 'enc:' passwords
|
# Shouldn't accept 'enc:' passwords
|
||||||
rv = self.__basic_auth_get("alice", "enc:" + hexlify("Alic3"))
|
rv = self.__basic_auth_get("alice", "enc:" + hexlify("Alic3"))
|
||||||
self.assertEqual(rv.status_code, 401)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="40"', rv.data)
|
self.assertIn('code="40"', rv.data)
|
||||||
|
|
||||||
@ -158,14 +158,14 @@ class ApiSetupTestCase(TestBase):
|
|||||||
"/rest/getVideos.view",
|
"/rest/getVideos.view",
|
||||||
query_string={"u": "alice", "p": "Alic3", "c": "tests"},
|
query_string={"u": "alice", "p": "Alic3", "c": "tests"},
|
||||||
)
|
)
|
||||||
self.assertEqual(rv.status_code, 501)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="0"', rv.data)
|
self.assertIn('code="0"', rv.data)
|
||||||
|
|
||||||
rv = self.client.post(
|
rv = self.client.post(
|
||||||
"/rest/getVideos.view", data={"u": "alice", "p": "Alic3", "c": "tests"}
|
"/rest/getVideos.view", data={"u": "alice", "p": "Alic3", "c": "tests"}
|
||||||
)
|
)
|
||||||
self.assertEqual(rv.status_code, 501)
|
self.assertEqual(rv.status_code, 200)
|
||||||
self.assertIn('status="failed"', rv.data)
|
self.assertIn('status="failed"', rv.data)
|
||||||
self.assertIn('code="0"', rv.data)
|
self.assertIn('code="0"', rv.data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user