def test_case_clarify_write_inverts_read_example(self): """Tests the write then read workflow of keyring.clarify.""" theResult = False someMessageText = str("This is a test Message") try: from piaplib.keyring import clarify as clarify if clarify.__name__ is None: raise ImportError("Failed to import clarify") elif (clarify.hasBackendCommand() is not True): raise unittest.SkipTest("Requires backend tool") from piaplib.keyring import rand as rand if rand.__name__ is None: raise ImportError("Failed to import rand") sometestfile = str("/tmp/the_test_file.enc") theteststore = clarify.makeKeystoreFile( str("testkeyneedstobelong"), str("/tmp/.weak_test_key_{}").format(rand.randInt(1, 10, 99))) self.assertIsNotNone(theteststore, "Bad Test Env: No Test Keystore") test_write = clarify.packToFile(sometestfile, str(someMessageText), theteststore) self.assertTrue(test_write) if (test_write is True): test_read = clarify.unpackFromFile(sometestfile, theteststore) clean_temp_file(theteststore) try: if isinstance(test_read, bytes): test_read = test_read.decode( """utf-8""", errors=clarify.getCTLModeForPY()) except UnicodeDecodeError: test_read = str(repr(bytes(test_read, """utf-8"""))) self.assertIsNotNone(test_read) self.assertIsInstance(test_read, str, "Test output is Not a string") self.assertIsInstance(someMessageText, str, "Test input is Not a string") if (str(someMessageText) in str(test_read)): theResult = True else: if sys.platform.startswith( "linux") or sys.platform.startswith("darwin"): print(str(repr(bytes(test_read, """utf-8""")))) theResult = False else: raise unittest.SkipTest( "BETA. Experemental feature not ready yet.") except Exception as err: print(str("")) print(str(type(err))) print(str(err)) print(str((err.args))) print(str("")) err = None del err if sys.platform.startswith("linux"): theResult = False else: raise unittest.SkipTest( "BETA. Experemental feature not ready yet.") self.assertTrue(theResult, """the write then read workflow failed""")
def test_z_case_clarify_setKeyFile_none(self): """Tests the helper function makeKeystoreFile(None) of keyring.clarify""" theResult = False try: from piaplib.keyring import clarify as clarify if clarify.__name__ is None: raise ImportError("Failed to import clarify") self.assertIsNotNone(clarify.makeKeystoreFile(None)) theResult = True except Exception as err: print(str("")) print(str(type(err))) print(str(err)) print(str((err.args))) print(str("")) self.skip(str("""[CWE-754] Error prevents proper test.""")) err = None del err theResult = False assert theResult
def test_case_clarify_write_inverts_read(self, someInput): # noqa C901 """Tests the write then read workflow of keyring.clarify with fuzzing.""" theResult = False someInput = str(someInput) assume(isinstance(someInput, str)) assume(len(str(someInput)) > 3) assume("""\"""" not in str(someInput)) assume("""'""" not in str(someInput)) assume(repr(str(someInput)) not in repr(str(repr(someInput)))) from piaplib.pku import utils as utils if utils.__name__ is None: raise ImportError("Failed to import utils") assume(str(someInput) in utils.literal_str(someInput)) assume(utils.literal_str(someInput) in str(someInput)) assume( utils.literal_str(someInput) in utils.literal_code(str(someInput))) assume( utils.literal_code(str(someInput)) in utils.literal_str(someInput)) assume(someInput in str(someInput)) someMessageText = str(repr(someInput)) try: from piaplib.keyring import clarify as clarify if clarify.__name__ is None: raise ImportError("Failed to import clarify") elif (clarify.hasBackendCommand() is not True): raise unittest.SkipTest("Requires backend tool") from piaplib.keyring import rand as rand if rand.__name__ is None: raise ImportError("Failed to import rand") sometestfile = str("./the_test_file.enc") theteststore = clarify.makeKeystoreFile( str("testkeyneedstobelong"), str("./.weak_test_key_{}").format(rand.randInt(1, 10, 99))) assume((theteststore is not None)) self.assertIsNotNone(theteststore) test_write = clarify.packToFile(sometestfile, str(someMessageText), theteststore) assume(test_write is True) self.assertTrue(test_write) check_wrap = clarify.packForRest(str(someMessageText), theteststore) assume((check_wrap is not None)) try: note( str("encoded: \"{}\"").format( utils.literal_str(someMessageText))) note(str("as str: \"{}\"").format(str(someMessageText))) note( str("as data: \"{}\"").format( utils.literal_str(check_wrap))) except Exception as noteErr: raise unittest.SkipTest(noteErr) noteErr = None del noteErr if (test_write is True): test_read = clarify.unpackFromFile(sometestfile, theteststore) try: if isinstance(test_read, bytes): test_read = test_read.decode( """utf-8""", errors=clarify.getCTLModeForPY()) except UnicodeDecodeError: test_read = str(repr(bytes(test_read, """utf-8"""))) assume(False) self.assertIsNotNone(test_read) if (str(someMessageText) in str(test_read)): theResult = True else: note( str("failed test: \"{}\" is not in \"{}\"").format( str(someMessageText), str(test_read))) note( str("decoded: \"{}\"").format( utils.literal_str(test_read))) note( str("should decoded: \"{}\"").format( utils.literal_code(str(someMessageText)))) note( str("from undecoded: \"{}\"").format( utils.literal_str(utils.readFile(sometestfile)))) note( str("with keystore: \"{}\"").format( utils.literal_str(theteststore))) theResult = False clean_temp_file(theteststore) except Exception as err: print(str("")) print(str(type(err))) print(str(err)) print(str((err.args))) print(str("")) err = None del err if sys.platform.startswith("linux"): theResult = False else: raise unittest.SkipTest( "BETA. Experemental feature not ready yet.") self.assertTrue(theResult, """fuzzing the write then read workflow failed""")