Compare commits

...
13 Commits
36 changed files with 136 additions and 183 deletions

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ on:
issue_comment:
types: [created]
schedule:
- cron: "0 * * * *" # Every hour, every day
- cron: "0 */6 * * *" # every 6 hours
jobs:
scan-issues:
+25
View File
@@ -1,5 +1,30 @@
## Changelog
### Version [2.1.3](https://github.com/majd/ipatool/releases/tag/v2.1.3)
- Fixed a bug where temporary files were not removed after downloading the app package.
- Fixed a bug where the `--keychain-passphrase` flag was marked as invalid.
### Version [2.1.2](https://github.com/majd/ipatool/releases/tag/v2.1.2)
- `FileBackend` keyring is now used when other options are not available.
### Version [2.1.1](https://github.com/majd/ipatool/releases/tag/v2.1.1)
- Fixed an issue when creating the config directory for the tool.
### Version [2.1.0](https://github.com/majd/ipatool/releases/tag/v2.1.0)
- Implemented `Lookup` API.
- Implemented `AccountInfo` API.
- Implemented `ReplicateSinf` API.
- Added storefront code for Georgia (GE).
- Build version is now set using linker flags.
- Refactored API interfaces.
- Improved tests for http package.
- Integrated `golangci-lint` linter.
- Added v2 suffix to module path.
### Version [2.0.3](https://github.com/majd/ipatool/releases/tag/v2.0.3)
- Added support for downloading Apple Arcade games.
-5
View File
@@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/majd/ipatool/v2/pkg/util"
@@ -22,10 +21,6 @@ func authCmd() *cobra.Command {
Short: "Authenticate with the App Store",
}
if keyringBackendType() == keyring.FileBackend {
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
cmd.AddCommand(loginCmd())
cmd.AddCommand(infoCmd())
cmd.AddCommand(revokeCmd())
+17 -34
View File
@@ -19,7 +19,6 @@ import (
"github.com/majd/ipatool/v2/pkg/util/operatingsystem"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"golang.org/x/term"
)
@@ -27,13 +26,12 @@ var dependencies = Dependencies{}
var keychainPassphrase string
type Dependencies struct {
Logger log.Logger
OS operatingsystem.OperatingSystem
Machine machine.Machine
CookieJar http.CookieJar
Keychain keychain.Keychain
AppStore appstore.AppStore
KeyringBackendType keyring.BackendType
Logger log.Logger
OS operatingsystem.OperatingSystem
Machine machine.Machine
CookieJar http.CookieJar
Keychain keychain.Keychain
AppStore appstore.AppStore
}
// newLogger returns a new logger instance.
@@ -62,10 +60,12 @@ func newCookieJar(machine machine.Machine) http.CookieJar {
}
// newKeychain returns a new keychain instance.
func newKeychain(machine machine.Machine, logger log.Logger, backendType keyring.BackendType, interactive bool) keychain.Keychain {
func newKeychain(machine machine.Machine, logger log.Logger, interactive bool) keychain.Keychain {
ring := util.Must(keyring.Open(keyring.Config{
AllowedBackends: []keyring.BackendType{
backendType,
keyring.KeychainBackend,
keyring.SecretServiceBackend,
keyring.FileBackend,
},
ServiceName: KeychainServiceName,
FileDir: filepath.Join(machine.HomeDirectory(), ConfigDirectoryName),
@@ -96,22 +96,6 @@ func newKeychain(machine machine.Machine, logger log.Logger, backendType keyring
return keychain.New(keychain.Args{Keyring: ring})
}
// keyringBackendType returns the backend type for the keyring.
func keyringBackendType() keyring.BackendType {
allowedBackends := []keyring.BackendType{
keyring.KeychainBackend,
keyring.SecretServiceBackend,
}
for _, backend := range allowedBackends {
if slices.Contains(keyring.AvailableBackends(), backend) {
return backend
}
}
return keyring.FileBackend
}
// initWithCommand initializes the dependencies of the command.
func initWithCommand(cmd *cobra.Command) {
verbose := cmd.Flag("verbose").Value.String() == "true"
@@ -122,8 +106,7 @@ func initWithCommand(cmd *cobra.Command) {
dependencies.OS = operatingsystem.New()
dependencies.Machine = machine.New(machine.Args{OS: dependencies.OS})
dependencies.CookieJar = newCookieJar(dependencies.Machine)
dependencies.KeyringBackendType = keyringBackendType()
dependencies.Keychain = newKeychain(dependencies.Machine, dependencies.Logger, dependencies.KeyringBackendType, interactive)
dependencies.Keychain = newKeychain(dependencies.Machine, dependencies.Logger, interactive)
dependencies.AppStore = appstore.NewAppStore(appstore.Args{
CookieJar: dependencies.CookieJar,
OperatingSystem: dependencies.OS,
@@ -131,16 +114,16 @@ func initWithCommand(cmd *cobra.Command) {
Machine: dependencies.Machine,
})
util.Must("", createConfigDirectory())
util.Must("", createConfigDirectory(dependencies.OS, dependencies.Machine))
}
// createConfigDirectory creates the configuration directory for the CLI tool, if needed.
func createConfigDirectory() error {
configDirectoryPath := filepath.Join(dependencies.Machine.HomeDirectory(), ConfigDirectoryName)
_, err := dependencies.OS.Stat(configDirectoryPath)
func createConfigDirectory(os operatingsystem.OperatingSystem, machine machine.Machine) error {
configDirectoryPath := filepath.Join(machine.HomeDirectory(), ConfigDirectoryName)
_, err := os.Stat(configDirectoryPath)
if err != nil && dependencies.OS.IsNotExist(err) {
err = dependencies.OS.MkdirAll(configDirectoryPath, 0700)
if err != nil && os.IsNotExist(err) {
err = os.MkdirAll(configDirectoryPath, 0700)
if err != nil {
return fmt.Errorf("failed to create config directory: %w", err)
}
+18 -20
View File
@@ -5,7 +5,6 @@ import (
"os"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/schollz/progressbar/v3"
@@ -56,20 +55,24 @@ func downloadCmd() *cobra.Command {
}
}
progress := progressbar.NewOptions64(1,
progressbar.OptionSetDescription("downloading"),
progressbar.OptionSetWriter(os.Stdout),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(20),
progressbar.OptionFullWidth(),
progressbar.OptionThrottle(65*time.Millisecond),
progressbar.OptionShowCount(),
progressbar.OptionClearOnFinish(),
progressbar.OptionSpinnerType(14),
progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSetElapsedTime(false),
progressbar.OptionSetPredictTime(false),
)
interactive, _ := cmd.Context().Value("interactive").(bool)
var progress *progressbar.ProgressBar
if interactive {
progress = progressbar.NewOptions64(1,
progressbar.OptionSetDescription("downloading"),
progressbar.OptionSetWriter(os.Stdout),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(20),
progressbar.OptionFullWidth(),
progressbar.OptionThrottle(65*time.Millisecond),
progressbar.OptionShowCount(),
progressbar.OptionClearOnFinish(),
progressbar.OptionSpinnerType(14),
progressbar.OptionSetRenderBlankState(true),
progressbar.OptionSetElapsedTime(false),
progressbar.OptionSetPredictTime(false),
)
}
out, err := dependencies.AppStore.Download(appstore.DownloadInput{Account: acc, App: lookupResult.App, OutputPath: outputPath, Progress: progress})
if err != nil {
@@ -112,11 +115,6 @@ func downloadCmd() *cobra.Command {
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "The bundle identifier of the target iOS app (required)")
cmd.Flags().StringVarP(&outputPath, "output", "o", "", "The destination path of the downloaded app package")
cmd.Flags().BoolVar(&acquireLicense, "purchase", false, "Obtain a license for the app if needed")
if keyringBackendType() == keyring.FileBackend {
cmd.Flags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
_ = cmd.MarkFlagRequired("bundle-identifier")
return cmd
-6
View File
@@ -4,7 +4,6 @@ import (
"errors"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
@@ -66,11 +65,6 @@ func purchaseCmd() *cobra.Command {
}
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "Bundle identifier of the target iOS app (required)")
if keyringBackendType() == keyring.FileBackend {
cmd.Flags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
_ = cmd.MarkFlagRequired("bundle-identifier")
return cmd
+1
View File
@@ -39,6 +39,7 @@ func rootCmd() *cobra.Command {
}, enumflag.EnumCaseSensitive), "format", "", "sets output format for command; can be 'text', 'json'")
cmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "enables verbose logs")
cmd.PersistentFlags().BoolVarP(&nonInteractive, "non-interactive", "", false, "run in non-interactive session")
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
cmd.AddCommand(authCmd())
cmd.AddCommand(downloadCmd())
-5
View File
@@ -1,7 +1,6 @@
package cmd
import (
"github.com/99designs/keyring"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
)
@@ -40,9 +39,5 @@ func searchCmd() *cobra.Command {
cmd.Flags().Int64VarP(&limit, "limit", "l", 5, "maximum amount of search results to retrieve")
if keyringBackendType() == keyring.FileBackend {
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
return cmd
}
+9 -9
View File
@@ -5,7 +5,6 @@ go 1.19
require (
github.com/99designs/keyring v1.2.1
github.com/avast/retry-go v3.0.0+incompatible
github.com/golang/mock v1.7.0-rc.1
github.com/juju/persistent-cookiejar v1.0.0
github.com/onsi/ginkgo/v2 v2.5.0
github.com/onsi/gomega v1.24.0
@@ -13,16 +12,16 @@ require (
github.com/schollz/progressbar/v3 v3.13.1
github.com/spf13/cobra v1.6.1
github.com/thediveo/enumflag/v2 v2.0.1
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/net v0.8.0
golang.org/x/term v0.6.0
go.uber.org/mock v0.4.0
golang.org/x/net v0.20.0
golang.org/x/term v0.16.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.5.0 // indirect
github.com/dvsekhvalnov/jose2go v1.6.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.5.9 // indirect
@@ -37,10 +36,11 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // 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
+16 -38
View File
@@ -11,8 +11,8 @@ github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnG
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.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM=
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
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=
@@ -20,8 +20,6 @@ github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
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/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/mock v1.7.0-rc.1 h1:YojYx61/OLFsiv6Rw1Z96LpldJIy31o+UHmwAUMJ6/U=
github.com/golang/mock v1.7.0-rc.1/go.mod h1:s42URUywIqd+OcERslBJvOjepvNymP31m3q8d/GkuRs=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
@@ -86,48 +84,28 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thediveo/enumflag/v2 v2.0.1 h1:2bmWZPD2uSARDsOjXIdLRlNcYBFNF9xX0RNUNF2vKic=
github.com/thediveo/enumflag/v2 v2.0.1/go.mod h1:SyxyCNvv0QeRtZ7fjuaUz4FRLC3cWuDiD7QdORU0MGg=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
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.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
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-20211019181941-9d821ace8654/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 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
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=
+1 -1
View File
@@ -4,10 +4,10 @@ import (
"errors"
"fmt"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/keychain"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (AccountInfo)", func() {
+1 -1
View File
@@ -9,13 +9,13 @@ import (
"os"
"strings"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/keychain"
"github.com/majd/ipatool/v2/pkg/util/machine"
"github.com/majd/ipatool/v2/pkg/util/operatingsystem"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
"howett.net/plist"
)
+2 -2
View File
@@ -6,12 +6,12 @@ import (
"fmt"
"strings"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/keychain"
"github.com/majd/ipatool/v2/pkg/util/machine"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (Login)", func() {
@@ -196,7 +196,7 @@ var _ = Describe("AppStore (Login)", func() {
})
})
When("sucessfully saves account in keychain", func() {
When("successfully saves account in keychain", func() {
BeforeEach(func() {
mockKeychain.EXPECT().
Set("account", gomock.Any()).
+1 -1
View File
@@ -3,10 +3,10 @@ package appstore
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (Lookup)", func() {
+1 -1
View File
@@ -3,12 +3,12 @@ package appstore
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/keychain"
"github.com/majd/ipatool/v2/pkg/util/machine"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (Purchase)", func() {
+4 -2
View File
@@ -29,7 +29,6 @@ func (t *appstore) ReplicateSinf(input ReplicateSinfInput) error {
if err != nil {
return errors.New("failed to open zip reader")
}
defer zipReader.Close()
tmpPath := fmt.Sprintf("%s.tmp", input.PackagePath)
tmpFile, err := t.os.OpenFile(tmpPath, os.O_CREATE|os.O_WRONLY, 0644)
@@ -39,7 +38,6 @@ func (t *appstore) ReplicateSinf(input ReplicateSinfInput) error {
}
zipWriter := zip.NewWriter(tmpFile)
defer zipWriter.Close()
err = t.replicateZip(zipReader, zipWriter)
if err != nil {
@@ -71,6 +69,10 @@ func (t *appstore) ReplicateSinf(input ReplicateSinfInput) error {
return fmt.Errorf("failed to replicate sinf: %w", err)
}
zipReader.Close()
zipWriter.Close()
tmpFile.Close()
err = t.os.Remove(input.PackagePath)
if err != nil {
return fmt.Errorf("failed to remove original file: %w", err)
+1 -1
View File
@@ -6,13 +6,13 @@ import (
"fmt"
"os"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
"github.com/majd/ipatool/v2/pkg/keychain"
"github.com/majd/ipatool/v2/pkg/util/machine"
"github.com/majd/ipatool/v2/pkg/util/operatingsystem"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
"howett.net/plist"
)
+1 -1
View File
@@ -3,10 +3,10 @@ package appstore
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/keychain"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (Revoke)", func() {
+1 -1
View File
@@ -3,10 +3,10 @@ package appstore
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/http"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("AppStore (Search)", func() {
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"howett.net/plist"
)
//go:generate go run github.com/golang/mock/mockgen -source=client.go -destination=client_mock.go -package=http
//go:generate go run go.uber.org/mock/mockgen -source=client.go -destination=client_mock.go -package=http
type Client[R interface{}] interface {
Send(request Request) (Result[R], error)
Do(req *http.Request) (*http.Response, error)
+1 -1
View File
@@ -5,9 +5,9 @@ import (
"net/http"
"net/http/httptest"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("Client", Ordered, func() {
+1 -1
View File
@@ -2,7 +2,7 @@ package http
import "net/http"
//go:generate go run github.com/golang/mock/mockgen -source=cookiejar.go -destination=cookiejar_mock.go -package=http
//go:generate go run go.uber.org/mock/mockgen -source=cookiejar.go -destination=cookiejar_mock.go -package=http
type CookieJar interface {
http.CookieJar
+1 -1
View File
@@ -1,6 +1,6 @@
package keychain
//go:generate go run github.com/golang/mock/mockgen -source=keychain.go -destination=keychain_mock.go -package keychain
//go:generate go run go.uber.org/mock/mockgen -source=keychain.go -destination=keychain_mock.go -package keychain
type Keychain interface {
Get(key string) ([]byte, error)
Set(key string, data []byte) error
+1 -1
View File
@@ -4,9 +4,9 @@ import (
"errors"
"github.com/99designs/keyring"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("Keychain (Get)", func() {
+1 -1
View File
@@ -3,9 +3,9 @@ package keychain
import (
"errors"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("Keychain (Remove)", func() {
+1 -1
View File
@@ -4,9 +4,9 @@ import (
"errors"
"github.com/99designs/keyring"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("Keychain (Set)", func() {
+1 -1
View File
@@ -2,7 +2,7 @@ package keychain
import "github.com/99designs/keyring"
//go:generate go run github.com/golang/mock/mockgen -source=keyring.go -destination=keyring_mock.go -package keychain
//go:generate go run go.uber.org/mock/mockgen -source=keyring.go -destination=keyring_mock.go -package keychain
type Keyring interface {
Get(key string) (keyring.Item, error)
Set(item keyring.Item) error
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/pkgerrors"
)
//go:generate go run github.com/golang/mock/mockgen -source=logger.go -destination=logger_mock.go -package log
//go:generate go run go.uber.org/mock/mockgen -source=logger.go -destination=logger_mock.go -package log
type Logger interface {
Verbose() *zerolog.Event
Log() *zerolog.Event
+1 -1
View File
@@ -4,8 +4,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/golang/mock/gomock"
"github.com/rs/zerolog"
"go.uber.org/mock/gomock"
)
var _ = Describe("Logger", func() {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog"
)
//go:generate go run github.com/golang/mock/mockgen -source=writer.go -destination=writer_mock.go -package log
//go:generate go run go.uber.org/mock/mockgen -source=writer.go -destination=writer_mock.go -package log
type Writer interface {
Write(p []byte) (n int, err error)
WriteLevel(level zerolog.Level, p []byte) (n int, err error)
+1 -1
View File
@@ -1,10 +1,10 @@
package log
import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rs/zerolog"
"go.uber.org/mock/gomock"
)
var _ = Describe("Writer", func() {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"golang.org/x/term"
)
//go:generate go run github.com/golang/mock/mockgen -source=machine.go -destination=machine_mock.go -package machine
//go:generate go run go.uber.org/mock/mockgen -source=machine.go -destination=machine_mock.go -package machine
type Machine interface {
MacAddress() (string, error)
HomeDirectory() string
+1 -1
View File
@@ -4,10 +4,10 @@ import (
"syscall"
"testing"
"github.com/golang/mock/gomock"
"github.com/majd/ipatool/v2/pkg/util/operatingsystem"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
func TestMachine(t *testing.T) {
+14 -38
View File
@@ -1,11 +1,10 @@
package operatingsystem
import (
"fmt"
"os"
)
//go:generate go run github.com/golang/mock/mockgen -source=operatingsystem.go -destination=operatingsystem_mock.go -package operatingsystem
//go:generate go run go.uber.org/mock/mockgen -source=operatingsystem.go -destination=operatingsystem_mock.go -package operatingsystem
type OperatingSystem interface {
Getenv(key string) string
Stat(name string) (os.FileInfo, error)
@@ -27,60 +26,37 @@ func (operatingSystem) Getenv(key string) string {
return os.Getenv(key)
}
// nolint:wrapcheck
func (operatingSystem) Stat(name string) (os.FileInfo, error) {
info, err := os.Stat(name)
if err != nil {
return nil, fmt.Errorf("failed to describe file '%s': %w", name, err)
}
return info, nil
return os.Stat(name)
}
// nolint:wrapcheck
func (operatingSystem) Getwd() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get current directory: %w", err)
}
return wd, nil
return os.Getwd()
}
// nolint:wrapcheck
func (operatingSystem) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
file, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, fmt.Errorf("failed to open file '%s': %w", name, err)
}
return file, nil
return os.OpenFile(name, flag, perm)
}
// nolint:wrapcheck
func (operatingSystem) Remove(name string) error {
err := os.Remove(name)
if err != nil {
return fmt.Errorf("failed to remove file '%s': %w", name, err)
}
return nil
return os.Remove(name)
}
// nolint:wrapcheck
func (operatingSystem) IsNotExist(err error) bool {
return os.IsNotExist(err)
}
// nolint:wrapcheck
func (operatingSystem) MkdirAll(path string, perm os.FileMode) error {
err := os.MkdirAll(path, perm)
if err != nil {
return fmt.Errorf("failed to create directory '%s': %w", path, err)
}
return nil
return os.MkdirAll(path, perm)
}
// nolint:wrapcheck
func (operatingSystem) Rename(oldPath, newPath string) error {
err := os.Rename(oldPath, newPath)
if err != nil {
return fmt.Errorf("failed to rename '%s' to '%s': %w", oldPath, newPath, err)
}
return nil
return os.Rename(oldPath, newPath)
}
@@ -1,7 +1,6 @@
package operatingsystem
import (
"errors"
"fmt"
"io/fs"
"math/rand"
@@ -70,7 +69,7 @@ var _ = Describe("OperatingSystem", func() {
Expect(err).ToNot(HaveOccurred())
_, err = sut.Stat(file.Name())
Expect(os.IsNotExist(errors.Unwrap(err))).To(BeTrue())
Expect(os.IsNotExist(err)).To(BeTrue())
})
It("renames file", func() {
+7
View File
@@ -0,0 +1,7 @@
//go:build tools
package main
import (
_ "go.uber.org/mock/mockgen"
)