|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Runtime.Versioning; |
4 | 5 | using System.Text.Json;
|
5 | 6 | using Microsoft.CodeAnalysis;
|
6 | 7 | using Microsoft.DotNet.Cli.Commands;
|
@@ -809,6 +810,42 @@ public void NoBuild_02()
|
809 | 810 | .And.HaveStdOut("Changed");
|
810 | 811 | }
|
811 | 812 |
|
| 813 | + [PlatformSpecificFact(TestPlatforms.AnyUnix), UnsupportedOSPlatform("windows")] |
| 814 | + public void ArtifactsDirectory_Permissions() |
| 815 | + { |
| 816 | + var testInstance = _testAssetsManager.CreateTestDirectory(); |
| 817 | + var programFile = Path.Join(testInstance.Path, "Program.cs"); |
| 818 | + File.WriteAllText(programFile, s_program); |
| 819 | + |
| 820 | + // Remove artifacts from possible previous runs of this test. |
| 821 | + var artifactsDir = VirtualProjectBuildingCommand.GetArtifactsPath(programFile); |
| 822 | + if (Directory.Exists(artifactsDir)) Directory.Delete(artifactsDir, recursive: true); |
| 823 | + |
| 824 | + new DotnetCommand(Log, "build", "Program.cs") |
| 825 | + .WithWorkingDirectory(testInstance.Path) |
| 826 | + .Execute() |
| 827 | + .Should().Pass(); |
| 828 | + |
| 829 | + new DirectoryInfo(artifactsDir).UnixFileMode |
| 830 | + .Should().Be(UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute, artifactsDir); |
| 831 | + |
| 832 | + // Re-create directory with incorrect permissions. |
| 833 | + Directory.Delete(artifactsDir, recursive: true); |
| 834 | + Directory.CreateDirectory(artifactsDir, UnixFileMode.GroupRead | UnixFileMode.GroupWrite | UnixFileMode.GroupExecute); |
| 835 | + var actualMode = new DirectoryInfo(artifactsDir).UnixFileMode |
| 836 | + .Should().NotBe(UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute, artifactsDir).And.Subject; |
| 837 | + |
| 838 | + new DotnetCommand(Log, "build", "Program.cs") |
| 839 | + .WithWorkingDirectory(testInstance.Path) |
| 840 | + .Execute() |
| 841 | + .Should().Fail() |
| 842 | + .And.HaveStdErrContaining("build-start.cache"); // Unhandled exception: Access to the path '.../build-start.cache' is denied. |
| 843 | + |
| 844 | + // Build shouldn't have changed the permissions. |
| 845 | + new DirectoryInfo(artifactsDir).UnixFileMode |
| 846 | + .Should().Be(actualMode, artifactsDir); |
| 847 | + } |
| 848 | + |
812 | 849 | [Fact]
|
813 | 850 | public void LaunchProfile()
|
814 | 851 | {
|
|
0 commit comments