Compare commits

...
20 Commits
Author SHA1 Message Date
Majd Alfhaily cffa279e31 Fix README formatting 2025-06-09 20:44:16 +02:00
Majd Alfhaily 034a0978ab Remove GitHub sponsors from FUNDING.yml 2025-06-09 20:40:45 +02:00
Majd Alfhaily 9657750fc1 Create FUNDING.yml 2025-06-09 20:39:51 +02:00
Majd Alfhaily 9969c18cef Strip 2FA code from whitespaces 2025-06-09 17:23:08 +02:00
Majd Alfhaily f09439ecde Handle disabled account errors on auth 2025-06-09 17:23:08 +02:00
Majd Alfhaily 55ef41fc20 Update README.md 2025-06-09 17:18:53 +02:00
Majd Alfhaily b4bd8d6580 Rename field to external-version-id 2025-06-09 17:18:53 +02:00
Majd Alfhaily 79250ae2a3 Implement GetVersionMetadata command 2025-06-09 17:18:53 +02:00
Majd Alfhaily a3212e0fd2 Use display version in filename 2025-06-09 12:13:32 +02:00
Majd Alfhaily 805678138e Fix running golangci-lint on GitHub Actions 2025-06-09 12:13:32 +02:00
Majd Alfhaily 3a537e7571 Update GitHub Actions to use Go v1.23.0 2025-06-09 12:13:32 +02:00
Majd Alfhaily e686248270 Update README.md 2025-06-09 12:13:32 +02:00
Majd Alfhaily ac081fa19d Use internal version ID in filename of app 2025-06-09 12:13:32 +02:00
Majd Alfhaily 7136f81fd1 Refactor VersionHistory subcommand to ListVersions 2025-06-09 12:13:32 +02:00
SoCuul 34866f5833 Update macOS package manager install instructions (#350) 2025-06-08 13:59:35 +00:00
Chris Lui 46f3369de0 Fix typo on "failed to reoslve the country code" (#367) 2025-06-08 13:48:53 +00:00
koraytutuncu 0bb134e9d7 Add version history and old app version download support (#370) 2025-06-08 15:44:15 +02:00
dependabot[bot] bbf3717456 Bump golang.org/x/net from 0.36.0 to 0.38.0 (#364)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.36.0 to 0.38.0.
- [Commits](https://github.com/golang/net/compare/v0.36.0...v0.38.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.38.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-17 23:50:00 +02:00
dependabot[bot] e1eda9f776 Bump golang.org/x/net from 0.33.0 to 0.36.0 (#355)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.33.0 to 0.36.0.
- [Commits](https://github.com/golang/net/compare/v0.33.0...v0.36.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-11 21:33:30 +02:00
Majd Alfhaily c406c36819 Replace Changelog with Releases link 2025-03-01 12:15:22 +01:00
30 changed files with 1112 additions and 250 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# github: [majd]
patreon: majd_dev
+7 -7
View File
@@ -12,12 +12,12 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ arm64, amd64 ]
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go build -o ipatool-$GOOS-$GOARCH.exe
env:
@@ -29,12 +29,12 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ arm64, amd64 ]
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go build -o ipatool-$GOOS-$GOARCH
env:
@@ -46,16 +46,16 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ arm64, amd64 ]
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go build -o ipatool-$GOOS-$GOARCH
env:
GOOS: darwin
GOARCH: ${{ matrix.arch }}
CGO_CFLAGS: -mmacosx-version-min=10.15
CGO_LDFLAGS: -mmacosx-version-min=10.15
CGO_LDFLAGS: -mmacosx-version-min=10.15
+2 -4
View File
@@ -9,13 +9,11 @@ jobs:
build:
name: Build
runs-on: macos-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go build -o ipatool
env:
@@ -40,4 +38,4 @@ jobs:
name: ipatool
path: build
- run: chmod +x ./build/ipatool
- run: ./build/ipatool ${{ matrix.command }} --help
- run: ./build/ipatool ${{ matrix.command }} --help
+3 -3
View File
@@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go generate github.com/majd/ipatool/...
- uses: golangci/golangci-lint-action@v3
- uses: golangci/golangci-lint-action@v8
with:
version: v1.52.2
version: v2.1
+5 -5
View File
@@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go generate github.com/majd/ipatool/...
- run: go test -v github.com/majd/ipatool/...
@@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-windows-arm64.exe
env:
@@ -108,7 +108,7 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ arm64, amd64 ]
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v4
@@ -135,7 +135,7 @@ jobs:
strategy:
fail-fast: false
matrix:
arch: [ arm64, amd64 ]
arch: [arm64, amd64]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v4
@@ -214,4 +214,4 @@ jobs:
git push "https://${{ secrets.GH_TOKEN }}@github.com/${{ secrets.HOMEBREW_REPO }}.git" --set-upstream "main"
env:
SHA256_ARM64: ${{ steps.sha256.outputs.sha256_arm64 }}
SHA256_AMD64: ${{ steps.sha256.outputs.sha256_amd64 }}
SHA256_AMD64: ${{ steps.sha256.outputs.sha256_amd64 }}
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '1.19.3'
go-version: "1.23.0"
cache: true
- run: go generate github.com/majd/ipatool/...
- run: go test -v github.com/majd/ipatool/...
+22 -6
View File
@@ -1,10 +1,6 @@
version: "2"
linters:
enable:
- errcheck
- govet
- goimports
- gofmt
- unused
- ginkgolinter
- godot
- godox
@@ -13,10 +9,30 @@ linters:
- nonamedreturns
- prealloc
- predeclared
- tenv
- unconvert
- unparam
- usestdlibvars
- wastedassign
- wrapcheck
- wsl
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
-132
View File
@@ -1,132 +0,0 @@
## Changelog
### Version [2.1.3](https://github.com/majd/ipatool/releases/tag/v2.1.3)
- Fixed a bug where temporary files were not removed after downloading the app package.
- Fixed a bug where the `--keychain-passphrase` flag was marked as invalid.
### Version [2.1.2](https://github.com/majd/ipatool/releases/tag/v2.1.2)
- `FileBackend` keyring is now used when other options are not available.
### Version [2.1.1](https://github.com/majd/ipatool/releases/tag/v2.1.1)
- Fixed an issue when creating the config directory for the tool.
### Version [2.1.0](https://github.com/majd/ipatool/releases/tag/v2.1.0)
- Implemented `Lookup` API.
- Implemented `AccountInfo` API.
- Implemented `ReplicateSinf` API.
- Added storefront code for Georgia (GE).
- Build version is now set using linker flags.
- Refactored API interfaces.
- Improved tests for http package.
- Integrated `golangci-lint` linter.
- Added v2 suffix to module path.
### Version [2.0.3](https://github.com/majd/ipatool/releases/tag/v2.0.3)
- Added support for downloading Apple Arcade games.
- Fixed windows builds not having exe extension.
### Version [2.0.2](https://github.com/majd/ipatool/releases/tag/v2.0.2)
- Fixed Sinf patches when the app contains an Apple Watch app.
- Added storefront code for Albania.
- Fixed default output path to be current working directory.
### Version [2.0.1](https://github.com/majd/ipatool/releases/tag/v2.0.1)
- Linux & Windows releases now include the sha256 hash.
- Added storefront code for Mongolia.
### Version [2.0.0](https://github.com/majd/ipatool/releases/tag/v2.0.0)
- Added support for Windows.
- Added support for Linux.
- Added support for generating autocompletion script using the `completion` command.
- Implemented new `auth info` command.
- Implemented `--verbose` flag that replaces the `--debug-level` flag to enable verbose logging.
- Implemented `--format` which allows specifying logs output format to either text or json (default: text).
- Implemented `--non-interactive` flag to disable running the tool in an interactive session.
- The relevant command (i.e. purchase) will now automatically determine the country and the device family from the authenticated account. The following flags have been deprecated.
- `--country`
- `--device-family`
- Improved structured logging.
- Improved error handling.
- Improved support for automated systems.
- Added unit tests to cover the majority of the private App Store API logic.
### Version [1.1.4](https://github.com/majd/ipatool/releases/tag/v1.1.4)
- Add support for patching old code signature revisions as a fallback mechanism.
### Version [1.1.3](https://github.com/majd/ipatool/releases/tag/v1.1.3)
- Fixed keychain access on iOS.
### Version [1.1.2](https://github.com/majd/ipatool/releases/tag/v1.1.2)
- Improved error message for expired token.
- Disabled print buffering and output errors to stderr.
- Added linter.
- Add support for running on iOS.
### Version [1.1.1](https://github.com/majd/ipatool/releases/tag/v1.1.1)
- Update swift-argument-parser dependency.
- Remove usage of Swift concurrency.
- Add backward-compatibility for macOS 10.11+.
### Version [1.1.0](https://github.com/majd/ipatool/releases/tag/v1.1.0)
- Added support for purchasing apps.
- Implemented auth command.
- Implemented purchase command.
- Implemented --purchase flag in download command.
- Added price checks for purchase flow.
### Version [1.0.9](https://github.com/majd/ipatool/releases/tag/v1.0.9)
- Fixed building for older macOS versions.
- Fixed 2FA code not being requested.
### Version [1.0.8](https://github.com/majd/ipatool/releases/tag/v1.0.8)
- Added --output option to the download command for specifying the destination path for the downloaded app package.
### Version [1.0.7](https://github.com/majd/ipatool/releases/tag/v1.0.7)
- Fixed login requests to the store API when the 2FA code is required.
### Version [1.0.6](https://github.com/majd/ipatool/releases/tag/v1.0.6)
- Added support for supplying 2FA code in non-interactive sessions.
### Version [1.0.5](https://github.com/majd/ipatool/releases/tag/v1.0.5)
- Added support for specifying device family.
### Version [1.0.4](https://github.com/majd/ipatool/releases/tag/v1.0.4)
- Added support for specifying the iTunes Store region.
### Version [1.0.3](https://github.com/majd/ipatool/releases/tag/v1.0.3)
- Improved console logging.
### Version [1.0.2](https://github.com/majd/ipatool/releases/tag/v1.0.2)
- Improved error messages.
### Version [1.0.1](https://github.com/majd/ipatool/releases/tag/v1.0.1)
- Grammatical fixes.
### Version [1.0.0](https://github.com/majd/ipatool/releases/tag/v1.0.0)
- Initial release.
+50 -8
View File
@@ -5,7 +5,7 @@
`ipatool` is a command line tool that allows you to search for iOS apps on the [App Store](https://apps.apple.com) and download a copy of the app package, known as an _ipa_ file.
![Demo](./demo.gif)
![Demo](./resources/demo.gif)
- [Requirements](#requirements)
- [Installation](#installation)
@@ -14,10 +14,11 @@
- [Usage](#usage)
- [Compiling](#compiling)
- [License](#license)
- [Changelog](https://github.com/majd/ipatool/blob/main/CHANGELOG.md)
- [Releases](https://github.com/majd/ipatool/releases)
- [FAQ](https://github.com/majd/ipatool/wiki/FAQ)
## Requirements
- Supported operating system (Windows, Linux or macOS).
- Apple ID set up to use the App Store.
@@ -32,7 +33,6 @@ You can grab the latest version of `ipatool` from [GitHub releases](https://gith
You can install `ipatool` using [Homebrew](https://brew.sh).
```shell
$ brew tap majd/repo
$ brew install ipatool
```
@@ -98,6 +98,26 @@ Global Flags:
--verbose enables verbose logs
```
To obtain a list of availble app versions to download, use the `list-versions` command.
```
List the available versions of an iOS app
Usage:
ipatool list-versions [flags]
Flags:
-i, --app-id int ID of the target iOS app (required)
-b, --bundle-identifier string The bundle identifier of the target iOS app (overrides the app ID)
-h, --help help for list-versions
Global Flags:
--format format sets output format for command; can be 'text', 'json' (default text)
--keychain-passphrase string passphrase for unlocking keychain
--non-interactive run in non-interactive session
--verbose enables verbose logs
```
To download a copy of the ipa file, use the `download` command.
```
@@ -107,11 +127,33 @@ Usage:
ipatool download [flags]
Flags:
-i, --app-id int ID of the target iOS app (required)
-b, --bundle-identifier string The bundle identifier of the target iOS app (overrides the app ID)
-h, --help help for download
-o, --output string The destination path of the downloaded app package
--purchase Obtain a license for the app if needed
-i, --app-id int ID of the target iOS app (required)
-b, --bundle-identifier string The bundle identifier of the target iOS app (overrides the app ID)
--external-version-id string External version identifier of the target iOS app (defaults to latest version when not specified)
-h, --help help for download
-o, --output string The destination path of the downloaded app package
--purchase Obtain a license for the app if needed
Global Flags:
--format format sets output format for command; can be 'text', 'json' (default text)
--keychain-passphrase string passphrase for unlocking keychain
--non-interactive run in non-interactive session
--verbose enables verbose logs
```
To resolve an external version identifier, returned by the `list-versions` command, use the `get-version-metadata` command.
```
Retrieves the metadata for a specific version of an app
Usage:
ipatool get-version-metadata [flags]
Flags:
-i, --app-id int ID of the target iOS app (required)
-b, --bundle-identifier string The bundle identifier of the target iOS app (overrides the app ID)
--external-version-id string External version identifier of the target iOS app (required)
-h, --help help for get-version-metadata
Global Flags:
--format format sets output format for command; can be 'text', 'json' (default text)
+9 -6
View File
@@ -14,10 +14,11 @@ import (
// nolint:wrapcheck
func downloadCmd() *cobra.Command {
var (
acquireLicense bool
outputPath string
appID int64
bundleID string
acquireLicense bool
outputPath string
appID int64
bundleID string
externalVersionID string
)
cmd := &cobra.Command{
@@ -30,7 +31,7 @@ func downloadCmd() *cobra.Command {
var lastErr error
var acc appstore.Account
var purchased bool = false
purchased := false
return retry.Do(func() error {
infoResult, err := dependencies.AppStore.AccountInfo()
@@ -89,7 +90,8 @@ func downloadCmd() *cobra.Command {
)
}
out, err := dependencies.AppStore.Download(appstore.DownloadInput{Account: acc, App: app, OutputPath: outputPath, Progress: progress})
out, err := dependencies.AppStore.Download(appstore.DownloadInput{
Account: acc, App: app, OutputPath: outputPath, Progress: progress, ExternalVersionID: externalVersionID})
if err != nil {
return err
}
@@ -131,6 +133,7 @@ func downloadCmd() *cobra.Command {
cmd.Flags().Int64VarP(&appID, "app-id", "i", 0, "ID of the target iOS app (required)")
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "The bundle identifier of the target iOS app (overrides the app ID)")
cmd.Flags().StringVarP(&outputPath, "output", "o", "", "The destination path of the downloaded app package")
cmd.Flags().StringVar(&externalVersionID, "external-version-id", "", "External version identifier of the target iOS app (defaults to latest version when not specified)")
cmd.Flags().BoolVar(&acquireLicense, "purchase", false, "Obtain a license for the app if needed")
return cmd
+96
View File
@@ -0,0 +1,96 @@
package cmd
import (
"errors"
"time"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
)
// nolint:wrapcheck
func getVersionMetadataCmd() *cobra.Command {
var (
appID int64
bundleID string
externalVersionID string
)
cmd := &cobra.Command{
Use: "get-version-metadata",
Short: "Retrieves the metadata for a specific version of an app",
RunE: func(cmd *cobra.Command, args []string) error {
if appID == 0 && bundleID == "" {
return errors.New("either the app ID or the bundle identifier must be specified")
}
var lastErr error
var acc appstore.Account
return retry.Do(func() error {
infoResult, err := dependencies.AppStore.AccountInfo()
if err != nil {
return err
}
acc = infoResult.Account
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
if err != nil {
return err
}
acc = loginResult.Account
}
app := appstore.App{ID: appID}
if bundleID != "" {
lookupResult, err := dependencies.AppStore.Lookup(appstore.LookupInput{Account: acc, BundleID: bundleID})
if err != nil {
return err
}
app = lookupResult.App
}
out, err := dependencies.AppStore.GetVersionMetadata(appstore.GetVersionMetadataInput{
Account: acc,
App: app,
VersionID: externalVersionID,
})
if err != nil {
return err
}
dependencies.Logger.Log().
Str("externalVersionID", externalVersionID).
Str("displayVersion", out.DisplayVersion).
Time("releaseDate", out.ReleaseDate).
Bool("success", true).
Send()
return nil
},
retry.LastErrorOnly(true),
retry.DelayType(retry.FixedDelay),
retry.Delay(time.Millisecond),
retry.Attempts(2),
retry.RetryIf(func(err error) bool {
lastErr = err
return errors.Is(err, appstore.ErrPasswordTokenExpired)
}),
)
},
}
cmd.Flags().Int64VarP(&appID, "app-id", "i", 0, "ID of the target iOS app (required)")
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "The bundle identifier of the target iOS app (overrides the app ID)")
cmd.Flags().StringVar(&externalVersionID, "external-version-id", "", "External version identifier of the target iOS app (required)")
_ = cmd.MarkFlagRequired("external-version-id")
return cmd
}
+87
View File
@@ -0,0 +1,87 @@
package cmd
import (
"errors"
"time"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
)
// nolint:wrapcheck
func ListVersionsCmd() *cobra.Command {
var (
appID int64
bundleID string
)
cmd := &cobra.Command{
Use: "list-versions",
Short: "List the available versions of an iOS app",
RunE: func(cmd *cobra.Command, args []string) error {
if appID == 0 && bundleID == "" {
return errors.New("either the app ID or the bundle identifier must be specified")
}
var lastErr error
var acc appstore.Account
return retry.Do(func() error {
infoResult, err := dependencies.AppStore.AccountInfo()
if err != nil {
return err
}
acc = infoResult.Account
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
if err != nil {
return err
}
acc = loginResult.Account
}
app := appstore.App{ID: appID}
if bundleID != "" {
lookupResult, err := dependencies.AppStore.Lookup(appstore.LookupInput{Account: acc, BundleID: bundleID})
if err != nil {
return err
}
app = lookupResult.App
}
out, err := dependencies.AppStore.ListVersions(appstore.ListVersionsInput{Account: acc, App: app})
if err != nil {
return err
}
dependencies.Logger.Log().
Interface("externalVersionIdentifiers", out.ExternalVersionIdentifiers).
Str("bundleID", app.BundleID).
Bool("success", true).
Send()
return nil
},
retry.LastErrorOnly(true),
retry.DelayType(retry.FixedDelay),
retry.Delay(time.Millisecond),
retry.Attempts(2),
retry.RetryIf(func(err error) bool {
lastErr = err
return errors.Is(err, appstore.ErrPasswordTokenExpired)
}),
)
},
}
cmd.Flags().Int64VarP(&appID, "app-id", "i", 0, "ID of the target iOS app (required)")
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "The bundle identifier of the target iOS app (overrides the app ID)")
return cmd
}
+2
View File
@@ -45,6 +45,8 @@ func rootCmd() *cobra.Command {
cmd.AddCommand(downloadCmd())
cmd.AddCommand(purchaseCmd())
cmd.AddCommand(searchCmd())
cmd.AddCommand(ListVersionsCmd())
cmd.AddCommand(getVersionMetadataCmd())
return cmd
}
+7 -5
View File
@@ -1,6 +1,8 @@
module github.com/majd/ipatool/v2
go 1.19
go 1.23.0
toolchain go1.23.2
require (
github.com/99designs/keyring v1.2.1
@@ -13,8 +15,8 @@ require (
github.com/spf13/cobra v1.6.1
github.com/thediveo/enumflag/v2 v2.0.1
go.uber.org/mock v0.4.0
golang.org/x/net v0.33.0
golang.org/x/term v0.27.0
golang.org/x/net v0.38.0
golang.org/x/term v0.30.0
howett.net/plist v1.0.0
)
@@ -38,8 +40,8 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/retry.v1 v1.0.3 // indirect
+9 -9
View File
@@ -90,21 +90,21 @@ golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfU
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210819135213-f52c844e1c1c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
+13
View File
@@ -12,6 +12,19 @@ type App struct {
Price float64 `json:"price,omitempty"`
}
type VersionHistoryInfo struct {
App App
LatestVersion string
VersionIdentifiers []string
}
type VersionDetails struct {
VersionID string
VersionString string
Success bool
Error string
}
type Apps []App
func (apps Apps) MarshalZerologArray(a *zerolog.Array) {
+1 -1
View File
@@ -74,6 +74,6 @@ var _ = Describe("App", func() {
Price: 0,
}
Expect(fileName(app)).To(Equal("app.bundle-id1_42_1.0.ipa"))
Expect(fileName(app, "1.0")).To(Equal("app.bundle-id1_42_1.0.ipa"))
})
})
+4
View File
@@ -25,6 +25,10 @@ type AppStore interface {
Download(input DownloadInput) (DownloadOutput, error)
// ReplicateSinf replicates the sinf for the IPA package.
ReplicateSinf(input ReplicateSinfInput) error
// VersionHistory lists the available versions of the specified app.
ListVersions(input ListVersionsInput) (ListVersionsOutput, error)
// GetVersionMetadata returns the metadata for the specified version.
GetVersionMetadata(input GetVersionMetadataInput) (GetVersionMetadataOutput, error)
}
type appstore struct {
+35 -21
View File
@@ -19,10 +19,11 @@ var (
)
type DownloadInput struct {
Account Account
App App
OutputPath string
Progress *progressbar.ProgressBar
Account Account
App App
OutputPath string
Progress *progressbar.ProgressBar
ExternalVersionID string
}
type DownloadOutput struct {
@@ -31,11 +32,6 @@ type DownloadOutput struct {
}
func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
destination, err := t.resolveDestinationPath(input.App, input.OutputPath)
if err != nil {
return DownloadOutput{}, fmt.Errorf("failed to resolve destination path: %w", err)
}
macAddr, err := t.machine.MacAddress()
if err != nil {
return DownloadOutput{}, fmt.Errorf("failed to get mac address: %w", err)
@@ -43,7 +39,7 @@ func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
guid := strings.ReplaceAll(strings.ToUpper(macAddr), ":", "")
req := t.downloadRequest(input.Account, input.App, guid)
req := t.downloadRequest(input.Account, input.App, guid, input.ExternalVersionID)
res, err := t.downloadClient.Send(req)
if err != nil {
@@ -72,6 +68,18 @@ func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
item := res.Data.Items[0]
version := "unknown"
// Read the version from the item metadata
if itemVersion, ok := item.Metadata["bundleShortVersionString"]; ok {
version = fmt.Sprintf("%v", itemVersion)
}
destination, err := t.resolveDestinationPath(input.App, version, input.OutputPath)
if err != nil {
return DownloadOutput{}, fmt.Errorf("failed to resolve destination path: %w", err)
}
err = t.downloadFile(item.URL, fmt.Sprintf("%s.tmp", destination), input.Progress)
if err != nil {
return DownloadOutput{}, fmt.Errorf("failed to download file: %w", err)
@@ -139,9 +147,19 @@ func (t *appstore) downloadFile(src, dst string, progress *progressbar.ProgressB
return nil
}
func (*appstore) downloadRequest(acc Account, app App, guid string) http.Request {
func (*appstore) downloadRequest(acc Account, app App, guid string, externalVersionID string) http.Request {
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
payload := map[string]interface{}{
"creditDisplay": "",
"guid": guid,
"salableAdamId": app.ID,
}
if externalVersionID != "" {
payload["externalVersionId"] = externalVersionID
}
return http.Request{
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
Method: http.MethodPOST,
@@ -152,16 +170,12 @@ func (*appstore) downloadRequest(acc Account, app App, guid string) http.Request
"X-Dsid": acc.DirectoryServicesID,
},
Payload: &http.XMLPayload{
Content: map[string]interface{}{
"creditDisplay": "",
"guid": guid,
"salableAdamId": app.ID,
},
Content: payload,
},
}
}
func fileName(app App) string {
func fileName(app App, version string) string {
var parts []string
if app.BundleID != "" {
@@ -172,15 +186,15 @@ func fileName(app App) string {
parts = append(parts, strconv.FormatInt(app.ID, 10))
}
if app.Version != "" {
parts = append(parts, app.Version)
if version != "" {
parts = append(parts, version)
}
return fmt.Sprintf("%s.ipa", strings.Join(parts, "_"))
}
func (t *appstore) resolveDestinationPath(app App, path string) (string, error) {
file := fileName(app)
func (t *appstore) resolveDestinationPath(app App, version string, path string) (string, error) {
file := fileName(app, version)
if path == "" {
workdir, err := t.os.Getwd()
+30 -40
View File
@@ -56,27 +56,8 @@ var _ = Describe("AppStore (Download)", func() {
ctrl.Finish()
})
When("fails to resolve output path", func() {
BeforeEach(func() {
mockOS.EXPECT().
Stat(gomock.Any()).
Return(nil, errors.New(""))
})
It("returns error", func() {
_, err := as.Download(DownloadInput{
OutputPath: "test-out",
})
Expect(err).To(HaveOccurred())
})
})
When("fails to read MAC address", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", errors.New(""))
@@ -90,10 +71,6 @@ var _ = Describe("AppStore (Download)", func() {
When("request fails", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", nil)
@@ -111,10 +88,6 @@ var _ = Describe("AppStore (Download)", func() {
When("password token is expired", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", nil)
@@ -136,10 +109,6 @@ var _ = Describe("AppStore (Download)", func() {
When("license is missing", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", nil)
@@ -161,10 +130,6 @@ var _ = Describe("AppStore (Download)", func() {
When("store API returns error", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", nil)
@@ -208,10 +173,6 @@ var _ = Describe("AppStore (Download)", func() {
When("store API returns no items", func() {
BeforeEach(func() {
mockOS.EXPECT().
Getwd().
Return("", nil)
mockMachine.EXPECT().
MacAddress().
Return("", nil)
@@ -231,6 +192,33 @@ var _ = Describe("AppStore (Download)", func() {
})
})
When("fails to resolve output path", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{{}},
},
}, nil)
mockOS.EXPECT().
Stat(gomock.Any()).
Return(nil, errors.New(""))
})
It("returns error", func() {
_, err := as.Download(DownloadInput{
OutputPath: "test-out",
})
Expect(err).To(HaveOccurred())
})
})
When("fails to download file", func() {
BeforeEach(func() {
mockOS.EXPECT().
@@ -345,7 +333,9 @@ var _ = Describe("AppStore (Download)", func() {
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{},
Metadata: map[string]interface{}{
"bundleShortVersionString": "xyz",
},
Sinfs: []Sinf{
{
ID: 0,
@@ -0,0 +1,94 @@
package appstore
import (
"errors"
"fmt"
"strings"
"time"
"github.com/majd/ipatool/v2/pkg/http"
)
type GetVersionMetadataInput struct {
Account Account
App App
VersionID string
}
type GetVersionMetadataOutput struct {
DisplayVersion string
ReleaseDate time.Time
}
func (t *appstore) GetVersionMetadata(input GetVersionMetadataInput) (GetVersionMetadataOutput, error) {
macAddr, err := t.machine.MacAddress()
if err != nil {
return GetVersionMetadataOutput{}, fmt.Errorf("failed to get mac address: %w", err)
}
guid := strings.ReplaceAll(strings.ToUpper(macAddr), ":", "")
req := t.getVersionMetadataRequest(input.Account, input.App, guid, input.VersionID)
res, err := t.downloadClient.Send(req)
if err != nil {
return GetVersionMetadataOutput{}, fmt.Errorf("failed to send http request: %w", err)
}
if res.Data.FailureType == FailureTypePasswordTokenExpired {
return GetVersionMetadataOutput{}, ErrPasswordTokenExpired
}
if res.Data.FailureType == FailureTypeLicenseNotFound {
return GetVersionMetadataOutput{}, ErrLicenseRequired
}
if res.Data.FailureType != "" && res.Data.CustomerMessage != "" {
return GetVersionMetadataOutput{}, NewErrorWithMetadata(fmt.Errorf("received error: %s", res.Data.CustomerMessage), res)
}
if res.Data.FailureType != "" {
return GetVersionMetadataOutput{}, NewErrorWithMetadata(fmt.Errorf("received error: %s", res.Data.FailureType), res)
}
if len(res.Data.Items) == 0 {
return GetVersionMetadataOutput{}, NewErrorWithMetadata(errors.New("invalid response"), res)
}
item := res.Data.Items[0]
releaseDate, err := time.Parse(time.RFC3339, fmt.Sprintf("%v", item.Metadata["releaseDate"]))
if err != nil {
return GetVersionMetadataOutput{}, fmt.Errorf("failed to parse release date: %w", err)
}
return GetVersionMetadataOutput{
DisplayVersion: fmt.Sprintf("%v", item.Metadata["bundleShortVersionString"]),
ReleaseDate: releaseDate,
}, nil
}
func (t *appstore) getVersionMetadataRequest(acc Account, app App, guid string, version string) http.Request {
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
payload := map[string]interface{}{
"creditDisplay": "",
"guid": guid,
"salableAdamId": app.ID,
"externalVersionId": version,
}
return http.Request{
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
Method: http.MethodPOST,
ResponseFormat: http.ResponseFormatXML,
Headers: map[string]string{
"Content-Type": "application/x-apple-plist",
"iCloud-DSID": acc.DirectoryServicesID,
"X-Dsid": acc.DirectoryServicesID,
},
Payload: &http.XMLPayload{
Content: payload,
},
}
}
@@ -0,0 +1,243 @@
package appstore
import (
"errors"
"time"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/util/machine"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (GetVersionMetadata)", func() {
var (
ctrl *gomock.Controller
mockMachine *machine.MockMachine
mockDownloadClient *http.MockClient[downloadResult]
as AppStore
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
mockMachine = machine.NewMockMachine(ctrl)
mockDownloadClient = http.NewMockClient[downloadResult](ctrl)
as = &appstore{
machine: mockMachine,
downloadClient: mockDownloadClient,
}
})
AfterEach(func() {
ctrl.Finish()
})
When("fails to get MAC address", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("", errors.New("mac error"))
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to get mac address"))
})
})
When("request fails", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{}, errors.New("request error"))
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to send http request"))
})
})
When("password token is expired", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: FailureTypePasswordTokenExpired,
},
}, nil)
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(Equal(ErrPasswordTokenExpired))
})
})
When("license is missing", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: FailureTypeLicenseNotFound,
},
}, nil)
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(Equal(ErrLicenseRequired))
})
})
When("store API returns error", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
})
When("response contains customer message", func() {
BeforeEach(func() {
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: "SOME_ERROR",
CustomerMessage: "Customer error message",
},
}, nil)
})
It("returns customer message as error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Customer error message"))
})
})
When("response does not contain customer message", func() {
BeforeEach(func() {
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: "SOME_ERROR",
},
}, nil)
})
It("returns generic error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("SOME_ERROR"))
})
})
})
When("store API returns no items", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{},
},
}, nil)
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid response"))
})
})
When("fails to parse release date", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{
"releaseDate": "invalid-date",
},
},
},
},
}, nil)
})
It("returns error", func() {
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to parse release date"))
})
})
When("successfully gets version metadata", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:11:22:33:44:55", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{
"releaseDate": "2024-03-20T12:00:00Z",
"bundleShortVersionString": "1.0.0",
},
},
},
},
}, nil)
})
It("returns version metadata", func() {
output, err := as.GetVersionMetadata(GetVersionMetadataInput{
Account: Account{
DirectoryServicesID: "test-dsid",
},
App: App{
ID: 1234567890,
},
VersionID: "test-version",
})
Expect(err).NotTo(HaveOccurred())
Expect(output.DisplayVersion).To(Equal("1.0.0"))
Expect(output.ReleaseDate).To(Equal(time.Date(2024, 3, 20, 12, 0, 0, 0, time.UTC)))
})
})
})
+101
View File
@@ -0,0 +1,101 @@
package appstore
import (
"errors"
"fmt"
"strings"
"github.com/majd/ipatool/v2/pkg/http"
)
type ListVersionsInput struct {
Account Account
App App
}
type ListVersionsOutput struct {
ExternalVersionIdentifiers []string
LatestExternalVersionID string
}
func (t *appstore) ListVersions(input ListVersionsInput) (ListVersionsOutput, error) {
macAddr, err := t.machine.MacAddress()
if err != nil {
return ListVersionsOutput{}, fmt.Errorf("failed to get mac address: %w", err)
}
guid := strings.ReplaceAll(strings.ToUpper(macAddr), ":", "")
req := t.listVersionsRequest(input.Account, input.App, guid)
res, err := t.downloadClient.Send(req)
if err != nil {
return ListVersionsOutput{}, fmt.Errorf("failed to send http request: %w", err)
}
if res.Data.FailureType == FailureTypePasswordTokenExpired {
return ListVersionsOutput{}, ErrPasswordTokenExpired
}
if res.Data.FailureType == FailureTypeLicenseNotFound {
return ListVersionsOutput{}, ErrLicenseRequired
}
if res.Data.FailureType != "" && res.Data.CustomerMessage != "" {
return ListVersionsOutput{}, NewErrorWithMetadata(fmt.Errorf("received error: %s", res.Data.CustomerMessage), res)
}
if res.Data.FailureType != "" {
return ListVersionsOutput{}, NewErrorWithMetadata(fmt.Errorf("received error: %s", res.Data.FailureType), res)
}
if len(res.Data.Items) == 0 {
return ListVersionsOutput{}, NewErrorWithMetadata(errors.New("invalid response"), res)
}
item := res.Data.Items[0]
rawIdentifiers, ok := item.Metadata["softwareVersionExternalIdentifiers"].([]interface{})
if !ok {
return ListVersionsOutput{}, NewErrorWithMetadata(fmt.Errorf("failed to get version identifiers from item metadata"), item.Metadata)
}
externalVersionIdentifiers := make([]string, len(rawIdentifiers))
for i, val := range rawIdentifiers {
externalVersionIdentifiers[i] = fmt.Sprintf("%v", val)
}
latestExternalVersionID := item.Metadata["softwareVersionExternalIdentifier"]
if latestExternalVersionID == nil {
return ListVersionsOutput{}, NewErrorWithMetadata(fmt.Errorf("failed to get latest version from item metadata"), item.Metadata)
}
return ListVersionsOutput{
ExternalVersionIdentifiers: externalVersionIdentifiers,
LatestExternalVersionID: fmt.Sprintf("%v", latestExternalVersionID),
}, nil
}
func (t *appstore) listVersionsRequest(acc Account, app App, guid string) http.Request {
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
payload := map[string]interface{}{
"creditDisplay": "",
"guid": guid,
"salableAdamId": app.ID,
}
return http.Request{
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
Method: http.MethodPOST,
ResponseFormat: http.ResponseFormatXML,
Headers: map[string]string{
"Content-Type": "application/x-apple-plist",
"iCloud-DSID": acc.DirectoryServicesID,
"X-Dsid": acc.DirectoryServicesID,
},
Payload: &http.XMLPayload{
Content: payload,
},
}
}
+264
View File
@@ -0,0 +1,264 @@
package appstore
import (
"errors"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/util/machine"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (ListVersions)", func() {
var (
ctrl *gomock.Controller
mockDownloadClient *http.MockClient[downloadResult]
mockMachine *machine.MockMachine
as AppStore
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
mockDownloadClient = http.NewMockClient[downloadResult](ctrl)
mockMachine = machine.NewMockMachine(ctrl)
as = &appstore{
downloadClient: mockDownloadClient,
machine: mockMachine,
}
})
AfterEach(func() {
ctrl.Finish()
})
When("fails to get MAC address", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("", errors.New(""))
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
})
})
When("request fails", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{}, errors.New(""))
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
})
})
When("password token is expired", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: FailureTypePasswordTokenExpired,
},
}, nil)
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
})
})
When("license is required", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: FailureTypeLicenseNotFound,
},
}, nil)
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
})
})
When("store API returns error with customer message", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: "test-failure",
CustomerMessage: "test error message",
},
}, nil)
})
It("returns error with customer message", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("test error message"))
})
})
When("store API returns error without customer message", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
FailureType: "test-failure",
},
}, nil)
})
It("returns error with failure type", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("test-failure"))
})
})
When("store API returns no items", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{},
},
}, nil)
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
})
})
When("version identifiers not found in metadata", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{
"someOtherKey": "someValue",
},
},
},
},
}, nil)
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to get version identifiers from item metadata"))
})
})
When("latest version not found in metadata", func() {
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{
"softwareVersionExternalIdentifiers": []interface{}{"12345678", "87654321"},
},
},
},
},
}, nil)
})
It("returns error", func() {
_, err := as.ListVersions(ListVersionsInput{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to get latest version from item metadata"))
})
})
When("successfully lists versions", func() {
const (
testVersion1 = "12345678"
testVersion2 = "87654321"
testLatest = "87654321"
)
BeforeEach(func() {
mockMachine.EXPECT().
MacAddress().
Return("00:00:00:00:00:00", nil)
mockDownloadClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[downloadResult]{
Data: downloadResult{
Items: []downloadItemResult{
{
Metadata: map[string]interface{}{
"softwareVersionExternalIdentifiers": []interface{}{testVersion1, testVersion2},
"softwareVersionExternalIdentifier": testLatest,
},
},
},
},
}, nil)
})
It("returns versions", func() {
out, err := as.ListVersions(ListVersionsInput{})
Expect(err).ToNot(HaveOccurred())
Expect(out.ExternalVersionIdentifiers).To(Equal([]string{testVersion1, testVersion2}))
Expect(out.LatestExternalVersionID).To(Equal(testLatest))
})
})
})
+3 -1
View File
@@ -135,6 +135,8 @@ func (t *appstore) parseLoginResponse(res *http.Result[loginResult], attempt int
retry = true
} else if res.Data.FailureType == "" && authCode == "" && res.Data.CustomerMessage == CustomerMessageBadLogin {
err = ErrAuthCodeRequired
} else if res.Data.FailureType == "" && res.Data.CustomerMessage == CustomerMessageAccountDisabled {
err = NewErrorWithMetadata(errors.New("account is disabled"), res)
} else if res.Data.FailureType != "" {
if res.Data.CustomerMessage != "" {
err = NewErrorWithMetadata(errors.New(res.Data.CustomerMessage), res)
@@ -161,7 +163,7 @@ func (t *appstore) loginRequest(email, password, authCode, guid string, attempt
"appleId": email,
"attempt": strconv.Itoa(attempt),
"guid": guid,
"password": fmt.Sprintf("%s%s", password, authCode),
"password": fmt.Sprintf("%s%s", password, strings.ReplaceAll(authCode, " ", "")),
"rmp": "0",
"why": "signIn",
},
+20
View File
@@ -123,6 +123,26 @@ var _ = Describe("AppStore (Login)", func() {
})
})
When("store API indicates account is disabled", func() {
BeforeEach(func() {
mockClient.EXPECT().
Send(gomock.Any()).
Return(http.Result[loginResult]{
Data: loginResult{
CustomerMessage: CustomerMessageAccountDisabled,
},
}, nil)
})
It("returns account disabled error", func() {
_, err := as.Login(LoginInput{
Password: testPassword,
})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("account is disabled"))
})
})
When("store API requires 2FA code", func() {
BeforeEach(func() {
mockClient.EXPECT().
+1 -1
View File
@@ -21,7 +21,7 @@ type LookupOutput struct {
func (t *appstore) Lookup(input LookupInput) (LookupOutput, error) {
countryCode, err := countryCodeFromStoreFront(input.Account.StoreFront)
if err != nil {
return LookupOutput{}, fmt.Errorf("failed to reoslve the country code: %w", err)
return LookupOutput{}, fmt.Errorf("failed to resolve the country code: %w", err)
}
request := t.lookupRequest(input.BundleID, countryCode)
+1
View File
@@ -7,6 +7,7 @@ const (
FailureTypeTemporarilyUnavailable = "2059"
CustomerMessageBadLogin = "MZFinance.BadLogin.Configurator_message"
CustomerMessageAccountDisabled = "Your account is disabled."
CustomerMessageSubscriptionRequired = "Subscription Required"
iTunesAPIDomain = "itunes.apple.com"
View File
File renamed without changes.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 KiB