As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit f1ee9c79 authored by Igor Drozdov's avatar Igor Drozdov Committed by Nick Thomas
Browse files

Read limited input for yes answer

parent 3f9890ef
No related branches found
No related tags found
No related merge requests found
v13.13.1
- Read limited input when asking to generate new two-factor recovery codes
v13.13.0
- GitLab API Client support for client certificates !432
Loading
Loading
13.13.0
13.13.1
Loading
Loading
@@ -3,6 +3,7 @@ package twofactorrecover
import (
"context"
"fmt"
"io"
"strings"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
Loading
Loading
@@ -11,6 +12,8 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/twofactorrecover"
)
const readerLimit = 1024
type Command struct {
Config *config.Config
Args *commandargs.Shell
Loading
Loading
@@ -34,7 +37,7 @@ func (c *Command) canContinue() bool {
fmt.Fprintln(c.ReadWriter.Out, question)
var answer string
fmt.Fscanln(c.ReadWriter.In, &answer)
fmt.Fscanln(io.LimitReader(c.ReadWriter.In, readerLimit), &answer)
return answer == "yes"
}
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/require"
Loading
Loading
@@ -114,6 +115,13 @@ func TestExecute(t *testing.T) {
expectedOutput: question +
"New recovery codes have *not* been generated. Existing codes will remain valid.\n",
},
{
desc: "With some other answer",
arguments: &commandargs.Shell{},
answer: strings.Repeat("yes, but not really\n", 2048),
expectedOutput: question +
"New recovery codes have *not* been generated. Existing codes will remain valid.\n",
},
}
for _, tc := range testCases {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment