runtime
468 / 500
question 468 Secure Python · hard

Test the path guard

safe_join(base, name) guards every download: it returns the resolved path of name inside base, and raises ValueError when the result would be outside base. Write unittest tests (or test_ functions) that pass for a correct guard and catch broken ones. Leave the calls to Check: don't run the tests yourself.

Targetsafe_join(base, name) → resolved Path inside base, or ValueError
Your testsa unittest.TestCase class or test_ functions in your file; the starter's guard is correct, so your tests should pass on it
Gradedyour tests must pass for a correct guard and fail for each of three broken guards

Loading your progress…

Test the path guard — Python practice · Runtime