diff --git a/Sources/XKit/Model/Entitlements/EntitlementTypes.swift b/Sources/XKit/Model/Entitlements/EntitlementTypes.swift index 7bc1ea5f..f287935b 100644 --- a/Sources/XKit/Model/Entitlements/EntitlementTypes.swift +++ b/Sources/XKit/Model/Entitlements/EntitlementTypes.swift @@ -29,6 +29,7 @@ extension EntitlementContainer { WiFiAwareEntitlement.self, HomeKitEntitlement.self, HealthKitEntitlement.self, + HealthKitBackgroundDeliveryEntitlement.self, AppleSignInEntitlement.self, ] } @@ -200,3 +201,12 @@ public struct HealthKitEntitlement: Entitlement, RawRepresentable { public var rawValue: Bool public init(rawValue: Bool) { self.rawValue = rawValue } } + +/// Not a capability of its own: it only needs to be present on the signed binary, +/// so unlike `HealthKitEntitlement` it has no `DeveloperServicesCapability`. +public struct HealthKitBackgroundDeliveryEntitlement: Entitlement, RawRepresentable { + public static let identifier = "com.apple.developer.healthkit.background-delivery" + + public var rawValue: Bool + public init(rawValue: Bool) { self.rawValue = rawValue } +} diff --git a/Tests/XToolTests/HealthKitEntitlementTests.swift b/Tests/XToolTests/HealthKitEntitlementTests.swift new file mode 100644 index 00000000..756ab444 --- /dev/null +++ b/Tests/XToolTests/HealthKitEntitlementTests.swift @@ -0,0 +1,46 @@ +import Foundation +import Testing +@testable import XKit + +private let healthKitPlist = """ + + + + + com.apple.developer.healthkit + + com.apple.developer.healthkit.background-delivery + + + +""" + +@Test func healthKitBackgroundDeliverySurvivesFreeTeamFiltering() throws { + let entitlements = try PropertyListDecoder().decode( + Entitlements.self, + from: Data(healthKitPlist.utf8) + ) + + // the same filter DeveloperServicesAddAppOperation applies on free teams + let filtered = try entitlements.entitlements().filter { $0.anyCapability?.isFree != false } + let encoded = try PropertyListEncoder().encode(Entitlements(entitlements: filtered)) + let dictionary = try #require( + PropertyListSerialization.propertyList(from: encoded, format: nil) as? [String: Any] + ) + + #expect(dictionary["com.apple.developer.healthkit"] as? Bool == true) + #expect(dictionary["com.apple.developer.healthkit.background-delivery"] as? Bool == true) +} + +@Test func healthKitBackgroundDeliveryIsNotRegisteredAsACapability() throws { + let entitlements = try PropertyListDecoder().decode( + Entitlements.self, + from: Data(healthKitPlist.utf8) + ) + let backgroundDelivery = try #require( + entitlements.entitlements().compactMap { $0 as? HealthKitBackgroundDeliveryEntitlement }.first + ) + + #expect(backgroundDelivery.rawValue) + #expect(backgroundDelivery.anyCapability == nil) +}