forked from Silverfish/proton-bridge
fix(BRIDGE-7): modify keychain test on macOS.
This commit is contained in:
@ -43,7 +43,7 @@ import (
|
|||||||
|
|
||||||
// nolint:gosec
|
// nolint:gosec
|
||||||
func migrateKeychainHelper(locations *locations.Locations) error {
|
func migrateKeychainHelper(locations *locations.Locations) error {
|
||||||
logrus.Info("Migrating keychain helper")
|
logrus.Trace("Checking if keychain helper needs to be migrated")
|
||||||
|
|
||||||
settings, err := locations.ProvideSettingsPath()
|
settings, err := locations.ProvideSettingsPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -75,7 +75,11 @@ func migrateKeychainHelper(locations *locations.Locations) error {
|
|||||||
return fmt.Errorf("failed to unmarshal old prefs file: %w", err)
|
return fmt.Errorf("failed to unmarshal old prefs file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return vault.SetHelper(settings, prefs.Helper)
|
err = vault.SetHelper(settings, prefs.Helper)
|
||||||
|
if err == nil {
|
||||||
|
logrus.Info("Keychain helper has been migrated")
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint:gosec
|
// nolint:gosec
|
||||||
|
|||||||
@ -22,9 +22,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||||
"github.com/docker/docker-credential-helpers/credentials"
|
"github.com/docker/docker-credential-helpers/credentials"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -216,10 +218,14 @@ func isUsable(helper credentials.Helper, err error) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := &credentials.Credentials{
|
creds := getTestCredentials()
|
||||||
ServerURL: "bridge/check",
|
|
||||||
Username: "check",
|
// If the test entry is already present from an interrupted previous test, we must wipe it first.
|
||||||
Secret: "check",
|
if _, _, err := helper.Get(creds.ServerURL); err == nil {
|
||||||
|
if err := helper.Delete(creds.ServerURL); err != nil {
|
||||||
|
l.WithError(err).Warn("Failed to delete existing test credentials from keychain")
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := retry(func() error {
|
if err := retry(func() error {
|
||||||
@ -242,6 +248,23 @@ func isUsable(helper credentials.Helper, err error) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTestCredentials() *credentials.Credentials {
|
||||||
|
// On macOS, a handful of users experience failures of the test credentials.
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
return &credentials.Credentials{
|
||||||
|
ServerURL: hostURL(constants.KeyChainName) + "/check",
|
||||||
|
Username: "", // username is ignored on macOS, it's extracted from splitting the server URL
|
||||||
|
Secret: "check",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &credentials.Credentials{
|
||||||
|
ServerURL: "bridge/check",
|
||||||
|
Username: "check",
|
||||||
|
Secret: "check",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func retry(condition func() error) error {
|
func retry(condition func() error) error {
|
||||||
var maxRetry = 5
|
var maxRetry = 5
|
||||||
for r := 0; ; r++ {
|
for r := 0; ; r++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user