Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/libraries/Common/tests/Tests/Interop/OSReleaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,29 @@ public void GetPrettyName_NoFile_ReturnsNull()
Assert.Null(name);
}

[Fact, PlatformSpecific(TestPlatforms.Linux)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotPrivilegedProcess)), PlatformSpecific(TestPlatforms.Linux)]
public void GetPrettyName_CannotRead_ReturnsNull()
{
string path = CreateTestFile();
File.SetUnixFileMode(path, UnixFileMode.None);
Assert.ThrowsAny<Exception>(() => File.ReadAllText(path));

Assert.ThrowsAny<Exception>(() => File.ReadAllText(path));

string? name = Interop.OSReleaseFile.GetPrettyName(path);
Assert.Null(name);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsPrivilegedProcess)), PlatformSpecific(TestPlatforms.Linux)]
public void GetPrettyName_NonePrivileges_CanRead_ReturnsNull()
{
string path = CreateTestFile();
File.SetUnixFileMode(path, UnixFileMode.None);

// If user have root permissions, kernel doesn't care about access privileges,
// so there is no point in expecting System.Exception
Assert.Equal(UnixFileMode.None, File.GetUnixFileMode(path));
// Because kernel ignored privileges check, file should be readable and empty
Assert.Equal("", File.ReadAllText(path));

string? name = Interop.OSReleaseFile.GetPrettyName(path);
Assert.Null(name);
Expand Down