Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5a76ad1
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
84e7e19
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
2c2402c
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
7e25da6
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
882512d
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
d46f5e5
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
a1a6ef3
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
089ea99
Merge in 'release/7.0' changes
dotnet-bot Mar 8, 2023
2f81831
Merge in 'release/7.0' changes
dotnet-bot Mar 9, 2023
21bd0a7
Merge in 'release/7.0' changes
dotnet-bot Mar 9, 2023
15f5d02
Merge in 'release/7.0' changes
dotnet-bot Mar 10, 2023
0f05efe
Merge in 'release/7.0' changes
dotnet-bot Mar 10, 2023
eaaed2a
Merge in 'release/7.0' changes
dotnet-bot Mar 10, 2023
5a1baeb
Merged PR 29231: [internal/release/7.0] Fix handling of load for msqu…
elinor-fung Mar 10, 2023
5359e8e
Merge in 'release/7.0' changes
dotnet-bot Mar 10, 2023
bfdc43b
Merge in 'release/7.0' changes
dotnet-bot Mar 11, 2023
71aa107
Merge in 'release/7.0' changes
dotnet-bot Mar 14, 2023
634640c
Merge in 'release/7.0' changes
dotnet-bot Mar 14, 2023
2c9e64f
Merge in 'release/7.0' changes
dotnet-bot Mar 15, 2023
90e3df4
Merge in 'release/7.0' changes
dotnet-bot Mar 17, 2023
fb541ff
Merge in 'release/7.0' changes
dotnet-bot Mar 20, 2023
8042d61
Merge in 'release/7.0' changes
dotnet-bot Mar 23, 2023
062f700
[release/7.0] Update dependencies from dotnet/runtime-assets (#84123)
dotnet-maestro[bot] Apr 7, 2023
a283bb9
Merge pull request #84594 from carlossanlop/release/7.0-staging
carlossanlop Apr 11, 2023
4e9cde7
Merge commit '8042d61b17540e49e53569e3728d2faa1c596583' into internal…
vseanreesermsft Apr 11, 2023
af23cd6
Merge pull request #84640 from vseanreesermsft/internal-merge-7.0-202…
carlossanlop Apr 11, 2023
d477fbf
Update dependencies from https://github.com/dotnet/arcade build 20230…
dotnet-maestro[bot] Apr 12, 2023
5266169
Update dependencies from https://github.com/dotnet/icu build 20230411…
dotnet-maestro[bot] Apr 12, 2023
43b5822
Update dependencies from https://github.com/dotnet/emsdk build 202304…
dotnet-maestro[bot] Apr 12, 2023
3de70ef
[release/7.0] Move mono.mscordbi subset off the offical buildMove mon…
steveisok Apr 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,69 @@ protected int CreateGroup(string groupName)
return GetGroupId(groupName);
}

protected int CreateUser(string userName)
{
Execute("useradd", userName);
return GetUserId(userName);
}

protected int GetGroupId(string groupName)
{
string standardOutput = Execute("getent", $"group {groupName}");
string[] values = standardOutput.Split(':', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
return int.Parse(values[^1]);
}


protected int GetUserId(string userName)
{
string standardOutput = Execute("id", $"-u {userName}");
return int.Parse(standardOutput);
}

protected void SetGroupAsOwnerOfFile(string groupName, string filePath) =>
Execute("chgrp", $"{groupName} {filePath}");

protected void SetUserAsOwnerOfFile(string userName, string filePath) =>
Execute("chown", $"{userName} {filePath}");

protected void DeleteGroup(string groupName) =>
protected void DeleteGroup(string groupName)
{
Execute("groupdel", groupName);
Threading.Thread.Sleep(250);
Assert.Throws<IOException>(() => GetGroupId(groupName));
}

protected void DeleteUser(string userName)
{
Execute("userdel", $"-f {userName}");
Threading.Thread.Sleep(250);
Assert.Throws<IOException>(() => GetUserId(userName));
}

private string Execute(string command, string arguments)
{
using Process p = new Process();

p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = command;
p.StartInfo.Arguments = arguments;

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;

string standardError = string.Empty;
p.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => { standardError += e.Data; });

string standardOutput = string.Empty;
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) => { standardOutput += e.Data; });

p.Start();

p.BeginOutputReadLine();
p.BeginErrorReadLine();

p.WaitForExit();

string standardOutput = p.StandardOutput.ReadToEnd();
string standardError = p.StandardError.ReadToEnd();

if (p.ExitCode != 0)
{
throw new IOException($"Error '{p.ExitCode}' when executing '{command} {arguments}'. Message: {standardError}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.RemoteExecutor;
using System.IO;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;

namespace System.Formats.Tar.Tests
Expand Down Expand Up @@ -177,8 +177,129 @@ public void CreateEntryFromFileOwnedByNonExistentGroup(TarEntryFormat f)
{
PosixTarEntry entry = reader.GetNextEntry() as PosixTarEntry;
Assert.NotNull(entry);
Assert.Equal(entry.GroupName, string.Empty);

Assert.Equal(string.Empty, entry.GroupName);
Assert.Equal(groupId, entry.Gid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
entry.ExtractToFile(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(reader.GetNextEntry());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
}

[ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
[InlineData(TarEntryFormat.Ustar)]
[InlineData(TarEntryFormat.Pax)]
[InlineData(TarEntryFormat.Gnu)]
public void CreateEntryFromFileOwnedByNonExistentUser(TarEntryFormat f)
{
RemoteExecutor.Invoke((string strFormat) =>
{
using TempDirectory root = new TempDirectory();

string fileName = "file.txt";
string filePath = Path.Join(root.Path, fileName);
File.Create(filePath).Dispose();

string userName = Path.GetRandomFileName()[0..6];
int userId = CreateUser(userName);

try
{
SetUserAsOwnerOfFile(userName, filePath);
}
finally
{
DeleteUser(userName);
}

using MemoryStream archive = new MemoryStream();
using (TarWriter writer = new TarWriter(archive, Enum.Parse<TarEntryFormat>(strFormat), leaveOpen: true))
{
writer.WriteEntry(filePath, fileName); // Should not throw
}
archive.Seek(0, SeekOrigin.Begin);

using (TarReader reader = new TarReader(archive, leaveOpen: false))
{
PosixTarEntry entry = reader.GetNextEntry() as PosixTarEntry;
Assert.NotNull(entry);

Assert.Equal(string.Empty, entry.UserName);
Assert.Equal(userId, entry.Uid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
entry.ExtractToFile(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(reader.GetNextEntry());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
}

[ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
[InlineData(TarEntryFormat.Ustar)]
[InlineData(TarEntryFormat.Pax)]
[InlineData(TarEntryFormat.Gnu)]
public void CreateEntryFromFileOwnedByNonExistentGroupAndUser(TarEntryFormat f)
{
RemoteExecutor.Invoke((string strFormat) =>
{
using TempDirectory root = new TempDirectory();

string fileName = "file.txt";
string filePath = Path.Join(root.Path, fileName);
File.Create(filePath).Dispose();

string groupName = Path.GetRandomFileName()[0..6];
int groupId = CreateGroup(groupName);

string userName = Path.GetRandomFileName()[0..6];
int userId = CreateUser(userName);

try
{
SetGroupAsOwnerOfFile(groupName, filePath);
}
finally
{
DeleteGroup(groupName);
}

try
{
SetUserAsOwnerOfFile(userName, filePath);
}
finally
{
DeleteUser(userName);
}

using MemoryStream archive = new MemoryStream();
using (TarWriter writer = new TarWriter(archive, Enum.Parse<TarEntryFormat>(strFormat), leaveOpen: true))
{
writer.WriteEntry(filePath, fileName); // Should not throw
}
archive.Seek(0, SeekOrigin.Begin);

using (TarReader reader = new TarReader(archive, leaveOpen: false))
{
PosixTarEntry entry = reader.GetNextEntry() as PosixTarEntry;
Assert.NotNull(entry);

Assert.Equal(string.Empty, entry.GroupName);
Assert.Equal(groupId, entry.Gid);

Assert.Equal(string.Empty, entry.UserName);
Assert.Equal(userId, entry.Uid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
entry.ExtractToFile(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(reader.GetNextEntry());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.RemoteExecutor;
using System.IO;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;

namespace System.Formats.Tar.Tests
Expand Down Expand Up @@ -187,8 +187,129 @@ public void CreateEntryFromFileOwnedByNonExistentGroup_Async(TarEntryFormat f)
{
PosixTarEntry entry = await reader.GetNextEntryAsync() as PosixTarEntry;
Assert.NotNull(entry);
Assert.Equal(entry.GroupName, string.Empty);

Assert.Equal(string.Empty, entry.GroupName);
Assert.Equal(groupId, entry.Gid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
await entry.ExtractToFileAsync(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(await reader.GetNextEntryAsync());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
}

[ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
[InlineData(TarEntryFormat.Ustar)]
[InlineData(TarEntryFormat.Pax)]
[InlineData(TarEntryFormat.Gnu)]
public void CreateEntryFromFileOwnedByNonExistentUser_Async(TarEntryFormat f)
{
RemoteExecutor.Invoke(async (string strFormat) =>
{
using TempDirectory root = new TempDirectory();

string fileName = "file.txt";
string filePath = Path.Join(root.Path, fileName);
File.Create(filePath).Dispose();

string userName = Path.GetRandomFileName()[0..6];
int userId = CreateUser(userName);

try
{
SetUserAsOwnerOfFile(userName, filePath);
}
finally
{
DeleteUser(userName);
}

await using MemoryStream archive = new MemoryStream();
await using (TarWriter writer = new TarWriter(archive, Enum.Parse<TarEntryFormat>(strFormat), leaveOpen: true))
{
await writer.WriteEntryAsync(filePath, fileName); // Should not throw
}
archive.Seek(0, SeekOrigin.Begin);

await using (TarReader reader = new TarReader(archive, leaveOpen: false))
{
PosixTarEntry entry = await reader.GetNextEntryAsync() as PosixTarEntry;
Assert.NotNull(entry);

Assert.Equal(string.Empty, entry.UserName);
Assert.Equal(userId, entry.Uid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
await entry.ExtractToFileAsync(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(await reader.GetNextEntryAsync());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
}

[ConditionalTheory(nameof(IsRemoteExecutorSupportedAndPrivilegedProcess))]
[InlineData(TarEntryFormat.Ustar)]
[InlineData(TarEntryFormat.Pax)]
[InlineData(TarEntryFormat.Gnu)]
public void CreateEntryFromFileOwnedByNonExistentGroupAndUser_Async(TarEntryFormat f)
{
RemoteExecutor.Invoke(async (string strFormat) =>
{
using TempDirectory root = new TempDirectory();

string fileName = "file.txt";
string filePath = Path.Join(root.Path, fileName);
File.Create(filePath).Dispose();

string groupName = Path.GetRandomFileName()[0..6];
int groupId = CreateGroup(groupName);

string userName = Path.GetRandomFileName()[0..6];
int userId = CreateUser(userName);

try
{
SetGroupAsOwnerOfFile(groupName, filePath);
}
finally
{
DeleteGroup(groupName);
}

try
{
SetUserAsOwnerOfFile(userName, filePath);
}
finally
{
DeleteUser(userName);
}

await using MemoryStream archive = new MemoryStream();
await using (TarWriter writer = new TarWriter(archive, Enum.Parse<TarEntryFormat>(strFormat), leaveOpen: true))
{
await writer.WriteEntryAsync(filePath, fileName); // Should not throw
}
archive.Seek(0, SeekOrigin.Begin);

await using (TarReader reader = new TarReader(archive, leaveOpen: false))
{
PosixTarEntry entry = await reader.GetNextEntryAsync() as PosixTarEntry;
Assert.NotNull(entry);

Assert.Equal(string.Empty, entry.GroupName);
Assert.Equal(groupId, entry.Gid);

Assert.Equal(string.Empty, entry.UserName);
Assert.Equal(userId, entry.Uid);

string extractedPath = Path.Join(root.Path, "extracted.txt");
await entry.ExtractToFileAsync(extractedPath, overwrite: false);
Assert.True(File.Exists(extractedPath));

Assert.Null(await reader.GetNextEntryAsync());
}
}, f.ToString(), new RemoteInvokeOptions { RunAsSudo = true }).Dispose();
Expand Down