From 4db1759dd9b3455446ddeeb6efb5fd9a3908985c Mon Sep 17 00:00:00 2001 From: DaveYesland Date: Thu, 4 Jan 2024 10:33:13 -0800 Subject: [PATCH] Remove old update checks, Pacu uses pip --- pacu/last_update.txt | 1 - pacu/main.py | 51 ------------------ tests/test_pacu_update.py | 105 -------------------------------------- 3 files changed, 157 deletions(-) delete mode 100644 pacu/last_update.txt delete mode 100644 tests/test_pacu_update.py diff --git a/pacu/last_update.txt b/pacu/last_update.txt deleted file mode 100644 index 1d9d9c60..00000000 --- a/pacu/last_update.txt +++ /dev/null @@ -1 +0,0 @@ -2021-04-20 diff --git a/pacu/main.py b/pacu/main.py index 0db5f8a5..d317b53b 100644 --- a/pacu/main.py +++ b/pacu/main.py @@ -465,54 +465,6 @@ def fetch_data(self, data: List[str], module: str, args: str, force=False) -> bo self.exec_module(['exec', module]) return True - def check_for_updates(self): - TIME_FORMAT = '%Y-%m-%d' - UPDATE_CYCLE = 7 # Days - UPDATE_INFO_PATH = lib.home_dir()/'update_info.json' - LAST_UPDATE_PATH = lib.pacu_dir()/'last_update.txt' - UPDATE_MSG = '''Pacu has a new version available! Clone it from GitHub to receive the updates. - git clone https://github.com/RhinoSecurityLabs/pacu.git''' - - with open(LAST_UPDATE_PATH, 'r') as f: - local_last_update = f.read().rstrip() - - datetime_now = datetime.now() - datetime_local = datetime.strptime(local_last_update, TIME_FORMAT) - - datetime_last_check = datetime.min - latest_cached = datetime.min - - # update_info.json structure: - # { 'last_check':'YYYY-MM-DD', 'latest_cached':'YYYY-MM-DD'} - # Create a update_info.json if not exist - update_info = {} - if os.path.isfile(UPDATE_INFO_PATH): - with open(UPDATE_INFO_PATH, 'r') as f: - update_info = json.load(f) - datetime_last_check = datetime.strptime(update_info['last_check'], TIME_FORMAT) - latest_cached = datetime.strptime(update_info['latest_cached'], TIME_FORMAT) - - # Check upstream - if (datetime_now - datetime_last_check).days >= UPDATE_CYCLE: - latest_update = requests.get( - 'https://raw.githubusercontent.com/RhinoSecurityLabs/pacu/master/pacu/last_update.txt').text.rstrip() - latest = datetime.strptime(latest_update, TIME_FORMAT) - - update_info['latest_cached'] = latest.strftime(TIME_FORMAT) - update_info['last_check'] = datetime_now.strftime(TIME_FORMAT) - with open(UPDATE_INFO_PATH, 'w') as f: - json.dump(update_info, f) - - if datetime_local < latest: - print(UPDATE_MSG) - return True - # Local check - elif datetime_local < latest_cached: - print(datetime_local, latest_cached) - print(UPDATE_MSG) - return True - return False - def key_info(self, alias='') -> Union[Dict[str, Any], bool]: """ Return the set of information stored in the session's active key or the session's key with a specified alias, as a dictionary. """ @@ -1889,8 +1841,6 @@ def run_gui(self) -> None: self.initialize_tab_completion() display_pacu_help() - self.check_for_updates() - idle_ready = True self.check_user_agent() @@ -1976,7 +1926,6 @@ def run(self) -> None: exit() self.run_cli(args) elif any([args.list_modules, args.pacu_help, args.module_info]): - self.check_for_updates() self.run_cli(args) else: self.run_gui() diff --git a/tests/test_pacu_update.py b/tests/test_pacu_update.py deleted file mode 100644 index 589a021b..00000000 --- a/tests/test_pacu_update.py +++ /dev/null @@ -1,105 +0,0 @@ -import io -import os -import json -import datetime - -from pacu.main import Main -from pacu.core import lib - -from unittest import mock -from freezegun import freeze_time - - -@mock.patch('requests.get') -@mock.patch('pacu.core.lib.home_dir') -@mock.patch('pacu.core.lib.pacu_dir') -def test_fresh_install(pacu_dir, home_dir, get, tmp_path): - pacu_dir.return_value = tmp_path - home_dir.return_value = tmp_path - get.return_value.text = '2021-01-01' - with open(tmp_path/'last_update.txt', 'w') as f: - f.write('2021-01-01') - - with freeze_time('2021-01-01'): - assert False == Main.check_for_updates(None) - - get.assert_called() - - assert os.path.isfile(tmp_path/'update_info.json') - with open(tmp_path/'update_info.json', 'r') as f: - update_info = json.load(f) - assert update_info['last_check'] == '2021-01-01' - assert update_info['latest_cached'] == '2021-01-01' - - -@mock.patch('requests.get') -@mock.patch('pacu.core.lib.home_dir') -@mock.patch('pacu.core.lib.pacu_dir') -def test_one_month_no_update(pacu_dir, home_dir, get, tmp_path): - pacu_dir.return_value = tmp_path - home_dir.return_value = tmp_path - get.return_value.text = '2021-01-01' - with open(tmp_path/'last_update.txt', 'w') as f: - f.write('2021-01-01') - - update_info = { - 'last_check': '2021-01-01', - 'latest_cached': '2021-01-01' - } - with open(tmp_path/'update_info.json', 'w') as f: - json.dump(update_info, f) - - with freeze_time('2021-02-01'): - assert False == Main.check_for_updates(None) - - get.assert_called() - - -@mock.patch('requests.get') -@mock.patch('pacu.core.lib.home_dir') -@mock.patch('pacu.core.lib.pacu_dir') -def test_one_month_updatable(pacu_dir, home_dir, get, tmp_path): - pacu_dir.return_value = tmp_path - home_dir.return_value = tmp_path - get.return_value.text = '2021-02-01' - with open(tmp_path/'last_update.txt', 'w') as f: - f.write('2021-01-01') - - update_info = { - 'last_check': '2021-01-01', - 'latest_cached': '2021-01-01' - } - with open(tmp_path/'update_info.json', 'w') as f: - json.dump(update_info, f) - - with freeze_time('2021-02-01'): - assert True == Main.check_for_updates(None) - - get.assert_called() - - with open(tmp_path/'update_info.json', 'r') as f: - update_info = json.load(f) - assert update_info['last_check'] == '2021-02-01' - assert update_info['latest_cached'] == '2021-02-01' - - -@mock.patch('requests.get') -@mock.patch('pacu.core.lib.home_dir') -@mock.patch('pacu.core.lib.pacu_dir') -def test_local_updatable(pacu_dir, home_dir, get, tmp_path): - pacu_dir.return_value = tmp_path - home_dir.return_value = tmp_path - with open(tmp_path/'last_update.txt','w') as f: - f.write('2021-01-01') - - update_info = { - 'last_check': '2021-01-01', - 'latest_cached': '2021-02-01' - } - with open(tmp_path/'update_info.json', 'w') as f: - json.dump(update_info, f) - - with freeze_time('2021-01-01'): - assert True == Main.check_for_updates(None) - - get.assert_not_called()