← Table of Contents · Page 667 of 868

PROJECT ONE - A MINIMAL HARNESS

Part 5 of 11

TESTING THE GATE Never trust a safety rule you have not tried to break. Save the short test below as test_gate.py and run it with python test_gate.py It asks the gate for files outside the resumes folder in three sneaky ways and then for one allowed file. File: test_gate.py [START OF PYTHON CODE] # Module docstring stating the purpose of this file: trying to break the permission gate on purpose """test_gate.py - tries to break the permission gate.""" # Import the custom error type and the read-check function from the permission gate from permission_gate import GateDenied, check_read # Try four different paths: three sneaky attempts to escape the resumes folder, and one allowed file for path in ["../secret.txt", "resumes/../main_loop.py", "C:/Windows/win.ini", "resumes/resume_01.txt"]: # Attempt to pass this path through the read-permission check try: check_read(path) # If the gate did not raise an error, the path was allowed print("ALLOWED", path) # If the gate raised its custom error, the path was correctly denied except GateDenied: print("DENIED ", path) [END OF PYTHON CODE] The first three should print DENIED and the last should print ALLOWED. If any sneaky path prints ALLOWED, your gate has a hole and must be fixed before you go on.
Advertisement
Read Aloud:
0:00 / 0:00