mirror of
https://github.com/majd/ipatool
synced 2026-11-28 02:07:52 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
779a2e66cb | ||
|
|
fd630343bc | ||
|
|
dcddce4650 | ||
|
|
a3fa2f09b3 | ||
|
|
85ae82d9c4 | ||
|
|
1bee8bc568 | ||
|
|
abaeccefec | ||
|
|
8c4e037aa3 | ||
|
|
4142ab48ad | ||
|
|
1858ad7a72 | ||
|
|
2140a26bdf | ||
|
|
e914156036 |
No files matched your search
@@ -1,2 +0,0 @@
|
||||
# github: [majd]
|
||||
patreon: majd_dev
|
||||
@@ -14,10 +14,10 @@ jobs:
|
||||
matrix:
|
||||
arch: [arm64, amd64]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -o ipatool-$GOOS-$GOARCH.exe
|
||||
env:
|
||||
@@ -25,20 +25,23 @@ jobs:
|
||||
GOARCH: ${{ matrix.arch }}
|
||||
build_linux:
|
||||
name: Build for Linux
|
||||
runs-on: macos-latest
|
||||
runs-on: ${{ matrix.runner }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [arm64, amd64]
|
||||
include:
|
||||
- arch: arm64
|
||||
runner: ubuntu-24.04-arm
|
||||
- arch: amd64
|
||||
runner: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -o ipatool-$GOOS-$GOARCH
|
||||
- run: go build -o ipatool-linux-$GOARCH
|
||||
env:
|
||||
GOOS: linux
|
||||
GOARCH: ${{ matrix.arch }}
|
||||
build_macos:
|
||||
name: Build for macOS
|
||||
@@ -48,14 +51,15 @@ jobs:
|
||||
matrix:
|
||||
arch: [arm64, amd64]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -o ipatool-$GOOS-$GOARCH
|
||||
env:
|
||||
GOOS: darwin
|
||||
GOARCH: ${{ matrix.arch }}
|
||||
CGO_ENABLED: 1
|
||||
CGO_CFLAGS: -mmacosx-version-min=10.15
|
||||
CGO_LDFLAGS: -mmacosx-version-min=10.15
|
||||
@@ -10,10 +10,10 @@ jobs:
|
||||
name: Build
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -o ipatool
|
||||
env:
|
||||
|
||||
@@ -10,12 +10,12 @@ jobs:
|
||||
name: Lint
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go generate github.com/majd/ipatool/...
|
||||
- uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
version: v2.1
|
||||
version: v2.9
|
||||
@@ -18,10 +18,10 @@ jobs:
|
||||
name: Run tests
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go generate github.com/majd/ipatool/...
|
||||
- run: go test -v github.com/majd/ipatool/...
|
||||
@@ -30,10 +30,10 @@ jobs:
|
||||
runs-on: macos-latest
|
||||
needs: [get_version, test]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-windows-arm64.exe
|
||||
env:
|
||||
@@ -45,16 +45,6 @@ jobs:
|
||||
GOOS: windows
|
||||
GOARCH: amd64
|
||||
VERSION: ${{ needs.get_version.outputs.version }}
|
||||
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-linux-arm64
|
||||
env:
|
||||
GOOS: linux
|
||||
GOARCH: arm64
|
||||
VERSION: ${{ needs.get_version.outputs.version }}
|
||||
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-linux-amd64
|
||||
env:
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
VERSION: ${{ needs.get_version.outputs.version }}
|
||||
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-macos-arm64
|
||||
env:
|
||||
GOOS: darwin
|
||||
@@ -81,16 +71,6 @@ jobs:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-windows-amd64.exe
|
||||
path: ipatool-${{ needs.get_version.outputs.version }}-windows-amd64.exe
|
||||
if-no-files-found: error
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-linux-arm64
|
||||
path: ipatool-${{ needs.get_version.outputs.version }}-linux-arm64
|
||||
if-no-files-found: error
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-linux-amd64
|
||||
path: ipatool-${{ needs.get_version.outputs.version }}-linux-amd64
|
||||
if-no-files-found: error
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-macos-arm64
|
||||
@@ -101,6 +81,33 @@ jobs:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-macos-amd64
|
||||
path: ipatool-${{ needs.get_version.outputs.version }}-macos-amd64
|
||||
if-no-files-found: error
|
||||
build_linux:
|
||||
name: Build for Linux
|
||||
runs-on: ${{ matrix.runner }}
|
||||
needs: [get_version, test]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- arch: arm64
|
||||
runner: ubuntu-24.04-arm
|
||||
- arch: amd64
|
||||
runner: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go build -ldflags="-X github.com/majd/ipatool/v2/cmd.version=$VERSION" -o ipatool-$VERSION-linux-$GOARCH
|
||||
env:
|
||||
GOARCH: ${{ matrix.arch }}
|
||||
VERSION: ${{ needs.get_version.outputs.version }}
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-linux-${{ matrix.arch }}
|
||||
path: ipatool-${{ needs.get_version.outputs.version }}-linux-${{ matrix.arch }}
|
||||
if-no-files-found: error
|
||||
release_windows:
|
||||
name: Release for Windows
|
||||
runs-on: ubuntu-latest
|
||||
@@ -110,7 +117,7 @@ jobs:
|
||||
matrix:
|
||||
arch: [arm64, amd64]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-windows-${{ matrix.arch }}.exe
|
||||
@@ -131,13 +138,13 @@ jobs:
|
||||
release_linux:
|
||||
name: Release for Linux
|
||||
runs-on: ubuntu-latest
|
||||
needs: [get_version, build, release_windows]
|
||||
needs: [get_version, build_linux, release_windows]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [arm64, amd64]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: ipatool-${{ needs.get_version.outputs.version }}-linux-${{ matrix.arch }}
|
||||
@@ -158,9 +165,9 @@ jobs:
|
||||
release_macos:
|
||||
name: Release for macOS
|
||||
runs-on: ubuntu-latest
|
||||
needs: [get_version, build, release_windows, release_linux]
|
||||
needs: [get_version, build, build_linux, release_windows, release_linux]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
path: ./ipatool
|
||||
- uses: actions/download-artifact@v4
|
||||
@@ -192,7 +199,7 @@ jobs:
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: false
|
||||
file_glob: true
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ secrets.HOMEBREW_REPO }}
|
||||
ref: main
|
||||
|
||||
@@ -10,10 +10,10 @@ jobs:
|
||||
name: Run tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.23.0"
|
||||
go-version: "1.25.0"
|
||||
cache: true
|
||||
- run: go generate github.com/majd/ipatool/...
|
||||
- run: go test -v github.com/majd/ipatool/...
|
||||
@@ -0,0 +1,34 @@
|
||||
# AGENTS.md
|
||||
|
||||
This file provides guidance for coding agents working in this repository.
|
||||
|
||||
## Repository overview
|
||||
- Project: `ipatool`
|
||||
- Language: Go
|
||||
- Entry point: `main.go`
|
||||
- CLI command implementations: `cmd/`
|
||||
|
||||
## Development workflow
|
||||
1. Keep changes focused and minimal.
|
||||
2. Prefer idiomatic Go and keep command behavior consistent with existing commands in `cmd/`.
|
||||
3. Run formatting and tests before finalizing changes.
|
||||
|
||||
## Local checks
|
||||
Use these commands from the repository root:
|
||||
|
||||
```bash
|
||||
go generate ./...
|
||||
go test ./...
|
||||
go build ./...
|
||||
```
|
||||
|
||||
## Coding conventions
|
||||
- Follow standard Go formatting (`gofmt`).
|
||||
- Avoid introducing new dependencies unless necessary.
|
||||
- Keep user-facing text consistent with existing CLI help/output tone.
|
||||
- Preserve backward compatibility for CLI flags and output formats unless explicitly asked to change them.
|
||||
|
||||
## Commit/PR guidance
|
||||
- Write clear, scoped commit messages.
|
||||
- Summarize what changed and why in PR descriptions.
|
||||
- Include test/build results in your handoff.
|
||||
@@ -65,14 +65,15 @@ Use "ipatool auth [command] --help" for more information about a command.
|
||||
To search for apps on the App Store, use the `search` command.
|
||||
|
||||
```
|
||||
Search for iOS apps available on the App Store
|
||||
Search for iOS and tvOS apps available on the App Store
|
||||
|
||||
Usage:
|
||||
ipatool search <term> [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for search
|
||||
-l, --limit int maximum amount of search results to retrieve (default 5)
|
||||
-h, --help help for search
|
||||
-l, --limit int maximum amount of search results to retrieve (default 5)
|
||||
--platform string Platform to search: iphone, ipad, or appletv
|
||||
|
||||
Global Flags:
|
||||
--format format sets output format for command; can be 'text', 'json' (default text)
|
||||
@@ -121,7 +122,7 @@ Global Flags:
|
||||
To download a copy of the ipa file, use the `download` command.
|
||||
|
||||
```
|
||||
Download (encrypted) iOS app packages from the App Store
|
||||
Download (encrypted) iOS and tvOS app packages from the App Store
|
||||
|
||||
Usage:
|
||||
ipatool download [flags]
|
||||
@@ -132,6 +133,7 @@ Flags:
|
||||
--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
|
||||
--platform string Platform to download for: iphone, ipad, or appletv
|
||||
--purchase Obtain a license for the app if needed
|
||||
|
||||
Global Flags:
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ func loginCmd() *cobra.Command {
|
||||
Use: "login",
|
||||
Short: "Login to the App Store",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
interactive := cmd.Context().Value("interactive").(bool)
|
||||
interactive := cmd.Context().Value(interactiveKey).(bool)
|
||||
|
||||
if password == "" && !interactive {
|
||||
return errors.New("password is required when not running in interactive mode; use the \"--password\" flag")
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/99designs/keyring"
|
||||
"github.com/byteness/keyring"
|
||||
cookiejar "github.com/juju/persistent-cookiejar"
|
||||
"github.com/majd/ipatool/v2/pkg/appstore"
|
||||
"github.com/majd/ipatool/v2/pkg/http"
|
||||
@@ -99,7 +99,7 @@ func newKeychain(machine machine.Machine, logger log.Logger, interactive bool) k
|
||||
// initWithCommand initializes the dependencies of the command.
|
||||
func initWithCommand(cmd *cobra.Command) {
|
||||
verbose := cmd.Flag("verbose").Value.String() == "true"
|
||||
interactive, _ := cmd.Context().Value("interactive").(bool)
|
||||
interactive, _ := cmd.Context().Value(interactiveKey).(bool)
|
||||
format := util.Must(OutputFormatFromString(cmd.Flag("format").Value.String()))
|
||||
|
||||
dependencies.Logger = newLogger(format, verbose)
|
||||
|
||||
+34
-7
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@@ -19,11 +20,12 @@ func downloadCmd() *cobra.Command {
|
||||
appID int64
|
||||
bundleID string
|
||||
externalVersionID string
|
||||
platformValue string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "download",
|
||||
Short: "Download (encrypted) iOS app packages from the App Store",
|
||||
Short: "Download (encrypted) iOS and tvOS app packages from the App Store",
|
||||
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")
|
||||
@@ -42,7 +44,16 @@ func downloadCmd() *cobra.Command {
|
||||
acc = infoResult.Account
|
||||
|
||||
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
|
||||
bagOutput, err := dependencies.AppStore.Bag(appstore.BagInput{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get bag: %w", err)
|
||||
}
|
||||
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{
|
||||
Email: acc.Email,
|
||||
Password: acc.Password,
|
||||
Endpoint: bagOutput.AuthEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -51,8 +62,17 @@ func downloadCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
app := appstore.App{ID: appID}
|
||||
platform, err := appstore.ParsePlatform(platformValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if bundleID != "" {
|
||||
lookupResult, err := dependencies.AppStore.Lookup(appstore.LookupInput{Account: acc, BundleID: bundleID})
|
||||
lookupResult, err := dependencies.AppStore.Lookup(appstore.LookupInput{
|
||||
Account: acc,
|
||||
BundleID: bundleID,
|
||||
Platform: platform,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -62,7 +82,7 @@ func downloadCmd() *cobra.Command {
|
||||
|
||||
if errors.Is(lastErr, appstore.ErrLicenseRequired) {
|
||||
err := dependencies.AppStore.Purchase(appstore.PurchaseInput{Account: acc, App: app})
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, appstore.ErrLicenseAlreadyExists) {
|
||||
return err
|
||||
}
|
||||
purchased = true
|
||||
@@ -71,7 +91,7 @@ func downloadCmd() *cobra.Command {
|
||||
Msg("purchase")
|
||||
}
|
||||
|
||||
interactive, _ := cmd.Context().Value("interactive").(bool)
|
||||
interactive, _ := cmd.Context().Value(interactiveKey).(bool)
|
||||
var progress *progressbar.ProgressBar
|
||||
if interactive {
|
||||
progress = progressbar.NewOptions64(1,
|
||||
@@ -91,7 +111,13 @@ func downloadCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
out, err := dependencies.AppStore.Download(appstore.DownloadInput{
|
||||
Account: acc, App: app, OutputPath: outputPath, Progress: progress, ExternalVersionID: externalVersionID})
|
||||
Account: acc,
|
||||
App: app,
|
||||
OutputPath: outputPath,
|
||||
Progress: progress,
|
||||
ExternalVersionID: externalVersionID,
|
||||
Platform: platform,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -112,7 +138,7 @@ func downloadCmd() *cobra.Command {
|
||||
retry.LastErrorOnly(true),
|
||||
retry.DelayType(retry.FixedDelay),
|
||||
retry.Delay(time.Millisecond),
|
||||
retry.Attempts(2),
|
||||
retry.Attempts(3),
|
||||
retry.RetryIf(func(err error) bool {
|
||||
lastErr = err
|
||||
|
||||
@@ -134,6 +160,7 @@ func downloadCmd() *cobra.Command {
|
||||
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().StringVar(&platformValue, "platform", "", "Platform to download for: iphone, ipad, or appletv")
|
||||
cmd.Flags().BoolVar(&acquireLicense, "purchase", false, "Obtain a license for the app if needed")
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/avast/retry-go"
|
||||
@@ -37,7 +38,16 @@ func getVersionMetadataCmd() *cobra.Command {
|
||||
acc = infoResult.Account
|
||||
|
||||
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
|
||||
bagOutput, err := dependencies.AppStore.Bag(appstore.BagInput{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get bag: %w", err)
|
||||
}
|
||||
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{
|
||||
Email: acc.Email,
|
||||
Password: acc.Password,
|
||||
Endpoint: bagOutput.AuthEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+11
-1
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/avast/retry-go"
|
||||
@@ -36,7 +37,16 @@ func ListVersionsCmd() *cobra.Command {
|
||||
acc = infoResult.Account
|
||||
|
||||
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
|
||||
bagOutput, err := dependencies.AppStore.Bag(appstore.BagInput{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get bag: %w", err)
|
||||
}
|
||||
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{
|
||||
Email: acc.Email,
|
||||
Password: acc.Password,
|
||||
Endpoint: bagOutput.AuthEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+16
-3
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/avast/retry-go"
|
||||
@@ -29,7 +30,16 @@ func purchaseCmd() *cobra.Command {
|
||||
acc = infoResult.Account
|
||||
|
||||
if errors.Is(lastErr, appstore.ErrPasswordTokenExpired) {
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{Email: acc.Email, Password: acc.Password})
|
||||
bagOutput, err := dependencies.AppStore.Bag(appstore.BagInput{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get bag: %w", err)
|
||||
}
|
||||
|
||||
loginResult, err := dependencies.AppStore.Login(appstore.LoginInput{
|
||||
Email: acc.Email,
|
||||
Password: acc.Password,
|
||||
Endpoint: bagOutput.AuthEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,11 +53,14 @@ func purchaseCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
err = dependencies.AppStore.Purchase(appstore.PurchaseInput{Account: acc, App: lookupResult.App})
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, appstore.ErrLicenseAlreadyExists) {
|
||||
return err
|
||||
}
|
||||
|
||||
dependencies.Logger.Log().Bool("success", true).Send()
|
||||
dependencies.Logger.Log().
|
||||
Bool("alreadyOwned", errors.Is(err, appstore.ErrLicenseAlreadyExists)).
|
||||
Bool("success", true).
|
||||
Send()
|
||||
|
||||
return nil
|
||||
},
|
||||
|
||||
+6
-2
@@ -1,17 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/majd/ipatool/v2/pkg/appstore"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/thediveo/enumflag/v2"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var version = "dev"
|
||||
|
||||
type contextKey string
|
||||
|
||||
const interactiveKey contextKey = "interactive"
|
||||
|
||||
func rootCmd() *cobra.Command {
|
||||
var (
|
||||
verbose bool
|
||||
@@ -26,7 +30,7 @@ func rootCmd() *cobra.Command {
|
||||
SilenceUsage: true,
|
||||
Version: version,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
ctx := context.WithValue(context.Background(), "interactive", !nonInteractive)
|
||||
ctx := context.WithValue(context.Background(), interactiveKey, !nonInteractive)
|
||||
cmd.SetContext(ctx)
|
||||
initWithCommand(cmd)
|
||||
},
|
||||
|
||||
+15
-5
@@ -7,11 +7,14 @@ import (
|
||||
|
||||
// nolint:wrapcheck
|
||||
func searchCmd() *cobra.Command {
|
||||
var limit int64
|
||||
var (
|
||||
limit int64
|
||||
platformValue string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "search <term>",
|
||||
Short: "Search for iOS apps available on the App Store",
|
||||
Short: "Search for iOS and tvOS apps available on the App Store",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
infoResult, err := dependencies.AppStore.AccountInfo()
|
||||
@@ -19,10 +22,16 @@ func searchCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
platform, err := appstore.ParsePlatform(platformValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
output, err := dependencies.AppStore.Search(appstore.SearchInput{
|
||||
Account: infoResult.Account,
|
||||
Term: args[0],
|
||||
Limit: limit,
|
||||
Account: infoResult.Account,
|
||||
Term: args[0],
|
||||
Limit: limit,
|
||||
Platform: platform,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -38,6 +47,7 @@ func searchCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
cmd.Flags().Int64VarP(&limit, "limit", "l", 5, "maximum amount of search results to retrieve")
|
||||
cmd.Flags().StringVar(&platformValue, "platform", "", "Platform to search: iphone, ipad, or appletv")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
module github.com/majd/ipatool/v2
|
||||
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.2
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/99designs/keyring v1.2.1
|
||||
github.com/avast/retry-go v3.0.0+incompatible
|
||||
github.com/byteness/keyring v1.9.0
|
||||
github.com/juju/persistent-cookiejar v1.0.0
|
||||
github.com/onsi/ginkgo/v2 v2.5.0
|
||||
github.com/onsi/gomega v1.24.0
|
||||
@@ -15,34 +13,51 @@ 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.38.0
|
||||
golang.org/x/term v0.30.0
|
||||
golang.org/x/term v0.43.0
|
||||
howett.net/plist v1.0.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/danieljoos/wincred v1.1.2 // indirect
|
||||
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
|
||||
github.com/1Password/connect-sdk-go v1.5.4-0.20250417152128-c154b387248b // indirect
|
||||
github.com/1password/onepassword-sdk-go v0.4.1-beta.1 // indirect
|
||||
github.com/byteness/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/byteness/go-libsecret v0.0.0-20260108215642-107379d3dee0 // indirect
|
||||
github.com/byteness/percent v0.2.2 // indirect
|
||||
github.com/danieljoos/wincred v1.2.3 // indirect
|
||||
github.com/dvsekhvalnov/jose2go v1.8.0 // indirect
|
||||
github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 // indirect
|
||||
github.com/extism/go-sdk v1.7.1 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // indirect
|
||||
github.com/godbus/dbus/v5 v5.2.2 // indirect
|
||||
github.com/google/go-cmp v0.7.0 // indirect
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20251118225945-96ee0021ea0f // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||
github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/mtibben/percent v0.2.1 // indirect
|
||||
github.com/noamcohen97/touchid-go v0.3.0 // indirect
|
||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect
|
||||
github.com/tetratelabs/wazero v1.11.0 // indirect
|
||||
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
|
||||
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
golang.org/x/crypto v0.51.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
|
||||
golang.org/x/mod v0.17.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
|
||||
golang.org/x/mod v0.35.0 // indirect
|
||||
golang.org/x/net v0.55.0 // indirect
|
||||
golang.org/x/sync v0.20.0 // indirect
|
||||
golang.org/x/sys v0.45.0 // indirect
|
||||
golang.org/x/text v0.37.0 // indirect
|
||||
golang.org/x/tools v0.44.0 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
gopkg.in/errgo.v1 v1.0.1 // indirect
|
||||
gopkg.in/retry.v1 v1.0.3 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -1,32 +1,50 @@
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
|
||||
github.com/99designs/keyring v1.2.1 h1:tYLp1ULvO7i3fI5vE21ReQuj99QFSs7lGm0xWyJo87o=
|
||||
github.com/99designs/keyring v1.2.1/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
|
||||
github.com/1Password/connect-sdk-go v1.5.4-0.20250417152128-c154b387248b h1:sVddTkAGVmDXJbZKgp+W1zC7hN4lLz9Nus1XmjbY7eo=
|
||||
github.com/1Password/connect-sdk-go v1.5.4-0.20250417152128-c154b387248b/go.mod h1:5rSymY4oIYtS4G3t0oMkGAXBeoYiukV3vkqlnEjIDJs=
|
||||
github.com/1password/onepassword-sdk-go v0.4.1-beta.1 h1:b/tt+bAXFXR5f3/irmPAaytfmsN6+5Nj6pbsx5nmKZA=
|
||||
github.com/1password/onepassword-sdk-go v0.4.1-beta.1/go.mod h1:j/CbzhucTywjlYrd6SE6k0LcQaFZ2l8OLBsAsOYtvD0=
|
||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=
|
||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
|
||||
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
|
||||
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
|
||||
github.com/byteness/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:HFl8GFmwK19hYuXB8OQ0rTO9WOCgZY9JUy964zaYawY=
|
||||
github.com/byteness/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:9HlL8SWBRtCZE7sCNq+c3//H/oHywgSwtocmPTdOij8=
|
||||
github.com/byteness/go-libsecret v0.0.0-20260108215642-107379d3dee0 h1:j59wGsxaBk6aFBuuYofk2oznMGZYyzFovjDqavlJHM8=
|
||||
github.com/byteness/go-libsecret v0.0.0-20260108215642-107379d3dee0/go.mod h1:3FrDGTXj08zj6qtqlIvt0vS8eWNrrYpnXOEbcQgFmvM=
|
||||
github.com/byteness/keyring v1.9.0 h1:9m+7pru+JkMJ8wxma5id5m6pSt2Zx/xPj77kyM+yAVE=
|
||||
github.com/byteness/keyring v1.9.0/go.mod h1:a6CV8t/qfEUERPTP+dqeVfKgib2wz3PIYbMWRfmvmes=
|
||||
github.com/byteness/percent v0.2.2 h1:vnIFh8WBR1xoC+U2etz0EMB1cgp+vsK6vynqTCeDziU=
|
||||
github.com/byteness/percent v0.2.2/go.mod h1:nwavge92FhIyfnldz4YWZD8uxPVvdh8NlzLRd1VYRDs=
|
||||
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
|
||||
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
|
||||
github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
|
||||
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dvsekhvalnov/jose2go v1.7.0 h1:bnQc8+GMnidJZA8zc6lLEAb4xNrIqHwO+9TzqvtQZPo=
|
||||
github.com/dvsekhvalnov/jose2go v1.7.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
|
||||
github.com/dvsekhvalnov/jose2go v1.8.0 h1:LqkkVKAlHFfH9LOEl5fe4p/zL02OhWE7pCufMBG2jLA=
|
||||
github.com/dvsekhvalnov/jose2go v1.8.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
|
||||
github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 h1:idfl8M8rPW93NehFw5H1qqH8yG158t5POr+LX9avbJY=
|
||||
github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
||||
github.com/extism/go-sdk v1.7.1 h1:lWJos6uY+tRFdlIHR+SJjwFDApY7OypS/2nMhiVQ9Sw=
|
||||
github.com/extism/go-sdk v1.7.1/go.mod h1:IT+Xdg5AZM9hVtpFUA+uZCJMge/hbvshl8bwzLtFyKA=
|
||||
github.com/frankban/quicktest v1.2.2 h1:xfmOhhoH5fGPgbEAlhLpJH9p0z/0Qizio9osmvn9IUY=
|
||||
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ=
|
||||
github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20251118225945-96ee0021ea0f h1:Fnl4pzx8SR7k7JuzyW8lEtSFH6EQ8xgcypgIn8pcGIE=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20251118225945-96ee0021ea0f/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
|
||||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
|
||||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
@@ -51,14 +69,16 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs=
|
||||
github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/noamcohen97/touchid-go v0.3.0 h1:fcXxVCizysD7KHRR6hrURt3nyNIs5JBGSbOIidD/3wo=
|
||||
github.com/noamcohen97/touchid-go v0.3.0/go.mod h1:X9MRNIBGEmPqwpDm1G3fQOAQX7fwBlhzUbnkDTxuta0=
|
||||
github.com/onsi/ginkgo/v2 v2.5.0 h1:TRtrvv2vdQqzkwrQ1ke6vtXf7IK34RBUJafIy1wMwls=
|
||||
github.com/onsi/ginkgo/v2 v2.5.0/go.mod h1:Luc4sArBICYCS8THh8v3i3i5CuSZO+RaQRaJoeNwomw=
|
||||
github.com/onsi/gomega v1.24.0 h1:+0glovB9Jd6z3VR+ScSwQqXVTIfJcGA9UBM8yzQxhqg=
|
||||
github.com/onsi/gomega v1.24.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2vQAg=
|
||||
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
|
||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -80,39 +100,52 @@ github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUq
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
|
||||
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZjBaFj3HgFonKXUcwgJ4djLb6i42S3Q=
|
||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
|
||||
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
|
||||
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
|
||||
github.com/thediveo/enumflag/v2 v2.0.1 h1:2bmWZPD2uSARDsOjXIdLRlNcYBFNF9xX0RNUNF2vKic=
|
||||
github.com/thediveo/enumflag/v2 v2.0.1/go.mod h1:SyxyCNvv0QeRtZ7fjuaUz4FRLC3cWuDiD7QdORU0MGg=
|
||||
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
|
||||
github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
|
||||
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
|
||||
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
|
||||
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
|
||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
|
||||
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
||||
golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
|
||||
golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
|
||||
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.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/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
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.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
||||
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=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4=
|
||||
golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk=
|
||||
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
|
||||
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
@@ -121,7 +154,6 @@ gopkg.in/errgo.v1 v1.0.1/go.mod h1:3NjfXwocQRYAPTq4/fzX+CwUhPRcR/azYRhj8G+LqMo=
|
||||
gopkg.in/retry.v1 v1.0.3 h1:a9CArYczAVv6Qs6VGoLMio99GEs7kY9UzSF9+LD+iGs=
|
||||
gopkg.in/retry.v1 v1.0.3/go.mod h1:FJkXmWiMaAo7xB+xhvDF59zhfjDWyzmyAxiT4dB688g=
|
||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
|
||||
|
||||
@@ -39,6 +39,7 @@ type appstore struct {
|
||||
searchClient http.Client[searchResult]
|
||||
purchaseClient http.Client[purchaseResult]
|
||||
downloadClient http.Client[downloadResult]
|
||||
platformClient http.Client[platformVersionLookupResult]
|
||||
bagClient http.Client[bagResult]
|
||||
httpClient http.Client[interface{}]
|
||||
machine machine.Machine
|
||||
@@ -63,6 +64,7 @@ func NewAppStore(args Args) AppStore {
|
||||
searchClient: http.NewClient[searchResult](clientArgs),
|
||||
purchaseClient: http.NewClient[purchaseResult](clientArgs),
|
||||
downloadClient: http.NewClient[downloadResult](clientArgs),
|
||||
platformClient: http.NewClient[platformVersionLookupResult](clientArgs),
|
||||
bagClient: http.NewClient[bagResult](clientArgs),
|
||||
httpClient: http.NewClient[interface{}](clientArgs),
|
||||
machine: args.Machine,
|
||||
|
||||
@@ -85,7 +85,7 @@ var _ = Describe("AppStore (Bag)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("request is successful", func() {
|
||||
When("request is successful with authenticateAccount in urlBag", func() {
|
||||
const testAuthEndpoint = "https://example.com"
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -117,4 +117,25 @@ var _ = Describe("AppStore (Bag)", func() {
|
||||
Expect(out.AuthEndpoint).To(Equal(testAuthEndpoint))
|
||||
})
|
||||
})
|
||||
|
||||
When("request is successful but authenticateAccount is empty", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("aa:bb:cc:dd:ee:ff", nil)
|
||||
|
||||
mockBagClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[bagResult]{
|
||||
StatusCode: gohttp.StatusOK,
|
||||
Data: bagResult{},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns empty auth endpoint", func() {
|
||||
out, err := as.Bag(BagInput{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(out.AuthEndpoint).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -24,6 +24,7 @@ type DownloadInput struct {
|
||||
OutputPath string
|
||||
Progress *progressbar.ProgressBar
|
||||
ExternalVersionID string
|
||||
Platform Platform
|
||||
}
|
||||
|
||||
type DownloadOutput struct {
|
||||
@@ -39,14 +40,25 @@ func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
|
||||
|
||||
guid := strings.ReplaceAll(strings.ToUpper(macAddr), ":", "")
|
||||
|
||||
req := t.downloadRequest(input.Account, input.App, guid, input.ExternalVersionID)
|
||||
externalVersionID := input.ExternalVersionID
|
||||
if externalVersionID == "" && input.Platform == PlatformAppleTV {
|
||||
externalVersionID, err = t.lookupLatestExternalVersionID(input.Account, input.App, input.Platform)
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to resolve platform version: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
req := t.downloadRequest(input.Account, input.App, guid, externalVersionID)
|
||||
|
||||
res, err := t.downloadClient.Send(req)
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to send http request: %w", err)
|
||||
}
|
||||
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired {
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired ||
|
||||
res.Data.FailureType == FailureTypeSignInRequired ||
|
||||
res.Data.FailureType == FailureTypeDeviceVerificationFailed ||
|
||||
res.Data.FailureType == FailureTypeLicenseAlreadyExists {
|
||||
return DownloadOutput{}, ErrPasswordTokenExpired
|
||||
}
|
||||
|
||||
@@ -80,16 +92,23 @@ func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to resolve destination path: %w", err)
|
||||
}
|
||||
|
||||
err = t.downloadFile(item.URL, fmt.Sprintf("%s.tmp", destination), input.Progress)
|
||||
tmpPath := fmt.Sprintf("%s.tmp", destination)
|
||||
|
||||
err = t.downloadFile(item.URL, tmpPath, input.Progress)
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to download file: %w", err)
|
||||
}
|
||||
|
||||
err = t.applyPatches(item, input.Account, fmt.Sprintf("%s.tmp", destination), destination)
|
||||
err = t.applyPatches(item, input.Account, tmpPath, destination)
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to apply patches: %w", err)
|
||||
}
|
||||
|
||||
err = t.validatePackagePlatform(destination, input.Platform)
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to validate package platform: %w", err)
|
||||
}
|
||||
|
||||
err = t.os.Remove(fmt.Sprintf("%s.tmp", destination))
|
||||
if err != nil {
|
||||
return DownloadOutput{}, fmt.Errorf("failed to remove file: %w", err)
|
||||
@@ -101,6 +120,59 @@ func (t *appstore) Download(input DownloadInput) (DownloadOutput, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
type platformPackageInfo struct {
|
||||
SupportedPlatforms []string `plist:"CFBundleSupportedPlatforms,omitempty"`
|
||||
}
|
||||
|
||||
func (*appstore) validatePackagePlatform(path string, platform Platform) error {
|
||||
if platform != PlatformAppleTV {
|
||||
return nil
|
||||
}
|
||||
|
||||
reader, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open zip reader: %w", err)
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
for _, file := range reader.File {
|
||||
if !strings.HasPrefix(file.Name, "Payload/") || !strings.HasSuffix(file.Name, ".app/Info.plist") {
|
||||
continue
|
||||
}
|
||||
|
||||
infoFile, err := file.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open info plist: %w", err)
|
||||
}
|
||||
|
||||
data, readErr := io.ReadAll(infoFile)
|
||||
closeErr := infoFile.Close()
|
||||
|
||||
if readErr != nil {
|
||||
return fmt.Errorf("failed to read info plist: %w", readErr)
|
||||
}
|
||||
|
||||
if closeErr != nil {
|
||||
return fmt.Errorf("failed to close info plist: %w", closeErr)
|
||||
}
|
||||
|
||||
var info platformPackageInfo
|
||||
|
||||
_, err = plist.Unmarshal(data, &info)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to decode info plist: %w", err)
|
||||
}
|
||||
|
||||
for _, supportedPlatform := range info.SupportedPlatforms {
|
||||
if supportedPlatform == "AppleTVOS" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors.New("downloaded package does not declare AppleTVOS support")
|
||||
}
|
||||
|
||||
type downloadItemResult struct {
|
||||
HashMD5 string `plist:"md5,omitempty"`
|
||||
URL string `plist:"URL,omitempty"`
|
||||
@@ -260,10 +332,11 @@ func (t *appstore) applyPatches(item downloadItemResult, acc Account, src, dst s
|
||||
}
|
||||
defer srcZip.Close()
|
||||
|
||||
dstFile, err := t.os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
dstFile, err := t.os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer dstFile.Close()
|
||||
|
||||
dstZip := zip.NewWriter(dstFile)
|
||||
defer dstZip.Close()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"io/fs"
|
||||
gohttp "net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -35,6 +36,7 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
ctrl *gomock.Controller
|
||||
mockKeychain *keychain.MockKeychain
|
||||
mockDownloadClient *http.MockClient[downloadResult]
|
||||
mockPlatformClient *http.MockClient[platformVersionLookupResult]
|
||||
mockPurchaseClient *http.MockClient[purchaseResult]
|
||||
mockLoginClient *http.MockClient[loginResult]
|
||||
mockHTTPClient *http.MockClient[interface{}]
|
||||
@@ -47,6 +49,7 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
ctrl = gomock.NewController(GinkgoT())
|
||||
mockKeychain = keychain.NewMockKeychain(ctrl)
|
||||
mockDownloadClient = http.NewMockClient[downloadResult](ctrl)
|
||||
mockPlatformClient = http.NewMockClient[platformVersionLookupResult](ctrl)
|
||||
mockLoginClient = http.NewMockClient[loginResult](ctrl)
|
||||
mockPurchaseClient = http.NewMockClient[purchaseResult](ctrl)
|
||||
mockHTTPClient = http.NewMockClient[interface{}](ctrl)
|
||||
@@ -57,6 +60,7 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
loginClient: mockLoginClient,
|
||||
purchaseClient: mockPurchaseClient,
|
||||
downloadClient: mockDownloadClient,
|
||||
platformClient: mockPlatformClient,
|
||||
httpClient: mockHTTPClient,
|
||||
machine: mockMachine,
|
||||
os: mockOS,
|
||||
@@ -127,6 +131,92 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("platform is AppleTV", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:11:22:33:44:55", nil)
|
||||
|
||||
mockPlatformClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
parsedURL, err := url.Parse(req.URL)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedURL.Host).To(Equal("uclient-api.itunes.apple.com"))
|
||||
Expect(parsedURL.Query().Get("platform")).To(Equal("atv9"))
|
||||
Expect(parsedURL.Query().Get("cc")).To(Equal("us"))
|
||||
}).
|
||||
Return(http.Result[platformVersionLookupResult]{
|
||||
StatusCode: 200,
|
||||
Data: platformVersionLookupResult{
|
||||
Results: map[string]platformVersionLookupItem{
|
||||
"42": {
|
||||
Offers: []platformVersionLookupOffer{
|
||||
{
|
||||
Version: platformVersionLookupVersion{
|
||||
ExternalID: platformVersionExternalID("123456"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
mockDownloadClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
payload, ok := req.Payload.(*http.XMLPayload)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(payload.Content["externalVersionId"]).To(Equal("123456"))
|
||||
}).
|
||||
Return(http.Result[downloadResult]{}, errors.New("request error"))
|
||||
})
|
||||
|
||||
It("resolves and sends the tvOS external version id", func() {
|
||||
_, err := as.Download(DownloadInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
App: App{
|
||||
ID: 42,
|
||||
},
|
||||
Platform: PlatformAppleTV,
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
DescribeTable("platform uses the standard download request",
|
||||
func(platform Platform) {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:11:22:33:44:55", nil)
|
||||
|
||||
mockDownloadClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
payload, ok := req.Payload.(*http.XMLPayload)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(payload.Content).ToNot(HaveKey("externalVersionId"))
|
||||
}).
|
||||
Return(http.Result[downloadResult]{}, errors.New("request error"))
|
||||
|
||||
_, err := as.Download(DownloadInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
App: App{
|
||||
ID: 42,
|
||||
},
|
||||
Platform: platform,
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
},
|
||||
Entry("iPhone", PlatformIPhone),
|
||||
Entry("iPad", PlatformIPad),
|
||||
)
|
||||
|
||||
When("password token is expired", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
@@ -148,6 +238,27 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("Sign In to the iTunes Store", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("", nil)
|
||||
|
||||
mockDownloadClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[downloadResult]{
|
||||
Data: downloadResult{
|
||||
FailureType: FailureTypeSignInRequired,
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
_, err := as.Download(DownloadInput{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("license is missing", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
@@ -512,4 +623,44 @@ var _ = Describe("AppStore (Download)", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("package platform validation", func() {
|
||||
writePackage := func(platforms []string) string {
|
||||
file, err := os.CreateTemp("", "ipatool-platform-*.ipa")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer file.Close()
|
||||
|
||||
zipFile := zip.NewWriter(file)
|
||||
w, err := zipFile.Create("Payload/Test.app/Info.plist")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
info, err := plist.Marshal(map[string]interface{}{
|
||||
"CFBundleSupportedPlatforms": platforms,
|
||||
}, plist.BinaryFormat)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = w.Write(info)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(zipFile.Close()).To(Succeed())
|
||||
|
||||
return file.Name()
|
||||
}
|
||||
|
||||
It("accepts AppleTVOS packages", func() {
|
||||
path := writePackage([]string{"AppleTVOS"})
|
||||
defer os.Remove(path)
|
||||
|
||||
err := (&appstore{}).validatePackagePlatform(path, PlatformAppleTV)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns an error for packages without AppleTVOS support", func() {
|
||||
path := writePackage([]string{"iPhoneOS"})
|
||||
defer os.Remove(path)
|
||||
|
||||
err := (&appstore{}).validatePackagePlatform(path, PlatformAppleTV)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("AppleTVOS"))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -35,7 +35,7 @@ func (t *appstore) GetVersionMetadata(input GetVersionMetadataInput) (GetVersion
|
||||
return GetVersionMetadataOutput{}, fmt.Errorf("failed to send http request: %w", err)
|
||||
}
|
||||
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired {
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired || res.Data.FailureType == FailureTypeSignInRequired {
|
||||
return GetVersionMetadataOutput{}, ErrPasswordTokenExpired
|
||||
}
|
||||
|
||||
@@ -57,15 +57,15 @@ func (t *appstore) GetVersionMetadata(input GetVersionMetadataInput) (GetVersion
|
||||
|
||||
item := res.Data.Items[0]
|
||||
|
||||
releaseDate, err := time.Parse(time.RFC3339, fmt.Sprintf("%v", item.Metadata["releaseDate"]))
|
||||
// Do not fall back to item.Metadata here. The App Store download API can
|
||||
// return stale version and release date values, so the IPA Info.plist is the
|
||||
// source of truth and failures should be visible to callers.
|
||||
metadata, err := t.readVersionMetadataFromIPA(item.URL)
|
||||
if err != nil {
|
||||
return GetVersionMetadataOutput{}, fmt.Errorf("failed to parse release date: %w", err)
|
||||
return GetVersionMetadataOutput{}, fmt.Errorf("failed to read version metadata: %w", err)
|
||||
}
|
||||
|
||||
return GetVersionMetadataOutput{
|
||||
DisplayVersion: fmt.Sprintf("%v", item.Metadata["bundleShortVersionString"]),
|
||||
ReleaseDate: releaseDate,
|
||||
}, nil
|
||||
return GetVersionMetadataOutput(metadata), nil
|
||||
}
|
||||
|
||||
func (t *appstore) getVersionMetadataRequest(acc Account, app App, guid string, version string) http.Request {
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
package appstore
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
gohttp "net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/majd/ipatool/v2/pkg/http"
|
||||
@@ -9,8 +18,155 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"go.uber.org/mock/gomock"
|
||||
"howett.net/plist"
|
||||
)
|
||||
|
||||
func testIPA(displayVersion string, releaseDate interface{}, modified time.Time) []byte {
|
||||
buffer := new(bytes.Buffer)
|
||||
zipWriter := zip.NewWriter(buffer)
|
||||
|
||||
fillerHeader := &zip.FileHeader{
|
||||
Name: "Payload/Test.app/Filler.bin",
|
||||
Method: zip.Store,
|
||||
}
|
||||
filler, err := zipWriter.CreateHeader(fillerHeader)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = filler.Write(make([]byte, 1024*1024))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
infoHeader := &zip.FileHeader{
|
||||
Name: "Payload/Test.app/Info.plist",
|
||||
Method: zip.Deflate,
|
||||
Modified: modified,
|
||||
}
|
||||
|
||||
infoFile, err := zipWriter.CreateHeader(infoHeader)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
info := map[string]interface{}{
|
||||
"CFBundleExecutable": "Test",
|
||||
"CFBundleShortVersionString": displayVersion,
|
||||
}
|
||||
if releaseDate != nil {
|
||||
info["releaseDate"] = releaseDate
|
||||
}
|
||||
|
||||
infoData, err := plist.Marshal(info, plist.BinaryFormat)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
_, err = infoFile.Write(infoData)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = zipWriter.Close()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
func testIPAServer(data []byte) (*httptest.Server, *int64, *int64) {
|
||||
return testIPAServerWithRangeLog(data, nil)
|
||||
}
|
||||
|
||||
func testIPAServerWithRangeLog(data []byte, rangeLog *[]string) (*httptest.Server, *int64, *int64) {
|
||||
var (
|
||||
servedBytes int64
|
||||
wholeGetCount int64
|
||||
)
|
||||
|
||||
server := httptest.NewServer(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) {
|
||||
if r.Method != gohttp.MethodGet {
|
||||
w.WriteHeader(gohttp.StatusMethodNotAllowed)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
rangeHeader := r.Header.Get("Range")
|
||||
if rangeLog != nil {
|
||||
*rangeLog = append(*rangeLog, rangeHeader)
|
||||
}
|
||||
|
||||
if rangeHeader == "" {
|
||||
atomic.AddInt64(&wholeGetCount, 1)
|
||||
w.WriteHeader(gohttp.StatusOK)
|
||||
_, _ = w.Write(data)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
start, end, err := testRangeBounds(rangeHeader, len(data))
|
||||
if err != nil {
|
||||
w.WriteHeader(gohttp.StatusRequestedRangeNotSatisfiable)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Accept-Ranges", "bytes")
|
||||
w.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", start, end, len(data)))
|
||||
w.Header().Set("Content-Length", strconv.Itoa(end-start+1))
|
||||
w.WriteHeader(gohttp.StatusPartialContent)
|
||||
|
||||
n, _ := w.Write(data[start : end+1])
|
||||
atomic.AddInt64(&servedBytes, int64(n))
|
||||
}))
|
||||
|
||||
return server, &servedBytes, &wholeGetCount
|
||||
}
|
||||
|
||||
func testRangeBounds(header string, size int) (int, int, error) {
|
||||
if !strings.HasPrefix(header, "bytes=") {
|
||||
return 0, 0, fmt.Errorf("invalid range header: %s", header)
|
||||
}
|
||||
|
||||
parts := strings.Split(strings.TrimPrefix(header, "bytes="), "-")
|
||||
if len(parts) != 2 {
|
||||
return 0, 0, fmt.Errorf("invalid range header: %s", header)
|
||||
}
|
||||
|
||||
start, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("failed to parse range start: %w", err)
|
||||
}
|
||||
|
||||
end := size - 1
|
||||
if parts[1] != "" {
|
||||
end, err = strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("failed to parse range end: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if start < 0 || start >= size || end < start {
|
||||
return 0, 0, fmt.Errorf("invalid range bounds: %s", header)
|
||||
}
|
||||
|
||||
if end >= size {
|
||||
end = size - 1
|
||||
}
|
||||
|
||||
return start, end, nil
|
||||
}
|
||||
|
||||
var _ = Describe("HTTPRangeReaderAt", func() {
|
||||
It("clamps reads that cross EOF", func() {
|
||||
data := []byte("abcdef")
|
||||
rangeLog := []string{}
|
||||
server, _, _ := testIPAServerWithRangeLog(data, &rangeLog)
|
||||
defer server.Close()
|
||||
|
||||
reader, size, err := newHTTPRangeReaderAt(http.NewClient[interface{}](http.Args{}), server.URL)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(size).To(Equal(int64(len(data))))
|
||||
|
||||
buf := make([]byte, 4)
|
||||
n, err := reader.ReadAt(buf, 4)
|
||||
Expect(n).To(Equal(2))
|
||||
Expect(err).To(Equal(io.EOF))
|
||||
Expect(string(buf[:n])).To(Equal("ef"))
|
||||
Expect(rangeLog).To(ContainElement("bytes=4-5"))
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
var (
|
||||
ctrl *gomock.Controller
|
||||
@@ -26,6 +182,7 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
as = &appstore{
|
||||
machine: mockMachine,
|
||||
downloadClient: mockDownloadClient,
|
||||
httpClient: http.NewClient[interface{}](http.Args{}),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -117,6 +274,27 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("Sign In to the iTunes Store", 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: FailureTypeSignInRequired,
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
|
||||
Expect(err).To(Equal(ErrPasswordTokenExpired))
|
||||
})
|
||||
})
|
||||
|
||||
When("license is missing", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
@@ -206,7 +384,12 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
})
|
||||
|
||||
When("fails to parse release date", func() {
|
||||
var server *httptest.Server
|
||||
|
||||
BeforeEach(func() {
|
||||
ipa := testIPA("1.0.0", "invalid-date", time.Date(2024, 3, 19, 12, 0, 0, 0, time.UTC))
|
||||
server, _, _ = testIPAServer(ipa)
|
||||
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:11:22:33:44:55", nil)
|
||||
@@ -217,8 +400,10 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
Data: downloadResult{
|
||||
Items: []downloadItemResult{
|
||||
{
|
||||
URL: server.URL,
|
||||
Metadata: map[string]interface{}{
|
||||
"releaseDate": "invalid-date",
|
||||
"bundleShortVersionString": "1.0.0",
|
||||
"releaseDate": "invalid-date",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -226,6 +411,10 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
}, nil)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
server.Close()
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
@@ -233,8 +422,14 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("successfully gets version metadata", func() {
|
||||
When("IPA metadata cannot be read", func() {
|
||||
var server *httptest.Server
|
||||
|
||||
BeforeEach(func() {
|
||||
server = httptest.NewServer(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) {
|
||||
w.WriteHeader(gohttp.StatusOK)
|
||||
}))
|
||||
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:11:22:33:44:55", nil)
|
||||
@@ -245,8 +440,57 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
Data: downloadResult{
|
||||
Items: []downloadItemResult{
|
||||
{
|
||||
URL: server.URL,
|
||||
Metadata: map[string]interface{}{
|
||||
"bundleShortVersionString": "1.0.0",
|
||||
"releaseDate": "2024-03-20T12:00:00Z",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
server.Close()
|
||||
})
|
||||
|
||||
It("returns error instead of falling back to API metadata", func() {
|
||||
_, err := as.GetVersionMetadata(GetVersionMetadataInput{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("failed to read version metadata"))
|
||||
})
|
||||
})
|
||||
|
||||
When("successfully gets version metadata", func() {
|
||||
var (
|
||||
server *httptest.Server
|
||||
ipa []byte
|
||||
servedBytes *int64
|
||||
wholeGetCount *int64
|
||||
releaseDate time.Time
|
||||
displayVersion string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
releaseDate = time.Date(2024, 4, 2, 12, 0, 0, 0, time.UTC)
|
||||
displayVersion = "2.0.0"
|
||||
ipa = testIPA(displayVersion, fmt.Sprintf(" \n%s\t", releaseDate.Format(time.RFC3339)), time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
server, servedBytes, wholeGetCount = testIPAServer(ipa)
|
||||
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:11:22:33:44:55", nil)
|
||||
|
||||
mockDownloadClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[downloadResult]{
|
||||
Data: downloadResult{
|
||||
Items: []downloadItemResult{
|
||||
{
|
||||
URL: server.URL,
|
||||
Metadata: map[string]interface{}{
|
||||
"releaseDate": "2020-01-01T00:00:00Z",
|
||||
"bundleShortVersionString": "1.0.0",
|
||||
},
|
||||
},
|
||||
@@ -255,6 +499,10 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
}, nil)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
server.Close()
|
||||
})
|
||||
|
||||
It("returns version metadata", func() {
|
||||
output, err := as.GetVersionMetadata(GetVersionMetadataInput{
|
||||
Account: Account{
|
||||
@@ -267,8 +515,10 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
|
||||
})
|
||||
|
||||
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)))
|
||||
Expect(output.DisplayVersion).To(Equal(displayVersion))
|
||||
Expect(output.ReleaseDate).To(Equal(releaseDate))
|
||||
Expect(atomic.LoadInt64(wholeGetCount)).To(BeZero())
|
||||
Expect(atomic.LoadInt64(servedBytes)).To(BeNumerically("<", int64(len(ipa)/2)))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -33,7 +33,7 @@ func (t *appstore) ListVersions(input ListVersionsInput) (ListVersionsOutput, er
|
||||
return ListVersionsOutput{}, fmt.Errorf("failed to send http request: %w", err)
|
||||
}
|
||||
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired {
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired || res.Data.FailureType == FailureTypeSignInRequired {
|
||||
return ListVersionsOutput{}, ErrPasswordTokenExpired
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,27 @@ var _ = Describe("AppStore (ListVersions)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("Sign In to the iTunes Store", 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: FailureTypeSignInRequired,
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
_, err := as.ListVersions(ListVersionsInput{})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("license is required", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
|
||||
@@ -160,7 +160,7 @@ func (t *appstore) parseLoginResponse(res *http.Result[loginResult], attempt int
|
||||
func (t *appstore) loginRequest(email, password, authCode, guid, endpoint string, attempt int) http.Request {
|
||||
return http.Request{
|
||||
Method: http.MethodPOST,
|
||||
URL: endpoint,
|
||||
URL: authenticateURL(endpoint),
|
||||
ResponseFormat: http.ResponseFormatXML,
|
||||
Headers: map[string]string{
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
@@ -177,3 +177,20 @@ func (t *appstore) loginRequest(email, password, authCode, guid, endpoint string
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// authenticateURL normalizes the bag-provided authentication endpoint. Apple's
|
||||
// current endpoint (https://auth.itunes.apple.com/auth/v1/native/fast) only
|
||||
// responds correctly when the path has a trailing slash; without it the request
|
||||
// is redirected/dropped and the login silently fails. The legacy MZFinance
|
||||
// authenticate endpoint is left untouched.
|
||||
func authenticateURL(endpoint string) string {
|
||||
if endpoint == "" {
|
||||
return endpoint
|
||||
}
|
||||
|
||||
if strings.Contains(endpoint, "/native/") && !strings.HasSuffix(endpoint, "/") {
|
||||
return endpoint + "/"
|
||||
}
|
||||
|
||||
return endpoint
|
||||
}
|
||||
@@ -84,20 +84,38 @@ var _ = Describe("AppStore (Login)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("store API returns invalid first response", func() {
|
||||
When("normalizes the native authentication endpoint", func() {
|
||||
BeforeEach(func() {
|
||||
mockClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
Expect(req.URL).To(Equal("https://auth.itunes.apple.com/auth/v1/native/fast/"))
|
||||
}).
|
||||
Return(http.Result[loginResult]{}, errors.New("stop"))
|
||||
})
|
||||
|
||||
It("appends the trailing slash", func() {
|
||||
_, err := as.Login(LoginInput{
|
||||
Password: testPassword,
|
||||
Endpoint: "https://auth.itunes.apple.com/auth/v1/native/fast",
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("store API returns invalid credentials on first attempt", func() {
|
||||
BeforeEach(func() {
|
||||
mockClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[loginResult]{
|
||||
Data: loginResult{
|
||||
FailureType: FailureTypeInvalidCredentials,
|
||||
CustomerMessage: "test",
|
||||
FailureType: FailureTypeInvalidCredentials,
|
||||
},
|
||||
}, nil).
|
||||
Times(2)
|
||||
})
|
||||
|
||||
It("retries one more time", func() {
|
||||
It("retries once then returns an error", func() {
|
||||
_, err := as.Login(LoginInput{
|
||||
Password: testPassword,
|
||||
})
|
||||
@@ -201,24 +219,6 @@ var _ = Describe("AppStore (Login)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("store API redirects too much", func() {
|
||||
BeforeEach(func() {
|
||||
mockClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[loginResult]{
|
||||
StatusCode: 302,
|
||||
Headers: map[string]string{"Location": "hello"},
|
||||
}, nil).
|
||||
Times(4)
|
||||
})
|
||||
It("bails out", func() {
|
||||
_, err := as.Login(LoginInput{
|
||||
Password: testPassword,
|
||||
})
|
||||
Expect(err).To(MatchError("too many attempts"))
|
||||
})
|
||||
})
|
||||
|
||||
When("store API returns valid response", func() {
|
||||
const (
|
||||
testPasswordToken = "test-password-token"
|
||||
@@ -249,37 +249,6 @@ var _ = Describe("AppStore (Login)", func() {
|
||||
}, nil)
|
||||
})
|
||||
|
||||
When("fails to save account in keychain", func() {
|
||||
BeforeEach(func() {
|
||||
mockKeychain.EXPECT().
|
||||
Set("account", gomock.Any()).
|
||||
Do(func(key string, data []byte) {
|
||||
want := Account{
|
||||
Name: fmt.Sprintf("%s %s", testFirstName, testLastName),
|
||||
Email: testEmail,
|
||||
PasswordToken: testPasswordToken,
|
||||
Password: testPassword,
|
||||
DirectoryServicesID: testDirectoryServicesID,
|
||||
StoreFront: testStoreFront,
|
||||
Pod: testPod,
|
||||
}
|
||||
|
||||
var got Account
|
||||
err := json.Unmarshal(data, &got)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(got).To(Equal(want))
|
||||
}).
|
||||
Return(errors.New(""))
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
_, err := as.Login(LoginInput{
|
||||
Password: testPassword,
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("successfully saves account in keychain", func() {
|
||||
BeforeEach(func() {
|
||||
mockKeychain.EXPECT().
|
||||
@@ -296,8 +265,7 @@ var _ = Describe("AppStore (Login)", func() {
|
||||
}
|
||||
|
||||
var got Account
|
||||
err := json.Unmarshal(data, &got)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(json.Unmarshal(data, &got)).To(Succeed())
|
||||
Expect(got).To(Equal(want))
|
||||
}).
|
||||
Return(nil)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
type LookupInput struct {
|
||||
Account Account
|
||||
BundleID string
|
||||
Platform Platform
|
||||
}
|
||||
|
||||
type LookupOutput struct {
|
||||
@@ -24,7 +25,10 @@ func (t *appstore) Lookup(input LookupInput) (LookupOutput, error) {
|
||||
return LookupOutput{}, fmt.Errorf("failed to resolve the country code: %w", err)
|
||||
}
|
||||
|
||||
request := t.lookupRequest(input.BundleID, countryCode)
|
||||
request, err := t.lookupRequest(input.BundleID, countryCode, input.Platform)
|
||||
if err != nil {
|
||||
return LookupOutput{}, fmt.Errorf("failed to create lookup request: %w", err)
|
||||
}
|
||||
|
||||
res, err := t.searchClient.Send(request)
|
||||
if err != nil {
|
||||
@@ -44,21 +48,31 @@ func (t *appstore) Lookup(input LookupInput) (LookupOutput, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *appstore) lookupRequest(bundleID, countryCode string) http.Request {
|
||||
func (t *appstore) lookupRequest(bundleID, countryCode string, platform Platform) (http.Request, error) {
|
||||
url, err := t.lookupURL(bundleID, countryCode, platform)
|
||||
if err != nil {
|
||||
return http.Request{}, err
|
||||
}
|
||||
|
||||
return http.Request{
|
||||
URL: t.lookupURL(bundleID, countryCode),
|
||||
URL: url,
|
||||
Method: http.MethodGET,
|
||||
ResponseFormat: http.ResponseFormatJSON,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *appstore) lookupURL(bundleID, countryCode string) string {
|
||||
func (t *appstore) lookupURL(bundleID, countryCode string, platform Platform) (string, error) {
|
||||
entity, err := platform.lookupEntity()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("entity", "software,iPadSoftware")
|
||||
params.Add("entity", entity)
|
||||
params.Add("limit", "1")
|
||||
params.Add("media", "software")
|
||||
params.Add("bundleId", bundleID)
|
||||
params.Add("country", countryCode)
|
||||
|
||||
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathLookup, params.Encode())
|
||||
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathLookup, params.Encode()), nil
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package appstore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/majd/ipatool/v2/pkg/http"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -85,6 +86,29 @@ var _ = Describe("AppStore (Lookup)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("platform is AppleTV", func() {
|
||||
BeforeEach(func() {
|
||||
mockClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
parsedURL, err := url.Parse(req.URL)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedURL.Query().Get("entity")).To(Equal("tvSoftware"))
|
||||
}).
|
||||
Return(http.Result[searchResult]{}, errors.New("request error"))
|
||||
})
|
||||
|
||||
It("uses the tvOS lookup entity", func() {
|
||||
_, err := as.Lookup(LookupInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
Platform: PlatformAppleTV,
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("store front is invalid", func() {
|
||||
It("returns error", func() {
|
||||
_, err := as.Lookup(LookupInput{
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
package appstore
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
apphttp "github.com/majd/ipatool/v2/pkg/http"
|
||||
"howett.net/plist"
|
||||
)
|
||||
|
||||
var infoPlistReleaseDateKeys = []string{
|
||||
"releaseDate",
|
||||
"ReleaseDate",
|
||||
}
|
||||
|
||||
var infoPlistDisplayVersionKeys = []string{
|
||||
"CFBundleShortVersionString",
|
||||
"bundleShortVersionString",
|
||||
}
|
||||
|
||||
type versionMetadata struct {
|
||||
DisplayVersion string
|
||||
ReleaseDate time.Time
|
||||
}
|
||||
|
||||
type httpRangeReaderAt struct {
|
||||
client apphttp.Client[interface{}]
|
||||
url string
|
||||
size int64
|
||||
}
|
||||
|
||||
func newHTTPRangeReaderAt(client apphttp.Client[interface{}], url string) (*httpRangeReaderAt, int64, error) {
|
||||
if url == "" {
|
||||
return nil, 0, errors.New("url is empty")
|
||||
}
|
||||
|
||||
size, err := remoteFileSize(client, url)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to read remote file size: %w", err)
|
||||
}
|
||||
|
||||
return &httpRangeReaderAt{
|
||||
client: client,
|
||||
url: url,
|
||||
size: size,
|
||||
}, size, nil
|
||||
}
|
||||
|
||||
func remoteFileSize(client apphttp.Client[interface{}], url string) (int64, error) {
|
||||
req, err := client.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Accept-Encoding", "identity")
|
||||
req.Header.Set("Range", "bytes=0-0")
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
|
||||
if res != nil && res.Body != nil {
|
||||
defer res.Body.Close()
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusPartialContent {
|
||||
return 0, fmt.Errorf("expected partial content response, got status %d", res.StatusCode)
|
||||
}
|
||||
|
||||
size, err := parseContentRangeSize(res.Header.Get("Content-Range"))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func parseContentRangeSize(header string) (int64, error) {
|
||||
if header == "" {
|
||||
return 0, errors.New("content range is empty")
|
||||
}
|
||||
|
||||
slash := strings.LastIndex(header, "/")
|
||||
if slash == -1 || slash == len(header)-1 {
|
||||
return 0, fmt.Errorf("invalid content range: %s", header)
|
||||
}
|
||||
|
||||
sizeText := header[slash+1:]
|
||||
if sizeText == "*" {
|
||||
return 0, fmt.Errorf("invalid content range size: %s", sizeText)
|
||||
}
|
||||
|
||||
size, err := strconv.ParseInt(sizeText, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to parse content range size: %w", err)
|
||||
}
|
||||
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (r *httpRangeReaderAt) ReadAt(p []byte, off int64) (int, error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if off < 0 {
|
||||
return 0, errors.New("offset is negative")
|
||||
}
|
||||
|
||||
if off >= r.size {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
requestEnd := off + int64(len(p)) - 1
|
||||
rangeEnd := requestEnd
|
||||
|
||||
if rangeEnd >= r.size {
|
||||
rangeEnd = r.size - 1
|
||||
}
|
||||
|
||||
req, err := r.client.NewRequest("GET", r.url, nil)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Accept-Encoding", "identity")
|
||||
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", off, rangeEnd))
|
||||
|
||||
res, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
|
||||
if res != nil && res.Body != nil {
|
||||
defer res.Body.Close()
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusPartialContent {
|
||||
return 0, fmt.Errorf("expected partial content response, got status %d", res.StatusCode)
|
||||
}
|
||||
|
||||
readLength := int(rangeEnd-off) + 1
|
||||
|
||||
n, err := io.ReadFull(res.Body, p[:readLength])
|
||||
if err == io.ErrUnexpectedEOF || err == io.EOF {
|
||||
return n, io.EOF
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return n, fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
if requestEnd >= r.size {
|
||||
return n, io.EOF
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (t *appstore) readVersionMetadataFromIPA(url string) (versionMetadata, error) {
|
||||
reader, size, err := newHTTPRangeReaderAt(t.httpClient, url)
|
||||
if err != nil {
|
||||
return versionMetadata{}, err
|
||||
}
|
||||
|
||||
zipReader, err := zip.NewReader(reader, size)
|
||||
if err != nil {
|
||||
return versionMetadata{}, fmt.Errorf("failed to open zip reader: %w", err)
|
||||
}
|
||||
|
||||
for _, file := range zipReader.File {
|
||||
if !isMainAppInfoPlist(file.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
metadata, err := readVersionMetadataFromInfoPlist(file)
|
||||
if err != nil {
|
||||
return versionMetadata{}, err
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
return versionMetadata{}, errors.New("could not find Info.plist")
|
||||
}
|
||||
|
||||
func isMainAppInfoPlist(name string) bool {
|
||||
parts := strings.Split(name, "/")
|
||||
|
||||
return len(parts) == 3 && parts[0] == "Payload" && strings.HasSuffix(parts[1], ".app") && parts[2] == "Info.plist"
|
||||
}
|
||||
|
||||
func readVersionMetadataFromInfoPlist(file *zip.File) (versionMetadata, error) {
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
return versionMetadata{}, fmt.Errorf("failed to open Info.plist: %w", err)
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
data := new(bytes.Buffer)
|
||||
|
||||
_, err = io.Copy(data, src)
|
||||
if err != nil {
|
||||
return versionMetadata{}, fmt.Errorf("failed to read Info.plist: %w", err)
|
||||
}
|
||||
|
||||
metadata := map[string]interface{}{}
|
||||
|
||||
_, err = plist.Unmarshal(data.Bytes(), &metadata)
|
||||
if err != nil {
|
||||
return versionMetadata{}, fmt.Errorf("failed to unmarshal Info.plist: %w", err)
|
||||
}
|
||||
|
||||
displayVersion, err := readDisplayVersionFromMetadata(metadata)
|
||||
if err != nil {
|
||||
return versionMetadata{}, err
|
||||
}
|
||||
|
||||
releaseDate, err := readReleaseDateFromInfoPlist(metadata, file.Modified)
|
||||
if err != nil {
|
||||
return versionMetadata{}, err
|
||||
}
|
||||
|
||||
return versionMetadata{
|
||||
DisplayVersion: displayVersion,
|
||||
ReleaseDate: releaseDate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func readDisplayVersionFromMetadata(metadata map[string]interface{}) (string, error) {
|
||||
for _, key := range infoPlistDisplayVersionKeys {
|
||||
value, ok := metadata[key]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
displayVersion := strings.TrimSpace(fmt.Sprintf("%v", value))
|
||||
if displayVersion == "" || displayVersion == "<nil>" {
|
||||
return "", fmt.Errorf("%s is empty", key)
|
||||
}
|
||||
|
||||
return displayVersion, nil
|
||||
}
|
||||
|
||||
return "", errors.New("info plist does not contain a display version")
|
||||
}
|
||||
|
||||
func readReleaseDateFromInfoPlist(metadata map[string]interface{}, modified time.Time) (time.Time, error) {
|
||||
for _, key := range infoPlistReleaseDateKeys {
|
||||
value, ok := metadata[key]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
releaseDate, err := parseReleaseDateValue(value)
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("failed to parse release date: %w", err)
|
||||
}
|
||||
|
||||
return releaseDate, nil
|
||||
}
|
||||
|
||||
if modified.IsZero() {
|
||||
return time.Time{}, errors.New("info plist does not contain a release date")
|
||||
}
|
||||
|
||||
return modified.UTC(), nil
|
||||
}
|
||||
|
||||
func parseReleaseDateValue(value interface{}) (time.Time, error) {
|
||||
switch val := value.(type) {
|
||||
case time.Time:
|
||||
return val.UTC(), nil
|
||||
case string:
|
||||
return parseReleaseDateString(val)
|
||||
case int:
|
||||
return time.Unix(int64(val), 0).UTC(), nil
|
||||
case int64:
|
||||
return time.Unix(val, 0).UTC(), nil
|
||||
case uint64:
|
||||
if val > math.MaxInt64 {
|
||||
return time.Time{}, fmt.Errorf("timestamp is too large: %d", val)
|
||||
}
|
||||
|
||||
return time.Unix(int64(val), 0).UTC(), nil
|
||||
case float64:
|
||||
return time.Unix(int64(val), 0).UTC(), nil
|
||||
default:
|
||||
return time.Time{}, fmt.Errorf("unsupported release date type %T", value)
|
||||
}
|
||||
}
|
||||
|
||||
func parseReleaseDateString(value string) (time.Time, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
|
||||
for _, layout := range []string{
|
||||
time.RFC3339,
|
||||
time.RFC3339Nano,
|
||||
"Monday, January 2, 2006",
|
||||
"2006-01-02",
|
||||
} {
|
||||
parsed, err := time.Parse(layout, value)
|
||||
if err == nil {
|
||||
return parsed.UTC(), nil
|
||||
}
|
||||
}
|
||||
|
||||
return time.Time{}, fmt.Errorf("invalid release date: %s", value)
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package appstore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
gohttp "net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/majd/ipatool/v2/pkg/http"
|
||||
)
|
||||
|
||||
type platformVersionLookupResult struct {
|
||||
Results map[string]platformVersionLookupItem `json:"results,omitempty"`
|
||||
}
|
||||
|
||||
type platformVersionLookupItem struct {
|
||||
BundleID string `json:"bundleId,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Offers []platformVersionLookupOffer `json:"offers,omitempty"`
|
||||
}
|
||||
|
||||
type platformVersionLookupOffer struct {
|
||||
BuyParams string `json:"buyParams,omitempty"`
|
||||
Version platformVersionLookupVersion `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type platformVersionLookupVersion struct {
|
||||
Display string `json:"display,omitempty"`
|
||||
ExternalID platformVersionExternalID `json:"externalId,omitempty"`
|
||||
}
|
||||
|
||||
type platformVersionExternalID string
|
||||
|
||||
func (id *platformVersionExternalID) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var stringID string
|
||||
if err := json.Unmarshal(data, &stringID); err == nil {
|
||||
*id = platformVersionExternalID(stringID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var numberID json.Number
|
||||
if err := json.Unmarshal(data, &numberID); err == nil {
|
||||
*id = platformVersionExternalID(numberID.String())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid external version id %s", string(data))
|
||||
}
|
||||
|
||||
func (t *appstore) lookupLatestExternalVersionID(acc Account, app App, platform Platform) (string, error) {
|
||||
if app.ID == 0 {
|
||||
return "", errors.New("app ID is required for platform version lookup")
|
||||
}
|
||||
|
||||
countryCode, err := countryCodeFromStoreFront(acc.StoreFront)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to resolve the country code: %w", err)
|
||||
}
|
||||
|
||||
request, err := t.platformVersionLookupRequest(app.ID, countryCode, platform)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create platform version lookup request: %w", err)
|
||||
}
|
||||
|
||||
res, err := t.platformClient.Send(request)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("platform version lookup request failed: %w", err)
|
||||
}
|
||||
|
||||
if res.StatusCode != gohttp.StatusOK {
|
||||
return "", NewErrorWithMetadata(errors.New("platform version lookup request failed"), res)
|
||||
}
|
||||
|
||||
item, ok := res.Data.Results[strconv.FormatInt(app.ID, 10)]
|
||||
if !ok {
|
||||
return "", NewErrorWithMetadata(errors.New("platform version lookup returned no app"), res)
|
||||
}
|
||||
|
||||
if len(item.Offers) == 0 {
|
||||
return "", NewErrorWithMetadata(errors.New("platform version lookup returned no offers"), res)
|
||||
}
|
||||
|
||||
offer := item.Offers[0]
|
||||
externalVersionID := string(offer.Version.ExternalID)
|
||||
|
||||
if externalVersionID == "" {
|
||||
externalVersionID, err = externalVersionIDFromBuyParams(offer.BuyParams)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse buy params: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if externalVersionID == "" {
|
||||
return "", NewErrorWithMetadata(errors.New("platform version lookup returned no external version id"), res)
|
||||
}
|
||||
|
||||
return externalVersionID, nil
|
||||
}
|
||||
|
||||
func (*appstore) platformVersionLookupRequest(appID int64, countryCode string, platform Platform) (http.Request, error) {
|
||||
metadataPlatform, err := platform.metadataPlatform()
|
||||
if err != nil {
|
||||
return http.Request{}, err
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("version", "2")
|
||||
params.Add("id", strconv.FormatInt(appID, 10))
|
||||
params.Add("p", "mdm-lockup")
|
||||
params.Add("caller", "MDM")
|
||||
params.Add("platform", metadataPlatform)
|
||||
params.Add("cc", strings.ToLower(countryCode))
|
||||
params.Add("l", "en")
|
||||
|
||||
return http.Request{
|
||||
URL: fmt.Sprintf("https://uclient-api.itunes.apple.com/WebObjects/MZStorePlatform.woa/wa/lookup?%s", params.Encode()),
|
||||
Method: http.MethodGET,
|
||||
ResponseFormat: http.ResponseFormatJSON,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func externalVersionIDFromBuyParams(buyParams string) (string, error) {
|
||||
if buyParams == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
values, err := url.ParseQuery(buyParams)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse query: %w", err)
|
||||
}
|
||||
|
||||
return values.Get("appExtVrsId"), nil
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
var (
|
||||
ErrPasswordTokenExpired = errors.New("password token is expired")
|
||||
ErrLicenseAlreadyExists = errors.New("license already exists")
|
||||
ErrSubscriptionRequired = errors.New("subscription required")
|
||||
ErrTemporarilyUnavailable = errors.New("item is temporarily unavailable")
|
||||
)
|
||||
@@ -72,10 +73,17 @@ func (t *appstore) purchaseWithParams(acc Account, app App, guid string, pricing
|
||||
return ErrSubscriptionRequired
|
||||
}
|
||||
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired {
|
||||
if res.Data.FailureType == FailureTypePasswordTokenExpired ||
|
||||
res.Data.FailureType == FailureTypeSignInRequired ||
|
||||
res.Data.FailureType == FailureTypeDeviceVerificationFailed ||
|
||||
res.Data.CustomerMessage == CustomerMessagePasswordChanged {
|
||||
return ErrPasswordTokenExpired
|
||||
}
|
||||
|
||||
if res.Data.FailureType == FailureTypeLicenseAlreadyExists {
|
||||
return ErrLicenseAlreadyExists
|
||||
}
|
||||
|
||||
if res.Data.FailureType != "" && res.Data.CustomerMessage != "" {
|
||||
return NewErrorWithMetadata(errors.New(res.Data.CustomerMessage), res)
|
||||
}
|
||||
@@ -85,7 +93,7 @@ func (t *appstore) purchaseWithParams(acc Account, app App, guid string, pricing
|
||||
}
|
||||
|
||||
if res.StatusCode == gohttp.StatusInternalServerError {
|
||||
return fmt.Errorf("license already exists")
|
||||
return ErrLicenseAlreadyExists
|
||||
}
|
||||
|
||||
if res.Data.JingleDocType != "purchaseSuccess" || res.Data.Status != 0 {
|
||||
|
||||
@@ -152,6 +152,57 @@ var _ = Describe("AppStore (Purchase)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("Sign In to the iTunes Store", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:00:00:00:00:00", nil)
|
||||
|
||||
mockPurchaseClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[purchaseResult]{
|
||||
Data: purchaseResult{
|
||||
FailureType: FailureTypeSignInRequired,
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
err := as.Purchase(PurchaseInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("customer message indicates password has changed", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:00:00:00:00:00", nil)
|
||||
|
||||
mockPurchaseClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[purchaseResult]{
|
||||
Data: purchaseResult{
|
||||
FailureType: "some_other_failure",
|
||||
CustomerMessage: CustomerMessagePasswordChanged,
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns password token expired error", func() {
|
||||
err := as.Purchase(PurchaseInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
})
|
||||
Expect(err).To(MatchError(ErrPasswordTokenExpired))
|
||||
})
|
||||
})
|
||||
|
||||
When("store API returns customer error message", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
@@ -203,7 +254,34 @@ var _ = Describe("AppStore (Purchase)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("account already has a license for the app", func() {
|
||||
When("account already has a license for the app (failure type)", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:00:00:00:00:00", nil)
|
||||
|
||||
mockPurchaseClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[purchaseResult]{
|
||||
StatusCode: 200,
|
||||
Data: purchaseResult{
|
||||
FailureType: FailureTypeLicenseAlreadyExists,
|
||||
CustomerMessage: "An unknown error has occurred",
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns license already exists error", func() {
|
||||
err := as.Purchase(PurchaseInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
})
|
||||
Expect(err).To(MatchError(ErrLicenseAlreadyExists))
|
||||
})
|
||||
})
|
||||
|
||||
When("account already has a license for the app (HTTP 500 legacy)", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
@@ -217,13 +295,40 @@ var _ = Describe("AppStore (Purchase)", func() {
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns error", func() {
|
||||
It("returns license already exists error", func() {
|
||||
err := as.Purchase(PurchaseInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(MatchError(ErrLicenseAlreadyExists))
|
||||
})
|
||||
})
|
||||
|
||||
When("device verification fails", func() {
|
||||
BeforeEach(func() {
|
||||
mockMachine.EXPECT().
|
||||
MacAddress().
|
||||
Return("00:00:00:00:00:00", nil)
|
||||
|
||||
mockPurchaseClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Return(http.Result[purchaseResult]{
|
||||
StatusCode: 200,
|
||||
Data: purchaseResult{
|
||||
FailureType: FailureTypeDeviceVerificationFailed,
|
||||
CustomerMessage: "Your device or computer could not be verified. Contact support for assistance.",
|
||||
},
|
||||
}, nil)
|
||||
})
|
||||
|
||||
It("returns password token expired error", func() {
|
||||
err := as.Purchase(PurchaseInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
})
|
||||
Expect(err).To(MatchError(ErrPasswordTokenExpired))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -135,21 +135,29 @@ func (t *appstore) replicateSinfFromInfo(info packageInfo, zip *zip.Writer, sinf
|
||||
|
||||
func (t *appstore) replicateZip(src *zip.ReadCloser, dst *zip.Writer) error {
|
||||
for _, file := range src.File {
|
||||
srcFile, err := file.OpenRaw()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open raw file: %w", err)
|
||||
}
|
||||
err := func() error {
|
||||
srcFile, err := file.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
header := file.FileHeader
|
||||
dstFile, err := dst.CreateRaw(&header)
|
||||
header := file.FileHeader
|
||||
dstFile, err := dst.CreateHeader(&header)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create raw file: %w", err)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create file: %w", err)
|
||||
}
|
||||
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to copy file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to copy file: %w", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
)
|
||||
|
||||
type SearchInput struct {
|
||||
Account Account
|
||||
Term string
|
||||
Limit int64
|
||||
Account Account
|
||||
Term string
|
||||
Limit int64
|
||||
Platform Platform
|
||||
}
|
||||
|
||||
type SearchOutput struct {
|
||||
@@ -27,7 +28,10 @@ func (t *appstore) Search(input SearchInput) (SearchOutput, error) {
|
||||
return SearchOutput{}, fmt.Errorf("country code is invalid: %w", err)
|
||||
}
|
||||
|
||||
request := t.searchRequest(input.Term, countryCode, input.Limit)
|
||||
request, err := t.searchRequest(input.Term, countryCode, input.Limit, input.Platform)
|
||||
if err != nil {
|
||||
return SearchOutput{}, fmt.Errorf("failed to create search request: %w", err)
|
||||
}
|
||||
|
||||
res, err := t.searchClient.Send(request)
|
||||
if err != nil {
|
||||
@@ -49,21 +53,31 @@ type searchResult struct {
|
||||
Results []App `json:"results,omitempty"`
|
||||
}
|
||||
|
||||
func (t *appstore) searchRequest(term, countryCode string, limit int64) http.Request {
|
||||
func (t *appstore) searchRequest(term, countryCode string, limit int64, platform Platform) (http.Request, error) {
|
||||
url, err := t.searchURL(term, countryCode, limit, platform)
|
||||
if err != nil {
|
||||
return http.Request{}, err
|
||||
}
|
||||
|
||||
return http.Request{
|
||||
URL: t.searchURL(term, countryCode, limit),
|
||||
URL: url,
|
||||
Method: http.MethodGET,
|
||||
ResponseFormat: http.ResponseFormatJSON,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *appstore) searchURL(term, countryCode string, limit int64) string {
|
||||
func (t *appstore) searchURL(term, countryCode string, limit int64, platform Platform) (string, error) {
|
||||
entity, err := platform.searchEntity()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("entity", "software,iPadSoftware")
|
||||
params.Add("entity", entity)
|
||||
params.Add("limit", strconv.Itoa(int(limit)))
|
||||
params.Add("media", "software")
|
||||
params.Add("term", term)
|
||||
params.Add("country", countryCode)
|
||||
|
||||
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathSearch, params.Encode())
|
||||
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathSearch, params.Encode()), nil
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package appstore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/majd/ipatool/v2/pkg/http"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -76,6 +77,29 @@ var _ = Describe("AppStore (Search)", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("platform is AppleTV", func() {
|
||||
BeforeEach(func() {
|
||||
mockClient.EXPECT().
|
||||
Send(gomock.Any()).
|
||||
Do(func(req http.Request) {
|
||||
parsedURL, err := url.Parse(req.URL)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedURL.Query().Get("entity")).To(Equal("software,tvSoftware"))
|
||||
}).
|
||||
Return(http.Result[searchResult]{}, errors.New("request error"))
|
||||
})
|
||||
|
||||
It("uses the tvOS search entity", func() {
|
||||
_, err := as.Search(SearchInput{
|
||||
Account: Account{
|
||||
StoreFront: "143441",
|
||||
},
|
||||
Platform: PlatformAppleTV,
|
||||
})
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
When("store front is invalid", func() {
|
||||
It("returns error", func() {
|
||||
_, err := as.Search(SearchInput{
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package appstore
|
||||
|
||||
const (
|
||||
FailureTypeInvalidCredentials = "-5000"
|
||||
FailureTypePasswordTokenExpired = "2034"
|
||||
FailureTypeLicenseNotFound = "9610"
|
||||
FailureTypeTemporarilyUnavailable = "2059"
|
||||
FailureTypeInvalidCredentials = "-5000"
|
||||
FailureTypePasswordTokenExpired = "2034"
|
||||
FailureTypeSignInRequired = "2042"
|
||||
FailureTypeLicenseNotFound = "9610"
|
||||
FailureTypeTemporarilyUnavailable = "2059"
|
||||
FailureTypeLicenseAlreadyExists = "5002"
|
||||
FailureTypeDeviceVerificationFailed = "1008"
|
||||
|
||||
CustomerMessageBadLogin = "MZFinance.BadLogin.Configurator_message"
|
||||
CustomerMessageAccountDisabled = "Your account is disabled."
|
||||
CustomerMessageSubscriptionRequired = "Subscription Required"
|
||||
CustomerMessagePasswordChanged = "Your password has changed."
|
||||
|
||||
iTunesAPIDomain = "itunes.apple.com"
|
||||
iTunesAPIPathSearch = "/search"
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package appstore
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Platform string
|
||||
|
||||
const (
|
||||
PlatformIPhone Platform = "iphone"
|
||||
PlatformIPad Platform = "ipad"
|
||||
PlatformAppleTV Platform = "appletv"
|
||||
)
|
||||
|
||||
func ParsePlatform(value string) (Platform, error) {
|
||||
switch value {
|
||||
case "":
|
||||
return "", nil
|
||||
case "iphone", "iPhone", "ios", "iOS":
|
||||
return PlatformIPhone, nil
|
||||
case "ipad", "iPad":
|
||||
return PlatformIPad, nil
|
||||
case "appletv", "AppleTV", "apple-tv", "tvos", "tvOS":
|
||||
return PlatformAppleTV, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid platform %q", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (p Platform) lookupEntity() (string, error) {
|
||||
switch p {
|
||||
case "":
|
||||
return "software,iPadSoftware", nil
|
||||
case PlatformIPhone:
|
||||
return "software", nil
|
||||
case PlatformIPad:
|
||||
return "iPadSoftware", nil
|
||||
case PlatformAppleTV:
|
||||
return "tvSoftware", nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid platform %q", p)
|
||||
}
|
||||
}
|
||||
|
||||
func (p Platform) searchEntity() (string, error) {
|
||||
switch p {
|
||||
case "":
|
||||
return "software,iPadSoftware", nil
|
||||
case PlatformIPhone:
|
||||
return "software", nil
|
||||
case PlatformIPad:
|
||||
return "iPadSoftware", nil
|
||||
case PlatformAppleTV:
|
||||
return "software,tvSoftware", nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid platform %q", p)
|
||||
}
|
||||
}
|
||||
|
||||
func (p Platform) metadataPlatform() (string, error) {
|
||||
switch p {
|
||||
case PlatformIPhone, PlatformIPad:
|
||||
return "enterprisestore", nil
|
||||
case PlatformAppleTV:
|
||||
return "atv9", nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid platform %q", p)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package appstore
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Platform", func() {
|
||||
DescribeTable("parses aliases",
|
||||
func(value string, expected Platform) {
|
||||
platform, err := ParsePlatform(value)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(platform).To(Equal(expected))
|
||||
},
|
||||
Entry("default", "", Platform("")),
|
||||
Entry("iPhone", "iphone", PlatformIPhone),
|
||||
Entry("iOS", "ios", PlatformIPhone),
|
||||
Entry("iPad", "ipad", PlatformIPad),
|
||||
Entry("AppleTV", "appletv", PlatformAppleTV),
|
||||
Entry("tvOS", "tvos", PlatformAppleTV),
|
||||
)
|
||||
|
||||
It("returns an error for invalid platforms", func() {
|
||||
_, err := ParsePlatform("watch")
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -20,6 +20,7 @@ var (
|
||||
documentXMLPattern = regexp.MustCompile(`(?is)<Document\b[^>]*>(.*)</Document>`)
|
||||
plistXMLPattern = regexp.MustCompile(`(?is)<plist\b[^>]*>.*?</plist>`)
|
||||
dictXMLPattern = regexp.MustCompile(`(?is)<dict\b[^>]*>.*</dict>`)
|
||||
htmlTagPattern = regexp.MustCompile(`(?is)<[^>]*>`)
|
||||
)
|
||||
|
||||
//go:generate go run go.uber.org/mock/mockgen -source=client.go -destination=client_mock.go -package=http
|
||||
@@ -160,10 +161,23 @@ func (c *client[R]) handleXMLResponse(res *http.Response) (Result[R], error) {
|
||||
return Result[R]{}, fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
if res.StatusCode == http.StatusTooManyRequests {
|
||||
return Result[R]{}, fmt.Errorf("rate limited by Apple (HTTP %d): %s", res.StatusCode, strings.TrimSpace(string(body)))
|
||||
}
|
||||
|
||||
var data R
|
||||
|
||||
normalizedBody := normalizeXMLPlistBody(body)
|
||||
|
||||
if !looksLikePropertyList(normalizedBody) {
|
||||
snippet := bodySnippet(body)
|
||||
if snippet == "" {
|
||||
return Result[R]{}, fmt.Errorf("unexpected response from Apple (HTTP %d): empty or non-plist body", res.StatusCode)
|
||||
}
|
||||
|
||||
return Result[R]{}, fmt.Errorf("unexpected response from Apple (HTTP %d): %s", res.StatusCode, snippet)
|
||||
}
|
||||
|
||||
_, err = plist.Unmarshal(normalizedBody, &data)
|
||||
if err != nil {
|
||||
return Result[R]{}, fmt.Errorf("failed to unmarshal xml: %w", err)
|
||||
@@ -206,6 +220,51 @@ func normalizeXMLPlistBody(body []byte) []byte {
|
||||
return normalized
|
||||
}
|
||||
|
||||
// looksLikePropertyList reports whether body appears to be a (binary or XML)
|
||||
// property list. Apple occasionally answers with an HTML error page or a plain
|
||||
// text message; those must not be handed to plist.Unmarshal, which would
|
||||
// misinterpret a leading "<h..." as an OpenStep hex-data block and fail with an
|
||||
// opaque "unexpected hex digit" error instead of surfacing Apple's actual response.
|
||||
func looksLikePropertyList(body []byte) bool {
|
||||
trimmed := bytes.TrimSpace(body)
|
||||
if len(trimmed) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if bytes.HasPrefix(trimmed, []byte("bplist")) {
|
||||
return true
|
||||
}
|
||||
|
||||
lower := bytes.ToLower(trimmed)
|
||||
for _, marker := range [][]byte{
|
||||
[]byte("<?xml"),
|
||||
[]byte("<plist"),
|
||||
[]byte("<dict"),
|
||||
[]byte("<key"),
|
||||
} {
|
||||
if bytes.Contains(lower, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// bodySnippet returns a compact, single-line excerpt of a non-plist response
|
||||
// body suitable for embedding in an error message. HTML markup is stripped so
|
||||
// the underlying message (if any) is readable.
|
||||
func bodySnippet(body []byte) string {
|
||||
text := htmlTagPattern.ReplaceAll(body, []byte(" "))
|
||||
snippet := strings.Join(strings.Fields(string(text)), " ")
|
||||
|
||||
const maxLen = 200
|
||||
if len(snippet) > maxLen {
|
||||
snippet = snippet[:maxLen] + "…"
|
||||
}
|
||||
|
||||
return snippet
|
||||
}
|
||||
|
||||
func extractEmbeddedPlist(body []byte) []byte {
|
||||
plistMatch := plistXMLPattern.Find(body)
|
||||
if len(plistMatch) == 0 {
|
||||
|
||||
@@ -183,6 +183,28 @@ var _ = Describe("Client", Ordered, func() {
|
||||
Expect(res.Data.Foo).To(Equal("bar"))
|
||||
})
|
||||
|
||||
It("returns a readable error when Apple responds with an HTML page instead of a plist", func() {
|
||||
mockHandler = func(w http.ResponseWriter, _r *http.Request) {
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
_, err := w.Write([]byte("<html><body><h1>Service Unavailable</h1></body></html>"))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
sut := NewClient[xmlResult](Args{
|
||||
CookieJar: mockCookieJar,
|
||||
})
|
||||
_, err := sut.Send(Request{
|
||||
URL: srv.URL,
|
||||
Method: MethodPOST,
|
||||
ResponseFormat: ResponseFormatXML,
|
||||
})
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).ToNot(ContainSubstring("hex digit"))
|
||||
Expect(err.Error()).To(ContainSubstring("Service Unavailable"))
|
||||
})
|
||||
|
||||
It("returns error when content type is not supported", func() {
|
||||
mockHandler = func(w http.ResponseWriter, _r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/xyz")
|
||||
|
||||
@@ -3,7 +3,7 @@ package keychain
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/99designs/keyring"
|
||||
"github.com/byteness/keyring"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
@@ -3,7 +3,7 @@ package keychain
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/99designs/keyring"
|
||||
"github.com/byteness/keyring"
|
||||
)
|
||||
|
||||
func (k *keychain) Set(key string, data []byte) error {
|
||||
|
||||
@@ -3,7 +3,7 @@ package keychain
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/99designs/keyring"
|
||||
"github.com/byteness/keyring"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package keychain
|
||||
|
||||
import "github.com/99designs/keyring"
|
||||
import "github.com/byteness/keyring"
|
||||
|
||||
//go:generate go run go.uber.org/mock/mockgen -source=keyring.go -destination=keyring_mock.go -package keychain
|
||||
type Keyring interface {
|
||||
|
||||
Reference in new issue
Block a user