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_case_clarify_main_keyring(self):
     """Tests the helper function main unpack of keyring.main(clarify)"""
     theResult = False
     try:
         from piaplib.pku import utils as utils
         if utils.__name__ is None:
             raise ImportError("Failed to import utils")
         import piaplib.keyring.__main__
         temp_msg = None
         test_args = []
         if sys.platform.startswith("linux") or True:
             temp_msg = str(
                 """U2FsdGVkX1/MMOdV6OYwAURQQg9b9K1AoVA0OCcanG9FjHk7gHk=""")
             test_args = [
                 str("clarify"),
                 str("--unpack"),
                 str("--msg='{}'").format(temp_msg),
                 str("-K=testkeyneedstobelong")
             ]
         else:
             temp_msg = str(
                 """U2FsdGVkX1/beHoH2ziXWcMFpb3fzzPxQqdeU1tO5UVoBUEnow8T9g=="""
             )
             test_args = [
                 str("clarify"),
                 str("--unpack"),
                 str("--msg={}").format(str(temp_msg)),
                 str("-K=testkeyneedstobelong")
             ]
         print(
             str("... test: piaplib.keyring.__main__({})").format(
                 str(test_args)))
         test_out = piaplib.keyring.__main__.main(test_args)
         print(str("... checking"))
         self.assertIsNotNone(test_out)
         self.assertIsNotNone(str(test_out))
         print(str("... is not none: PASS"))
         if (int(0) == int(test_out)):
             theResult = True
         else:
             if sys.platform.startswith("darwin"):
                 print(str(test_out))
                 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("darwin"):
             theResult = False
         else:
             raise unittest.SkipTest(
                 "BETA. Experemental feature not ready yet.")
     assert theResult
 def test_case_utils_read_url_file(self):
     """Tests the fetch url and clean functions"""
     theResult = False
     try:
         from piaplib import pku as pku
         if pku.__name__ is None:
             raise ImportError("Failed to import pku")
         from pku import utils as utils
         if utils.__name__ is None:
             raise ImportError("Failed to import utils")
         someURL = str(
             "https://raw.githubusercontent.com/reactive-firewall" +
             "/PiAP-python-tools/master/requirements.txt")
         somefile = str("the_test_url_file.txt")
         if (utils.getFileResource(someURL, somefile) is True):
             utils.cleanFileResource(somefile)
             theResult = True
         else:
             theResult = False
         if (theResult is False):
             if sys.platform.startswith("linux"):
                 print(str("fetch failed"))
                 print(str(""))
             else:
                 raise unittest.SkipTest(
                     "BETA. Experemental feature not ready yet.")
     except unittest.SkipTest as skiper:
         skiper = None
         del skiper
         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
         theResult = False
     self.assertTrue(theResult)
 def test_case_clarify_main_a(self):
     """Tests the helper function main pack of keyring.clarify"""
     theResult = False
     try:
         from piaplib.keyring import clarify as clarify
         if clarify.__name__ is None:
             raise ImportError("Failed to import clarify")
         test_out = clarify.main([
             str("--pack"),
             str("--msg=\"This is a test Message\""),
             str("-K=testkeyneedstobelong")
         ])
         self.assertIsNotNone(test_out)
         try:
             if isinstance(test_out, bytes):
                 test_out = test_out.decode("""utf-8""")
         except UnicodeDecodeError:
             test_out = str(
                 repr(
                     bytes(test_out).decode(
                         """utf-8""", errors=clarify.getCTLModeForPY())))
         if (str("U2FsdGVkX") in str(test_out)):
             theResult = True
         else:
             theResult = False
     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.")
     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""")
 def test_case_clarify_main_b(self):
     """Tests the helper function main unpack of keyring.clarify"""
     theResult = False
     try:
         from piaplib.pku import utils as utils
         if utils.__name__ is None:
             raise ImportError("Failed to import utils")
         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")
         temp_msg = None
         test_args = []
         # temp_msg = str("""U2FsdGVkX1+dD6bFlND+Xa0bzNttrZfB5zYCp0mSEYfhMTpaM7U=""")
         if sys.platform.startswith("linux"):
             # temp_msg = str("""U2FsdGVkX1+dD6bFlND+Xa0bzNttrZfB5zYCp0mSEYfhMTpaM7U=""")
             temp_msg = str(
                 """U2FsdGVkX1/MMOdV6OYwAURQQg9b9K1AoVA0OCcanG9FjHk7gHk=""")
             test_args = [
                 str("--unpack"),
                 str("--msg=\"{}\"").format(temp_msg),
                 str("-K=testkeyneedstobelong")
             ]
         else:
             temp_msg = str(
                 """U2FsdGVkX1/beHoH2ziXWcMFpb3fzzPxQqdeU1tO5UVoBUEnow8T9g=="""
             )
             test_args = [
                 str("--unpack"),
                 str("--msg={}").format(str(temp_msg)),
                 str("-K=testkeyneedstobelong")
             ]
         print(str("... args {}").format(str(test_args)))
         print(str("... test"))
         test_out = clarify.main(test_args)
         print(str("... checking"))
         try:
             if isinstance(test_out, bytes):
                 test_out = test_out.decode(
                     """utf-8""", errors=clarify.getCTLModeForPY())
         except UnicodeDecodeError as unierr:
             print(str(type(unierr)))
             print(str(unierr))
             test_out = str(
                 repr(
                     bytes(test_out, encoding="""utf-8""").decode(
                         """utf-8""", errors=clarify.getCTLModeForPY())))
         print(str("... assert not none or junk"))
         self.assertIsNotNone(test_out)
         self.assertIsNotNone(str(test_out))
         print(str("... assert not junk"))
         if (str("""This is a test Message""") in str(test_out)):
             theResult = True
         else:
             if sys.platform.startswith("linux") or sys.platform.startswith(
                     "darwin"):
                 print(
                     str(
                         repr(
                             bytes(test_out, encoding="""utf-8""").decode(
                                 """utf-8""",
                                 errors=clarify.getCTLModeForPY()))))
                 theResult = False
                 print(str(""))
                 print(str("... DECODE BUG CONFIRMED ..."))
                 print(str(""))
                 print(str(test_out))
                 print(str("vs"))
                 print(str("""This is a test Message"""))
             else:
                 raise unittest.SkipTest(
                     "BETA. Experemental feature not ready yet.")
     except Exception as err:
         print(str(""))
         print(str(sys.getdefaultencoding()))
         print(str(type(err)))
         print(str(err))
         print(str((err.args)))
         print(str(""))
         err = None
         del err
         if sys.platform.startswith("linux") or sys.platform.startswith(
                 "darwin"):
             theResult = False
         else:
             raise unittest.SkipTest(
                 "BETA. Experemental feature not ready yet.")
     assert theResult
示例#7
0
 def test_keyring_salt_test_entropy(self):
     """Test deversity of saltify hashes."""
     theResult = True
     try:
         from piaplib import keyring as keyring
         from keyring import saltify as saltify
         from keyring import rand as rand
         for depends in [keyring, saltify, rand]:
             if depends.__name__ is None:
                 theResult = False
         randomSalt = str(rand.randStr(10))
         space = str(""" """)
         randomSalt_shift1 = randomSalt + space
         randomSalt_shift2 = randomSalt_shift1 + space
         randomSalt_shift3 = randomSalt_shift2 + space
         randomSalt_shift4 = randomSalt_shift3 + space
         randomSalt_shift5 = randomSalt_shift4 + space
         randomSalt_shift6 = randomSalt_shift5 + space
         randomSalt_shift7 = randomSalt_shift6 + space
         randomSalt_shift8 = randomSalt_shift7 + space
         randomSalt_shift9 = randomSalt_shift8 + space
         randomSalt_shiftX = randomSalt_shift9 + space
         salt_list = [
             randomSalt, randomSalt_shift1, randomSalt_shift2,
             randomSalt_shift3, randomSalt_shift4, randomSalt_shift5,
             randomSalt_shift6, randomSalt_shift7, randomSalt_shift8,
             randomSalt_shift9, randomSalt_shiftX
         ]
         if theResult is not True:
             self.assertTrue(theResult)
         for someRandomTest in range(10000):
             this_test = str(rand.randStr(10))
             that_test = str(rand.randStr(10))
             try:
                 with self.subTest(i=someRandomTest,
                                   this_test=that_test,
                                   that_test=that_test):
                     self.assertIsNotNone(that_test)
                     self.assertIsNotNone(this_test)
                     self.assertNotEqual(this_test, that_test)
                     for test_salt in salt_list:
                         a = saltify.saltify(str(this_test),
                                             str(randomSalt))
                         b = saltify.saltify(str(that_test), str(test_salt))
                         self.assertIsNotNone(a)
                         self.assertIsInstance(a, str)
                         self.assertIsNotNone(b)
                         self.assertIsInstance(b, str)
                         self.assertNotEqual(a, b)
             except Exception:
                 raise unittest.SkipTest()
     except unittest.SkipTest:
         raise unittest.SkipTest(
             "Testing Framework does not allow subTest()")
     except Exception as testErr:
         print(str("Entropy - Fuzzing Crash Found new test"))
         print(str(""))
         print(str(type(testErr)))
         print(str(testErr))
         print(str((testErr.args)))
         print(str(""))
         testErr = None
         del (testErr)
         theResult = False
     assert theResult