Skip to content

FileSystem.AccessControl tests not cleaning files properly#47074

Merged
carlossanlop merged 14 commits intodotnet:masterfrom
carlossanlop:ACLTests
Feb 9, 2021
Merged

FileSystem.AccessControl tests not cleaning files properly#47074
carlossanlop merged 14 commits intodotnet:masterfrom
carlossanlop:ACLTests

Conversation

@carlossanlop
Copy link
Copy Markdown
Contributor

Fixes #44766

The TempDirectory helper class is disposable. The finalizer calls a function that deletes the folders left behind, without throwing exceptions on fail.

This protective try catch hid some additional errors that were not caught when these unit tests were first written, so I'm fixing them:

  • I created a class that inherits from TempDirectory to override the folder deleting method
  • In the finalizer, I iterate through all the files and folders created by the test, ensure their ACLs give me full control (in case the tests prevent deletion), then attempt to delete the tree.
  • To verify my changes, I did not put the finalizer code in a try catch, so I could see the errors thrown when attempting to delete the tree.
  • The deletion exceptions helped me find that GetAccessControl needs to be called with the AccessControlSections.Access argument, otherwise they throw "PrivilegeNotHeldException: The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation."
  • I avoided creating files and directories using a FileSecurity or DirectorySecurity that did not have its access rules defined. Files and folders created this way could not be deleted.
  • I avoided testing AccessControlType.Deny. This would also cause deletion exceptions.
  • Moved some repeated code into common methods.
  • Before commiting, I made sure to put the file/folder deletion code inside a try catch to prevent finalizer exceptions.

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.IO.FileSystem.AccessControl tests leave behind files ACL'ed to be difficult to delete

4 participants