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:
chihyuwu 2019-10-30 07:10:38 +00:00
parent feae563269
commit 0e92a480bf
2 changed files with 6 additions and 3 deletions

View File

@ -23,6 +23,7 @@ from unittest import mock
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import padding from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric import rsa
import ddt
from oslo_utils import units from oslo_utils import units
import requests import requests
from six.moves import http_client from six.moves import http_client
@ -323,6 +324,7 @@ class SynoSessionTestCase(test.TestCase):
) )
@ddt.ddt
class SynoAPIRequestTestCase(test.TestCase): class SynoAPIRequestTestCase(test.TestCase):
@mock.patch('requests.post') @mock.patch('requests.post')
def setUp(self, _mock_post): def setUp(self, _mock_post):
@ -427,7 +429,8 @@ class SynoAPIRequestTestCase(test.TestCase):
{'http_status': http_client.INTERNAL_SERVER_ERROR}, result) {'http_status': http_client.INTERNAL_SERVER_ERROR}, result)
@mock.patch.object(common.LOG, 'debug') @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 version = 1
self.request._start = mock.Mock(return_value='fake.cgi') self.request._start = mock.Mock(return_value='fake.cgi')
@ -435,7 +438,7 @@ class SynoAPIRequestTestCase(test.TestCase):
self.request.new_session = mock.Mock() self.request.new_session = mock.Mock()
requests.post = mock.Mock(return_value= requests.post = mock.Mock(return_value=
MockResponse({ MockResponse({
'error': {'code': 105}, 'error': {'code': _code},
'success': False 'success': False
}, http_client.OK)) }, http_client.OK))

View File

@ -398,7 +398,7 @@ class APIRequest(object):
reason=reason) reason=reason)
if ('error' in result and 'code' in result["error"] 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.')) raise SynoAuthError(reason=_('Session might have expired.'))
return result return result