Skip to content

Commit 93d9799

Browse files
committed
tests: Revert the unix umask async code because of error: Field marshaling is not supported by Invoke: async.
Split the ExtractOutOfRoot tests into two separate tests.
1 parent 5e65d26 commit 93d9799

File tree

4 files changed

+84
-77
lines changed

4 files changed

+84
-77
lines changed

src/libraries/Common/tests/System/IO/Compression/ZipTestHelper.ZipFile.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,6 @@ protected static Task CallZipFileExtensionsExtractToDirectory(bool async, ZipArc
265265
}
266266
}
267267

268-
public static IEnumerable<object[]> Get_ExtractOutOfRoot_Data()
269-
{
270-
foreach (bool async in _bools)
271-
{
272-
yield return new object[] { "../Foo", async };
273-
yield return new object[] { "../Barbell", async };
274-
}
275-
}
276-
277268
public static IEnumerable<object[]> Get_Unix_ZipWithInvalidFileNames_Data()
278269
{
279270
foreach (bool async in _bools)

src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Extract.Stream.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,35 @@ public async Task ExtractToDirectoryUnicode(bool async)
9191
}
9292

9393
[Theory]
94-
[MemberData(nameof(Get_ExtractOutOfRoot_Data))]
95-
public async Task ExtractOutOfRoot(string entryName, bool async)
94+
[InlineData("../Foo")]
95+
[InlineData("../Barbell")]
96+
public void ExtractOutOfRoot(string entryName)
9697
{
97-
FileStream source = new(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, bufferSize: 4096, useAsync: async);
98+
using FileStream source = new(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite);
99+
using (ZipArchive archive = new(source, ZipArchiveMode.Create, leaveOpen: true))
100+
{
101+
ZipArchiveEntry entry = archive.CreateEntry(entryName);
102+
}
98103

99-
ZipArchive archive = await CreateZipArchive(async, source, ZipArchiveMode.Create, leaveOpen: true, entryNameEncoding: null);
100-
ZipArchiveEntry entry = archive.CreateEntry(entryName);
101-
await DisposeZipArchive(async, archive);
104+
DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
105+
source.Position = 0;
106+
Assert.Throws<IOException>(() => ZipFile.ExtractToDirectory(source, destination.FullName));
107+
}
108+
109+
[Theory]
110+
[InlineData("../Foo")]
111+
[InlineData("../Barbell")]
112+
public async Task ExtractOutOfRoot_Async(string entryName)
113+
{
114+
using FileStream source = new(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite);
115+
await using (ZipArchive archive = await ZipArchive.CreateAsync(source, ZipArchiveMode.Create, leaveOpen: true, entryNameEncoding: null))
116+
{
117+
ZipArchiveEntry entry = archive.CreateEntry(entryName);
118+
}
102119

103120
DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
104121
source.Position = 0;
105-
await Assert.ThrowsAsync<IOException>(() => CallZipFileExtractToDirectory(async, source, destination.FullName));
106-
await DisposeStream(async, source);
122+
await Assert.ThrowsAsync<IOException>(() => ZipFile.ExtractToDirectoryAsync(source, destination.FullName));
107123
}
108124

109125
/// <summary>

src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Extract.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,37 @@ public async Task ExtractToDirectoryUnicode(bool async)
5656
}
5757
}
5858

59+
5960
[Theory]
60-
[MemberData(nameof(Get_ExtractOutOfRoot_Data))]
61-
public async Task ExtractOutOfRoot(string entryName, bool async)
61+
[InlineData("../Foo")]
62+
[InlineData("../Barbell")]
63+
public void ExtractOutOfRoot(string entryName)
6264
{
6365
string archivePath = GetTestFilePath();
6466
using (FileStream stream = new FileStream(archivePath, FileMode.Create))
67+
using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
6568
{
66-
ZipArchive archive = await CreateZipArchive(async, stream, ZipArchiveMode.Create, leaveOpen: true, entryNameEncoding: null);
6769
ZipArchiveEntry entry = archive.CreateEntry(entryName);
68-
await DisposeZipArchive(async, archive);
70+
}
71+
72+
DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
73+
Assert.Throws<IOException>(() => ZipFile.ExtractToDirectory(archivePath, destination.FullName));
74+
}
6975

70-
DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
71-
await Assert.ThrowsAsync<IOException>(() => CallZipFileExtractToDirectory(async, archivePath, destination.FullName));
76+
[Theory]
77+
[InlineData("../Foo")]
78+
[InlineData("../Barbell")]
79+
public async Task ExtractOutOfRoot_Async(string entryName)
80+
{
81+
string archivePath = GetTestFilePath();
82+
using (FileStream stream = new FileStream(archivePath, FileMode.Create))
83+
await using (ZipArchive archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Create, leaveOpen: true, entryNameEncoding: null))
84+
{
85+
ZipArchiveEntry entry = archive.CreateEntry(entryName);
7286
}
87+
88+
DirectoryInfo destination = Directory.CreateDirectory(Path.Combine(GetTestFilePath(), "Bar"));
89+
await Assert.ThrowsAsync<IOException>(() => ZipFile.ExtractToDirectoryAsync(archivePath, destination.FullName));
7390
}
7491

7592
/// <summary>

src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ namespace System.IO.Compression.Tests
1414
{
1515
public partial class ZipFile_Unix : ZipFileTestBase
1616
{
17-
[Theory]
18-
[MemberData(nameof(Get_Booleans_Data))]
19-
public async Task UnixCreateSetsPermissionsInExternalAttributes(bool async)
17+
[Fact]
18+
public void UnixCreateSetsPermissionsInExternalAttributes()
2019
{
2120
// '7600' tests that S_ISUID, S_ISGID, and S_ISVTX bits get preserved in ExternalAttributes
2221
string[] testPermissions = new[] { "777", "755", "644", "600", "7600" };
@@ -26,29 +25,28 @@ public async Task UnixCreateSetsPermissionsInExternalAttributes(bool async)
2625
string[] expectedPermissions = CreateFiles(tempFolder.Path, testPermissions);
2726

2827
string archivePath = GetTestFilePath();
29-
await CallZipFileCreateFromDirectory(async, tempFolder.Path, archivePath);
30-
31-
ZipArchive archive = await CallZipFileOpenRead(async, archivePath);
28+
ZipFile.CreateFromDirectory(tempFolder.Path, archivePath);
3229

33-
Assert.Equal(expectedPermissions.Length, archive.Entries.Count);
34-
35-
foreach (ZipArchiveEntry entry in archive.Entries)
30+
using (ZipArchive archive = ZipFile.OpenRead(archivePath))
3631
{
37-
Assert.EndsWith(".txt", entry.Name, StringComparison.Ordinal);
38-
EnsureExternalAttributes(entry.Name.Substring(0, entry.Name.Length - 4), entry);
39-
}
32+
Assert.Equal(expectedPermissions.Length, archive.Entries.Count);
4033

41-
void EnsureExternalAttributes(string permissions, ZipArchiveEntry entry)
42-
{
43-
Assert.Equal(Convert.ToInt32(permissions, 8), (entry.ExternalAttributes >> 16) & 0xFFF);
44-
}
34+
foreach (ZipArchiveEntry entry in archive.Entries)
35+
{
36+
Assert.EndsWith(".txt", entry.Name, StringComparison.Ordinal);
37+
EnsureExternalAttributes(entry.Name.Substring(0, entry.Name.Length - 4), entry);
38+
}
4539

46-
await DisposeZipArchive(async, archive);
40+
void EnsureExternalAttributes(string permissions, ZipArchiveEntry entry)
41+
{
42+
Assert.Equal(Convert.ToInt32(permissions, 8), (entry.ExternalAttributes >> 16) & 0xFFF);
43+
}
44+
}
4745

4846
// test that round tripping the archive has the same file permissions
4947
using (var extractFolder = new TempDirectory(Path.Combine(GetTestFilePath(), "extract")))
5048
{
51-
await CallZipFileExtractToDirectory(async, archivePath, extractFolder.Path);
49+
ZipFile.ExtractToDirectory(archivePath, extractFolder.Path);
5250

5351
foreach (string permission in expectedPermissions)
5452
{
@@ -61,72 +59,57 @@ void EnsureExternalAttributes(string permissions, ZipArchiveEntry entry)
6159
}
6260
}
6361

64-
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
65-
[MemberData(nameof(Get_Booleans_Data))]
66-
public void UnixCreateSetsPermissionsInExternalAttributesUMaskZero(bool async)
62+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
63+
public void UnixCreateSetsPermissionsInExternalAttributesUMaskZero()
6764
{
68-
RemoteExecutor.Invoke(async () =>
65+
RemoteExecutor.Invoke(() =>
6966
{
7067
umask(0);
71-
await new ZipFile_Unix().UnixCreateSetsPermissionsInExternalAttributes(async);
68+
new ZipFile_Unix().UnixCreateSetsPermissionsInExternalAttributes();
7269
}).Dispose();
7370
}
7471

75-
[Theory]
76-
[MemberData(nameof(Get_Booleans_Data))]
77-
public async Task UnixExtractSetsFilePermissionsFromExternalAttributes(bool async)
72+
[Fact]
73+
public void UnixExtractSetsFilePermissionsFromExternalAttributes()
7874
{
7975
// '7600' tests that S_ISUID, S_ISGID, and S_ISVTX bits don't get extracted to file permissions
8076
string[] testPermissions = new[] { "777", "755", "644", "754", "7600" };
8177

8278
string archivePath = GetTestFilePath();
8379
using (FileStream fileStream = new FileStream(archivePath, FileMode.CreateNew))
80+
using (ZipArchive archive = new ZipArchive(fileStream, ZipArchiveMode.Create))
8481
{
85-
ZipArchive archive = await CreateZipArchive(async, fileStream, ZipArchiveMode.Create);
86-
8782
foreach (string permission in testPermissions)
8883
{
8984
ZipArchiveEntry entry = archive.CreateEntry(permission + ".txt");
9085
entry.ExternalAttributes = Convert.ToInt32(permission, 8) << 16;
91-
Stream stream = await OpenEntryStream(async, entry);
92-
ReadOnlySpan<byte> contents = "contents"u8;
93-
if (async)
94-
{
95-
await stream.WriteAsync(contents.ToArray());
96-
}
97-
else
98-
{
99-
stream.Write(contents);
100-
}
86+
using Stream stream = entry.Open();
87+
stream.Write("contents"u8);
10188
stream.Flush();
102-
await DisposeStream(async, stream);
10389
}
90+
}
10491

105-
await DisposeZipArchive(async, archive);
92+
using (var tempFolder = new TempDirectory(GetTestFilePath()))
93+
{
94+
ZipFile.ExtractToDirectory(archivePath, tempFolder.Path);
10695

107-
using (var tempFolder = new TempDirectory(GetTestFilePath()))
96+
foreach (string permission in testPermissions)
10897
{
109-
await CallZipFileExtractToDirectory(async, archivePath, tempFolder.Path);
110-
111-
foreach (string permission in testPermissions)
112-
{
113-
string filename = Path.Combine(tempFolder.Path, permission + ".txt");
114-
Assert.True(File.Exists(filename));
98+
string filename = Path.Combine(tempFolder.Path, permission + ".txt");
99+
Assert.True(File.Exists(filename));
115100

116-
EnsureFilePermissions(filename, permission);
117-
}
101+
EnsureFilePermissions(filename, permission);
118102
}
119103
}
120104
}
121105

122-
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
123-
[MemberData(nameof(Get_Booleans_Data))]
124-
public void UnixExtractSetsFilePermissionsFromExternalAttributesUMaskZero(bool async)
106+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
107+
public void UnixExtractSetsFilePermissionsFromExternalAttributesUMaskZero()
125108
{
126-
RemoteExecutor.Invoke(async () =>
109+
RemoteExecutor.Invoke(() =>
127110
{
128111
umask(0);
129-
await new ZipFile_Unix().UnixExtractSetsFilePermissionsFromExternalAttributes(async);
112+
new ZipFile_Unix().UnixExtractSetsFilePermissionsFromExternalAttributes();
130113
}).Dispose();
131114
}
132115

0 commit comments

Comments
 (0)