mirror of
https://github.com/majd/ipatool
synced 2026-11-29 10:38:08 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07a0f3310d | ||
|
|
9cfd72d142 | ||
|
|
a16afb5c7b | ||
|
|
ec4b6cfc29 | ||
|
|
83515013cd | ||
|
|
1577e1b8bc | ||
|
|
8d3167cc6e |
No files matched your search
@@ -31,12 +31,10 @@ jobs:
|
||||
${{ runner.os }}-spm-
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: swift build
|
||||
- name: Run tests
|
||||
run: swift test
|
||||
build:
|
||||
name: Build
|
||||
build_macos:
|
||||
name: Build (macOS)
|
||||
runs-on: macos-12
|
||||
needs: [get_version, test]
|
||||
steps:
|
||||
@@ -53,33 +51,79 @@ jobs:
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
run: make build-macos
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
path: .build/apple/Products/Release/ipatool
|
||||
name: ipatool-macos-v${{ needs.get_version.outputs.version }}
|
||||
path: .build/ipatool
|
||||
if-no-files-found: error
|
||||
build_ios:
|
||||
name: Build (iOS)
|
||||
runs-on: macos-12
|
||||
needs: [get_version, test]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache SwiftPM packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .build/checkouts
|
||||
key: ${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
${{ runner.os }}-spm-
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Install dependencies
|
||||
run: brew install xcodegen ldid
|
||||
- name: Build
|
||||
run: make build-ios
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ipatool-ios-v${{ needs.get_version.outputs.version }}
|
||||
path: .build/ipatool
|
||||
if-no-files-found: error
|
||||
distribute:
|
||||
name: Distribute
|
||||
runs-on: ubuntu-20.04
|
||||
needs: [get_version, build]
|
||||
needs: [get_version, build_ios, build_macos]
|
||||
steps:
|
||||
- name: Download binary
|
||||
- name: Download binary (macOS)
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
path: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
- name: Archive binary
|
||||
name: ipatool-macos-v${{ needs.get_version.outputs.version }}
|
||||
path: ipatool-macos-v${{ needs.get_version.outputs.version }}
|
||||
- name: Archive binary (macOS)
|
||||
run: |
|
||||
mv ipatool-v${{ needs.get_version.outputs.version }}/ipatool ipatool
|
||||
zip ipatool-v${{ needs.get_version.outputs.version }}.zip ipatool
|
||||
- name: Upload binary to release
|
||||
mv ipatool-macos-v${{ needs.get_version.outputs.version }}/ipatool ipatool
|
||||
zip ipatool-macos-v${{ needs.get_version.outputs.version }}.zip ipatool
|
||||
rm ipatool
|
||||
- name: Upload release (macOS)
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: ipatool-v${{ needs.get_version.outputs.version }}.zip
|
||||
asset_name: ipatool-v${{ needs.get_version.outputs.version }}.zip
|
||||
file: ipatool-macos-v${{ needs.get_version.outputs.version }}.zip
|
||||
asset_name: ipatool-macos-v${{ needs.get_version.outputs.version }}.zip
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: false
|
||||
- name: Download binary (iOS)
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: ipatool-ios-v${{ needs.get_version.outputs.version }}
|
||||
path: ipatool-ios-v${{ needs.get_version.outputs.version }}
|
||||
- name: Archive binary (iOS)
|
||||
run: |
|
||||
mv ipatool-ios-v${{ needs.get_version.outputs.version }}/ipatool ipatool
|
||||
zip ipatool-ios-v${{ needs.get_version.outputs.version }}.zip ipatool
|
||||
rm ipatool
|
||||
- name: Upload release (iOS)
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: ipatool-ios-v${{ needs.get_version.outputs.version }}.zip
|
||||
asset_name: ipatool-ios-v${{ needs.get_version.outputs.version }}.zip
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: false
|
||||
- name: Checkout homebrew repo
|
||||
@@ -91,10 +135,11 @@ jobs:
|
||||
token: ${{ secrets.GH_TOKEN }}
|
||||
- name: Update homebrew repo
|
||||
run: |
|
||||
SHA256=$(sha256sum ipatool-v${{ needs.get_version.outputs.version }}.zip | awk '{print $1}')
|
||||
SHA256=$(sha256sum ipatool-macos-v${{ needs.get_version.outputs.version }}.zip | awk '{print $1}')
|
||||
cd repo
|
||||
sed -i "3s/.*/ sha256 \"$SHA256\"/" Casks/ipatool.rb
|
||||
sed -i "2s/.*/ version \"${{ needs.get_version.outputs.version }}\"/" Casks/ipatool.rb
|
||||
sed -i "5s/.*/ url \"https:\/\/github.com\/majd\/ipatool\/releases\/download\/v${{ needs.get_version.outputs.version }}\/ipatool-macos-v${{ needs.get_version.outputs.version }}.zip\"/" Casks/ipatool.rb
|
||||
git config --local user.name ${{ secrets.GH_NAME }}
|
||||
git config --local user.email ${{ secrets.GH_EMAIL }}
|
||||
git add Casks/ipatool.rb
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
name: Dry Builds
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build_ios:
|
||||
name: Dry build (iOS)
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache SwiftPM packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .build/checkouts
|
||||
key: ${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
${{ runner.os }}-spm-
|
||||
- name: Install dependencies
|
||||
run: brew install xcodegen ldid
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: |
|
||||
make build-ios
|
||||
file .build/ipatool
|
||||
build_macos:
|
||||
name: Dry build (macOS)
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache SwiftPM packages
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: .build/checkouts
|
||||
key: ${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
${{ runner.os }}-spm-
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: |
|
||||
make build-macos
|
||||
file .build/ipatool
|
||||
@@ -1,6 +1,9 @@
|
||||
name: Integration Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
@@ -23,12 +26,12 @@ jobs:
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
run: make build-macos
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ipatool
|
||||
path: .build/apple/Products/Release/ipatool
|
||||
path: .build/ipatool
|
||||
if-no-files-found: error
|
||||
test:
|
||||
name: Test
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
name: Unit Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
disabled_rules:
|
||||
- cyclomatic_complexity
|
||||
- type_body_length
|
||||
- identifier_name
|
||||
- function_body_length
|
||||
|
||||
opt_in_rules:
|
||||
- multiline_function_chains
|
||||
- anyobject_protocol
|
||||
- overridden_super_call
|
||||
- prohibited_super_call
|
||||
- last_where
|
||||
- contains_over_first_not_nil
|
||||
- vertical_parameter_alignment_on_call
|
||||
- multiline_arguments
|
||||
- multiline_literal_brackets
|
||||
- closure_end_indentation
|
||||
- collection_alignment
|
||||
- reduce_into
|
||||
- explicit_init
|
||||
- static_operator
|
||||
- sorted_first_last
|
||||
- no_space_in_method_call
|
||||
- contains_over_filter_count
|
||||
- contains_over_filter_is_empty
|
||||
- empty_collection_literal
|
||||
- empty_count
|
||||
|
||||
type_name:
|
||||
validates_start_with_lowercase: false
|
||||
|
||||
nesting:
|
||||
type_level:
|
||||
warning: 3
|
||||
|
||||
line_length:
|
||||
warning: 120
|
||||
error: 120
|
||||
ignore_comments: true
|
||||
ignore_urls: true
|
||||
|
||||
file_length:
|
||||
warning: 1000
|
||||
error: 1000
|
||||
|
||||
reporter: "xcode"
|
||||
@@ -90,6 +90,20 @@
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "SwiftLint"
|
||||
BuildableName = "SwiftLint"
|
||||
BlueprintName = "SwiftLint"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
|
||||
@@ -1,17 +1,57 @@
|
||||
prefix ?= /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
|
||||
build:
|
||||
xcrun swift build -c release --arch arm64 --arch x86_64
|
||||
define ios_entitlements
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>ipatool</string>
|
||||
</array>
|
||||
<key>application-identifier</key>
|
||||
<string>ipatool</string>
|
||||
<key>platform-application</key>
|
||||
<true />
|
||||
<key>com.apple.private.security.container-required</key>
|
||||
<false />
|
||||
</dict>
|
||||
</plist>
|
||||
endef
|
||||
|
||||
install: build
|
||||
lint:
|
||||
swiftlint lint --config .swiftlint.yml --path Sources/ Tests/m Plugins/
|
||||
|
||||
build-macos: lint
|
||||
swift build -c release --arch arm64
|
||||
swift build -c release --arch x86_64
|
||||
lipo -create -output .build/ipatool .build/arm64-apple-macosx/release/ipatool .build/x86_64-apple-macosx/release/ipatool
|
||||
|
||||
build-ios: lint
|
||||
xcodegen -s ios-project.yml
|
||||
xcodebuild archive -scheme CLI \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
-derivedDataPath .build \
|
||||
-archivePath .build/ipatool.xcarchive \
|
||||
CODE_SIGN_IDENTITY='' \
|
||||
CODE_SIGNING_REQUIRED=NO \
|
||||
CODE_SIGN_ENTITLEMENTS='' \
|
||||
CODE_SIGNING_ALLOWED=NO
|
||||
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
|
||||
echo "$$ios_entitlements" > "${PWD}/.build/entitlements.xml"
|
||||
ldid -S.build/entitlements.xml ./.build/ipatool
|
||||
|
||||
install-macos: build
|
||||
install -d "$(bindir)"
|
||||
install ".build/apple/Products/Release/ipatool" "$(bindir)"
|
||||
install ".build/ipatool" "$(bindir)"
|
||||
|
||||
uninstall:
|
||||
uninstall-macos:
|
||||
rm -rf "$(bindir)/ipatool"
|
||||
|
||||
clean:
|
||||
rm -rf .build
|
||||
|
||||
.PHONY: build install uninstall clean
|
||||
.PHONY: build-macos install-macos uninstall-macos clean
|
||||
|
||||
export ios_entitlements
|
||||
+29
-31
@@ -1,34 +1,32 @@
|
||||
{
|
||||
"object": {
|
||||
"pins": [
|
||||
{
|
||||
"package": "KeychainAccess",
|
||||
"repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess",
|
||||
"state": {
|
||||
"branch": "v4.2.2",
|
||||
"revision": "84e546727d66f1adc5439debad16270d0fdd04e7",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-argument-parser",
|
||||
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
||||
"state": {
|
||||
"branch": "1.1.2",
|
||||
"revision": "f3c9084a71ef4376f2fabbdf1d3d90a49f1fabdb",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "ZIPFoundation",
|
||||
"repositoryURL": "https://github.com/weichsel/ZIPFoundation",
|
||||
"state": {
|
||||
"branch": "0.9.14",
|
||||
"revision": "7254c74b49cec2cb81520523ba993c671f71b066",
|
||||
"version": null
|
||||
}
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "keychainaccess",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kishikawakatsumi/KeychainAccess",
|
||||
"state" : {
|
||||
"branch" : "v4.2.2",
|
||||
"revision" : "84e546727d66f1adc5439debad16270d0fdd04e7"
|
||||
}
|
||||
]
|
||||
},
|
||||
"version": 1
|
||||
},
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-argument-parser",
|
||||
"state" : {
|
||||
"branch" : "1.1.2",
|
||||
"revision" : "f3c9084a71ef4376f2fabbdf1d3d90a49f1fabdb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "zipfoundation",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/weichsel/ZIPFoundation",
|
||||
"state" : {
|
||||
"branch" : "0.9.14",
|
||||
"revision" : "7254c74b49cec2cb81520523ba993c671f71b066"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 2
|
||||
}
|
||||
+30
-7
@@ -17,6 +17,7 @@ let package = Package(
|
||||
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", revision: "v4.2.2")
|
||||
],
|
||||
targets: [
|
||||
// IPATool CLI
|
||||
.executableTarget(
|
||||
name: "CLI",
|
||||
dependencies: [
|
||||
@@ -24,20 +25,42 @@ let package = Package(
|
||||
.byName(name: "Networking"),
|
||||
.byName(name: "StoreAPI"),
|
||||
.byName(name: "Persistence")
|
||||
]
|
||||
],
|
||||
plugins: ["SwiftLint"]
|
||||
),
|
||||
|
||||
// StoreAPI
|
||||
.target(
|
||||
name: "StoreAPI",
|
||||
dependencies: [
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
.product(name: "ZIPFoundation", package: "ZIPFoundation"),
|
||||
.byName(name: "Networking"),
|
||||
]
|
||||
],
|
||||
plugins: ["SwiftLint"]
|
||||
),
|
||||
.target(name: "Networking", dependencies: []),
|
||||
.testTarget(name: "NetworkingTests", dependencies: ["Networking"]),
|
||||
.target(name: "Persistence", dependencies: [
|
||||
.byName(name: "KeychainAccess")
|
||||
]),
|
||||
|
||||
// Networking
|
||||
.target(
|
||||
name: "Networking",
|
||||
plugins: ["SwiftLint"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "NetworkingTests",
|
||||
dependencies: ["Networking"],
|
||||
plugins: ["SwiftLint"]
|
||||
),
|
||||
|
||||
// Persistence
|
||||
.target(
|
||||
name: "Persistence",
|
||||
dependencies: [
|
||||
.byName(name: "KeychainAccess")
|
||||
],
|
||||
plugins: ["SwiftLint"]
|
||||
),
|
||||
|
||||
// SwiftLint
|
||||
.plugin(name: "SwiftLint", capability: .buildTool())
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// main.swift
|
||||
// SwiftLint
|
||||
//
|
||||
// Created by Majd Alfhaily on 15.06.22.
|
||||
//
|
||||
|
||||
import PackagePlugin
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct SwiftLint: BuildToolPlugin {
|
||||
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
|
||||
let toolPath = try determinePath(forTool: "swiftlint")
|
||||
let configPath = context.package.directory.appending(".swiftlint.yml")
|
||||
|
||||
return [
|
||||
.buildCommand(
|
||||
displayName: "Run SwiftLint",
|
||||
executable: toolPath,
|
||||
arguments: [
|
||||
"lint",
|
||||
"--in-process-sourcekit",
|
||||
"--config",
|
||||
configPath.string,
|
||||
"--path",
|
||||
target.directory.string
|
||||
]
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
private func determinePath(forTool toolName: String) throws -> Path {
|
||||
let prefixes: [String] = [
|
||||
"/opt/homebrew/bin",
|
||||
"/usr/local/bin",
|
||||
"/usr/bin",
|
||||
"/bin"
|
||||
]
|
||||
|
||||
for path in prefixes where FileManager.default.fileExists(atPath: "\(path)/\(toolName)") {
|
||||
return Path("\(path)/\(toolName)")
|
||||
}
|
||||
|
||||
throw NSError(
|
||||
domain: Bundle.main.bundleIdentifier ?? String(describing: type(of: self)),
|
||||
code: 0,
|
||||
userInfo: [NSLocalizedDescriptionKey: "Could not find tool: \(toolName)."]
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
[](https://GitHub.com/majd/ipatool/releases/)
|
||||
[](https://github.com/majd/ipatool/blob/main/LICENSE)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/unit-tests.yml)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/integration-tests.yml)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/unit-tests.yml)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/integration-tests.yml)
|
||||

|
||||

|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@ extension Auth.Login {
|
||||
return email
|
||||
} else if let email = ProcessInfo.processInfo.environment["IPATOOL_EMAIL"] {
|
||||
return email
|
||||
} else if let email = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))) {
|
||||
} else if let email = String(
|
||||
validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))
|
||||
) {
|
||||
return email
|
||||
} else {
|
||||
logger.log("An Apple ID email address is required.", level: .error)
|
||||
@@ -74,7 +76,9 @@ extension Auth.Login {
|
||||
return password
|
||||
} else if let password = ProcessInfo.processInfo.environment["IPATOOL_PASSWORD"] {
|
||||
return password
|
||||
} else if let password = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))) {
|
||||
} else if let password = String(
|
||||
validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))
|
||||
) {
|
||||
return password
|
||||
} else {
|
||||
logger.log("An Apple ID password is required.", level: .error)
|
||||
@@ -87,7 +91,9 @@ extension Auth.Login {
|
||||
return authCode
|
||||
} else if let authCode = ProcessInfo.processInfo.environment["IPATOOL_2FA_CODE"] {
|
||||
return authCode
|
||||
} else if let authCode = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning)))) {
|
||||
} else if let authCode = String(
|
||||
validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning)))
|
||||
) {
|
||||
return authCode
|
||||
} else {
|
||||
logger.log("A 2FA auth-code is required.", level: .error)
|
||||
|
||||
@@ -49,7 +49,10 @@ extension Download {
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...", level: .info)
|
||||
logger.log(
|
||||
"Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...",
|
||||
level: .info
|
||||
)
|
||||
return try itunesClient.lookup(
|
||||
bundleIdentifier: bundleIdentifier,
|
||||
countryCode: countryCode,
|
||||
@@ -69,10 +72,12 @@ extension Download {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private mutating func purchase(app: iTunesResponse.Result, account: Account) {
|
||||
guard app.price == 0 else {
|
||||
logger.log("It is only possible to obtain a license for free apps. Purchase the app manually and run the \"download\" command again.", level: .error)
|
||||
logger.log([
|
||||
"It is only possible to obtain a license for free apps.",
|
||||
"Purchase the app manually and run the \"download\" command again."
|
||||
].joined(separator: " "), level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
@@ -101,7 +106,10 @@ extension Download {
|
||||
case StoreResponse.Error.priceMismatch:
|
||||
logger.log("Price mismatch. It is only possible to obtain a license for free apps.", level: .error)
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
logger.log([
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
@@ -131,7 +139,7 @@ extension Download {
|
||||
)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.invalidResponse:
|
||||
logger.log("Received invalid response.", level: .error)
|
||||
@@ -146,20 +154,29 @@ extension Download {
|
||||
|
||||
return item(from: app, account: account, purchaseAttempted: true)
|
||||
} else {
|
||||
logger.log("Your Apple ID does not have a license for this app. Use the \"purchase\" command or the \"--purchase\" to obtain a license.", level: .error)
|
||||
logger.log([
|
||||
"Your Apple ID does not have a license for this app.",
|
||||
"Use the \"purchase\" command or the \"--purchase\" to obtain a license."
|
||||
].joined(separator: " "), level: .error)
|
||||
}
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
logger.log([
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
logger.log([
|
||||
"An unknown error has occurred.",
|
||||
"The token may have already expired - try loggin in again using the \"auth\" command."
|
||||
].joined(separator: " "), level: .error)
|
||||
}
|
||||
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private mutating func download(item: StoreResponse.Item, to targetURL: URL) {
|
||||
logger.log("Creating download client...", level: .debug)
|
||||
let downloadClient = HTTPDownloadClient()
|
||||
@@ -177,7 +194,7 @@ extension Download {
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private mutating func applyPatches(item: StoreResponse.Item, email: String, path: String) {
|
||||
logger.log("Creating signature client...", level: .debug)
|
||||
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
|
||||
@@ -192,30 +209,30 @@ extension Download {
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private mutating func makeOutputPath(app: iTunesResponse.Result) -> String {
|
||||
let fileName: String = "/\(bundleIdentifier)_\(app.identifier)_v\(app.version)_\(Int.random(in: 100...999)).ipa"
|
||||
|
||||
|
||||
guard let output = output else {
|
||||
return FileManager.default.currentDirectoryPath.appending(fileName)
|
||||
}
|
||||
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
FileManager.default.fileExists(atPath: output, isDirectory: &isDirectory)
|
||||
|
||||
|
||||
return isDirectory.boolValue ? output.appending(fileName) : output
|
||||
}
|
||||
|
||||
mutating func validate() throws {
|
||||
guard let output = output else { return }
|
||||
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
guard !FileManager.default.fileExists(atPath: output, isDirectory: &isDirectory) || isDirectory.boolValue else {
|
||||
logger.log("A file already exists at \(output).", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mutating func run() throws {
|
||||
// Authenticate with the App Store
|
||||
let keychainStore = KeychainStore(service: "ipatool.service")
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
@main
|
||||
struct IPATool: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return CommandConfiguration(
|
||||
|
||||
@@ -43,7 +43,10 @@ extension Purchase {
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...", level: .info)
|
||||
logger.log(
|
||||
"Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...",
|
||||
level: .info
|
||||
)
|
||||
let app = try itunesClient.lookup(
|
||||
bundleIdentifier: bundleIdentifier,
|
||||
countryCode: countryCode,
|
||||
@@ -96,7 +99,10 @@ extension Purchase {
|
||||
case StoreResponse.Error.priceMismatch:
|
||||
logger.log("Price mismatch. It is only possible to obtain a license for free apps.", level: .error)
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
logger.log([
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
|
||||
@@ -32,7 +32,7 @@ struct Search: ParsableCommand {
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ extension Search {
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mutating func run() throws {
|
||||
// Search the iTunes store
|
||||
let results = results(with: term)
|
||||
|
||||
@@ -6,22 +6,34 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Darwin
|
||||
|
||||
final class ConsoleLogger: Logging {
|
||||
private let level: LogLevel
|
||||
|
||||
|
||||
init(level: LogLevel) {
|
||||
self.level = level
|
||||
}
|
||||
|
||||
|
||||
func log(_ message: String, level: LogLevel) {
|
||||
guard level <= self.level else { return }
|
||||
print(compile(message, level: level))
|
||||
|
||||
switch level {
|
||||
case .error:
|
||||
fputs("\(compile(message, level: level))\n", stderr)
|
||||
default:
|
||||
print(compile(message, level: level))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func log(_ message: String, prefix: String, level: LogLevel) {
|
||||
guard level <= self.level else { return }
|
||||
print("\(prefix)\(compile(message, level: level))")
|
||||
switch level {
|
||||
case .error:
|
||||
fputs("\(prefix)\(compile(message, level: level))\n", stderr)
|
||||
default:
|
||||
print("\(prefix)\(compile(message, level: level))")
|
||||
}
|
||||
}
|
||||
|
||||
func compile(_ message: String, level: LogLevel) -> String {
|
||||
|
||||
@@ -28,7 +28,7 @@ extension LogLevel {
|
||||
return "🛠\t[Debug] "
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var priority: Int {
|
||||
switch self {
|
||||
case .error:
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// main.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 15.06.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func disablePrintBuffering() {
|
||||
setbuf(stderr, nil)
|
||||
setbuf(stdout, nil)
|
||||
}
|
||||
|
||||
disablePrintBuffering()
|
||||
IPATool.main()
|
||||
@@ -13,7 +13,7 @@ public protocol HTTPClientInterface {
|
||||
|
||||
public final class HTTPClient: HTTPClientInterface {
|
||||
private let session: URLSessionInterface
|
||||
|
||||
|
||||
public init(session: URLSessionInterface) {
|
||||
self.session = session
|
||||
}
|
||||
@@ -23,10 +23,12 @@ public final class HTTPClient: HTTPClientInterface {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: (data: Data?, response: URLResponse?, error: Swift.Error?)
|
||||
|
||||
session.dataTask(with: request) { (data, response, error) in
|
||||
result = (data, response, error)
|
||||
semaphore.signal()
|
||||
}.resume()
|
||||
session
|
||||
.dataTask(with: request) { (data, response, error) in
|
||||
result = (data, response, error)
|
||||
semaphore.signal()
|
||||
}
|
||||
.resume()
|
||||
|
||||
semaphore.wait()
|
||||
|
||||
@@ -40,7 +42,7 @@ public final class HTTPClient: HTTPClientInterface {
|
||||
|
||||
return HTTPResponse(statusCode: response.statusCode, data: result.data)
|
||||
}
|
||||
|
||||
|
||||
private func makeURLRequest(from request: HTTPRequest) throws -> URLRequest {
|
||||
var urlRequest = URLRequest(url: request.endpoint.url)
|
||||
urlRequest.httpMethod = request.method.rawValue
|
||||
@@ -69,7 +71,7 @@ public final class HTTPClient: HTTPClientInterface {
|
||||
urlRequest.setValue("application/xml", forHTTPHeaderField: "Content-Type")
|
||||
urlRequest.httpBody = try PropertyListSerialization.data(fromPropertyList: value, format: .xml, options: 0)
|
||||
}
|
||||
|
||||
|
||||
request.headers.forEach { urlRequest.setValue($0.value, forHTTPHeaderField: $0.key) }
|
||||
|
||||
return urlRequest
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class HTTPDownloadClient: NSObject, HTTPDownloadClientInterface {
|
||||
super.init()
|
||||
self.session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
|
||||
}
|
||||
|
||||
|
||||
public func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void) throws {
|
||||
assert(progressHandler == nil)
|
||||
assert(semaphore == nil)
|
||||
@@ -61,7 +61,7 @@ extension HTTPDownloadClient: URLSessionDownloadDelegate {
|
||||
|
||||
result = .failure(error)
|
||||
}
|
||||
|
||||
|
||||
public func urlSession(
|
||||
_ session: URLSession,
|
||||
downloadTask: URLSessionDownloadTask,
|
||||
@@ -71,7 +71,7 @@ extension HTTPDownloadClient: URLSessionDownloadDelegate {
|
||||
) {
|
||||
progressHandler?(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite))
|
||||
}
|
||||
|
||||
|
||||
public func urlSession(
|
||||
_ session: URLSession,
|
||||
downloadTask: URLSessionDownloadTask,
|
||||
@@ -83,12 +83,12 @@ extension HTTPDownloadClient: URLSessionDownloadDelegate {
|
||||
semaphore = nil
|
||||
targetURL = nil
|
||||
}
|
||||
|
||||
|
||||
guard let target = targetURL else {
|
||||
result = .failure(Error.invalidTarget)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
try FileManager.default.moveItem(at: location, to: target)
|
||||
result = .success(())
|
||||
|
||||
@@ -17,7 +17,7 @@ extension HTTPResponse {
|
||||
guard let data = data else {
|
||||
throw Error.noData
|
||||
}
|
||||
|
||||
|
||||
switch decoder {
|
||||
case .json:
|
||||
let decoder = JSONDecoder()
|
||||
@@ -36,7 +36,7 @@ extension HTTPResponse {
|
||||
case json
|
||||
case xml
|
||||
}
|
||||
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case noData
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
// https://web.archive.org/web/20191206001952/https://affiliate.itunes.apple.com/resources/documentation/linking-to-the-itunes-music-store
|
||||
// https://web.archive.org/web/20191206001952/
|
||||
// https://affiliate.itunes.apple.com/resources/documentation/linking-to-the-itunes-music-store
|
||||
public enum Storefront: String, CaseIterable {
|
||||
case AE = "143481"
|
||||
case AG = "143540"
|
||||
|
||||
@@ -16,14 +16,14 @@ public protocol SignatureClientInterface {
|
||||
public final class SignatureClient: SignatureClientInterface {
|
||||
private let fileManager: FileManager
|
||||
private let filePath: String
|
||||
|
||||
|
||||
public init(fileManager: FileManager, filePath: String) {
|
||||
self.fileManager = fileManager
|
||||
self.filePath = filePath
|
||||
}
|
||||
|
||||
|
||||
public func appendMetadata(item: StoreResponse.Item, email: String) throws {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
|
||||
@@ -31,31 +31,44 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
metadata["apple-id"] = email
|
||||
metadata["userName"] = email
|
||||
|
||||
let metadataUrl = URL(fileURLWithPath: NSTemporaryDirectory().appending("\(UUID().uuidString)/iTunesMetadata.plist"))
|
||||
let metadataPath = NSTemporaryDirectory().appending("\(UUID().uuidString)/iTunesMetadata.plist")
|
||||
let metadataUrl = URL(fileURLWithPath: metadataPath)
|
||||
|
||||
try fileManager.createDirectory(at: metadataUrl.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
try PropertyListSerialization.data(fromPropertyList: metadata, format: .xml, options: .zero).write(to: metadataUrl)
|
||||
try PropertyListSerialization
|
||||
.data(
|
||||
fromPropertyList: metadata,
|
||||
format: .xml,
|
||||
options: .zero
|
||||
)
|
||||
.write(to: metadataUrl)
|
||||
try archive.addEntry(with: metadataUrl.lastPathComponent, relativeTo: metadataUrl.deletingLastPathComponent())
|
||||
try fileManager.removeItem(at: metadataUrl)
|
||||
}
|
||||
|
||||
|
||||
public func appendSignature(item: StoreResponse.Item) throws {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
|
||||
let manifest = try readPlist(archive: archive, matchingSuffix: ".app/SC_Info/Manifest.plist", type: Manifest.self)
|
||||
let manifest = try readPlist(
|
||||
archive: archive,
|
||||
matchingSuffix: ".app/SC_Info/Manifest.plist",
|
||||
type: Manifest.self
|
||||
)
|
||||
|
||||
guard let infoEntry = archive.first(where: { $0.path.hasSuffix(".app/Info.plist") }) else {
|
||||
throw Error.invalidAppBundle
|
||||
}
|
||||
|
||||
|
||||
let appBundleName = URL(fileURLWithPath: infoEntry.path)
|
||||
.deletingLastPathComponent()
|
||||
.deletingPathExtension()
|
||||
.lastPathComponent
|
||||
|
||||
guard let signatureItem = item.signatures.first(where: { $0.id == 0 }), let signatureTargetPath = manifest.paths.first else {
|
||||
guard let signatureItem = item.signatures.first(where: {
|
||||
return $0.id == 0
|
||||
}), let signatureTargetPath = manifest.paths.first else {
|
||||
throw Error.invalidSignature
|
||||
}
|
||||
|
||||
@@ -65,7 +78,7 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
.appendingPathComponent(appBundleName)
|
||||
.appendingPathExtension("app")
|
||||
.appendingPathComponent(signatureTargetPath)
|
||||
|
||||
|
||||
let signatureRelativePath = signatureUrl.path.replacingOccurrences(of: "\(signatureBaseUrl.path)/", with: "")
|
||||
|
||||
try fileManager.createDirectory(at: signatureUrl.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
@@ -73,13 +86,15 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
try archive.addEntry(with: signatureRelativePath, relativeTo: signatureBaseUrl)
|
||||
try fileManager.removeItem(at: signatureBaseUrl)
|
||||
}
|
||||
|
||||
|
||||
private func readPlist<T: Decodable>(archive: Archive, matchingSuffix: String, type: T.Type) throws -> T {
|
||||
guard let entry = archive.first(where: { $0.path.hasSuffix(matchingSuffix) }) else {
|
||||
throw Error.fileNotFound(matchingSuffix)
|
||||
}
|
||||
|
||||
let url = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(UUID().uuidString).appendingPathExtension("plist")
|
||||
|
||||
let url = URL(fileURLWithPath: NSHomeDirectory())
|
||||
.appendingPathComponent(UUID().uuidString)
|
||||
.appendingPathExtension("plist")
|
||||
_ = try archive.extract(entry, to: url)
|
||||
|
||||
let data = try Data(contentsOf: url)
|
||||
@@ -94,7 +109,7 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
extension SignatureClient {
|
||||
struct Manifest: Codable {
|
||||
let paths: [String]
|
||||
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case paths = "SinfPaths"
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ public protocol StoreClientInterface {
|
||||
|
||||
public final class StoreClient: StoreClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
|
||||
public init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
|
||||
public func authenticate(email: String, password: String, code: String?) throws -> StoreResponse.Account {
|
||||
try authenticate(email: email, password: password, code: code, isFirstAttempt: true)
|
||||
}
|
||||
|
||||
|
||||
public func item(identifier: String, directoryServicesIdentifier: String) throws -> StoreResponse.Item {
|
||||
let request = StoreRequest.download(
|
||||
appIdentifier: identifier,
|
||||
@@ -82,7 +82,7 @@ public final class StoreClient: StoreClientInterface {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func authenticate(email: String,
|
||||
password: String,
|
||||
code: String?,
|
||||
|
||||
@@ -21,7 +21,7 @@ extension StoreEndpoint: HTTPEndpoint {
|
||||
components.host = host
|
||||
return components.url!
|
||||
}
|
||||
|
||||
|
||||
private var host: String {
|
||||
switch self {
|
||||
case let .authenticate(prefix, _):
|
||||
@@ -32,7 +32,7 @@ extension StoreEndpoint: HTTPEndpoint {
|
||||
return "buy.itunes.apple.com"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var path: String {
|
||||
switch self {
|
||||
case let .authenticate(_, guid):
|
||||
|
||||
@@ -30,17 +30,17 @@ extension StoreRequest: HTTPRequest {
|
||||
return StoreEndpoint.purchase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var method: HTTPMethod {
|
||||
return .post
|
||||
}
|
||||
|
||||
|
||||
var headers: [String: String] {
|
||||
var headers: [String: String] = [
|
||||
"User-Agent": "Configurator/2.15 (Macintosh; OS X 11.0.0; 16G29) AppleWebKit/2603.3.8",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
]
|
||||
|
||||
|
||||
switch self {
|
||||
case .authenticate:
|
||||
break
|
||||
@@ -54,10 +54,10 @@ extension StoreRequest: HTTPRequest {
|
||||
headers["X-Apple-Store-Front"] = Storefront(countryCode: countryCode)?.rawValue
|
||||
headers["X-Token"] = passwordToken
|
||||
}
|
||||
|
||||
|
||||
return headers
|
||||
}
|
||||
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .authenticate(email, password, code):
|
||||
@@ -104,8 +104,8 @@ extension StoreRequest {
|
||||
let bsds: [String] = ["en0", "en1"]
|
||||
var bsd: String = bsds[0]
|
||||
|
||||
var length : size_t = 0
|
||||
var buffer : [CChar]
|
||||
var length: size_t = 0
|
||||
var buffer: [CChar]
|
||||
|
||||
var bsdIndex = Int32(if_nametoindex(bsd))
|
||||
if bsdIndex == 0 {
|
||||
@@ -113,7 +113,7 @@ extension StoreRequest {
|
||||
bsdIndex = Int32(if_nametoindex(bsd))
|
||||
guard bsdIndex != 0 else { fatalError("Could not read MAC address") }
|
||||
}
|
||||
|
||||
|
||||
let bsdData = Data(bsd.utf8)
|
||||
var managementInfoBase = [CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, bsdIndex]
|
||||
|
||||
@@ -136,7 +136,7 @@ extension StoreRequest {
|
||||
let lower = rangeOfToken.upperBound
|
||||
let upper = lower + MAC_ADDRESS_LENGTH
|
||||
let macAddressData = infoData[lower..<upper]
|
||||
let addressBytes = macAddressData.map{ String(format:"%02x", $0) }
|
||||
let addressBytes = macAddressData.map { String(format: "%02x", $0) }
|
||||
return addressBytes.joined().uppercased()
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,13 @@ extension StoreResponse: Decodable {
|
||||
let directoryServicesIdentifier = try container.decode(String.self, forKey: .directoryServicesIdentifier)
|
||||
let passwordToken = try container.decode(String.self, forKey: .passwordToken)
|
||||
let accountContainer = try container.nestedContainer(keyedBy: AccountInfoCodingKeys.self, forKey: .account)
|
||||
let addressContainer = try accountContainer.nestedContainer(keyedBy: AddressCodingKeys.self, forKey: .address)
|
||||
let addressContainer = try accountContainer.nestedContainer(
|
||||
keyedBy: AddressCodingKeys.self,
|
||||
forKey: .address
|
||||
)
|
||||
let firstName = try addressContainer.decode(String.self, forKey: .firstName)
|
||||
let lastName = try addressContainer.decode(String.self, forKey: .lastName)
|
||||
|
||||
|
||||
self = .account(
|
||||
Account(
|
||||
firstName: firstName,
|
||||
@@ -56,7 +59,7 @@ extension StoreResponse: Decodable {
|
||||
} else if container.contains(.statusCode) {
|
||||
let statusCode = try container.decode(Int.self, forKey: .statusCode)
|
||||
let statusType = try container.decode(String.self, forKey: .statusType)
|
||||
|
||||
|
||||
self = .purchase(Receipt(statusCode: statusCode, status: Receipt.Status(rawValue: statusType)))
|
||||
} else if let error = error, !error.isEmpty {
|
||||
self = .failure(error: Error(rawValue: Int(error) ?? 0) ?? .unknownError)
|
||||
@@ -64,18 +67,24 @@ extension StoreResponse: Decodable {
|
||||
switch message {
|
||||
case "Your account information was entered incorrectly.":
|
||||
self = .failure(error: Error.invalidCredentials)
|
||||
case "An Apple ID verification code is required to sign in. Type your password followed by the verification code shown on your other devices.":
|
||||
case [
|
||||
"An Apple ID verification code is required to sign in.",
|
||||
"Type your password followed by the verification code shown on your other devices."
|
||||
].joined(separator: " "):
|
||||
self = .failure(error: Error.codeRequired)
|
||||
case "MZFinance.BadLogin.Configurator_message":
|
||||
self = .failure(error: Error.codeRequired)
|
||||
case "This Apple ID has been locked for security reasons. Visit iForgot to reset your account (https://iforgot.apple.com).":
|
||||
case [
|
||||
"This Apple ID has been locked for security reasons.",
|
||||
"Visit iForgot to reset your account (https://iforgot.apple.com)."
|
||||
].joined(separator: " "):
|
||||
self = .failure(error: Error.lockedAccount)
|
||||
default:
|
||||
self = .failure(error: Error.unknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case directoryServicesIdentifier = "dsPersonId"
|
||||
case passwordToken = "passwordToken"
|
||||
@@ -86,7 +95,7 @@ extension StoreResponse: Decodable {
|
||||
case statusCode = "status"
|
||||
case statusType = "jingleDocType"
|
||||
}
|
||||
|
||||
|
||||
private enum AccountInfoCodingKeys: String, CodingKey {
|
||||
case address
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ public protocol iTunesClientInterface {
|
||||
|
||||
public final class iTunesClient: iTunesClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
|
||||
public init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
|
||||
public func lookup(
|
||||
bundleIdentifier: String,
|
||||
countryCode: String,
|
||||
@@ -45,7 +45,7 @@ public final class iTunesClient: iTunesClientInterface {
|
||||
guard let result = decoded.results.first else { throw Error.appNotFound }
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
public func search(
|
||||
term: String,
|
||||
limit: Int,
|
||||
|
||||
@@ -20,7 +20,7 @@ extension iTunesEndpoint: HTTPEndpoint {
|
||||
components.host = "itunes.apple.com"
|
||||
return components.url!
|
||||
}
|
||||
|
||||
|
||||
private var path: String {
|
||||
switch self {
|
||||
case .search:
|
||||
|
||||
@@ -11,18 +11,20 @@ import XCTest
|
||||
final class HTTPClientTests: XCTestCase {
|
||||
private var sut: HTTPClient!
|
||||
private var session: URLSessionMock!
|
||||
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
session = URLSessionMock()
|
||||
sut = HTTPClient(session: session)
|
||||
}
|
||||
|
||||
|
||||
func test_GET_success_returnsValidResposne() throws {
|
||||
session.onDataTask = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(request.httpMethod, "GET")
|
||||
|
||||
|
||||
let data = try XCTUnwrap("foo".data(using: .utf8))
|
||||
let response = HTTPURLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
@@ -32,7 +34,7 @@ final class HTTPClientTests: XCTestCase {
|
||||
)
|
||||
return (data, response)
|
||||
}
|
||||
|
||||
|
||||
let response = try sut.send(TestRequest.get(nil))
|
||||
let data = try XCTUnwrap(response.data)
|
||||
XCTAssertEqual(String(data: data, encoding: .utf8), "foo")
|
||||
@@ -43,9 +45,9 @@ final class HTTPClientTests: XCTestCase {
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(request.httpMethod, "GET")
|
||||
|
||||
|
||||
let data = try XCTUnwrap("foo".data(using: .utf8))
|
||||
|
||||
|
||||
let response = URLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
@@ -57,12 +59,12 @@ final class HTTPClientTests: XCTestCase {
|
||||
|
||||
do {
|
||||
_ = try sut.send(TestRequest.get(nil))
|
||||
XCTFail()
|
||||
XCTFail("Call succeeded while expecting a failure.")
|
||||
} catch {
|
||||
XCTAssertNotNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func test_POST_xmlEncoding_returnsValidResponse() throws {
|
||||
session.onDataTask = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
@@ -70,12 +72,14 @@ final class HTTPClientTests: XCTestCase {
|
||||
XCTAssertEqual(request.httpMethod, "POST")
|
||||
|
||||
let data = try XCTUnwrap(request.httpBody)
|
||||
let decoded = try PropertyListSerialization.propertyList(
|
||||
from: data,
|
||||
options: [],
|
||||
format: nil
|
||||
) as! [String: String]
|
||||
|
||||
let decoded = try XCTUnwrap(
|
||||
PropertyListSerialization.propertyList(
|
||||
from: data,
|
||||
options: [],
|
||||
format: nil
|
||||
) as? [String: String]
|
||||
)
|
||||
|
||||
XCTAssertEqual(decoded["foo"], "bar")
|
||||
|
||||
let response = HTTPURLResponse(
|
||||
@@ -86,10 +90,10 @@ final class HTTPClientTests: XCTestCase {
|
||||
)
|
||||
return (data, response)
|
||||
}
|
||||
|
||||
|
||||
_ = try sut.send(TestRequest.post(.xml(["foo": "bar"])))
|
||||
}
|
||||
|
||||
|
||||
func test_GET_urlEncoding_returnsValidResponse() throws {
|
||||
session.onDataTask = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
@@ -105,17 +109,17 @@ final class HTTPClientTests: XCTestCase {
|
||||
)
|
||||
return (Data(), response)
|
||||
}
|
||||
|
||||
|
||||
_ = try sut.send(TestRequest.get(.urlEncoding(["foo": "bar"])))
|
||||
}
|
||||
|
||||
|
||||
func test_POST_urlEncoding_returnsValidResponse() throws {
|
||||
session.onDataTask = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
let data = try XCTUnwrap(request.httpBody)
|
||||
let decoded = String(data: data, encoding: .utf8)
|
||||
let headerValue = try XCTUnwrap(request.allHTTPHeaderFields?["X-Test"])
|
||||
|
||||
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(decoded, "foo=bar")
|
||||
XCTAssertEqual(request.httpMethod, "POST")
|
||||
@@ -129,7 +133,7 @@ final class HTTPClientTests: XCTestCase {
|
||||
)
|
||||
return (Data(), response)
|
||||
}
|
||||
|
||||
|
||||
_ = try sut.send(TestRequest.post(.urlEncoding(["foo": "bar"])))
|
||||
}
|
||||
}
|
||||
@@ -137,7 +141,7 @@ final class HTTPClientTests: XCTestCase {
|
||||
private enum TestRequest: HTTPRequest {
|
||||
case get(HTTPPayload?)
|
||||
case post(HTTPPayload)
|
||||
|
||||
|
||||
var method: HTTPMethod {
|
||||
switch self {
|
||||
case .get:
|
||||
@@ -146,14 +150,14 @@ private enum TestRequest: HTTPRequest {
|
||||
return .post
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var endpoint: HTTPEndpoint {
|
||||
switch self {
|
||||
case .get, .post:
|
||||
return TestEndpoint.generic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .get(payload):
|
||||
@@ -162,7 +166,7 @@ private enum TestRequest: HTTPRequest {
|
||||
return payload
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var headers: [String: String] {
|
||||
switch self {
|
||||
case .get, .post:
|
||||
@@ -173,7 +177,7 @@ private enum TestRequest: HTTPRequest {
|
||||
|
||||
private enum TestEndpoint: HTTPEndpoint {
|
||||
case generic
|
||||
|
||||
|
||||
var url: URL {
|
||||
switch self {
|
||||
case .generic:
|
||||
|
||||
@@ -10,11 +10,13 @@ import XCTest
|
||||
|
||||
final class HTTPDownloadClientTests: XCTestCase {
|
||||
private var sut: HTTPDownloadClient!
|
||||
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
sut = HTTPDownloadClient()
|
||||
}
|
||||
|
||||
|
||||
func test_download_success_returnsValidResponse() throws {
|
||||
let source = try XCTUnwrap(URL(string: "https://proof.ovh.net/files/1Mb.dat"))
|
||||
let target = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
@@ -24,10 +26,10 @@ final class HTTPDownloadClientTests: XCTestCase {
|
||||
XCTAssertGreaterThanOrEqual(value, lastValue)
|
||||
lastValue = value
|
||||
}
|
||||
|
||||
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: target.path))
|
||||
}
|
||||
|
||||
|
||||
func test_download_failure_throwsError() throws {
|
||||
let source = try XCTUnwrap(URL(string: "https://\(UUID().uuidString).test"))
|
||||
let target = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
|
||||
@@ -12,7 +12,7 @@ final class HTTPResponseTests: XCTestCase {
|
||||
func test_decode_jsonData_returnsObject() throws {
|
||||
let data = try JSONEncoder().encode(["foo": "bar"])
|
||||
let response = HTTPResponse(statusCode: 200, data: data)
|
||||
|
||||
|
||||
let object = try response.decode([String: String].self, as: .json)
|
||||
XCTAssertEqual(object["foo"], "bar")
|
||||
}
|
||||
@@ -20,7 +20,7 @@ final class HTTPResponseTests: XCTestCase {
|
||||
func test_decode_xmlData_returnsObject() throws {
|
||||
let data = try PropertyListEncoder().encode(["foo": "bar"])
|
||||
let response = HTTPResponse(statusCode: 200, data: data)
|
||||
|
||||
|
||||
let object = try response.decode([String: String].self, as: .xml)
|
||||
XCTAssertEqual(object["foo"], "bar")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
name: IPATool
|
||||
packages:
|
||||
ArgumentParser:
|
||||
url: https://github.com/apple/swift-argument-parser
|
||||
revision: 1.1.2
|
||||
ZIPFoundation:
|
||||
url: https://github.com/weichsel/ZIPFoundation
|
||||
revision: 0.9.14
|
||||
KeychainAccess:
|
||||
url: https://github.com/kishikawakatsumi/KeychainAccess
|
||||
revision: v4.2.2
|
||||
targets:
|
||||
CLI:
|
||||
type: application
|
||||
platform: iOS
|
||||
deploymentTarget: 13.0
|
||||
settings:
|
||||
ENABLE_BITCODE: NO
|
||||
PRODUCT_BUNDLE_IDENTIFIER: ipatool
|
||||
CODE_SIGN_STYLE: Manual
|
||||
sources:
|
||||
- Sources/CLI
|
||||
dependencies:
|
||||
- package: ArgumentParser
|
||||
- package: KeychainAccess
|
||||
- package: ZIPFoundation
|
||||
- target: StoreAPI
|
||||
- target: Networking
|
||||
- target: Persistence
|
||||
StoreAPI:
|
||||
type: library.static
|
||||
platform: iOS
|
||||
deploymentTarget: 13.0
|
||||
sources:
|
||||
- Sources/StoreAPI
|
||||
dependencies:
|
||||
- package: ArgumentParser
|
||||
- package: ZIPFoundation
|
||||
- target: Networking
|
||||
Networking:
|
||||
type: library.static
|
||||
platform: iOS
|
||||
deploymentTarget: 13.0
|
||||
sources:
|
||||
- Sources/Networking
|
||||
Persistence:
|
||||
type: library.static
|
||||
platform: iOS
|
||||
deploymentTarget: 13.0
|
||||
sources:
|
||||
- Sources/Persistence
|
||||
dependencies:
|
||||
- package: KeychainAccess
|
||||
Reference in new issue
Block a user