Lock/unlock did not return error on missing key

This has been fixed, and the appropriate unit tests have been added.