diff options
author | kmcknight <kmcknight@gitlab.com> | 2021-04-08 18:57:27 -0700 |
---|---|---|
committer | kmcknight <kmcknight@gitlab.com> | 2021-04-08 18:57:27 -0700 |
commit | 3ec31c34ae9c3fbf1dc70361ba25474bf3a30a62 (patch) | |
tree | 40397f0cc37969cb9de422eb38ca7c84174652f2 | |
parent | 6b6b6e0d9f491bded5b6e8f3caad5182fb3b2f9f (diff) | |
download | gitlab-shell-3ec31c34ae9c3fbf1dc70361ba25474bf3a30a62.tar.gz |
Fix test race condition
-rw-r--r-- | internal/command/twofactorverify/twofactorverify.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/internal/command/twofactorverify/twofactorverify.go b/internal/command/twofactorverify/twofactorverify.go index c6fd14a..9f11895 100644 --- a/internal/command/twofactorverify/twofactorverify.go +++ b/internal/command/twofactorverify/twofactorverify.go @@ -13,6 +13,7 @@ import ( type Command struct { Config *config.Config + Client *twofactorverify.Client Args *commandargs.Shell ReadWriter *readwriter.ReadWriter } @@ -24,6 +25,14 @@ type Result struct { } func (c *Command) Execute(ctx context.Context) error { + // config.GetHTTPClient isn't thread-safe so save Client in struct for concurrency + // workaround until #518 is fixed + var err error + c.Client, err = twofactorverify.NewClient(c.Config) + if err != nil { + return err + } + verify := make(chan Result) pushauth := make(chan Result) @@ -71,14 +80,9 @@ func (c *Command) getOTP() string { } func (c *Command) pushAuth(ctx context.Context) (status string, success bool, err error) { - client, err := twofactorverify.NewClient(c.Config) - if err != nil { - return "", false, err - } - reason := "" - success, reason, err = client.PushAuth(ctx, c.Args) + success, reason, err = c.Client.PushAuth(ctx, c.Args) if success { status = fmt.Sprintf("\nPush OTP validation successful. Git operations are now allowed.\n") } else { @@ -93,14 +97,9 @@ func (c *Command) pushAuth(ctx context.Context) (status string, success bool, er } func (c *Command) verifyOTP(ctx context.Context, otp string) (status string, success bool, err error) { - client, err := twofactorverify.NewClient(c.Config) - if err != nil { - return "", false, err - } - reason := "" - success, reason, err = client.VerifyOTP(ctx, c.Args, otp) + success, reason, err = c.Client.VerifyOTP(ctx, c.Args, otp) if success { status = fmt.Sprintf("\nOTP validation successful. Git operations are now allowed.\n") } else { |