Example #1
0
    def test_redact(self):
        username = "******"
        password = "******"
        redacted = "REDACTED"

        print_statment = f"{username}'s password is {password}," \
            + "don't tell anyone"

        redacted_print = f"{redacted}'s password is {redacted}," \
            + "don't tell anyone"

        outcome = None

        redacted_list = [username, password]
        redacted_print_std = RedactedPrint(STDOutOptions.STDOUT, redacted_list)

        redacted_print_std.enable()

        file_path = "./TEST_REDACT.txt"
        with open(file_path, "w+") as content_file:
            content_file = RedactedFile(content_file, redacted_list)
            content_file.write(print_statment)

        with open(file_path, 'r') as content_file:
            outcome = content_file.read()

        os.remove(file_path)
        self.assertEqual(redacted_print, outcome)
Example #2
0
def add_new_user_instance(username):
    file_path = instance_path(state)
    if not check_user_exists(username):
        stored_username = custom_hash(username)
        with open(file_path, "a+") as instance_file:
            redacted_list = [username]
            instance_file = RedactedFile(instance_file, redacted_list)
            instance_file.write("{0} : {1}\n".format(stored_username,
                                                     os.getpid()))
        return True
    return False
Example #3
0
def remove_user_instance(username):
    file_path = instance_path(state)
    file = ""

    if not os.path.isfile(file_path):
        return

    stored_username = custom_hash(username)
    with open(file_path) as oldfile:
        for line in oldfile:
            if stored_username not in line:
                file += line
    with open(file_path, 'w+') as newfile:
        redacted_list = [username]
        newfile = RedactedFile(newfile, redacted_list)
        newfile.writelines(file)