Skip to content

Commit 3f78f4d

Browse files
committed
feat(BRIDGE-281): disable keychain test on macOS.
1 parent 5fbe94c commit 3f78f4d

File tree

9 files changed

+25
-127
lines changed

9 files changed

+25
-127
lines changed

internal/app/app.go

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,21 @@ const (
9797
appShortName = "bridge"
9898
)
9999

100+
// the two flags below have been deprecated by BRIDGE-281. We however keep them so that bridge does not error if they are passed on startup.
100101
var cliFlagEnableKeychainTest = &cli.BoolFlag{ //nolint:gochecknoglobals
101102
Name: flagEnableKeychainTest,
102-
Usage: "Enable the keychain test for the current and future executions of the application",
103+
Usage: "This flag is deprecated and does nothing",
103104
Value: false,
104105
DisableDefaultText: true,
105-
} //nolint:gochecknoglobals
106+
Hidden: true,
107+
}
106108

107109
var cliFlagDisableKeychainTest = &cli.BoolFlag{ //nolint:gochecknoglobals
108110
Name: flagDisableKeychainTest,
109-
Usage: "Disable the keychain test for the current and future executions of the application",
111+
Usage: "This flag is deprecated and does nothing",
110112
Value: false,
111113
DisableDefaultText: true,
114+
Hidden: true,
112115
}
113116

114117
func New() *cli.App {
@@ -212,6 +215,7 @@ func New() *cli.App {
212215

213216
if onMacOS() {
214217
// The two flags below were introduced for BRIDGE-116, and are available only on macOS.
218+
// They have been later removed fro BRIDGE-281.
215219
app.Flags = append(app.Flags, cliFlagEnableKeychainTest, cliFlagDisableKeychainTest)
216220
}
217221

@@ -283,8 +287,7 @@ func run(c *cli.Context) error {
283287

284288
return withSingleInstance(settings, locations.GetLockFile(), version, func() error {
285289
// Look for available keychains
286-
skipKeychainTest := checkSkipKeychainTest(c, settings)
287-
return WithKeychainList(crashHandler, skipKeychainTest, func(keychains *keychain.List) error {
290+
return WithKeychainList(crashHandler, func(keychains *keychain.List) error {
288291
// Unlock the encrypted vault.
289292
return WithVault(reporter, locations, keychains, crashHandler, func(v *vault.Vault, insecure, corrupt bool) error {
290293
if !v.Migrated() {
@@ -548,11 +551,11 @@ func withCookieJar(vault *vault.Vault, fn func(http.CookieJar) error) error {
548551
}
549552

550553
// WithKeychainList init the list of usable keychains.
551-
func WithKeychainList(panicHandler async.PanicHandler, skipKeychainTest bool, fn func(*keychain.List) error) error {
554+
func WithKeychainList(panicHandler async.PanicHandler, fn func(*keychain.List) error) error {
552555
logrus.Debug("Creating keychain list")
553556
defer logrus.Debug("Keychain list stop")
554557
defer async.HandlePanic(panicHandler)
555-
return fn(keychain.NewList(skipKeychainTest))
558+
return fn(keychain.NewList())
556559
}
557560

558561
func setDeviceCookies(jar *cookies.Jar) error {
@@ -573,38 +576,6 @@ func setDeviceCookies(jar *cookies.Jar) error {
573576
return nil
574577
}
575578

576-
func checkSkipKeychainTest(c *cli.Context, settingsDir string) bool {
577-
if !onMacOS() {
578-
return false
579-
}
580-
581-
enable := c.Bool(flagEnableKeychainTest)
582-
disable := c.Bool(flagDisableKeychainTest)
583-
584-
skip, err := vault.GetShouldSkipKeychainTest(settingsDir)
585-
if err != nil {
586-
logrus.WithError(err).Error("Could not load keychain settings.")
587-
}
588-
589-
if (!enable) && (!disable) {
590-
return skip
591-
}
592-
593-
// if both switches are passed, 'enable' has priority
594-
if disable {
595-
skip = true
596-
}
597-
if enable {
598-
skip = false
599-
}
600-
601-
if err := vault.SetShouldSkipKeychainTest(settingsDir, skip); err != nil {
602-
logrus.WithError(err).Error("Could not save keychain settings.")
603-
}
604-
605-
return skip
606-
}
607-
608579
func onMacOS() bool {
609580
return runtime.GOOS == "darwin"
610581
}

internal/app/app_test.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

pkg/keychain/helper_darwin.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,12 @@ const (
3131
MacOSKeychain = "macos-keychain"
3232
)
3333

34-
func listHelpers(skipKeychainTest bool) (Helpers, string) {
34+
func listHelpers() (Helpers, string) {
3535
helpers := make(Helpers)
3636

3737
// MacOS always provides a keychain.
38-
if skipKeychainTest {
39-
logrus.WithField("pkg", "keychain").Info("Skipping macOS keychain test")
40-
helpers[MacOSKeychain] = newMacOSHelper
41-
} else {
42-
if isUsable(newMacOSHelper("")) {
43-
helpers[MacOSKeychain] = newMacOSHelper
44-
logrus.WithField("keychain", "MacOSKeychain").Info("Keychain is usable.")
45-
} else {
46-
logrus.WithField("keychain", "MacOSKeychain").Debug("Keychain is not available.")
47-
}
48-
}
38+
logrus.WithField("pkg", "keychain").Info("Skipping macOS keychain test")
39+
helpers[MacOSKeychain] = newMacOSHelper
4940

5041
// Use MacOSKeychain by default.
5142
return helpers, MacOSKeychain

pkg/keychain/helper_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
SecretServiceDBus = "secret-service-dbus"
3232
)
3333

34-
func listHelpers(_ bool) (Helpers, string) {
34+
func listHelpers() (Helpers, string) {
3535
helpers := make(Helpers)
3636

3737
if isUsable(newDBusHelper("")) {

pkg/keychain/helper_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
const WindowsCredentials = "windows-credentials"
2727

28-
func listHelpers(_ bool) (Helpers, string) {
28+
func listHelpers() (Helpers, string) {
2929
helpers := make(Helpers)
3030
// Windows always provides a keychain.
3131
if isUsable(newWinCredHelper("")) {

pkg/keychain/keychain.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ type List struct {
6262
// NewList checks availability of every keychains detected on the User Operating System
6363
// This will ask the user to unlock keychain(s) to check their usability.
6464
// This should only be called once.
65-
func NewList(skipKeychainTest bool) *List {
65+
func NewList() *List {
6666
var list = List{locker: &sync.Mutex{}}
67-
list.helpers, list.defaultHelper = listHelpers(skipKeychainTest)
67+
list.helpers, list.defaultHelper = listHelpers()
6868
return &list
6969
}
7070

@@ -210,7 +210,7 @@ func (kc *Keychain) secretURL(userID string) string {
210210
}
211211

212212
// isUsable returns whether the credentials helper is usable.
213-
func isUsable(helper credentials.Helper, err error) bool {
213+
func isUsable(helper credentials.Helper, err error) bool { //nolint:unused
214214
l := logrus.WithField("helper", reflect.TypeOf(helper))
215215

216216
if err != nil {
@@ -240,7 +240,7 @@ func isUsable(helper credentials.Helper, err error) bool {
240240
return true
241241
}
242242

243-
func getTestCredentials() *credentials.Credentials {
243+
func getTestCredentials() *credentials.Credentials { //nolint:unused
244244
// On macOS, a handful of users experience failures of the test credentials.
245245
if runtime.GOOS == "darwin" {
246246
return &credentials.Credentials{
@@ -257,7 +257,7 @@ func getTestCredentials() *credentials.Credentials {
257257
}
258258
}
259259

260-
func retry(condition func() error) error {
260+
func retry(condition func() error) error { //nolint:unused
261261
var maxRetry = 5
262262
for r := 0; ; r++ {
263263
err := condition()

pkg/keychain/keychain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestInsertReadRemove(t *testing.T) {
117117

118118
func TestIsErrKeychainNoItem(t *testing.T) {
119119
r := require.New(t)
120-
helpers := NewList(false).GetHelpers()
120+
helpers := NewList().GetHelpers()
121121

122122
for helperName := range helpers {
123123
kc, err := NewKeychain(helperName, "bridge-test", helpers, helperName)

utils/bridge-rollout/bridge-rollout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func main() {
6161

6262
func getRollout(_ *cli.Context) error {
6363
return app.WithLocations(func(locations *locations.Locations) error {
64-
return app.WithKeychainList(async.NoopPanicHandler{}, false, func(keychains *keychain.List) error {
64+
return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
6565
return app.WithVault(nil, locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, _, _ bool) error {
6666
fmt.Println(vault.GetUpdateRollout())
6767
return nil
@@ -72,7 +72,7 @@ func getRollout(_ *cli.Context) error {
7272

7373
func setRollout(c *cli.Context) error {
7474
return app.WithLocations(func(locations *locations.Locations) error {
75-
return app.WithKeychainList(async.NoopPanicHandler{}, false, func(keychains *keychain.List) error {
75+
return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
7676
return app.WithVault(nil, locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, _, _ bool) error {
7777
clamped := max(0.0, min(1.0, c.Float64("value")))
7878
if err := vault.SetUpdateRollout(clamped); err != nil {

utils/vault-editor/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func main() {
5151

5252
func readAction(c *cli.Context) error {
5353
return app.WithLocations(func(locations *locations.Locations) error {
54-
return app.WithKeychainList(async.NoopPanicHandler{}, false, func(keychains *keychain.List) error {
54+
return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
5555
return app.WithVault(nil, locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error {
5656
if _, err := os.Stdout.Write(vault.ExportJSON()); err != nil {
5757
return fmt.Errorf("failed to write vault: %w", err)
@@ -65,7 +65,7 @@ func readAction(c *cli.Context) error {
6565

6666
func writeAction(c *cli.Context) error {
6767
return app.WithLocations(func(locations *locations.Locations) error {
68-
return app.WithKeychainList(async.NoopPanicHandler{}, false, func(keychains *keychain.List) error {
68+
return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error {
6969
return app.WithVault(nil, locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error {
7070
b, err := io.ReadAll(os.Stdin)
7171
if err != nil {

0 commit comments

Comments
 (0)