Skip to content

Commit

Permalink
[msbuild] Re-added wildcard (*) expandsion for application-identifier… (
Browse files Browse the repository at this point in the history
#2182)

* [msbuild] Re-added wildcard (*) expandsion for application-identifier in Entitlements.plist

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=57119

* Fixed unit tests
  • Loading branch information
jstedfast authored Jun 8, 2017
1 parent 25468bf commit 2f4e818
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected virtual bool MergeProfileEntitlements {
get { return true; }
}

PString MergeEntitlementString (PString pstr, MobileProvision profile)
PString MergeEntitlementString (PString pstr, MobileProvision profile, bool expandWildcards)
{
string TeamIdentifierPrefix;
string AppIdentifierPrefix;
Expand Down Expand Up @@ -96,6 +96,25 @@ PString MergeEntitlementString (PString pstr, MobileProvision profile)

var expanded = StringParserService.Parse (pstr.Value, customTags);

if (expandWildcards && expanded.IndexOf ('*') != -1) {
int asterisk = expanded.IndexOf ('*');
string prefix;

if (expanded.StartsWith (TeamIdentifierPrefix, StringComparison.Ordinal))
prefix = TeamIdentifierPrefix;
else if (expanded.StartsWith (AppIdentifierPrefix, StringComparison.Ordinal))
prefix = AppIdentifierPrefix;
else
prefix = string.Empty;

var baseBundleIdentifier = expanded.Substring (prefix.Length, asterisk - prefix.Length);

if (!BundleIdentifier.StartsWith (baseBundleIdentifier, StringComparison.Ordinal))
expanded = expanded.Replace ("*", BundleIdentifier);
else
expanded = prefix + BundleIdentifier;
}

return new PString (expanded);
}

Expand All @@ -109,7 +128,7 @@ PArray MergeEntitlementArray (PArray array, MobileProvision profile)
if (item is PDictionary)
value = MergeEntitlementDictionary ((PDictionary) item, profile);
else if (item is PString)
value = MergeEntitlementString ((PString) item, profile);
value = MergeEntitlementString ((PString) item, profile, false);
else if (item is PArray)
value = MergeEntitlementArray ((PArray) item, profile);
else
Expand All @@ -135,7 +154,7 @@ PDictionary MergeEntitlementDictionary (PDictionary dict, MobileProvision profil
if (value is PDictionary)
value = MergeEntitlementDictionary ((PDictionary) value, profile);
else if (value is PString)
value = MergeEntitlementString ((PString) value, profile);
value = MergeEntitlementString ((PString) value, profile, false);
else if (value is PArray)
value = MergeEntitlementArray ((PArray) value, profile);
else
Expand Down Expand Up @@ -210,7 +229,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile,
else if (value is PDictionary)
value = MergeEntitlementDictionary ((PDictionary) value, profile);
else if (value is PString)
value = MergeEntitlementString ((PString) value, profile);
value = MergeEntitlementString ((PString) value, profile, item.Key == ApplicationIdentifierKey);
else if (value is PArray)
value = MergeEntitlementArray ((PArray) value, profile);
else
Expand Down Expand Up @@ -244,7 +263,7 @@ protected virtual PDictionary GetCompiledEntitlements (MobileProvision profile,
if (value is PDictionary)
value = MergeEntitlementDictionary ((PDictionary) value, profile);
else if (value is PString)
value = MergeEntitlementString ((PString) value, profile);
value = MergeEntitlementString ((PString) value, profile, item.Key == ApplicationIdentifierKey);
else if (value is PArray)
value = MergeEntitlementArray ((PArray) value, profile);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ValidateEntitlement ()
ExecuteTask (task);
var compiled = PDictionary.FromFile (compiledEntitlements);
Assert.IsTrue (compiled.Get<PBoolean> (EntitlementKeys.GetTaskAllow).Value, "#1");
Assert.AreEqual ("32UV7A8CDE.*", compiled.Get<PString> ("application-identifier").Value, "#2");
Assert.AreEqual ("32UV7A8CDE.com.xamarin.MySingleView", compiled.Get<PString> ("application-identifier").Value, "#2");
Assert.AreEqual ("Z8CSQKJE7R", compiled.Get<PString> ("com.apple.developer.team-identifier").Value, "#3");
Assert.AreEqual ("applinks:*.xamarin.com", compiled.GetAssociatedDomains ().ToStringArray ().First (), "#4");
Assert.AreEqual ("Z8CSQKJE7R.*", compiled.GetPassBookIdentifiers ().ToStringArray ().First (), "#5");
Expand Down

0 comments on commit 2f4e818

Please sign in to comment.