def verify_tokens(self): try: db: Session = self.sc_session() tokens = db.query(tb_tokens).all() db.close() except: print( "The token table is corrupted. If you modified your database encryption secret key located in your " "config file all existing tokens become invalid. Insight will not work until this issue is resolved. " "You must either restore your previous encryption key or delete all existing tokens." ) with open(0) as i: sys.stdin = i resp = input( "\n\nReset all tokens? Note: You will be unable to use Insight until this error goes away. " "[Y/n]: ").lower() if resp.startswith('y'): tb_contacts_alliances.__table__.drop(self.engine) tb_contacts_corps.__table__.drop(self.engine) tb_contacts_pilots.__table__.drop(self.engine) tb_discord_tokens.__table__.drop(self.engine) tb_tokens.__table__.drop(self.engine) ColumnEncryption().reset_key() print("Issue resolved. You must restart Insight.") sys.exit(0) elif resp.startswith('n'): print( "No changes you were made. You must resolve this issue before starting Insight." ) sys.exit(1) else: print("Unknown response. No changes were made.") sys.exit(1)
def setUp(self): super().setUp() ColumnEncryption()._set_random_key() self.sso = EVEsso.EVEsso(self.service) self.service.sso = self.sso self.client_id = os.environ.get("sso_client_id") self.secret_key = os.environ.get("sso_secret_key") self.callback_url = os.environ.get("sso_callback_url") self.refresh_token = os.environ.get("sso_refresh_token") self.assert_char_id = int(os.environ.get("sso_char_id")) self.assert_corp_id = int(os.environ.get("sso_corp_id")) self.assert_alliance_id = int(os.environ.get("sso_alliance_id")) self.assert_sso_login = "******" \ "&client_id={}&scope=esi-characters.read_contacts.v1%20esi-corporations.read_" \ "contacts.v1%20esi-alliances.read_contacts.v1".format(self.callback_url, self.client_id)
def verify_tokens(self): db: Session = self.sc_session() try: tokens = db.query(tb_tokens).all() db.close() except: db.close() env_auto_purge_on_error = self.service.config.get( "CLEAR_TOKEN_TABLE_ON_ERROR") print( "The token table is corrupted. If you modified your database encryption secret key located in your " "config file all existing tokens become invalid. Insight will not work until this issue is resolved. " "You must either restore your previous encryption key or delete all existing tokens." ) if not env_auto_purge_on_error: with open(0) as i: sys.stdin = i resp = input( "\n\nReset all tokens? Note: You will be unable to use Insight until this error goes away. " "[Y/n]: ").lower() else: print( "Auto purging token table as env var \"CLEAR_TOKEN_TABLE_ON_ERROR\" is TRUE." ) resp = "y" if resp.startswith('y'): self.engine.execute("DELETE FROM discord_tokens;") self.engine.execute("DELETE FROM contacts_characters;") self.engine.execute("DELETE FROM contacts_corporations;") self.engine.execute("DELETE FROM contacts_alliances;") self.engine.execute("DELETE FROM tokens;") ColumnEncryption().reset_key() print("Issue resolved. You must restart Insight.") sys.exit(0) elif resp.startswith('n'): print( "No changes you were made. You must resolve this issue before starting Insight." ) sys.exit(1) else: print("Unknown response. No changes were made.") sys.exit(1)
def setUp(self): super().setUp() self.set_resource_path("config") shutil.copy(os.path.join(self.resources, "config.ini"), os.getcwd()) self.ce = ColumnEncryption()
class TestColumnEncryption(InsightTestBase.InsightTestBase): def setUp(self): super().setUp() self.set_resource_path("config") shutil.copy(os.path.join(self.resources, "config.ini"), os.getcwd()) self.ce = ColumnEncryption() def tearDown(self): super().tearDown() InsightSingleton.clear_instance_references() if os.path.exists("config.ini"): os.remove("config.ini") def helper_current_key_in_file(self): cfile = configparser.ConfigParser() cfile.read(self.ce._config_file_path) return cfile.get("encryption", "secret_key") def test__generate_new_key(self): k1 = self.ce._generate_new_key() self.assertLess(64, len(k1)) self.assertNotEqual(k1, self.ce._generate_new_key()) def test__set_key(self): k = self.ce._generate_new_key() self.ce._set_key(k) self.assertEqual(k, self.ce._key) def test__load_key(self): self.ce._load_key() k = self.helper_current_key_in_file() self.assertIsInstance(k, str) self.assertLess(64, len(k)) self.assertEqual(k, self.ce._key) self.assertEqual(k, self.ce.get_key()) self.ce._load_key() self.assertEqual(k, self.ce._key) def test_get_key(self): k = self.ce.get_key() self.assertIsInstance(k, str) self.assertLess(64, len(k)) def test_reset_key(self): k1 = self.ce.get_key() self.assertLess(64, len(k1)) self.assertEqual(k1, self.helper_current_key_in_file()) self.ce.reset_key() k2 = self.ce.get_key() self.assertNotEqual(k1, k2) self.assertLess(64, len(k2)) self.assertEqual(k2, self.helper_current_key_in_file())
def setUpClass(cls): super().setUpClass() ColumnEncryption()._set_random_key()
def setUp(self): super().setUp() self.db.add(tb_tokens(1, "test123")) self.db.commit() self.db.close() ColumnEncryption()._set_random_key()