Synology: Improve session expired error handling
Session may not reconnect when current session is expired because error handling only handles Error Code 105 (No Permission) but 119 (SID Not Found) is needed as well. Change-Id: Ida093a1ebf3395a73298cb087c28290229fbb92e Closes-Bug: #1850601
This commit is contained in:
parent
feae563269
commit
0e92a480bf
|
@ -23,6 +23,7 @@ from unittest import mock
|
|||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
import ddt
|
||||
from oslo_utils import units
|
||||
import requests
|
||||
from six.moves import http_client
|
||||
|
@ -323,6 +324,7 @@ class SynoSessionTestCase(test.TestCase):
|
|||
)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class SynoAPIRequestTestCase(test.TestCase):
|
||||
@mock.patch('requests.post')
|
||||
def setUp(self, _mock_post):
|
||||
|
@ -427,7 +429,8 @@ class SynoAPIRequestTestCase(test.TestCase):
|
|||
{'http_status': http_client.INTERNAL_SERVER_ERROR}, result)
|
||||
|
||||
@mock.patch.object(common.LOG, 'debug')
|
||||
def test_request_auth_error(self, _log):
|
||||
@ddt.data(105, 119)
|
||||
def test_request_auth_error(self, _code, _log):
|
||||
version = 1
|
||||
|
||||
self.request._start = mock.Mock(return_value='fake.cgi')
|
||||
|
@ -435,7 +438,7 @@ class SynoAPIRequestTestCase(test.TestCase):
|
|||
self.request.new_session = mock.Mock()
|
||||
requests.post = mock.Mock(return_value=
|
||||
MockResponse({
|
||||
'error': {'code': 105},
|
||||
'error': {'code': _code},
|
||||
'success': False
|
||||
}, http_client.OK))
|
||||
|
||||
|
|
|
@ -398,7 +398,7 @@ class APIRequest(object):
|
|||
reason=reason)
|
||||
|
||||
if ('error' in result and 'code' in result["error"]
|
||||
and result['error']['code'] == 105):
|
||||
and result['error']['code'] in [105, 119]):
|
||||
raise SynoAuthError(reason=_('Session might have expired.'))
|
||||
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue