def setUpClass(self): # Setup test_data dictionary to hold test data dictionary. # Setup return_data to hold the dictionary returned from # the sign_json call. test_data["data"] = {'hostname': 'inapp11wk20', 'os': 'Darwin Kernel 12.6.0', 'Arguments': '-v'} # Call the sign_json function to populate the test_data dictonary. return_data["cdata"] = signing.sign_json(test_data["data"]).copy()
def test_keystore(self): # Compare the before/after timestamp of keystore file # to confirm the file was updated. Also, check at least # one line exists is in the file to validate file write # occurs. time1 = utils.get_file_modification_time(KEYFILE) signing.sign_json(test_data["data"].copy()) time2 = utils.get_file_modification_time(KEYFILE) count2 = utils.file_line_counter(KEYFILE) # Raise an error if the keystore file hasn't updated after signing. self.assertTrue(time1 < time2, "The " + KEYFILE + " file was NOT updated after signing.") # Raise an error if the keystore does not contain at least 1 entry # after signing. self.assertTrue(count2 >= 1, "The " + KEYFILE + " file does NOT contain an entry.") # Search the file and make sure that we cannot see the public key. found_word = utils.word_found_in_file(KEYFILE, "public") self.assertFalse(found_word, "The keystore.txt file contains word 'public'.")
def setUpClass(self): # Setup test_data dictionary to hold test data dictionary. # Setup return_data to hold the dictionary returned from # the sign_json call. test_data["data"] = { 'hostname': 'inapp11wk20', 'os': 'Darwin Kernel 12.6.0', 'Arguments': '-v' } # Call the sign_json function to populate the test_data dictonary. return_data["cdata"] = signing.sign_json(test_data["data"]).copy()
def test_keystore(self): # Compare the before/after timestamp of keystore file # to confirm the file was updated. Also, check at least # one line exists is in the file to validate file write # occurs. time1 = utils.get_file_modification_time(KEYFILE) signing.sign_json(test_data["data"].copy()) time2 = utils.get_file_modification_time(KEYFILE) count2 = utils.file_line_counter(KEYFILE) # Raise an error if the keystore file hasn't updated after signing. self.assertTrue( time1 < time2, "The " + KEYFILE + " file was NOT updated after signing.") # Raise an error if the keystore does not contain at least 1 entry # after signing. self.assertTrue(count2 >= 1, "The " + KEYFILE + " file does NOT contain an entry.") # Search the file and make sure that we cannot see the public key. found_word = utils.word_found_in_file(KEYFILE, "public") self.assertFalse(found_word, "The keystore.txt file contains word 'public'.")
def main(): """ <Purpose> Straightforward function to encapsulate the program's core logic. Called at the end of this file. <Arguments> None. <Exceptions> TBD. <Return> None. """ # Setup the command line parser args = get_command_line_args() # Grab the command line arguments cmd_string = args.command input_filepath = args.input if args.policy: policy_filepath = args.policy else: home_directory = os.path.dirname(os.path.realpath(__file__)) policy_filepath = os.path.join(home_directory, DEFAULT_POLICY_FILENAME) # Setup the metadata dictionary metadata = dict() metadata['variables'] = dict() metadata['application'] = dict() # Execute the given command and fill the metadata dict process_env_vars(metadata) stdout, stderr, return_code = exec_cmd(cmd_string, input_filepath) process_app_data(metadata, cmd_string, input_filepath, stdout, stderr, return_code) policy_dict = process_policy_file(metadata, policy_filepath) check_file_against_wordlists(metadata, policy_dict["supplied_data"]["word_lists"], "out", "output_data") check_file_against_wordlists(metadata, policy_dict["supplied_data"]["word_lists"], "err", "err_data") # Generate the signed JSON signed_metadata = signing.sign_json(metadata) utils.gen_json(signed_metadata, "metadata")