From 6b6e944d551464902d7a35800d736af11c9a204d Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Fri, 30 Sep 2022 14:55:24 +0400 Subject: [PATCH] Removed sensitive data from logging; 1 more test --- pylintrc | 3 ++- python_aternos/atconnect.py | 15 +++++++++++++-- tests/test_login.py | 27 +++++++++++++++++++++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/pylintrc b/pylintrc index 776f6ba..01a77f6 100644 --- a/pylintrc +++ b/pylintrc @@ -42,7 +42,8 @@ disable=raw-checker-failed, no-member, too-many-arguments, too-many-public-methods, - too-many-instance-attributes + too-many-instance-attributes, + too-many-locals enable=c-extension-no-member diff --git a/python_aternos/atconnect.py b/python_aternos/atconnect.py index 340fa9b..b70cdec 100644 --- a/python_aternos/atconnect.py +++ b/python_aternos/atconnect.py @@ -201,6 +201,7 @@ class AternosConnect: old_cookies = self.session.cookies self.session = CloudScraper() self.session.cookies.update(old_cookies) + del old_cookies params = params or {} data = data or {} @@ -221,12 +222,22 @@ class AternosConnect: reqcookies['ATERNOS_SESSION'] = self.atsession del self.session.cookies['ATERNOS_SESSION'] + reqcookies_dbg = { + k: str(v or '')[:3] + for k, v in reqcookies.items() + } + + session_cookies_dbg = { + k: str(v or '')[:3] + for k, v in self.session.cookies.items() + } + logging.debug('Requesting(%s)%s', method, url) logging.debug('headers=%s', headers) logging.debug('params=%s', params) logging.debug('data=%s', data) - logging.debug('req-cookies=%s', reqcookies) - logging.debug('session-cookies=%s', self.session.cookies) + logging.debug('req-cookies=%s', reqcookies_dbg) + logging.debug('session-cookies=%s', session_cookies_dbg) if method == 'POST': sendreq = partial( diff --git a/tests/test_login.py b/tests/test_login.py index 3f6a50c..182f8f0 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -1,4 +1,5 @@ import unittest +from typing import Optional from python_aternos import Client @@ -9,6 +10,10 @@ AUTH_MD5 = '0efdb2cd6b36d5e54d0e3c161e567a4e' class TestLogin(unittest.TestCase): + def setUp(self) -> None: + + self.at: Optional[Client] = None + def test_md5(self) -> None: self.assertEqual( @@ -18,22 +23,32 @@ class TestLogin(unittest.TestCase): def test_auth(self) -> None: - at = Client.from_hashed(AUTH_USER, AUTH_MD5) - self.assertIsNotNone(at) + self.at = Client.from_hashed(AUTH_USER, AUTH_MD5) + self.assertIsNotNone(self.at) def test_servers(self) -> None: - at = Client.from_hashed( - AUTH_USER, AUTH_MD5 - ) + if self.at is None: + self.at = Client.from_hashed( + AUTH_USER, AUTH_MD5 + ) srvs = len( - at.list_servers( + self.at.list_servers( cache=False ) ) self.assertTrue(srvs > 0) + def test_logout(self) -> None: + + if self.at is None: + self.at = Client.from_hashed( + AUTH_USER, AUTH_MD5 + ) + + self.at.logout() + if __name__ == '__main__': unittest.main()