-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileSystem.AccessControl tests not cleaning files properly #47074
Conversation
Thank you, @danmosemsft for your suggestion to look inside the TempDirectory dispose/finalizer code. |
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
914a68a
to
09e2397
Compare
The last commit has the When the CI finishes successfully, I'll uncomment the |
All checks passed for commit ed55700 with the try catch commented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please run the code coverage report and verify that it is not being regressed by this change? You can do so by running dotnet build /t:test /p:coverage=true
.
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Outdated
Show resolved
Hide resolved
I compared before and after my changes (making sure I had the same commit as the baseline for both runs). There is a ~1% reduction in code coverage in the System.IO.FileSystem.AccessControl unit tests. I needed to remove some @danmosemsft is a ~1% code coverage reduction tolerated? Would we consider it a blocker for merging? Before:
After:
AFTER_coverage.opencover.xml.txt |
We trust your judgement as the engineering owner of this area. Whether or not we should, we've not (except maybe in JSON) applied a hard rule - or even been consistent about measuring it. My inclination would be: the most important thing is whether something significant has been left uncovered, than reaching a particular number. |
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.
… Bring back InlineData for test, but only when a Read is included.
614e44c
to
df559c0
Compare
The unit test failures are unrelated to my change:
|
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
…. Bring back all FileSystemRights with annotations on why some need to be skipped. Ensure DeleteDirectory can successfully reset permissions before deleting all files and folders deleted by the unit test.
@jozkee @adamsitnik I submitted a new commit where I address your suggestions:
I ran all these tests with the |
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
[Fact] | ||
public void DirectorySecurity_CreateDirectory_DefaultDirectorySecurity() | ||
{ | ||
DirectorySecurity security = new DirectorySecurity(); | ||
Verify_DirectorySecurity_CreateDirectory(security); | ||
} | ||
|
||
[Theory] | ||
[InlineData(FileSystemRights.ReadAndExecute, AccessControlType.Allow)] | ||
[InlineData(FileSystemRights.ReadAndExecute, AccessControlType.Deny)] | ||
[InlineData(FileSystemRights.WriteData, AccessControlType.Allow)] | ||
[InlineData(FileSystemRights.WriteData, AccessControlType.Deny)] | ||
[InlineData(FileSystemRights.FullControl, AccessControlType.Allow)] | ||
[InlineData(FileSystemRights.FullControl, AccessControlType.Deny)] | ||
public void DirectorySecurity_CreateDirectory_DirectorySecurityWithSpecificAccessRule( | ||
FileSystemRights rights, | ||
AccessControlType controlType) | ||
{ | ||
DirectorySecurity security = GetDirectorySecurity(rights, controlType); | ||
Verify_DirectorySecurity_CreateDirectory(security); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like these two tests are still missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I improved this test and renamed it to DirectoryInfo_Create_MultipleAddAccessRules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about DirectorySecurity_CreateDirectory_DefaultDirectorySecurity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like DirectorySecurity_CreateDirectory_DefaultDirectorySecurity is testing the same as DirectoryInfo_Create_DefaultDirectorySecurity. How odd.
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/TempAclDirectory.cs
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs
Outdated
Show resolved
Hide resolved
Code coverage with the latest commits:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @carlossanlop
also big thanks to @jozkee for a great review!
I'm investigating this failure in mono x64 windows release:
|
Not sure why all the Linux CI legs failed to install the SDK during the build step. I'm restarting them. |
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: