From 1d074887187705a9a7e8d8bb92f8112bf80718e9 Mon Sep 17 00:00:00 2001 From: Connor Wybranowski Date: Wed, 11 Oct 2023 14:47:26 -0400 Subject: [PATCH 1/2] Improve iTunesConnectService with platform --- .../Services/iTunesConnectService.swift | 24 ++++++++---- ...iTunesConnectServiceTests_testErrors.1.txt | 3 +- .../iTunesConnectServiceTests.swift | 37 ++++++++++++------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Sources/SignHereLibrary/Services/iTunesConnectService.swift b/Sources/SignHereLibrary/Services/iTunesConnectService.swift index 58a2ced..68e3337 100644 --- a/Sources/SignHereLibrary/Services/iTunesConnectService.swift +++ b/Sources/SignHereLibrary/Services/iTunesConnectService.swift @@ -26,7 +26,8 @@ internal protocol iTunesConnectService { func determineBundleIdITCId( jsonWebToken: String, bundleIdentifier: String, - bundleIdentifierName: String? + bundleIdentifierName: String?, + platform: String ) throws -> String func fetchITCDeviceIDs(jsonWebToken: String) throws -> Set func createProfile( @@ -46,7 +47,7 @@ internal class iTunesConnectServiceImp: iTunesConnectService { enum Error: Swift.Error, CustomStringConvertible { case invalidURL(string: String) case unableToCreateURL(urlComponents: URLComponents) - case unableToDetermineITCIdForBundleId(bundleIdentifier: String) + case unableToDetermineITCIdForBundleId(bundleIdentifier: String, platform: String) case unableToDetermineModulusForCertificate(output: ShellOutput) case unableToDetermineModulusForPrivateKey(privateKeyPath: String, output: ShellOutput) case unableToBase64DecodeCertificate(displayName: String) @@ -64,10 +65,11 @@ internal class iTunesConnectServiceImp: iTunesConnectService { return """ [iTunesConnectServiceImp] Unable to create url for itunes connect request from url components: \(urlComponents.description) """ - case let .unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier): + case let .unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier, platform: platform): return """ [iTunesConnectServiceImp] Unable to determine iTunesConnect API ID for bundle identifier - Bundle Identifier: \(bundleIdentifier) + - Platform: \(platform) """ case let .unableToDetermineModulusForCertificate(output: output): return """ @@ -226,7 +228,8 @@ internal class iTunesConnectServiceImp: iTunesConnectService { func determineBundleIdITCId( jsonWebToken: String, bundleIdentifier: String, - bundleIdentifierName: String? + bundleIdentifierName: String?, + platform: String ) throws -> String { var urlComponents: URLComponents = .init() urlComponents.scheme = Constants.httpsScheme @@ -250,20 +253,22 @@ internal class iTunesConnectServiceImp: iTunesConnectService { return try makeFirstITCIdForBundleId( data: data, bundleIdentifier: bundleIdentifier, - bundleIdentifierName: bundleIdentifierName + bundleIdentifierName: bundleIdentifierName, + platform: platform ) } private func makeFirstITCIdForBundleId( data: Data, bundleIdentifier: String, - bundleIdentifierName: String? + bundleIdentifierName: String?, + platform: String ) throws -> String { do { let listBundleIDsResponse: ListBundleIDsResponse = try createITCApiJSONDecoder().decode(ListBundleIDsResponse.self, from: data) guard let bundleIdITCId: String = listBundleIDsResponse.data.compactMap({ bundleData in guard bundleData.attributes.identifier == bundleIdentifier, - bundleData.attributes.platform == "IOS" + bundleData.attributes.platform == platform else { return nil } @@ -276,7 +281,10 @@ internal class iTunesConnectServiceImp: iTunesConnectService { return bundleData.id }).first else { - throw Error.unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier) + throw Error.unableToDetermineITCIdForBundleId( + bundleIdentifier: bundleIdentifier, + platform: platform + ) } return bundleIdITCId } catch let decodingError as DecodingError { diff --git a/Tests/SignHereLibraryTests/__Snapshots__/iTunesConnectServiceTests/iTunesConnectServiceTests_testErrors.1.txt b/Tests/SignHereLibraryTests/__Snapshots__/iTunesConnectServiceTests/iTunesConnectServiceTests_testErrors.1.txt index 253ccf9..e1868ad 100644 --- a/Tests/SignHereLibraryTests/__Snapshots__/iTunesConnectServiceTests/iTunesConnectServiceTests_testErrors.1.txt +++ b/Tests/SignHereLibraryTests/__Snapshots__/iTunesConnectServiceTests/iTunesConnectServiceTests_testErrors.1.txt @@ -1,2 +1,3 @@ [iTunesConnectServiceImp] Unable to determine iTunesConnect API ID for bundle identifier -- Bundle Identifier: bundleIdentifier \ No newline at end of file +- Bundle Identifier: bundleIdentifier +- Platform: platform \ No newline at end of file diff --git a/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift b/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift index eb4743a..08a10da 100644 --- a/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift +++ b/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift @@ -60,7 +60,8 @@ final class iTunesConnectServiceTests: XCTestCase { func testErrors() { assertSnapshot( matching: iTunesConnectServiceImp.Error.unableToDetermineITCIdForBundleId( - bundleIdentifier: "bundleIdentifier" + bundleIdentifier: "bundleIdentifier", + platform: "platform" ).description, as: .lines ) @@ -383,7 +384,8 @@ final class iTunesConnectServiceTests: XCTestCase { let value: String = try subject.determineBundleIdITCId( jsonWebToken: "jsonWebToken", bundleIdentifier: "bundleIdentifier", - bundleIdentifierName: nil + bundleIdentifierName: nil, + platform: "platform" ) // THEN @@ -407,7 +409,8 @@ final class iTunesConnectServiceTests: XCTestCase { let value: String = try subject.determineBundleIdITCId( jsonWebToken: "jsonWebToken", bundleIdentifier: "bundleIdentifier", - bundleIdentifierName: "name" + bundleIdentifierName: "name", + platform: "platform" ) // THEN @@ -428,11 +431,14 @@ final class iTunesConnectServiceTests: XCTestCase { } // WHEN - XCTAssertThrowsError(try subject.determineBundleIdITCId( - jsonWebToken: "jsonWebToken", - bundleIdentifier: "bundleIdentifier", - bundleIdentifierName: "invalid" - )) { + XCTAssertThrowsError( + try subject.determineBundleIdITCId( + jsonWebToken: "jsonWebToken", + bundleIdentifier: "bundleIdentifier", + bundleIdentifierName: "invalid", + platform: "platform" + ) + ) { if case iTunesConnectServiceImp.Error.unableToDetermineITCIdForBundleId = $0 { return } @@ -455,11 +461,14 @@ final class iTunesConnectServiceTests: XCTestCase { } // WHEN - XCTAssertThrowsError(try subject.determineBundleIdITCId( - jsonWebToken: "jsonWebToken", - bundleIdentifier: "bundleIdentifier", - bundleIdentifierName: nil - )) { + XCTAssertThrowsError( + try subject.determineBundleIdITCId( + jsonWebToken: "jsonWebToken", + bundleIdentifier: "bundleIdentifier", + bundleIdentifierName: nil, + platform: "platform" + ) + ) { if case iTunesConnectServiceImp.Error.unableToDecodeResponse = $0 { return } @@ -757,7 +766,7 @@ final class iTunesConnectServiceTests: XCTestCase { attributes: ListBundleIDsResponse.BundleId.Attributes( name: "name", identifier: "bundleIdentifier", - platform: "IOS" + platform: "platform" ) ) ] From 3428713e1551ef9df74095601bb0298d26eea795 Mon Sep 17 00:00:00 2001 From: Connor Wybranowski Date: Wed, 11 Oct 2023 14:47:39 -0400 Subject: [PATCH 2/2] Improve CreateProvisioningProfileCommand with platform --- .../CreateProvisioningProfileCommand.swift | 14 +++++++++++--- .../CreateProvisioningProfileCommandTests.swift | 7 +++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift index 08d308a..b3ced21 100644 --- a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift +++ b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift @@ -114,6 +114,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { case keychainPassword = "keychainPassword" case bundleIdentifier = "bundleIdentifier" case bundleIdentifierName = "bundleIdentifierName" + case platform = "platform" case profileType = "profileType" case certificateType = "certificateType" case outputPath = "outputPath" @@ -146,6 +147,9 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { @Option(help: "The bundle identifier name for the desired bundle identifier, this is optional but if it is not set the logic will select the first bundle id it finds that matches `--bundle-identifier`") internal var bundleIdentifierName: String? + @Option(help: "The intended operating system for the target (https://developer.apple.com/documentation/appstoreconnectapi/bundleidplatform)") + internal var platform: String + @Option(help: "The profile type which you wish to create (https://developer.apple.com/documentation/appstoreconnectapi/profilecreaterequest/data/attributes)") internal var profileType: String @@ -218,7 +222,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { opensslPath: String, intermediaryAppleCertificates: [String], certificateSigningRequestSubject: String, - bundleIdentifierName: String? + bundleIdentifierName: String?, + platform: String ) { self.files = files self.log = log @@ -240,6 +245,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { self.intermediaryAppleCertificates = intermediaryAppleCertificates self.certificateSigningRequestSubject = certificateSigningRequestSubject self.bundleIdentifierName = bundleIdentifierName + self.platform = platform } internal init(from decoder: Decoder) throws { @@ -272,7 +278,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { opensslPath: try container.decode(String.self, forKey: .opensslPath), intermediaryAppleCertificates: try container.decodeIfPresent([String].self, forKey: .intermediaryAppleCertificates) ?? [], certificateSigningRequestSubject: try container.decode(String.self, forKey: .certificateSigningRequestSubject), - bundleIdentifierName: try container.decodeIfPresent(String.self, forKey: .bundleIdentifierName) + bundleIdentifierName: try container.decodeIfPresent(String.self, forKey: .bundleIdentifierName), + platform: try container.decode(String.self, forKey: .platform) ) } @@ -303,7 +310,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { bundleId: try iTunesConnectService.determineBundleIdITCId( jsonWebToken: jsonWebToken, bundleIdentifier: bundleIdentifier, - bundleIdentifierName: bundleIdentifierName + bundleIdentifierName: bundleIdentifierName, + platform: platform ), certificateId: certificateId, deviceIDs: deviceIDs, diff --git a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift index 091ffbb..0974396 100644 --- a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift +++ b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift @@ -55,7 +55,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { opensslPath: "/opensslPath", intermediaryAppleCertificates: ["/intermediaryAppleCertificate"], certificateSigningRequestSubject: "certificateSigningRequestSubject", - bundleIdentifierName: "bundleIdentifierName" + bundleIdentifierName: "bundleIdentifierName", + platform: "platform" ) isRecording = false } @@ -158,7 +159,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { "outputPath": "/outputPath", "opensslPath": "/opensslPath", "certificateSigningRequestSubject": "certificateSigningRequestSubject", - "bundleIdentifierName": "bundleIdentifierName" + "bundleIdentifierName": "bundleIdentifierName", + "platform": "platform" } """.utf8) @@ -177,6 +179,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { XCTAssertEqual(subject.certificateType, "certificateType") XCTAssertEqual(subject.outputPath, "/outputPath") XCTAssertEqual(subject.bundleIdentifierName, "bundleIdentifierName") + XCTAssertEqual(subject.platform, "platform") } func test_execute_alreadyActiveCertificate() throws {