public async Task UploadFile() { // Verify that we can upload a text file to the distribution // and set its owner and permissions. var imagePath = await TestHelper.GetTestImageAsync(); using (var tempFolder = new TempFolder()) { try { Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); var distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); var text = @"Line 1 Line 2 Line 3 Line 4 "; // Write a file using the defaults to convert CRLF-->LF with // no special permissions. distro.UploadFile($"/home/{KubeConst.SysAdminUser}/test1.txt", text, toLinuxText: true); Assert.Equal("Line 1\nLine 2\nLine 3\nLine 4\n", File.ReadAllText(distro.ToWindowsPath($"/home/{KubeConst.SysAdminUser}/test1.txt"))); var response = distro.SudoExecute("ls", "-l", $"/home/{KubeConst.SysAdminUser}/test1.txt"); response.EnsureSuccess(); Assert.StartsWith("-rw-r--r-- ", response.OutputText); // Write another file using the leaving the line endings as CRLF // and some permissions. Also verify that the file is owned by // the default distro user. distro.UploadFile($"/home/{KubeConst.SysAdminUser}/test2.txt", text, permissions: "666", toLinuxText: false); Assert.Equal("Line 1\r\nLine 2\r\nLine 3\r\nLine 4\r\n", File.ReadAllText(distro.ToWindowsPath($"/home/{KubeConst.SysAdminUser}/test2.txt"))); response = distro.SudoExecute("ls", "-l", $"/home/{KubeConst.SysAdminUser}/test2.txt"); response.EnsureSuccess(); Assert.StartsWith("-rw-rw-rw- ", response.OutputText); Assert.Contains($"{KubeConst.SysAdminUser} {KubeConst.SysAdminUser}", response.OutputText); } finally { TestHelper.RemoveTestDistro(); } } }
public async Task Execute_WithPathSpaces() { // Verify that we can execute SUDO and non-SUDO commands from a temporary // folder that includes spaces. This happens when the user's Windows username // include spaces. var imagePath = await TestHelper.GetTestImageAsync(); using (var folderWithSpaces = new TempFolder(folder: Path.Combine(Path.GetTempPath(), $"test {Guid.NewGuid().ToString("d")}"))) { using (var tempFolder = new TempFolder()) { try { Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); var distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); distro.TempFolder = folderWithSpaces.Path; Assert.Contains("Hello World!", distro.Execute("echo", "Hello World!").OutputText); Assert.Contains("Hello World!", distro.SudoExecute("echo", "Hello World!").OutputText); } finally { TestHelper.RemoveTestDistro(); } } } }
public async Task NoSudoPassword() { // Verify that the distribution doesn't prompt for a SUDO password. var imagePath = await TestHelper.GetTestImageAsync(); using (var tempFolder = new TempFolder()) { try { Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); Assert.True(Wsl2Proxy.Exists(TestHelper.TestDistroName)); var distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); Assert.Contains("Hello World!", distro.SudoExecute("echo", "Hello World!").OutputText); } finally { TestHelper.RemoveTestDistro(); } } }
public async Task Execute() { // Verify that we can execute SUDO and non-SUDO commands. var imagePath = await TestHelper.GetTestImageAsync(); using (var tempFolder = new TempFolder()) { try { Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); var distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); Assert.Contains("Hello World!", distro.Execute("echo", "Hello World!").OutputText); Assert.Contains("Hello World!", distro.SudoExecute("echo", "Hello World!").OutputText); } finally { TestHelper.RemoveTestDistro(); } } }