Skip to content

Commit 1deba35

Browse files
committed
Test codesign enabled and disabled
1 parent c0b1c8f commit 1deba35

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

test/Microsoft.NET.Build.Tests/AppHostTests.cs

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,40 +79,6 @@ public void It_builds_a_runnable_apphost_by_default(string targetFramework)
7979
.HaveStdOutContaining("Hello World!");
8080
}
8181

82-
[PlatformSpecificTheory(TestPlatforms.OSX)]
83-
[InlineData("netcoreapp3.1")]
84-
[InlineData("net5.0")]
85-
[InlineData(ToolsetInfo.CurrentTargetFramework)]
86-
public void It_can_disable_codesign_if_opt_out(string targetFramework)
87-
{
88-
var testAsset = _testAssetsManager
89-
.CopyTestAsset("HelloWorld", identifier: targetFramework)
90-
.WithSource()
91-
.WithTargetFramework(targetFramework);
92-
93-
var buildCommand = new BuildCommand(testAsset);
94-
buildCommand
95-
.Execute(new string[] {
96-
"/p:_EnableMacOSCodeSign=false;ProduceReferenceAssembly=false",
97-
})
98-
.Should()
99-
.Pass();
100-
101-
var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);
102-
var appHostFullPath = Path.Combine(outputDirectory.FullName, "HelloWorld");
103-
104-
// Check that the apphost was not signed
105-
var codesignPath = @"/usr/bin/codesign";
106-
new RunExeCommand(Log, codesignPath, new string[] { "-d", appHostFullPath })
107-
.Execute()
108-
.Should()
109-
.Fail()
110-
.And
111-
.HaveStdErrContaining($"{appHostFullPath}: code object is not signed at all");
112-
113-
outputDirectory.Should().OnlyHaveFiles(GetExpectedFilesFromBuild(testAsset, targetFramework));
114-
}
115-
11682
[PlatformSpecificTheory(TestPlatforms.OSX)]
11783
[InlineData("netcoreapp3.1", "win-x64")]
11884
[InlineData("net5.0", "win-x64")]
@@ -153,11 +119,15 @@ public void It_does_not_try_to_codesign_non_osx_app_hosts(string targetFramework
153119
}
154120

155121
[Theory]
156-
[InlineData("net6.0", "osx-x64")]
157-
[InlineData("net6.0", "osx-arm64")]
158-
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-x64")]
159-
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-arm64")]
160-
public void It_codesigns_an_app_targeting_osx(string targetFramework, string rid)
122+
[InlineData("net8.0", "osx-x64", true)]
123+
[InlineData("net8.0", "osx-arm64", true)]
124+
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-x64", true)]
125+
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-arm64", true)]
126+
[InlineData("net8.0", "osx-x64", false)]
127+
[InlineData("net8.0", "osx-arm64", false)]
128+
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-x64", false)]
129+
[InlineData(ToolsetInfo.CurrentTargetFramework, "osx-arm64", false)]
130+
public void It_codesigns_an_app_targeting_osx(string targetFramework, string rid, bool shouldSign)
161131
{
162132
const string testAssetName = "HelloWorld";
163133
var testAsset = _testAssetsManager
@@ -166,7 +136,7 @@ public void It_codesigns_an_app_targeting_osx(string targetFramework, string rid
166136
.WithTargetFramework(targetFramework);
167137

168138
var buildCommand = new BuildCommand(testAsset);
169-
var buildArgs = new List<string>() { $"/p:RuntimeIdentifier={rid}" };
139+
var buildArgs = new List<string>() { $"/p:RuntimeIdentifier={rid}", $"/p:_EnableMacOSCodeSign={shouldSign}" };
170140
buildCommand
171141
.Execute(buildArgs.ToArray())
172142
.Should()
@@ -176,12 +146,12 @@ public void It_codesigns_an_app_targeting_osx(string targetFramework, string rid
176146
var appHostFullPath = Path.Combine(outputDirectory.FullName, testAssetName);
177147

178148
// Check that the apphost is signed
179-
MachOSignature.HasMachOSignatureLoadCommand(new FileInfo(appHostFullPath)).Should().BeTrue();
149+
MachOSignature.HasMachOSignatureLoadCommand(new FileInfo(appHostFullPath)).Should().Be(shouldSign, $"The app host should {(shouldSign ? "" : "not ")}have a Mach-O signature load command.");
180150
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
181151
{
182-
MachOSignature.HasValidMachOSignature(new FileInfo(appHostFullPath))
152+
MachOSignature.HasValidMachOSignature(new FileInfo(appHostFullPath), Log)
183153
.Should()
184-
.BeTrue($"The app host should have a valid Mach-O signature for {rid}.");
154+
.Be(shouldSign, $"The app host should have a valid Mach-O signature for {rid}.");
185155
}
186156
}
187157

test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,11 @@ static void VerifyPrepareForBundle(XDocument project)
11281128
}
11291129

11301130
[Theory]
1131-
[InlineData("osx-x64")]
1132-
[InlineData("osx-arm64")]
1133-
public void It_codesigns_an_app_targeting_osx(string rid)
1131+
[InlineData("osx-x64", true)]
1132+
[InlineData("osx-arm64", true)]
1133+
[InlineData("osx-x64", false)]
1134+
[InlineData("osx-arm64", false)]
1135+
public void It_codesigns_an_app_targeting_osx(string rid, bool enableMacOSCodeSign)
11341136
{
11351137
var targetFramework = ToolsetInfo.CurrentTargetFramework;
11361138
var testProject = new TestProject()
@@ -1143,10 +1145,10 @@ public void It_codesigns_an_app_targeting_osx(string rid)
11431145

11441146
var testAsset = _testAssetsManager.CreateTestProject(
11451147
testProject,
1146-
identifier: rid);
1148+
identifier: $"{rid}_{enableMacOSCodeSign}");
11471149
var publishCommand = new PublishCommand(testAsset);
11481150

1149-
publishCommand.Execute(PublishSingleFile, $"/p:RuntimeIdentifier={rid}", IncludeDefault)
1151+
publishCommand.Execute(PublishSingleFile, $"/p:RuntimeIdentifier={rid}", $"/p:_EnableMacOSCodeSign={enableMacOSCodeSign}")
11501152
.Should()
11511153
.Pass();
11521154

@@ -1155,13 +1157,13 @@ public void It_codesigns_an_app_targeting_osx(string rid)
11551157

11561158
MachOSignature.HasMachOSignatureLoadCommand(new FileInfo(singleFilePath))
11571159
.Should()
1158-
.BeTrue($"The app host should have a Mach-O signature load command for {rid}.");
1160+
.Be(enableMacOSCodeSign, $"The app host should {(enableMacOSCodeSign ? "" : "not ")}have a Mach-O signature load command.");
11591161

11601162
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
11611163
{
11621164
MachOSignature.HasValidMachOSignature(new FileInfo(singleFilePath), Log)
11631165
.Should()
1164-
.BeTrue($"The app host should have a valid Mach-O signature for {rid}.");
1166+
.Be(enableMacOSCodeSign, $"The app host should {(enableMacOSCodeSign ? "" : "not ")}have a valid Mach-O signature for {rid}.");
11651167
}
11661168
}
11671169
}

0 commit comments

Comments
 (0)