forked from dotnet/macios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectSigningIdentityTaskTests.cs
More file actions
137 lines (118 loc) · 5.63 KB
/
Copy pathDetectSigningIdentityTaskTests.cs
File metadata and controls
137 lines (118 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#nullable enable
using System;
using System.IO;
using System.Linq;
using Microsoft.Build.Utilities;
using NUnit.Framework;
using Xamarin.iOS.Tasks;
using Xamarin.MacDev;
using Xamarin.MacDev.Tasks;
using Xamarin.Utils;
namespace Xamarin.MacDev.Tasks {
[TestFixture]
public class DetectSigningIdentityTaskTests : TestBase {
DetectSigningIdentity CreateTask (string? tmpdir = null, ApplePlatform platform = ApplePlatform.iOS, bool simulator = true, bool isDotNet = true)
{
if (string.IsNullOrEmpty (tmpdir))
tmpdir = Cache.CreateTemporaryDirectory ();
var task = CreateTask<DetectSigningIdentity> ();
task.AppBundleName = "AssemblyName";
task.SdkPlatform = PlatformFrameworkHelper.GetSdkPlatform (platform, simulator);
task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform, isDotNet).ToString ();
return task;
}
[Test]
public void Default ()
{
var dir = Cache.CreateTemporaryDirectory ();
var task = CreateTask (dir);
ExecuteTask (task);
Assert.IsNull (task.DetectedAppId, "DetectedAppId");
Assert.AreEqual ("-", task.DetectedCodeSigningKey, "DetectedCodeSigningKey");
Assert.AreEqual ($"{Xamarin.Tests.Configuration.XcodeLocation}/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate", task.DetectedCodesignAllocate, "DetectedCodesignAllocate");
Assert.AreEqual ("Any", task.DetectedDistributionType, "DetectedDistributionType");
Assert.IsNull (task.DetectedProvisioningProfile, "DetectedProvisioningProfile");
}
const string EmptyEntitlements1 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
</dict>
</plist>";
const string EmptyEntitlements2 = @"<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
</dict>
</plist>";
const string EmptyEntitlements3 = @"<plist version=""1.0"">
<dict>
</dict>
</plist>";
const string EmptyEntitlements4 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
<!-- comment here! -->
</dict>
</plist>";
const string NonEmptyEntitlements1 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
<plist version=""1.0"">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>";
public class EntitlementTestCase
{
public string Name = string.Empty;
public string Entitlements = string.Empty;
public bool Required;
public bool IsSimulator;
public bool? CodesignRequireProvisioningProfile;
public override string ToString ()
{
return Name;
}
}
static EntitlementTestCase[] GetEntitlementsTestCases ()
{
return new EntitlementTestCase[]
{
new EntitlementTestCase { Name = nameof (EmptyEntitlements1), Entitlements = EmptyEntitlements1, Required = false, IsSimulator = true },
new EntitlementTestCase { Name = nameof (EmptyEntitlements2), Entitlements = EmptyEntitlements2, Required = false, IsSimulator = true },
new EntitlementTestCase { Name = nameof (EmptyEntitlements3), Entitlements = EmptyEntitlements3, Required = false, IsSimulator = true },
new EntitlementTestCase { Name = nameof (EmptyEntitlements4), Entitlements = EmptyEntitlements4, Required = false, IsSimulator = true },
new EntitlementTestCase { Name = nameof (NonEmptyEntitlements1), Entitlements = NonEmptyEntitlements1, Required = true, IsSimulator = true },
new EntitlementTestCase { Name = nameof (EmptyEntitlements1) + "_Required", Entitlements = EmptyEntitlements1, Required = true, IsSimulator = true, CodesignRequireProvisioningProfile = true },
new EntitlementTestCase { Name = nameof (NonEmptyEntitlements1) + "_NotRequired", Entitlements = NonEmptyEntitlements1, Required = false, IsSimulator = true, CodesignRequireProvisioningProfile = false },
};
}
[Test]
[TestCaseSource (nameof (GetEntitlementsTestCases))]
public void EmptyEntitlements (EntitlementTestCase testCase)
{
var dir = Cache.CreateTemporaryDirectory ();
var entitlementsPath = Path.Combine (dir, "Entitlements.plist");
File.WriteAllText (entitlementsPath, testCase.Entitlements);
var task = CreateTask (dir, simulator: testCase.IsSimulator);
task.CodesignEntitlements = new TaskItem (entitlementsPath);
task.SdkIsSimulator = testCase.IsSimulator;
if (testCase.CodesignRequireProvisioningProfile.HasValue)
task.CodesignRequireProvisioningProfile = testCase.CodesignRequireProvisioningProfile.Value.ToString ();
ExecuteTask (task);
if (testCase.Required) {
Assert.That (task.DetectedAppId, Is.Not.Null.And.Not.Empty, "DetectedAppId");
Assert.AreEqual ("-", task.DetectedCodeSigningKey, "DetectedCodeSigningKey");
Assert.That (task.DetectedDistributionType, Is.EqualTo ("Development").Or.EqualTo ("AppStore"), "DetectedDistributionType");
Assert.That (task.DetectedProvisioningProfile, Is.Not.Null.And.Not.Empty, "DetectedProvisioningProfile");
} else {
Assert.IsNull (task.DetectedAppId, "DetectedAppId");
Assert.IsNull (task.DetectedCodeSigningKey, "DetectedCodeSigningKey");
Assert.AreEqual ("Any", task.DetectedDistributionType, "DetectedDistributionType");
Assert.IsNull (task.DetectedProvisioningProfile, "DetectedProvisioningProfile");
}
Assert.AreEqual ($"{Xamarin.Tests.Configuration.XcodeLocation}/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate", task.DetectedCodesignAllocate, "DetectedCodesignAllocate");
}
}
}