diff --git a/README.md b/README.md index b6905ba0..cc34db24 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ let issuerId = "99b16628-15e4-4668-972b-eeff55eeff55" let keyId = "ABCDEFGHIJ" let bundleId = "com.example" let encodedKey = try! String(contentsOfFile: "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8") -let environment = Environment.sandbox +let environment = AppStoreEnvironment.sandbox // try! used for example purposes only let client = try! AppStoreServerAPIClient(signingKey: encodedKey, keyId: keyId, issuerId: issuerId, bundleId: bundleId, environment: environment) @@ -71,7 +71,7 @@ let bundleId = "com.example" let appleRootCAs = loadRootCAs() // Specific implementation may vary let appAppleId: Int64? = nil // appAppleId must be provided for the Production environment let enableOnlineChecks = true -let environment = Environment.sandbox +let environment = AppStoreEnvironment.sandbox // try! used for example purposes only let verifier = try! SignedDataVerifier(rootCertificates: appleRootCAs, bundleId: bundleId, appAppleId: appAppleId, environment: environment, enableOnlineChecks: enableOnlineChecks) @@ -95,7 +95,7 @@ let issuerId = "99b16628-15e4-4668-972b-eeff55eeff55" let keyId = "ABCDEFGHIJ" let bundleId = "com.example" let encodedKey = try! String(contentsOfFile: "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8") -let environment = Environment.sandbox +let environment = AppStoreEnvironment.sandbox // try! used for example purposes only let client = try! AppStoreServerAPIClient(signingKey: encodedKey, keyId: keyId, issuerId: issuerId, bundleId: bundleId, environment: environment) diff --git a/Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift b/Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift index 9c881dad..a748d1a6 100644 --- a/Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift +++ b/Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift @@ -32,7 +32,7 @@ public class AppStoreServerAPIClient { ///- Parameter issuerId: Your issuer ID from the Keys page in App Store Connect ///- Parameter bundleId: Your app’s bundle ID ///- Parameter environment: The environment to target - public init(signingKey: String, keyId: String, issuerId: String, bundleId: String, environment: Environment) throws { + public init(signingKey: String, keyId: String, issuerId: String, bundleId: String, environment: AppStoreEnvironment) throws { self.signingKey = try P256.Signing.PrivateKey(pemRepresentation: signingKey) self.keyId = keyId self.issuerId = issuerId diff --git a/Sources/AppStoreServerLibrary/ChainVerifier.swift b/Sources/AppStoreServerLibrary/ChainVerifier.swift index e9f6f066..62dadc2c 100644 --- a/Sources/AppStoreServerLibrary/ChainVerifier.swift +++ b/Sources/AppStoreServerLibrary/ChainVerifier.swift @@ -23,7 +23,7 @@ struct ChainVerifier { self.requester = Requester() } - func verify(signedData: String, type: T.Type, onlineVerification: Bool, environment: Environment) async -> VerificationResult where T: Decodable { + func verify(signedData: String, type: T.Type, onlineVerification: Bool, environment: AppStoreEnvironment) async -> VerificationResult where T: Decodable { let header: JWTHeader; let decodedBody: T; do { @@ -41,7 +41,7 @@ struct ChainVerifier { return VerificationResult.invalid(VerificationError.INVALID_JWT_FORMAT) } - if (environment == Environment.xcode || environment == Environment.localTesting) { + if (environment == AppStoreEnvironment.xcode || environment == AppStoreEnvironment.localTesting) { // Data is not signed by the App Store, and verification should be skipped // The environment MUST be checked in the public method calling this return VerificationResult.valid(decodedBody) diff --git a/Sources/AppStoreServerLibrary/Models/Environment.swift b/Sources/AppStoreServerLibrary/Models/AppStoreEnvironment.swift similarity index 81% rename from Sources/AppStoreServerLibrary/Models/Environment.swift rename to Sources/AppStoreServerLibrary/Models/AppStoreEnvironment.swift index 05faa03e..da0b4b97 100644 --- a/Sources/AppStoreServerLibrary/Models/Environment.swift +++ b/Sources/AppStoreServerLibrary/Models/AppStoreEnvironment.swift @@ -3,7 +3,7 @@ ///The server environment, either sandbox or production. /// ///[environment](https://developer.apple.com/documentation/appstoreserverapi/environment) -public enum Environment: String, Decodable, Encodable, Hashable, Sendable { +public enum AppStoreEnvironment: String, Decodable, Encodable, Hashable, Sendable { case sandbox = "Sandbox" case production = "Production" case xcode = "Xcode" diff --git a/Sources/AppStoreServerLibrary/Models/AppTransaction.swift b/Sources/AppStoreServerLibrary/Models/AppTransaction.swift index 01e57f8a..03b162f8 100644 --- a/Sources/AppStoreServerLibrary/Models/AppTransaction.swift +++ b/Sources/AppStoreServerLibrary/Models/AppTransaction.swift @@ -8,7 +8,7 @@ import Foundation ///[AppTransaction](https://developer.apple.com/documentation/storekit/apptransaction) public struct AppTransaction: DecodedSignedData, Decodable, Encodable, Hashable, Sendable { - public init(receiptType: Environment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, applicationVersion: String? = nil, versionExternalIdentifier: Int64? = nil, receiptCreationDate: Date? = nil, originalPurchaseDate: Date? = nil, originalApplicationVersion: String? = nil, deviceVerification: String? = nil, deviceVerificationNonce: UUID? = nil, preorderDate: Date? = nil) { + public init(receiptType: AppStoreEnvironment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, applicationVersion: String? = nil, versionExternalIdentifier: Int64? = nil, receiptCreationDate: Date? = nil, originalPurchaseDate: Date? = nil, originalApplicationVersion: String? = nil, deviceVerification: String? = nil, deviceVerificationNonce: UUID? = nil, preorderDate: Date? = nil) { self.receiptType = receiptType self.appAppleId = appAppleId self.bundleId = bundleId @@ -39,9 +39,9 @@ public struct AppTransaction: DecodedSignedData, Decodable, Encodable, Hashable, ///The server environment that signs the app transaction. /// ///[environment](https://developer.apple.com/documentation/storekit/apptransaction/3963901-environment) - public var receiptType: Environment? { + public var receiptType: AppStoreEnvironment? { get { - return rawReceiptType.flatMap { Environment(rawValue: $0) } + return rawReceiptType.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawReceiptType = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/HistoryResponse.swift b/Sources/AppStoreServerLibrary/Models/HistoryResponse.swift index dee8d05d..d43b8c89 100644 --- a/Sources/AppStoreServerLibrary/Models/HistoryResponse.swift +++ b/Sources/AppStoreServerLibrary/Models/HistoryResponse.swift @@ -5,7 +5,7 @@ ///[HistoryResponse](https://developer.apple.com/documentation/appstoreserverapi/historyresponse) public struct HistoryResponse: Decodable, Encodable, Hashable, Sendable { - public init(revision: String? = nil, hasMore: Bool? = nil, bundleId: String? = nil, appAppleId: Int64? = nil, environment: Environment? = nil, signedTransactions: [String]? = nil) { + public init(revision: String? = nil, hasMore: Bool? = nil, bundleId: String? = nil, appAppleId: Int64? = nil, environment: AppStoreEnvironment? = nil, signedTransactions: [String]? = nil) { self.revision = revision self.hasMore = hasMore self.bundleId = bundleId @@ -46,9 +46,9 @@ public struct HistoryResponse: Decodable, Encodable, Hashable, Sendable { ///The server environment in which you’re making the request, whether sandbox or production. /// ///[environment](https://developer.apple.com/documentation/appstoreserverapi/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift b/Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift index b95ad2bb..a96cec92 100644 --- a/Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift +++ b/Sources/AppStoreServerLibrary/Models/JWSRenewalInfoDecodedPayload.swift @@ -6,7 +6,7 @@ import Foundation ///[JWSRenewalInfoDecodedPayload](https://developer.apple.com/documentation/appstoreserverapi/jwsrenewalinfodecodedpayload) public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encodable, Hashable, Sendable { - public init(expirationIntent: ExpirationIntent? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, autoRenewStatus: AutoRenewStatus? = nil, isInBillingRetryPeriod: Bool? = nil, priceIncreaseStatus: PriceIncreaseStatus? = nil, gracePeriodExpiresDate: Date? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, environment: Environment? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil, eligibleWinBackOfferIds: [String]? = nil) { + public init(expirationIntent: ExpirationIntent? = nil, originalTransactionId: String? = nil, autoRenewProductId: String? = nil, productId: String? = nil, autoRenewStatus: AutoRenewStatus? = nil, isInBillingRetryPeriod: Bool? = nil, priceIncreaseStatus: PriceIncreaseStatus? = nil, gracePeriodExpiresDate: Date? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, signedDate: Date? = nil, environment: AppStoreEnvironment? = nil, recentSubscriptionStartDate: Date? = nil, renewalDate: Date? = nil, currency: String? = nil, renewalPrice: Int64? = nil, offerDiscountType: OfferDiscountType? = nil, eligibleWinBackOfferIds: [String]? = nil) { self.expirationIntent = expirationIntent self.originalTransactionId = originalTransactionId self.autoRenewProductId = autoRenewProductId @@ -146,9 +146,9 @@ public struct JWSRenewalInfoDecodedPayload: DecodedSignedData, Decodable, Encoda ///The server environment, either sandbox or production. /// ///[environment](https://developer.apple.com/documentation/appstoreserverapi/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/JWSTransactionDecodedPayload.swift b/Sources/AppStoreServerLibrary/Models/JWSTransactionDecodedPayload.swift index 4439ac90..cc16290f 100644 --- a/Sources/AppStoreServerLibrary/Models/JWSTransactionDecodedPayload.swift +++ b/Sources/AppStoreServerLibrary/Models/JWSTransactionDecodedPayload.swift @@ -6,7 +6,7 @@ import Foundation ///[JWSTransactionDecodedPayload](https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload) public struct JWSTransactionDecodedPayload: DecodedSignedData, Decodable, Encodable, Hashable, Sendable { - public init(originalTransactionId: String? = nil, transactionId: String? = nil, webOrderLineItemId: String? = nil, bundleId: String? = nil, productId: String? = nil, subscriptionGroupIdentifier: String? = nil, purchaseDate: Date? = nil, originalPurchaseDate: Date? = nil, expiresDate: Date? = nil, quantity: Int32? = nil, type: ProductType? = nil, appAccountToken: UUID? = nil, inAppOwnershipType: InAppOwnershipType? = nil, signedDate: Date? = nil, revocationReason: RevocationReason? = nil, revocationDate: Date? = nil, isUpgraded: Bool? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, environment: Environment? = nil, storefront: String? = nil, storefrontId: String? = nil, transactionReason: TransactionReason? = nil, currency: String? = nil, price: Int64? = nil, offerDiscountType: OfferDiscountType? = nil) { + public init(originalTransactionId: String? = nil, transactionId: String? = nil, webOrderLineItemId: String? = nil, bundleId: String? = nil, productId: String? = nil, subscriptionGroupIdentifier: String? = nil, purchaseDate: Date? = nil, originalPurchaseDate: Date? = nil, expiresDate: Date? = nil, quantity: Int32? = nil, type: ProductType? = nil, appAccountToken: UUID? = nil, inAppOwnershipType: InAppOwnershipType? = nil, signedDate: Date? = nil, revocationReason: RevocationReason? = nil, revocationDate: Date? = nil, isUpgraded: Bool? = nil, offerType: OfferType? = nil, offerIdentifier: String? = nil, environment: AppStoreEnvironment? = nil, storefront: String? = nil, storefrontId: String? = nil, transactionReason: TransactionReason? = nil, currency: String? = nil, price: Int64? = nil, offerDiscountType: OfferDiscountType? = nil) { self.originalTransactionId = originalTransactionId self.transactionId = transactionId self.webOrderLineItemId = webOrderLineItemId @@ -202,9 +202,9 @@ public struct JWSTransactionDecodedPayload: DecodedSignedData, Decodable, Encoda ///The server environment, either sandbox or production. /// /// [environment](https://developer.apple.com/documentation/appstoreserverapi/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/NotificationData.swift b/Sources/AppStoreServerLibrary/Models/NotificationData.swift index 7f70feec..21566e47 100644 --- a/Sources/AppStoreServerLibrary/Models/NotificationData.swift +++ b/Sources/AppStoreServerLibrary/Models/NotificationData.swift @@ -5,7 +5,7 @@ ///[data](https://developer.apple.com/documentation/appstoreservernotifications/data) public struct NotificationData: Decodable, Encodable, Hashable, Sendable { - public init(environment: Environment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, bundleVersion: String? = nil, signedTransactionInfo: String? = nil, signedRenewalInfo: String? = nil, status: Status? = nil, consumptionRequestReason: ConsumptionRequestReason? = nil) { + public init(environment: AppStoreEnvironment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, bundleVersion: String? = nil, signedTransactionInfo: String? = nil, signedRenewalInfo: String? = nil, status: Status? = nil, consumptionRequestReason: ConsumptionRequestReason? = nil) { self.environment = environment self.appAppleId = appAppleId self.bundleId = bundleId @@ -30,9 +30,9 @@ public struct NotificationData: Decodable, Encodable, Hashable, Sendable { ///The server environment that the notification applies to, either sandbox or production. /// ///[environment](https://developer.apple.com/documentation/appstoreservernotifications/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/StatusResponse.swift b/Sources/AppStoreServerLibrary/Models/StatusResponse.swift index aaddac99..57053a8b 100644 --- a/Sources/AppStoreServerLibrary/Models/StatusResponse.swift +++ b/Sources/AppStoreServerLibrary/Models/StatusResponse.swift @@ -5,7 +5,7 @@ ///[StatusResponse](https://developer.apple.com/documentation/appstoreserverapi/statusresponse) public struct StatusResponse: Decodable, Encodable, Hashable, Sendable { - public init(environment: Environment? = nil, bundleId: String? = nil, appAppleId: Int64? = nil, data: [SubscriptionGroupIdentifierItem]? = nil) { + public init(environment: AppStoreEnvironment? = nil, bundleId: String? = nil, appAppleId: Int64? = nil, data: [SubscriptionGroupIdentifierItem]? = nil) { self.environment = environment self.bundleId = bundleId self.appAppleId = appAppleId @@ -22,9 +22,9 @@ public struct StatusResponse: Decodable, Encodable, Hashable, Sendable { ///The server environment, sandbox or production, in which the App Store generated the response. /// ///[environment](https://developer.apple.com/documentation/appstoreserverapi/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/Models/Summary.swift b/Sources/AppStoreServerLibrary/Models/Summary.swift index 99f1ecf4..11438714 100644 --- a/Sources/AppStoreServerLibrary/Models/Summary.swift +++ b/Sources/AppStoreServerLibrary/Models/Summary.swift @@ -5,7 +5,7 @@ ///[summary](https://developer.apple.com/documentation/appstoreservernotifications/summary) public struct Summary: Decodable, Encodable, Hashable, Sendable { - public init(environment: Environment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, productId: String? = nil, requestIdentifier: String? = nil, storefrontCountryCodes: [String]? = nil, succeededCount: Int64? = nil, failedCount: Int64? = nil) { + public init(environment: AppStoreEnvironment? = nil, appAppleId: Int64? = nil, bundleId: String? = nil, productId: String? = nil, requestIdentifier: String? = nil, storefrontCountryCodes: [String]? = nil, succeededCount: Int64? = nil, failedCount: Int64? = nil) { self.environment = environment self.appAppleId = appAppleId self.bundleId = bundleId @@ -30,9 +30,9 @@ public struct Summary: Decodable, Encodable, Hashable, Sendable { ///The server environment that the notification applies to, either sandbox or production. /// ///[environment](https://developer.apple.com/documentation/appstoreservernotifications/environment) - public var environment: Environment? { + public var environment: AppStoreEnvironment? { get { - return rawEnvironment.flatMap { Environment(rawValue: $0) } + return rawEnvironment.flatMap { AppStoreEnvironment(rawValue: $0) } } set { self.rawEnvironment = newValue.map { $0.rawValue } diff --git a/Sources/AppStoreServerLibrary/SignedDataVerifier.swift b/Sources/AppStoreServerLibrary/SignedDataVerifier.swift index bcde26bb..2df7b3a2 100644 --- a/Sources/AppStoreServerLibrary/SignedDataVerifier.swift +++ b/Sources/AppStoreServerLibrary/SignedDataVerifier.swift @@ -11,7 +11,7 @@ public struct SignedDataVerifier { private var bundleId: String private var appAppleId: Int64? - private var environment: Environment + private var environment: AppStoreEnvironment private var chainVerifier: ChainVerifier private var enableOnlineChecks: Bool @@ -21,7 +21,7 @@ public struct SignedDataVerifier { /// - Parameter environment: The server environment, either sandbox or production. /// - Parameter enableOnlineChecks: Whether to enable revocation checking and check expiration using the current date /// - Throws: When the root certificates are malformed - public init(rootCertificates: [Data], bundleId: String, appAppleId: Int64?, environment: Environment, enableOnlineChecks: Bool) throws { + public init(rootCertificates: [Data], bundleId: String, appAppleId: Int64?, environment: AppStoreEnvironment, enableOnlineChecks: Bool) throws { guard !(environment == .production && appAppleId == nil) else { throw ConfigurationError.INVALID_APP_APPLE_ID @@ -79,13 +79,13 @@ public struct SignedDataVerifier { return await verifyAndDecodeNotification(signedPayload: signedPayload, validateNotification: self.verifyNotificationAppIdentifierAndEnvironment) } - internal func verifyAndDecodeNotification(signedPayload: String, validateNotification: (_ appBundleID: String?, _ appAppleID: Int64?, _ environment: Environment?) -> VerificationError?) async -> VerificationResult { + internal func verifyAndDecodeNotification(signedPayload: String, validateNotification: (_ appBundleID: String?, _ appAppleID: Int64?, _ environment: AppStoreEnvironment?) -> VerificationError?) async -> VerificationResult { let notificationResult = await decodeSignedData(signedData: signedPayload, type: ResponseBodyV2DecodedPayload.self) switch notificationResult { case .valid(let notification): let appAppleId: Int64? let bundleId : String? - let environment: Environment? + let environment: AppStoreEnvironment? if let data = notification.data { appAppleId = data.appAppleId bundleId = data.bundleId @@ -116,7 +116,7 @@ public struct SignedDataVerifier { return notificationResult } - internal func verifyNotificationAppIdentifierAndEnvironment(bundleId: String?, appAppleId: Int64?, environment: Environment?) -> VerificationError? { + internal func verifyNotificationAppIdentifierAndEnvironment(bundleId: String?, appAppleId: Int64?, environment: AppStoreEnvironment?) -> VerificationError? { if self.bundleId != bundleId || (self.environment == .production && self.appAppleId != appAppleId) { return .INVALID_APP_IDENTIFIER } diff --git a/Tests/AppStoreServerLibraryTests/AppStoreServerAPIClientTests.swift b/Tests/AppStoreServerLibraryTests/AppStoreServerAPIClientTests.swift index be4c9e76..7ceacf43 100644 --- a/Tests/AppStoreServerLibraryTests/AppStoreServerAPIClientTests.swift +++ b/Tests/AppStoreServerLibraryTests/AppStoreServerAPIClientTests.swift @@ -87,7 +87,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { XCTAssertTrue(false) return } - XCTAssertEqual(Environment.localTesting, statusResponse.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, statusResponse.environment) XCTAssertEqual("LocalTesting", statusResponse.rawEnvironment) XCTAssertEqual("com.example", statusResponse.bundleId) XCTAssertEqual(5454545, statusResponse.appAppleId) @@ -307,7 +307,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { XCTAssertEqual(true, historyResponse.hasMore) XCTAssertEqual("com.example", historyResponse.bundleId) XCTAssertEqual(323232, historyResponse.appAppleId) - XCTAssertEqual(Environment.localTesting, historyResponse.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, historyResponse.environment) XCTAssertEqual("LocalTesting", historyResponse.rawEnvironment) XCTAssertEqual(["signed_transaction_value", "signed_transaction_value2"], historyResponse.signedTransactions) TestingUtility.confirmCodableInternallyConsistent(historyResponse) @@ -355,7 +355,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { XCTAssertEqual(true, historyResponse.hasMore) XCTAssertEqual("com.example", historyResponse.bundleId) XCTAssertEqual(323232, historyResponse.appAppleId) - XCTAssertEqual(Environment.localTesting, historyResponse.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, historyResponse.environment) XCTAssertEqual("LocalTesting", historyResponse.rawEnvironment) XCTAssertEqual(["signed_transaction_value", "signed_transaction_value2"], historyResponse.signedTransactions) TestingUtility.confirmCodableInternallyConsistent(historyResponse) @@ -627,7 +627,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { public func testXcodeEnvironmentForAppStoreServerAPIClient() async throws { let key = getSigningKey() do { - let client = try AppStoreServerAPIClient(signingKey: key, keyId: "keyId", issuerId: "issuerId", bundleId: "com.example", environment: Environment.xcode) + let client = try AppStoreServerAPIClient(signingKey: key, keyId: "keyId", issuerId: "issuerId", bundleId: "com.example", environment: AppStoreEnvironment.xcode) XCTAssertTrue(false) return } catch (let e) { @@ -646,7 +646,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { private func getAppStoreServerAPIClient(_ body: String, _ status: HTTPResponseStatus, _ requestVerifier: RequestVerifier?) throws -> AppStoreServerAPIClient { let key = getSigningKey() - let client = try AppStoreServerAPIClientTest(signingKey: key, keyId: "keyId", issuerId: "issuerId", bundleId: "com.example", environment: Environment.localTesting) { request, requestBody in + let client = try AppStoreServerAPIClientTest(signingKey: key, keyId: "keyId", issuerId: "issuerId", bundleId: "com.example", environment: AppStoreEnvironment.localTesting) { request, requestBody in try requestVerifier.map { try $0(request, requestBody) } let headers = [("Content-Type", "application/json")] let bufferedBody = HTTPClientResponse.Body.bytes(.init(string: body)) @@ -663,7 +663,7 @@ final class AppStoreServerAPIClientTests: XCTestCase { private var requestOverride: ((HTTPClientRequest, Data?) throws -> HTTPClientResponse)? - public init(signingKey: String, keyId: String, issuerId: String, bundleId: String, environment: Environment, requestOverride: @escaping (HTTPClientRequest, Data?) throws -> HTTPClientResponse) throws { + public init(signingKey: String, keyId: String, issuerId: String, bundleId: String, environment: AppStoreEnvironment, requestOverride: @escaping (HTTPClientRequest, Data?) throws -> HTTPClientResponse) throws { try super.init(signingKey: signingKey, keyId: keyId, issuerId: issuerId, bundleId: bundleId, environment: environment) self.requestOverride = requestOverride } diff --git a/Tests/AppStoreServerLibraryTests/SignedDataVerifierTests.swift b/Tests/AppStoreServerLibraryTests/SignedDataVerifierTests.swift index f85f41d9..2854ee5a 100644 --- a/Tests/AppStoreServerLibraryTests/SignedDataVerifierTests.swift +++ b/Tests/AppStoreServerLibraryTests/SignedDataVerifierTests.swift @@ -173,7 +173,7 @@ final class SignedDataVerifierTests: XCTestCase { let renewalInfoResult = await verifier.verifyAndDecodeRenewalInfo(signedRenewalInfo: renewalInfo) switch renewalInfoResult { case .valid(let renewalInfo): - XCTAssertEqual(Environment.sandbox, renewalInfo.environment) + XCTAssertEqual(AppStoreEnvironment.sandbox, renewalInfo.environment) case .invalid(_): XCTAssert(false) } @@ -185,7 +185,7 @@ final class SignedDataVerifierTests: XCTestCase { let transactionInfoResult = await verifier.verifyAndDecodeTransaction(signedTransaction: transactionInfo) switch transactionInfoResult { case .valid(let transactionInfo): - XCTAssertEqual(Environment.sandbox, transactionInfo.environment) + XCTAssertEqual(AppStoreEnvironment.sandbox, transactionInfo.environment) case .invalid(_): XCTAssert(false) } diff --git a/Tests/AppStoreServerLibraryTests/SignedModelTests.swift b/Tests/AppStoreServerLibraryTests/SignedModelTests.swift index e3733915..44e57707 100644 --- a/Tests/AppStoreServerLibraryTests/SignedModelTests.swift +++ b/Tests/AppStoreServerLibraryTests/SignedModelTests.swift @@ -25,7 +25,7 @@ final class SignedModelTests: XCTestCase { XCTAssertNotNil(notification.data) XCTAssertNil(notification.summary) XCTAssertNil(notification.externalPurchaseToken) - XCTAssertEqual(Environment.localTesting, notification.data!.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, notification.data!.environment) XCTAssertEqual("LocalTesting", notification.data!.rawEnvironment) XCTAssertEqual(41234, notification.data!.appAppleId) XCTAssertEqual("com.example", notification.data!.bundleId) @@ -59,7 +59,7 @@ final class SignedModelTests: XCTestCase { XCTAssertNotNil(notification.data) XCTAssertNil(notification.summary) XCTAssertNil(notification.externalPurchaseToken) - XCTAssertEqual(Environment.localTesting, notification.data!.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, notification.data!.environment) XCTAssertEqual("LocalTesting", notification.data!.rawEnvironment) XCTAssertEqual(41234, notification.data!.appAppleId) XCTAssertEqual("com.example", notification.data!.bundleId) @@ -93,7 +93,7 @@ final class SignedModelTests: XCTestCase { XCTAssertNil(notification.data) XCTAssertNotNil(notification.summary) XCTAssertNil(notification.externalPurchaseToken) - XCTAssertEqual(Environment.localTesting, notification.summary!.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, notification.summary!.environment) XCTAssertEqual("LocalTesting", notification.summary!.rawEnvironment) XCTAssertEqual(41234, notification.summary!.appAppleId) XCTAssertEqual("com.example", notification.summary!.bundleId) @@ -206,7 +206,7 @@ final class SignedModelTests: XCTestCase { XCTAssertEqual("143441", transaction.storefrontId) XCTAssertEqual(TransactionReason.purchase, transaction.transactionReason) XCTAssertEqual("PURCHASE", transaction.rawTransactionReason) - XCTAssertEqual(Environment.localTesting, transaction.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, transaction.environment) XCTAssertEqual("LocalTesting", transaction.rawEnvironment) XCTAssertEqual(10990, transaction.price) XCTAssertEqual("USD", transaction.currency) @@ -240,7 +240,7 @@ final class SignedModelTests: XCTestCase { XCTAssertEqual(2, renewalInfo.rawOfferType) XCTAssertEqual("abc.123", renewalInfo.offerIdentifier) XCTAssertEqual(Date(timeIntervalSince1970: 1698148800), renewalInfo.signedDate) - XCTAssertEqual(Environment.localTesting, renewalInfo.environment) + XCTAssertEqual(AppStoreEnvironment.localTesting, renewalInfo.environment) XCTAssertEqual("LocalTesting", renewalInfo.rawEnvironment) XCTAssertEqual(Date(timeIntervalSince1970: 1698148800), renewalInfo.recentSubscriptionStartDate) XCTAssertEqual(Date(timeIntervalSince1970: 1698148850), renewalInfo.renewalDate) @@ -262,7 +262,7 @@ final class SignedModelTests: XCTestCase { return } - XCTAssertEqual(Environment.localTesting, appTransaction.receiptType) + XCTAssertEqual(AppStoreEnvironment.localTesting, appTransaction.receiptType) XCTAssertEqual("LocalTesting", appTransaction.rawReceiptType) XCTAssertEqual(531412, appTransaction.appAppleId) XCTAssertEqual("com.example", appTransaction.bundleId) diff --git a/Tests/AppStoreServerLibraryTests/TestingUtility.swift b/Tests/AppStoreServerLibraryTests/TestingUtility.swift index 955f94f2..70976299 100644 --- a/Tests/AppStoreServerLibraryTests/TestingUtility.swift +++ b/Tests/AppStoreServerLibraryTests/TestingUtility.swift @@ -19,11 +19,11 @@ public class TestingUtility { return try! Data(contentsOf: absolutePath) } - public static func getSignedDataVerifier(_ environment: Environment, _ bundleId: String, _ appAppleId: Int64) -> SignedDataVerifier { + public static func getSignedDataVerifier(_ environment: AppStoreEnvironment, _ bundleId: String, _ appAppleId: Int64) -> SignedDataVerifier { return try! SignedDataVerifier(rootCertificates: [readBytes("resources/certs/testCA.der")], bundleId: bundleId, appAppleId: appAppleId, environment: environment, enableOnlineChecks: false) } - public static func getSignedDataVerifier(_ environment: Environment, _ bundleId: String) -> SignedDataVerifier { + public static func getSignedDataVerifier(_ environment: AppStoreEnvironment, _ bundleId: String) -> SignedDataVerifier { return getSignedDataVerifier(environment, bundleId, 1234) } diff --git a/Tests/AppStoreServerLibraryTests/XcodeSignedDataVerifierTests.swift b/Tests/AppStoreServerLibraryTests/XcodeSignedDataVerifierTests.swift index 67c711b3..2ebac362 100644 --- a/Tests/AppStoreServerLibraryTests/XcodeSignedDataVerifierTests.swift +++ b/Tests/AppStoreServerLibraryTests/XcodeSignedDataVerifierTests.swift @@ -66,7 +66,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase { XCTAssertEqual(OfferType.introductoryOffer, transaction.offerType) XCTAssertEqual(1, transaction.rawOfferType) XCTAssertNil(transaction.offerIdentifier) - XCTAssertEqual(Environment.xcode, transaction.environment) + XCTAssertEqual(AppStoreEnvironment.xcode, transaction.environment) XCTAssertEqual("Xcode", transaction.rawEnvironment) XCTAssertEqual("USA", transaction.storefront) XCTAssertEqual("143441", transaction.storefrontId) @@ -98,7 +98,7 @@ final class XcodeSignedDataVerifierTests: XCTestCase { XCTAssertNil(renewalInfo.offerType) XCTAssertNil(renewalInfo.offerIdentifier) compareXcodeDates(Date(timeIntervalSince1970: 1697679936.711), renewalInfo.signedDate) - XCTAssertEqual(Environment.xcode, renewalInfo.environment) + XCTAssertEqual(AppStoreEnvironment.xcode, renewalInfo.environment) XCTAssertEqual("Xcode", renewalInfo.rawEnvironment) compareXcodeDates(Date(timeIntervalSince1970: 1697679936.049), renewalInfo.recentSubscriptionStartDate) compareXcodeDates(Date(timeIntervalSince1970: 1700358336.049), renewalInfo.renewalDate)